1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-13 05:19:59 +00:00

Register our block entities with DFU

This ensures that data fixers will be applied to items in these
inventories.
This commit is contained in:
Jonathan Coates 2024-03-22 21:47:11 +00:00
parent 0a9e5c78f3
commit 7b9a156abc
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
5 changed files with 71 additions and 0 deletions

View File

@ -36,6 +36,7 @@ dependencies {
implementation(commonClasses(project(":common-api")))
clientImplementation(clientClasses(project(":common-api")))
compileOnly(libs.mixin)
compileOnly(libs.bundles.externalMods.common)
clientCompileOnly(variantOf(libs.emi) { classifier("api") })

View File

@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
//
// SPDX-License-Identifier: MPL-2.0
package dan200.computercraft.mixin;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.templates.TypeTemplate;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.peripheral.diskdrive.DiskDriveBlockEntity;
import dan200.computercraft.shared.peripheral.printer.PrinterBlockEntity;
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity;
import net.minecraft.util.datafix.fixes.References;
import net.minecraft.util.datafix.schemas.V1460;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Map;
import java.util.function.Supplier;
/**
* Register our item-contianing block entities.
*
* @see DiskDriveBlockEntity
* @see PrinterBlockEntity
* @see TurtleBlockEntity
*/
@Mixin(V1460.class)
class V1460Mixin {
@Inject(at = @At("RETURN"), method = "registerBlockEntities")
@SuppressWarnings("UnusedMethod")
private void registerBlockEntities(Schema schema, CallbackInfoReturnable<Map<String, Supplier<TypeTemplate>>> ci) {
var map = ci.getReturnValue();
// Basic inventories
registerInventory(schema, map, ModRegistry.BlockEntities.TURTLE_NORMAL.id().toString());
registerInventory(schema, map, ModRegistry.BlockEntities.TURTLE_ADVANCED.id().toString());
registerInventory(schema, map, ModRegistry.BlockEntities.PRINTER.id().toString());
// Disk drives contain a single item
schema.register(map, ModRegistry.BlockEntities.DISK_DRIVE.id().toString(), () -> DSL.optionalFields(
"Item", References.ITEM_STACK.in(schema)
));
}
@Shadow
protected static void registerInventory(Schema schema, Map<String, Supplier<TypeTemplate>> map, String name) {
}
}

View File

@ -0,0 +1,13 @@
{
"required": true,
"package": "dan200.computercraft.mixin",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_17",
"injectors": {
"defaultRequire": 1
},
"mixins": [
"V1460Mixin"
],
"refmap": "computercraft.refmap.json"
}

View File

@ -37,6 +37,7 @@
]
},
"mixins": [
"computercraft.mixins.json",
"computercraft.fabric.mixins.json",
{
"config": "computercraft-client.fabric.mixins.json",

View File

@ -30,5 +30,8 @@ CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles a
ordering="NONE"
side="BOTH"
[[mixins]]
config = "computercraft.mixins.json"
[[mixins]]
config = "computercraft-client.forge.mixins.json"