From 727808adbc95f79a344a48d2904208c1a4ea1c87 Mon Sep 17 00:00:00 2001 From: GiantLuigi4 <49770992+GiantLuigi4@users.noreply.github.com> Date: Wed, 7 Jun 2023 15:51:40 -0400 Subject: [PATCH] deduplication --- .../montoyo/wd/block/BlockKeyboardLeft.java | 7 +- .../montoyo/wd/block/BlockKeyboardRight.java | 3 +- .../net/montoyo/wd/block/BlockPeripheral.java | 60 +------- .../java/net/montoyo/wd/block/BlockRCTRL.java | 145 ------------------ .../net/montoyo/wd/block/BlockRedCTRL.java | 145 ------------------ .../net/montoyo/wd/block/BlockScreen.java | 21 +-- .../net/montoyo/wd/block/BlockServer.java | 145 ------------------ .../java/net/montoyo/wd/block/WDBlock.java | 30 ---- .../montoyo/wd/core/DefaultPeripheral.java | 9 +- .../montoyo/wd/entity/TileEntityKeyboard.java | 6 - .../montoyo/wd/entity/TileEntityRCtrl.java | 8 - .../montoyo/wd/entity/TileEntityRedCtrl.java | 5 - .../java/net/montoyo/wd/init/BlockInit.java | 14 +- .../assets/webdisplays/blockstates/rctrl.json | 11 +- .../webdisplays/blockstates/redctrl.json | 11 +- .../webdisplays/blockstates/server.json | 11 +- 16 files changed, 35 insertions(+), 596 deletions(-) delete mode 100644 src/main/java/net/montoyo/wd/block/BlockRCTRL.java delete mode 100644 src/main/java/net/montoyo/wd/block/BlockRedCTRL.java delete mode 100644 src/main/java/net/montoyo/wd/block/BlockServer.java delete mode 100644 src/main/java/net/montoyo/wd/block/WDBlock.java diff --git a/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java b/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java index 6ba1b93..8981c39 100644 --- a/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java +++ b/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java @@ -50,6 +50,7 @@ public class BlockKeyboardLeft extends BlockPeripheral { private static final Property[] properties = new Property[] {TYPE, FACING}; public BlockKeyboardLeft() { + super(DefaultPeripheral.KEYBOARD); } // TODO: make non static (for extensibility purposes) @@ -63,7 +64,7 @@ public class BlockKeyboardLeft extends BlockPeripheral { BlockPos relative = pos.relative(BlockKeyboardLeft.mapDirection(state.getValue(FACING).getOpposite())); BlockState ns = world.getBlockState(relative); - if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) { + if(ns.getBlock() instanceof BlockPeripheral) { BlockEntity te = world.getBlockEntity(relative); // TODO: check? if (te instanceof TileEntityKeyboard) return (TileEntityKeyboard) te; @@ -150,10 +151,6 @@ public class BlockKeyboardLeft extends BlockPeripheral { super.onRemove(arg, arg2, arg3, arg4, bl); } - public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) { - return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension()); - } - @Override public VoxelShape getOcclusionShape(BlockState arg, BlockGetter arg2, BlockPos arg3) { return Shapes.empty(); diff --git a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java index 56b724e..faba084 100644 --- a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java +++ b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java @@ -33,6 +33,7 @@ import net.montoyo.wd.utilities.Vector3i; import org.jetbrains.annotations.NotNull; import static net.montoyo.wd.block.BlockKeyboardLeft.KEYBOARD_AABBS; +import static net.montoyo.wd.block.BlockPeripheral.point; // TODO: merge into KeyboardLeft public class BlockKeyboardRight extends Block implements IPeripheral { @@ -58,7 +59,7 @@ public class BlockKeyboardRight extends Block implements IPeripheral { if (setState) { world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); } - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> BlockKeyboardLeft.point(world, pos)), new S2CMessageCloseGui(pos)); + WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } @Override diff --git a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java index 30c344c..76a8a5e 100644 --- a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java +++ b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java @@ -5,11 +5,9 @@ package net.montoyo.wd.block; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -17,15 +15,11 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.phys.BlockHitResult; @@ -36,7 +30,6 @@ import net.minecraftforge.network.PacketDistributor; import net.montoyo.mcef.utilities.Log; import net.montoyo.wd.core.DefaultPeripheral; import net.montoyo.wd.entity.TileEntityInterfaceBase; -import net.montoyo.wd.entity.TileEntityKeyboard; import net.montoyo.wd.entity.TileEntityPeripheralBase; import net.montoyo.wd.entity.TileEntityServer; import net.montoyo.wd.item.ItemLinker; @@ -45,23 +38,17 @@ import net.montoyo.wd.net.client_bound.S2CMessageCloseGui; import org.jetbrains.annotations.Nullable; public class BlockPeripheral extends WDBlockContainer { + DefaultPeripheral type; - public static final EnumProperty type = EnumProperty.create("type", DefaultPeripheral.class); - private static final Property[] properties = new Property[] { type }; - - public BlockPeripheral() { + public BlockPeripheral(DefaultPeripheral type) { super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f)); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(properties); + this.type = type; } @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - BlockEntityType.BlockEntitySupplier cls = state.getValue(type).getTEClass(); + BlockEntityType.BlockEntitySupplier cls = type.getTEClass(); if(cls == null) return null; @@ -123,39 +110,16 @@ public class BlockPeripheral extends WDBlockContainer { return PushReaction.IGNORE; } - private void removeRightPiece(Level world, BlockPos pos) { - for(Direction nf: Direction.Plane.HORIZONTAL) { - BlockPos np = pos.offset(nf.getNormal()); - - if(world.getBlockState(np).getBlock() instanceof BlockKeyboardRight) { - world.setBlock(np, Blocks.AIR.defaultBlockState(), 3); - break; - } - } - } - @Override public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) { BlockEntity te = world.getBlockEntity(pos); - if(te != null && te instanceof TileEntityPeripheralBase) + if(te instanceof TileEntityPeripheralBase) ((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor); - - if(world.isClientSide || state.getValue(type) != DefaultPeripheral.KEYBOARD) - return; - - if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) { - removeRightPiece(world, pos); - world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); - } } @Override public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) { if(!world.isClientSide) { - if(state.getBlock() == this && state.getValue(type) == DefaultPeripheral.KEYBOARD) - removeRightPiece(world, pos); - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } super.playerDestroy(world, player, pos, state, blockEntity, tool); @@ -166,20 +130,6 @@ public class BlockPeripheral extends WDBlockContainer { playerDestroy(level, null, pos, level.getBlockState(pos), null, null); } - @Override - public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { - if(!world.isClientSide && world.getBlockState(pos).getValue(type) == DefaultPeripheral.KEYBOARD) { - double rpos = (entity.getY() - ((double) pos.getY())) * 16.0; - - if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) { - BlockEntity te = world.getBlockEntity(pos); - - if(te != null && te instanceof TileEntityKeyboard) - ((TileEntityKeyboard) te).simulateCat(entity); - } - } - } - public static PacketDistributor.TargetPoint point(Player exclude, Level world, BlockPos bp) { return new PacketDistributor.TargetPoint((ServerPlayer) exclude, bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension()); } diff --git a/src/main/java/net/montoyo/wd/block/BlockRCTRL.java b/src/main/java/net/montoyo/wd/block/BlockRCTRL.java deleted file mode 100644 index 617b22a..0000000 --- a/src/main/java/net/montoyo/wd/block/BlockRCTRL.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2019 BARBOTIN Nicolas - */ - -package net.montoyo.wd.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.level.block.state.properties.Property; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.PushReaction; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.network.PacketDistributor; -import net.montoyo.wd.core.DefaultPeripheral; -import net.montoyo.wd.entity.*; -import net.montoyo.wd.item.ItemLinker; -import net.montoyo.wd.net.WDNetworkRegistry; -import net.montoyo.wd.net.client_bound.S2CMessageCloseGui; -import org.jetbrains.annotations.Nullable; - -public class BlockRCTRL extends WDBlockContainer { - - public static final EnumProperty type = BlockPeripheral.type; - private static final Property[] properties = new Property[] {type}; - - public BlockRCTRL() { - super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f)); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(properties); - } - - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return new TileEntityRCtrl(pos, state); - } - - @Override - public RenderShape getRenderShape(BlockState state) { - return RenderShape.MODEL; - } - - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if(player.isShiftKeyDown()) - return InteractionResult.FAIL; - - if(player.getItemInHand(hand).getItem() instanceof ItemLinker) - return InteractionResult.FAIL; - - BlockEntity te = world.getBlockEntity(pos); - System.out.println(te); - if(te instanceof TileEntityRCtrl) - return ((TileEntityRCtrl) te).onRightClick(player, hand); - else if(te instanceof TileEntityServer) { - ((TileEntityServer) te).onPlayerRightClick(player); - return InteractionResult.PASS; - } else - return InteractionResult.FAIL; - } - - @Override - public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { - if(world.isClientSide) - return; - if(placer instanceof Player) { - BlockEntity te = world.getBlockEntity(pos); - - if(te instanceof TileEntityServer) - ((TileEntityServer) te).setOwner((Player) placer); - else if(te instanceof TileEntityInterfaceBase) - ((TileEntityInterfaceBase) te).setOwner((Player) placer); - } - } - - @Override - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.IGNORE; - } - - @Override - public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) { - BlockEntity te = world.getBlockEntity(pos); - if(te != null && te instanceof TileEntityPeripheralBase) - ((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor); - - if(world.isClientSide) - return; - - if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) { - world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); - } - } - - @Override - public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) { - if(!world.isClientSide) { - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); - } - super.playerDestroy(world, player, pos, state, blockEntity, tool); - } - - @Override - public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) { - playerDestroy(level, null, pos, level.getBlockState(pos), null, null); - } - - @Override - public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { - if(!world.isClientSide) { - double rpos = (entity.getY() - ((double) pos.getY())) * 16.0; - - if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) { - BlockEntity te = world.getBlockEntity(pos); - - if(te != null && te instanceof TileEntityKeyboard) - ((TileEntityKeyboard) te).simulateCat(entity); - } - } - } - - public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) { - return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension()); - } - -} diff --git a/src/main/java/net/montoyo/wd/block/BlockRedCTRL.java b/src/main/java/net/montoyo/wd/block/BlockRedCTRL.java deleted file mode 100644 index 3b57af3..0000000 --- a/src/main/java/net/montoyo/wd/block/BlockRedCTRL.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2019 BARBOTIN Nicolas - */ - -package net.montoyo.wd.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.level.block.state.properties.Property; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.PushReaction; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.network.PacketDistributor; -import net.montoyo.wd.core.DefaultPeripheral; -import net.montoyo.wd.entity.*; -import net.montoyo.wd.item.ItemLinker; -import net.montoyo.wd.net.WDNetworkRegistry; -import net.montoyo.wd.net.client_bound.S2CMessageCloseGui; -import org.jetbrains.annotations.Nullable; - -public class BlockRedCTRL extends WDBlockContainer { - - public static final EnumProperty type = BlockPeripheral.type; - private static final Property[] properties = new Property[] {type}; - - public BlockRedCTRL() { - super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f)); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(properties); - } - - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return new TileEntityRedCtrl(pos, state); - } - - @Override - public RenderShape getRenderShape(BlockState state) { - return RenderShape.MODEL; - } - - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if(player.isShiftKeyDown()) - return InteractionResult.FAIL; - - if(player.getItemInHand(hand).getItem() instanceof ItemLinker) - return InteractionResult.FAIL; - - BlockEntity te = world.getBlockEntity(pos); - - if(te instanceof TileEntityRedCtrl) - return ((TileEntityRedCtrl) te).onRightClick(player, hand); - else if(te instanceof TileEntityServer) { - ((TileEntityServer) te).onPlayerRightClick(player); - return InteractionResult.PASS; - } else - return InteractionResult.FAIL; - } - - @Override - public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { - if(world.isClientSide) - return; - if(placer instanceof Player) { - BlockEntity te = world.getBlockEntity(pos); - - if(te instanceof TileEntityServer) - ((TileEntityServer) te).setOwner((Player) placer); - else if(te instanceof TileEntityInterfaceBase) - ((TileEntityInterfaceBase) te).setOwner((Player) placer); - } - } - - @Override - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.IGNORE; - } - - @Override - public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) { - BlockEntity te = world.getBlockEntity(pos); - if(te != null && te instanceof TileEntityPeripheralBase) - ((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor); - - if(world.isClientSide) - return; - - if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) { - world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); - } - } - - @Override - public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) { - if(!world.isClientSide) { - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); - } - super.playerDestroy(world, player, pos, state, blockEntity, tool); - } - - @Override - public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) { - playerDestroy(level, null, pos, level.getBlockState(pos), null, null); - } - - @Override - public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { - if(!world.isClientSide) { - double rpos = (entity.getY() - ((double) pos.getY())) * 16.0; - - if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) { - BlockEntity te = world.getBlockEntity(pos); - - if(te != null && te instanceof TileEntityKeyboard) - ((TileEntityKeyboard) te).simulateCat(entity); - } - } - } - - public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) { - return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension()); - } - -} diff --git a/src/main/java/net/montoyo/wd/block/BlockScreen.java b/src/main/java/net/montoyo/wd/block/BlockScreen.java index fac0299..b855586 100644 --- a/src/main/java/net/montoyo/wd/block/BlockScreen.java +++ b/src/main/java/net/montoyo/wd/block/BlockScreen.java @@ -12,7 +12,6 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; @@ -38,13 +37,9 @@ import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.init.BlockInit; import net.montoyo.wd.item.ItemLaserPointer; -import net.montoyo.wd.item.WDItem; import net.montoyo.wd.utilities.*; import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - public class BlockScreen extends BaseEntityBlock { public static final BooleanProperty hasTE = BooleanProperty.create("haste"); @@ -326,7 +321,7 @@ public class BlockScreen extends BaseEntityBlock { BlockPos bp = pos.toBlock(); BlockEntity te = world.getBlockEntity(bp); - if (te != null && te instanceof TileEntityScreen) { + if (te instanceof TileEntityScreen) { ((TileEntityScreen) te).onDestroy(source); world.setBlock(bp, world.getBlockState(bp).setValue(hasTE, false), Block.UPDATE_ALL_IMMEDIATE); //Destroy tile entity. } @@ -377,18 +372,4 @@ public class BlockScreen extends BaseEntityBlock { public boolean isSignalSource (BlockState state){ return state.getValue(emitting); } - - private static class ItemBlockScreen extends BlockItem implements WDItem { - - public ItemBlockScreen(BlockScreen screen) { - super(screen, new Properties()); - } - - @Nullable - @Override - public String getWikiName(@Nonnull ItemStack is) { - return is.getItem().getName(is).getString(); - } - - } } diff --git a/src/main/java/net/montoyo/wd/block/BlockServer.java b/src/main/java/net/montoyo/wd/block/BlockServer.java deleted file mode 100644 index 11e7400..0000000 --- a/src/main/java/net/montoyo/wd/block/BlockServer.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2019 BARBOTIN Nicolas - */ - -package net.montoyo.wd.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.level.block.state.properties.Property; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.PushReaction; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.network.PacketDistributor; -import net.montoyo.wd.core.DefaultPeripheral; -import net.montoyo.wd.entity.TileEntityInterfaceBase; -import net.montoyo.wd.entity.TileEntityKeyboard; -import net.montoyo.wd.entity.TileEntityPeripheralBase; -import net.montoyo.wd.entity.TileEntityServer; -import net.montoyo.wd.item.ItemLinker; -import net.montoyo.wd.net.WDNetworkRegistry; -import net.montoyo.wd.net.client_bound.S2CMessageCloseGui; -import org.jetbrains.annotations.Nullable; - -public class BlockServer extends WDBlockContainer{ - - public static final EnumProperty type = BlockPeripheral.type; - private static final Property[] properties = new Property[] {type}; - - public BlockServer() { - super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f)); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(properties); - } - - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return new TileEntityServer(pos, state); - } - - @Override - public RenderShape getRenderShape(BlockState state) { - return RenderShape.MODEL; - } - - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if(player.isShiftKeyDown()) - return InteractionResult.FAIL; - - if(player.getItemInHand(hand).getItem() instanceof ItemLinker) - return InteractionResult.FAIL; - - BlockEntity te = world.getBlockEntity(pos); - - if(te instanceof TileEntityServer) { - ((TileEntityServer) te).onPlayerRightClick(player); - return InteractionResult.SUCCESS; - } else - return InteractionResult.FAIL; - } - - @Override - public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { - if(world.isClientSide) - return; - if(placer instanceof Player) { - BlockEntity te = world.getBlockEntity(pos); - - if(te instanceof TileEntityServer) - ((TileEntityServer) te).setOwner((Player) placer); - else if(te instanceof TileEntityInterfaceBase) - ((TileEntityInterfaceBase) te).setOwner((Player) placer); - } - } - - @Override - public PushReaction getPistonPushReaction(BlockState state) { - return PushReaction.IGNORE; - } - - @Override - public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) { - BlockEntity te = world.getBlockEntity(pos); - if(te != null && te instanceof TileEntityPeripheralBase) - ((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor); - - if(world.isClientSide) - return; - - if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) { - world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); - } - } - - @Override - public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) { - if(!world.isClientSide) { - WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); - } - super.playerDestroy(world, player, pos, state, blockEntity, tool); - } - - @Override - public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) { - playerDestroy(level, null, pos, level.getBlockState(pos), null, null); - } - - @Override - public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { - if(!world.isClientSide) { - double rpos = (entity.getY() - ((double) pos.getY())) * 16.0; - - if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) { - BlockEntity te = world.getBlockEntity(pos); - - if(te != null && te instanceof TileEntityKeyboard) - ((TileEntityKeyboard) te).simulateCat(entity); - } - } - } - - public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) { - return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension()); - } -} diff --git a/src/main/java/net/montoyo/wd/block/WDBlock.java b/src/main/java/net/montoyo/wd/block/WDBlock.java deleted file mode 100644 index c51821a..0000000 --- a/src/main/java/net/montoyo/wd/block/WDBlock.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2018 BARBOTIN Nicolas - */ - -package net.montoyo.wd.block; - -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; - -public abstract class WDBlock extends Block { - - protected BlockItem itemBlock; - - public WDBlock(Properties properties) { - super(properties); - } - - public void makeItemBlock() { - if(itemBlock != null) - throw new RuntimeException("WDBlock.makeItemBlock() called twice!"); - - itemBlock = new BlockItem(this, new Item.Properties()); - } - - public BlockItem getItem() { - return itemBlock; - } - -} diff --git a/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java b/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java index c550be5..89b9f5c 100644 --- a/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java +++ b/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java @@ -12,18 +12,19 @@ import net.montoyo.wd.entity.TileEntityKeyboard; import net.montoyo.wd.entity.TileEntityRCtrl; import net.montoyo.wd.entity.TileEntityRedCtrl; import net.montoyo.wd.entity.TileEntityServer; +import net.montoyo.wd.init.BlockInit; import org.jetbrains.annotations.NotNull; import java.util.function.Supplier; public enum DefaultPeripheral implements StringRepresentable { - KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard::new, TileEntityKeyboard::getBlockFromTE), //WITH FACING (< 3) + KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard::new, BlockInit.blockKeyBoard), //WITH FACING (< 3) // CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class), // OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class), - REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl::new ,TileEntityRCtrl::getBlockFromTE), //WITHOUT FACING (>= 3) - REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl::new ,TileEntityRedCtrl::getBlockFromTE), - SERVER("server", "Server", TileEntityServer::new, TileEntityServer::getBlockFromTE); + REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl::new ,BlockInit.blockRControl), //WITHOUT FACING (>= 3) + REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl::new ,BlockInit.blockRedControl), + SERVER("server", "Server", TileEntityServer::new, BlockInit.blockServer); private final String name; private final String wikiName; diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java b/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java index 915a9f0..7237309 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java @@ -11,10 +11,8 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.animal.Ocelot; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.montoyo.wd.WebDisplays; -import net.montoyo.wd.block.BlockPeripheral; import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.data.KeyboardData; import net.montoyo.wd.init.TileInit; @@ -32,10 +30,6 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase { blockState = arg3; } - public static Block getBlockFromTE() { - return new BlockPeripheral().defaultBlockState().getBlock(); - } - @Override public InteractionResult onRightClick(Player player, InteractionHand hand) { if(level.isClientSide) diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java b/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java index 2acba26..67f71da 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java @@ -9,14 +9,10 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.montoyo.wd.block.BlockPeripheral; import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.init.TileInit; -import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Util; public class TileEntityRCtrl extends TileEntityPeripheralBase { @@ -29,10 +25,6 @@ public class TileEntityRCtrl extends TileEntityPeripheralBase { blockState = arg3; } - public static Block getBlockFromTE() { - return new BlockPeripheral().defaultBlockState().getBlock(); - } - @Override public InteractionResult onRightClick(Player player, InteractionHand hand) { if(level.isClientSide) diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java b/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java index d68e9d9..4f2fe25 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java @@ -12,7 +12,6 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.montoyo.wd.block.BlockPeripheral; import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.data.RedstoneCtrlData; import net.montoyo.wd.init.TileInit; @@ -33,10 +32,6 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase { blockPos = arg2; blockState = arg3; } - - public static Block getBlockFromTE() { - return new BlockPeripheral().defaultBlockState().getBlock(); - } @Override public void load(CompoundTag tag) { diff --git a/src/main/java/net/montoyo/wd/init/BlockInit.java b/src/main/java/net/montoyo/wd/init/BlockInit.java index 00fe5b4..b276e6d 100644 --- a/src/main/java/net/montoyo/wd/init/BlockInit.java +++ b/src/main/java/net/montoyo/wd/init/BlockInit.java @@ -7,7 +7,11 @@ import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; -import net.montoyo.wd.block.*; +import net.montoyo.wd.block.BlockKeyboardLeft; +import net.montoyo.wd.block.BlockKeyboardRight; +import net.montoyo.wd.block.BlockPeripheral; +import net.montoyo.wd.block.BlockScreen; +import net.montoyo.wd.core.DefaultPeripheral; public class BlockInit { @@ -22,9 +26,7 @@ public class BlockInit { public static final RegistryObject blockKeyBoard = BlockInit.BLOCKS.register("kb_left", BlockKeyboardLeft::new); public static final RegistryObject blockKbRight = BLOCKS.register("kb_right", BlockKeyboardRight::new); - public static final RegistryObject blockRedControl = BlockInit.BLOCKS.register("redctrl", BlockRedCTRL::new); - - public static final RegistryObject blockRControl = BlockInit.BLOCKS.register("rctrl", BlockRCTRL::new); - - public static final RegistryObject blockServer = BlockInit.BLOCKS.register("server", BlockServer::new); + public static final RegistryObject blockRedControl = BlockInit.BLOCKS.register("redctrl", () -> new BlockPeripheral(DefaultPeripheral.REDSTONE_CONTROLLER)); + public static final RegistryObject blockRControl = BlockInit.BLOCKS.register("rctrl", () -> new BlockPeripheral(DefaultPeripheral.REMOTE_CONTROLLER)); + public static final RegistryObject blockServer = BlockInit.BLOCKS.register("server", () -> new BlockPeripheral(DefaultPeripheral.SERVER)); } diff --git a/src/main/resources/assets/webdisplays/blockstates/rctrl.json b/src/main/resources/assets/webdisplays/blockstates/rctrl.json index 06ea585..5a02fd6 100644 --- a/src/main/resources/assets/webdisplays/blockstates/rctrl.json +++ b/src/main/resources/assets/webdisplays/blockstates/rctrl.json @@ -1,10 +1,7 @@ { - "forge_marker": 1, - "uvlock": false, "variants": { - "facing=north": { "model": "webdisplays:block/rctrl" }, - "facing=east": { "model": "webdisplays:block/rctrl" }, - "facing=south": { "model": "webdisplays:block/rctrl" }, - "facing=west": { "model": "webdisplays:block/rctrl" } + "": { + "model": "webdisplays:block/rctrl" + } } -} +} \ No newline at end of file diff --git a/src/main/resources/assets/webdisplays/blockstates/redctrl.json b/src/main/resources/assets/webdisplays/blockstates/redctrl.json index 8dc09aa..6976298 100644 --- a/src/main/resources/assets/webdisplays/blockstates/redctrl.json +++ b/src/main/resources/assets/webdisplays/blockstates/redctrl.json @@ -1,10 +1,7 @@ { - "forge_marker": 1, - "uvlock": false, "variants": { - "facing=north": { "model": "webdisplays:block/redctrl" }, - "facing=east": { "model": "webdisplays:block/redctrl" }, - "facing=south": { "model": "webdisplays:block/redctrl" }, - "facing=west": { "model": "webdisplays:block/redctrl" } + "": { + "model": "webdisplays:block/redctrl" + } } -} +} \ No newline at end of file diff --git a/src/main/resources/assets/webdisplays/blockstates/server.json b/src/main/resources/assets/webdisplays/blockstates/server.json index 8a5bf8a..6c78fc7 100644 --- a/src/main/resources/assets/webdisplays/blockstates/server.json +++ b/src/main/resources/assets/webdisplays/blockstates/server.json @@ -1,10 +1,7 @@ { - "forge_marker": 1, - "uvlock": false, "variants": { - "facing=north": { "model": "webdisplays:block/server" }, - "facing=east": { "model": "webdisplays:block/server" }, - "facing=south": { "model": "webdisplays:block/server" }, - "facing=west": { "model": "webdisplays:block/server" } + "": { + "model": "webdisplays:block/server" + } } -} +} \ No newline at end of file