Skip to content

Commit

Permalink
ref: update linkableapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeronimo97 committed Aug 6, 2024
1 parent c86e970 commit d191820
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 56 deletions.
88 changes: 49 additions & 39 deletions src/main/java/com/troblecodings/tcredstone/init/TCInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,61 @@

public class TCInit {

public static final Item RS_LINKER = registerItem("linker", new Linkingtool(null, TCInit::acceptAcceptor),
ItemGroups.REDSTONE);
public static final Item RS_MULTILINKER = registerItem("multilinker",
new MultiLinkingTool(null, TCInit::acceptAcceptor), ItemGroups.REDSTONE);
public static final Item REMOTE_ACTIVATOR = registerItem("activator", new RemoteActivator(), ItemGroups.REDSTONE);
public static final Item RS_LINKER = registerItem("linker",
new Linkingtool(null, TCInit::acceptAcceptor), ItemGroups.REDSTONE);
public static final Item RS_MULTILINKER = registerItem("multilinker",
new MultiLinkingTool(null, TCInit::acceptAcceptor), ItemGroups.REDSTONE);
public static final Item REMOTE_ACTIVATOR = registerItem("activator",
new RemoteActivator(TCInit::acceptAcceptor), ItemGroups.REDSTONE);

@SuppressWarnings("deprecation")
public static final Block RS_ACCEPTOR = registerBlock("acceptor",
new BlockRedstoneAcceptor(FabricBlockSettings.of().strength(1.5f, 6.0f)), ItemGroups.REDSTONE);
@SuppressWarnings("deprecation")
public static final Block RS_EMITTER = registerBlock("emitter",
new BlockRedstoneEmitter(FabricBlockSettings.of().strength(1.5f, 6.0f)), ItemGroups.REDSTONE);
@SuppressWarnings("deprecation")
public static final Block RS_MULTI_EMITTER = registerBlock("multiemitter",
new BlockRedstoneMultiEmitter(FabricBlockSettings.of().strength(1.5f, 6.0f)), ItemGroups.REDSTONE);
@SuppressWarnings("deprecation")
public static final Block RS_ACCEPTOR = registerBlock("acceptor",
new BlockRedstoneAcceptor(FabricBlockSettings.of().strength(1.5f, 6.0f)),
ItemGroups.REDSTONE);
@SuppressWarnings("deprecation")
public static final Block RS_EMITTER = registerBlock("emitter",
new BlockRedstoneEmitter(FabricBlockSettings.of().strength(1.5f, 6.0f)),
ItemGroups.REDSTONE);
@SuppressWarnings("deprecation")
public static final Block RS_MULTI_EMITTER = registerBlock("multiemitter",
new BlockRedstoneMultiEmitter(FabricBlockSettings.of().strength(1.5f, 6.0f)),
ItemGroups.REDSTONE);

public static final BlockEntityType<TileRedstoneEmitter> EMITER_TILE = Registry.register(
Registries.BLOCK_ENTITY_TYPE, new Identifier(TCRedstoneMain.MODID, "emitter"),
FabricBlockEntityTypeBuilder.create(TileRedstoneEmitter::new, RS_EMITTER).build());
public static final BlockEntityType<TileRedstoneMultiEmitter> MULTI_EMITER_TILE = Registry.register(
Registries.BLOCK_ENTITY_TYPE, new Identifier(TCRedstoneMain.MODID, "multiemitter"),
FabricBlockEntityTypeBuilder.create(TileRedstoneMultiEmitter::new, RS_MULTI_EMITTER).build());
public static final BlockEntityType<TileRedstoneEmitter> EMITER_TILE = Registry.register(
Registries.BLOCK_ENTITY_TYPE, new Identifier(TCRedstoneMain.MODID, "emitter"),
FabricBlockEntityTypeBuilder.create(TileRedstoneEmitter::new, RS_EMITTER).build());
public static final BlockEntityType<TileRedstoneMultiEmitter> MULTI_EMITER_TILE =
Registry.register(Registries.BLOCK_ENTITY_TYPE,
new Identifier(TCRedstoneMain.MODID, "multiemitter"),
FabricBlockEntityTypeBuilder
.create(TileRedstoneMultiEmitter::new, RS_MULTI_EMITTER).build());

public static boolean acceptAcceptor(final World level, final BlockPos pos) {
return level.getBlockState(pos).getBlock() instanceof BlockRedstoneAcceptor;
}
public static boolean acceptAcceptor(final World level, final BlockPos pos) {
return level.getBlockState(pos).getBlock() instanceof BlockRedstoneAcceptor;
}

private static Block registerBlock(String name, Block block, RegistryKey<ItemGroup> group) {
registerBlockItem(name, block, group);
return Registry.register(Registries.BLOCK, new Identifier(TCRedstoneMain.MODID, name), block);
}
private static Block registerBlock(final String name, final Block block,
final RegistryKey<ItemGroup> group) {
registerBlockItem(name, block, group);
return Registry.register(Registries.BLOCK, new Identifier(TCRedstoneMain.MODID, name),
block);
}

private static Item registerBlockItem(String name, Block block, RegistryKey<ItemGroup> group) {
Item item = Registry.register(Registries.ITEM, new Identifier(TCRedstoneMain.MODID, name),
new BlockItem(block, new FabricItemSettings()));
ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item));
return item;
}
private static Item registerBlockItem(final String name, final Block block,
final RegistryKey<ItemGroup> group) {
Item item = Registry.register(Registries.ITEM, new Identifier(TCRedstoneMain.MODID, name),
new BlockItem(block, new FabricItemSettings()));
ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item));
return item;
}

