Skip to content

Commit

Permalink
ref: update linkableapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeronimo97 committed Jul 28, 2024
1 parent e7f2638 commit 2a2aab3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

public class GIRCInit {

public static final DeferredRegister<Item> ITEM_REGISTRY = DeferredRegister
.create(ForgeRegistries.ITEMS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<Block> BLOCK_REGISTRY = DeferredRegister
.create(ForgeRegistries.BLOCKS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<BlockEntityType<?>> TILEENTITY_REGISTRY = DeferredRegister
.create(ForgeRegistries.BLOCK_ENTITY_TYPES, GIRCRedstoneMain.MODID);
public static final DeferredRegister<Item> ITEM_REGISTRY =
DeferredRegister.create(ForgeRegistries.ITEMS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<Block> BLOCK_REGISTRY =
DeferredRegister.create(ForgeRegistries.BLOCKS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<BlockEntityType<?>> TILEENTITY_REGISTRY =
DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, GIRCRedstoneMain.MODID);

public static final RegistryObject<Block> RS_ACCEPTOR = internalRegisterBlock("acceptor",
() -> new BlockRedstoneAcceptor(BlockBehaviour.Properties.of(Material.METAL)
Expand All @@ -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<Item> RS_LINKER = ITEM_REGISTRY.register("linker",
() -> new Linkingtool(null, GIRCInit::acceptAcceptor));
public static final RegistryObject<Item> RS_LINKER =
ITEM_REGISTRY.register("linker", () -> new Linkingtool(null, GIRCInit::acceptAcceptor));
public static final RegistryObject<Item> RS_MULTILINKER = ITEM_REGISTRY.register("multilinker",
() -> new MultiLinkingTool(null, GIRCInit::acceptAcceptor));
public static final RegistryObject<Item> REMOTE_ACTIVATOR = ITEM_REGISTRY.register("activator",
() -> new RemoteActivator());
() -> new RemoteActivator(null, GIRCInit::acceptAcceptor));

public static final RegistryObject<BlockEntityType<?>> EMITER_TILE = TILEENTITY_REGISTRY
.register("emitter", () -> BlockEntityType.Builder
public static final RegistryObject<BlockEntityType<?>> EMITER_TILE =
TILEENTITY_REGISTRY.register("emitter", () -> BlockEntityType.Builder
.of(TileRedstoneEmitter::new, RS_EMITTER.get()).build(null));

public static final RegistryObject<BlockEntityType<?>> MULTI_EMITER_TILE = TILEENTITY_REGISTRY
.register("multiemitter", () -> BlockEntityType.Builder
public static final RegistryObject<BlockEntityType<?>> MULTI_EMITER_TILE =
TILEENTITY_REGISTRY.register("multiemitter", () -> BlockEntityType.Builder
.of(TileRedstoneMultiEmitter::new, RS_MULTI_EMITTER.get()).build(null));

private static final RegistryObject<Block> internalRegisterBlock(final String name,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Level, BlockPos> predicate) {
super(tab, predicate, _u -> false);
}

@Override
public InteractionResultHolder<ItemStack> 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);
}

Expand Down

0 comments on commit 2a2aab3

Please sign in to comment.