mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-14 05:44:52 +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:
parent
0a9e5c78f3
commit
7b9a156abc
@ -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") })
|
||||
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
13
projects/common/src/main/resources/computercraft.mixins.json
Normal file
13
projects/common/src/main/resources/computercraft.mixins.json
Normal 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"
|
||||
}
|
@ -37,6 +37,7 @@
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"computercraft.mixins.json",
|
||||
"computercraft.fabric.mixins.json",
|
||||
{
|
||||
"config": "computercraft-client.fabric.mixins.json",
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user