private static Item registerItem(String name, Item item, RegistryKey<ItemGroup> group) {
ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item));
return Registry.register(Registries.ITEM, new Identifier(TCRedstoneMain.MODID, name), item);
}
private static Item registerItem(final String name, final Item item,
final RegistryKey<ItemGroup> group) {
ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item));
return Registry.register(Registries.ITEM, new Identifier(TCRedstoneMain.MODID, name), item);
}

public static void init() {
}
public static void init() {
}

}
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.TCInit;
import com.troblecodings.tcredstone.tile.TileRedstoneEmitter;

import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -15,20 +16,28 @@

public class RemoteActivator extends Linkingtool {

public RemoteActivator() {
super(null, TCInit::acceptAcceptor, _u1 -> false);
}

@Override
public TypedActionResult<ItemStack> use(final World level, final PlayerEntity player, final Hand hand) {
final ItemStack itemstack = player.getStackInHand(hand);
if (!hand.equals(Hand.MAIN_HAND) || level.isClient())
return TypedActionResult.pass(itemstack);
final NbtCompound comp = itemstack.getNbt();
final BlockPos linkpos = NbtHelper.toBlockPos(comp);
final boolean state = TileRedstoneEmitter.redstoneUpdate(linkpos, level);
message(player, "ra.state", String.valueOf(state));
return TypedActionResult.success(itemstack);
}
public RemoteActivator(final BiPredicate<World, BlockPos> predicate) {
super(null, predicate, _u1 -> false);
}

@Override
public TypedActionResult<ItemStack> use(final World level, final PlayerEntity player,
final Hand hand) {
final ItemStack itemstack = player.getStackInHand(hand);
final NbtCompound tag = itemstack.getOrCreateNbt();
if (tag.contains(LINKINGTOOL_TAG)) {
if (!hand.equals(Hand.MAIN_HAND) || level.isClient())
return TypedActionResult.pass(itemstack);
final NbtCompound comp = tag.getCompound(LINKINGTOOL_TAG);
final boolean containsPos =
comp.contains("X") && comp.contains("Y") && comp.contains("Z");
if (containsPos) {
final BlockPos linkpos = NbtHelper.toBlockPos(comp);
final boolean state = TileRedstoneEmitter.redstoneUpdate(linkpos, level);
message(player, "ra.state", String.valueOf(state));
return TypedActionResult.success(itemstack);
}
}
return TypedActionResult.success(itemstack);
}
}

0 comments on commit d191820

Please sign in to comment.