From 2a2aab3dc89b6348373c8ba7c5a7c4a84691a141 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 28 Jul 2024 15:09:09 +0200 Subject: [PATCH] ref: update linkableapi --- changelog.md | 5 ++++ linkableapi | 2 +- .../tcredstone/init/GIRCInit.java | 26 ++++++++--------- .../tcredstone/item/RemoteActivator.java | 29 +++++++++++++------ 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/changelog.md b/changelog.md index 728166c..deb066d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## [1.19.4 - 3.2.3] + +* feat: add item damage +* ref: update linkable api + ## [1.19.4 - 3.2.2] * rem: debug output diff --git a/linkableapi b/linkableapi index dc69c38..a82ad39 160000 --- a/linkableapi +++ b/linkableapi @@ -1 +1 @@ -Subproject commit dc69c387f1abc46f772e499743e361595f2ec127 +Subproject commit a82ad39cdc05bbb5f48e98ae73ac0888b3290c3a diff --git a/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java b/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java index 809b8c6..d31fbe4 100644 --- a/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java +++ b/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java @@ -32,12 +32,12 @@ public class GIRCInit { - public static final DeferredRegister ITEM_REGISTRY = DeferredRegister - .create(ForgeRegistries.ITEMS, GIRCRedstoneMain.MODID); - public static final DeferredRegister BLOCK_REGISTRY = DeferredRegister - .create(ForgeRegistries.BLOCKS, GIRCRedstoneMain.MODID); - public static final DeferredRegister> TILEENTITY_REGISTRY = DeferredRegister - .create(ForgeRegistries.BLOCK_ENTITY_TYPES, GIRCRedstoneMain.MODID); + public static final DeferredRegister ITEM_REGISTRY = + DeferredRegister.create(ForgeRegistries.ITEMS, GIRCRedstoneMain.MODID); + public static final DeferredRegister BLOCK_REGISTRY = + DeferredRegister.create(ForgeRegistries.BLOCKS, GIRCRedstoneMain.MODID); + public static final DeferredRegister> TILEENTITY_REGISTRY = + DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, GIRCRedstoneMain.MODID); public static final RegistryObject RS_ACCEPTOR = internalRegisterBlock("acceptor", () -> new BlockRedstoneAcceptor(BlockBehaviour.Properties.of(Material.METAL) @@ -53,19 +53,19 @@ public static boolean acceptAcceptor(final Level level, final BlockPos pos) { return level.getBlockState(pos).getBlock() instanceof BlockRedstoneAcceptor; } - public static final RegistryObject RS_LINKER = ITEM_REGISTRY.register("linker", - () -> new Linkingtool(null, GIRCInit::acceptAcceptor)); + public static final RegistryObject RS_LINKER = + ITEM_REGISTRY.register("linker", () -> new Linkingtool(null, GIRCInit::acceptAcceptor)); public static final RegistryObject RS_MULTILINKER = ITEM_REGISTRY.register("multilinker", () -> new MultiLinkingTool(null, GIRCInit::acceptAcceptor)); public static final RegistryObject REMOTE_ACTIVATOR = ITEM_REGISTRY.register("activator", - () -> new RemoteActivator()); + () -> new RemoteActivator(null, GIRCInit::acceptAcceptor)); - public static final RegistryObject> EMITER_TILE = TILEENTITY_REGISTRY - .register("emitter", () -> BlockEntityType.Builder + public static final RegistryObject> EMITER_TILE = + TILEENTITY_REGISTRY.register("emitter", () -> BlockEntityType.Builder .of(TileRedstoneEmitter::new, RS_EMITTER.get()).build(null)); - public static final RegistryObject> MULTI_EMITER_TILE = TILEENTITY_REGISTRY - .register("multiemitter", () -> BlockEntityType.Builder + public static final RegistryObject> MULTI_EMITER_TILE = + TILEENTITY_REGISTRY.register("multiemitter", () -> BlockEntityType.Builder .of(TileRedstoneMultiEmitter::new, RS_MULTI_EMITTER.get()).build(null)); private static final RegistryObject internalRegisterBlock(final String name, diff --git a/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java b/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java index 7136ca3..444775c 100644 --- a/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java +++ b/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java @@ -1,7 +1,8 @@ package com.troblecodings.tcredstone.item; +import java.util.function.BiPredicate; + import com.troblecodings.linkableapi.Linkingtool; -import com.troblecodings.tcredstone.init.GIRCInit; import com.troblecodings.tcredstone.tile.TileRedstoneEmitter; import net.minecraft.core.BlockPos; @@ -10,25 +11,35 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; public class RemoteActivator extends Linkingtool { - public RemoteActivator() { - super(null, GIRCInit::acceptAcceptor, _u1 -> false); + public RemoteActivator(final CreativeModeTab tab, + final BiPredicate predicate) { + super(tab, predicate, _u -> false); } @Override public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { final ItemStack itemstack = player.getItemInHand(hand); - if (!hand.equals(InteractionHand.MAIN_HAND) || level.isClientSide) - return InteractionResultHolder.pass(itemstack); - final CompoundTag comp = itemstack.getTag(); - final BlockPos linkpos = NbtUtils.readBlockPos(comp); - final boolean state = TileRedstoneEmitter.redstoneUpdate(linkpos, level); - message(player, "ra.state", String.valueOf(state)); + final CompoundTag tag = itemstack.getOrCreateTag(); + if (tag.contains(LINKINGTOOL_TAG)) { + if (!hand.equals(InteractionHand.MAIN_HAND) || level.isClientSide) + return InteractionResultHolder.pass(itemstack); + final CompoundTag comp = tag.getCompound(LINKINGTOOL_TAG); + final boolean containsPos = + comp.contains("X") && comp.contains("Y") && comp.contains("Z"); + if (containsPos) { + final BlockPos linkpos = NbtUtils.readBlockPos(comp); + final boolean state = TileRedstoneEmitter.redstoneUpdate(linkpos, level); + message(player, "ra.state", String.valueOf(state)); + return InteractionResultHolder.success(itemstack); + } + } return InteractionResultHolder.success(itemstack); }