From 0dda6eafb7f3454c855cec7428540079db719bbc Mon Sep 17 00:00:00 2001 From: GiantLuigi4 <49770992+GiantLuigi4@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:55:32 -0400 Subject: [PATCH] loot tables, and some code cleanup --- build.gradle | 4 +- .../montoyo/wd/block/BlockKeyboardLeft.java | 3 - .../montoyo/wd/block/BlockKeyboardRight.java | 3 - .../net/montoyo/wd/block/BlockPeripheral.java | 72 +---- .../java/net/montoyo/wd/block/BlockRCTRL.java | 71 +---- .../net/montoyo/wd/block/BlockRedCTRL.java | 71 +---- .../net/montoyo/wd/block/BlockScreen.java | 272 ++++++++---------- .../net/montoyo/wd/block/BlockServer.java | 72 +---- .../montoyo/wd/block/WDBlockContainer.java | 19 -- .../net/montoyo/wd/client/ClientProxy.java | 245 ++++++++-------- .../montoyo/wd/client/gui/GuiKeyboard.java | 3 + .../net/montoyo/wd/item/ItemMinePad2.java | 13 +- .../loot_tables/blocks/kb_left.json | 14 + .../loot_tables/blocks/kb_right.json | 14 + .../webdisplays/loot_tables/blocks/rctrl.json | 14 + .../loot_tables/blocks/redctrl.json | 14 + .../loot_tables/blocks/screen.json | 14 + .../loot_tables/blocks/server.json | 14 + 18 files changed, 354 insertions(+), 578 deletions(-) create mode 100644 src/main/resources/data/webdisplays/loot_tables/blocks/kb_left.json create mode 100644 src/main/resources/data/webdisplays/loot_tables/blocks/kb_right.json create mode 100644 src/main/resources/data/webdisplays/loot_tables/blocks/rctrl.json create mode 100644 src/main/resources/data/webdisplays/loot_tables/blocks/redctrl.json create mode 100644 src/main/resources/data/webdisplays/loot_tables/blocks/screen.json create mode 100644 src/main/resources/data/webdisplays/loot_tables/blocks/server.json diff --git a/build.gradle b/build.gradle index 1c7db84..2c1f059 100644 --- a/build.gradle +++ b/build.gradle @@ -75,9 +75,9 @@ dependencies { minecraft 'net.minecraftforge:forge:1.19.2-43.2.10' annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' - implementation fg.deobf("com.github.Mysticpasta1:mcef-forge:17731a6bbb") + implementation fg.deobf("com.github.Mysticpasta1:mcef-forge:0b89f5faab") // implementation fg.deobf("curse.maven:cloth_config_forge-348521:3972423") - implementation fg.deobf("curse.maven:SU-370704:4410614") + implementation fg.deobf("curse.maven:SU-370704:4485052") implementation fg.deobf("curse.maven:spark-361579:4381167") compileOnly fg.deobf("curse.maven:vivecraft-667903:4409427") diff --git a/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java b/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java index 430507e..e22ce6b 100644 --- a/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java +++ b/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java @@ -130,9 +130,6 @@ public class BlockKeyboardLeft extends BlockPeripheral { public static void remove(BlockState state, Level world, BlockPos pos, boolean setState, boolean drop) { removeRightPiece(state, world, pos); if (setState) { - if (drop) { - // TODO: force drop item - } world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); } WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); diff --git a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java index ab2d104..4752e77 100644 --- a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java +++ b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java @@ -55,9 +55,6 @@ public class BlockKeyboardRight extends Block implements IPeripheral { public static void remove(BlockState state, Level world, BlockPos pos, boolean setState, boolean drop) { removeLeftPiece(state, world, pos); if (setState) { - if (drop) { - // TODO: force drop item - } world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); } WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> BlockKeyboardLeft.point(world, pos)), new S2CMessageCloseGui(pos)); diff --git a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java index 0a31ed9..2a02465 100644 --- a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java +++ b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java @@ -52,7 +52,6 @@ public class BlockPeripheral extends WDBlockContainer { public BlockPeripheral() { super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f)); -// setName("peripheral"); } @Override @@ -60,44 +59,6 @@ public class BlockPeripheral extends WDBlockContainer { builder.add(properties); } - // @Nullable TODO: Fix -// @Override -// public BlockState getStateForPlacement(BlockPlaceContext context) { -// Direction rot = Direction.fromYRot(placer.getYHeadRot()); -// return defaultBlockState().setValue(type, DefaultPeripheral.fromMetadata(meta)).setValue(facing, rot); -// -// -// return getStateForPlacement(context); -// } -// -// public BlockState getStateForPlacement(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction nocare, float hitX, -// float hitY, float hitZ, int meta, @Nonnull LivingEntity placer, InteractionHand hand) { -// } - -// @Override -// public void getSubBlocks(CreativeTabs tab, NonNullList list) { -// for(DefaultPeripheral dp : DefaultPeripheral.values()) -// list.add(new ItemStack(getItem(), 1, dp.toMetadata(0))); -// } - -// @Override -// @Nonnull -// public IBlockState getStateFromMeta(int meta) { -// DefaultPeripheral dp = DefaultPeripheral.fromMetadata(meta); -// IBlockState state = getDefaultState().withProperty(type, dp); -// -// if(dp.hasFacing()) -// state = state.withProperty(facing, (meta >> 2) & 3); -// -// return state; -// } -// -// @Override -// public int getMetaFromState(IBlockState state) { -// return state.getValue(type).toMetadata(state.getValue(facing)); -// } - - @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @@ -119,12 +80,6 @@ public class BlockPeripheral extends WDBlockContainer { return RenderShape.MODEL; } -// @Override -// public int damageDropped(IBlockState state) { -// return state.getValue(type).toMetadata(0); -// } - - @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if(player.isShiftKeyDown()) @@ -144,31 +99,6 @@ public class BlockPeripheral extends WDBlockContainer { return InteractionResult.FAIL; } -// @Override -// public boolean isFullCube(IBlockState state) { TODO: FIx. -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isFullBlock(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isOpaqueCube(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } - @Override public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { return state.getValue(type) == DefaultPeripheral.KEYBOARD ? BlockKeyboardRight.KEYBOARD_AABB : Shapes.block(); @@ -217,7 +147,6 @@ public class BlockPeripheral extends WDBlockContainer { 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); -// dropBlockAsItem(world, pos, state, 0); //TODO Loottable WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } } @@ -230,6 +159,7 @@ public class BlockPeripheral extends WDBlockContainer { WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } + super.playerDestroy(world, player, pos, state, blockEntity, tool); } @Override diff --git a/src/main/java/net/montoyo/wd/block/BlockRCTRL.java b/src/main/java/net/montoyo/wd/block/BlockRCTRL.java index c61076e..7651b30 100644 --- a/src/main/java/net/montoyo/wd/block/BlockRCTRL.java +++ b/src/main/java/net/montoyo/wd/block/BlockRCTRL.java @@ -50,44 +50,6 @@ public class BlockRCTRL extends WDBlockContainer { builder.add(properties); } - // @Nullable TODO: Fix -// @Override -// public BlockState getStateForPlacement(BlockPlaceContext context) { -// Direction rot = Direction.fromYRot(placer.getYHeadRot()); -// return defaultBlockState().setValue(type, DefaultPeripheral.fromMetadata(meta)).setValue(facing, rot); -// -// -// return getStateForPlacement(context); -// } -// -// public BlockState getStateForPlacement(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction nocare, float hitX, -// float hitY, float hitZ, int meta, @Nonnull LivingEntity placer, InteractionHand hand) { -// } - -// @Override -// public void getSubBlocks(CreativeTabs tab, NonNullList list) { -// for(DefaultPeripheral dp : DefaultPeripheral.values()) -// list.add(new ItemStack(getItem(), 1, dp.toMetadata(0))); -// } - -// @Override -// @Nonnull -// public IBlockState getStateFromMeta(int meta) { -// DefaultPeripheral dp = DefaultPeripheral.fromMetadata(meta); -// IBlockState state = getDefaultState().withProperty(type, dp); -// -// if(dp.hasFacing()) -// state = state.withProperty(facing, (meta >> 2) & 3); -// -// return state; -// } -// -// @Override -// public int getMetaFromState(IBlockState state) { -// return state.getValue(type).toMetadata(state.getValue(facing)); -// } - - @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @@ -99,12 +61,6 @@ public class BlockRCTRL extends WDBlockContainer { return RenderShape.MODEL; } -// @Override -// public int damageDropped(IBlockState state) { -// return state.getValue(type).toMetadata(0); -// } - - @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if(player.isShiftKeyDown()) @@ -124,31 +80,6 @@ public class BlockRCTRL extends WDBlockContainer { return InteractionResult.FAIL; } -// @Override -// public boolean isFullCube(IBlockState state) { TODO: FIx. -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isFullBlock(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isOpaqueCube(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } - @Override public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { if(world.isClientSide) @@ -179,7 +110,6 @@ public class BlockRCTRL extends WDBlockContainer { if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) { world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); -// dropBlockAsItem(world, pos, state, 0); //TODO Loottable WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } } @@ -189,6 +119,7 @@ public class BlockRCTRL extends WDBlockContainer { if(!world.isClientSide) { WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } + super.playerDestroy(world, player, pos, state, blockEntity, tool); } @Override diff --git a/src/main/java/net/montoyo/wd/block/BlockRedCTRL.java b/src/main/java/net/montoyo/wd/block/BlockRedCTRL.java index 59b821b..a1a2c4a 100644 --- a/src/main/java/net/montoyo/wd/block/BlockRedCTRL.java +++ b/src/main/java/net/montoyo/wd/block/BlockRedCTRL.java @@ -50,44 +50,6 @@ public class BlockRedCTRL extends WDBlockContainer { builder.add(properties); } - // @Nullable TODO: Fix -// @Override -// public BlockState getStateForPlacement(BlockPlaceContext context) { -// Direction rot = Direction.fromYRot(placer.getYHeadRot()); -// return defaultBlockState().setValue(type, DefaultPeripheral.fromMetadata(meta)).setValue(facing, rot); -// -// -// return getStateForPlacement(context); -// } -// -// public BlockState getStateForPlacement(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction nocare, float hitX, -// float hitY, float hitZ, int meta, @Nonnull LivingEntity placer, InteractionHand hand) { -// } - -// @Override -// public void getSubBlocks(CreativeTabs tab, NonNullList list) { -// for(DefaultPeripheral dp : DefaultPeripheral.values()) -// list.add(new ItemStack(getItem(), 1, dp.toMetadata(0))); -// } - -// @Override -// @Nonnull -// public IBlockState getStateFromMeta(int meta) { -// DefaultPeripheral dp = DefaultPeripheral.fromMetadata(meta); -// IBlockState state = getDefaultState().withProperty(type, dp); -// -// if(dp.hasFacing()) -// state = state.withProperty(facing, (meta >> 2) & 3); -// -// return state; -// } -// -// @Override -// public int getMetaFromState(IBlockState state) { -// return state.getValue(type).toMetadata(state.getValue(facing)); -// } - - @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @@ -99,12 +61,6 @@ public class BlockRedCTRL extends WDBlockContainer { return RenderShape.MODEL; } -// @Override -// public int damageDropped(IBlockState state) { -// return state.getValue(type).toMetadata(0); -// } - - @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if(player.isShiftKeyDown()) @@ -124,31 +80,6 @@ public class BlockRedCTRL extends WDBlockContainer { return InteractionResult.FAIL; } -// @Override -// public boolean isFullCube(IBlockState state) { TODO: FIx. -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isFullBlock(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isOpaqueCube(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } - @Override public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { if(world.isClientSide) @@ -179,7 +110,6 @@ public class BlockRedCTRL extends WDBlockContainer { if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) { world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); -// dropBlockAsItem(world, pos, state, 0); //TODO Loottable WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } } @@ -189,6 +119,7 @@ public class BlockRedCTRL extends WDBlockContainer { if(!world.isClientSide) { WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } + super.playerDestroy(world, player, pos, state, blockEntity, tool); } @Override diff --git a/src/main/java/net/montoyo/wd/block/BlockScreen.java b/src/main/java/net/montoyo/wd/block/BlockScreen.java index a0f3028..9dd6e8c 100644 --- a/src/main/java/net/montoyo/wd/block/BlockScreen.java +++ b/src/main/java/net/montoyo/wd/block/BlockScreen.java @@ -60,8 +60,6 @@ public class BlockScreen extends BaseEntityBlock { public BlockScreen(Properties properties) { super(properties.strength(1.5f, 10.f)); -// setCreativeTab(WebDisplays.CREATIVE_TAB); -// setName("screen"); this.registerDefaultState(this.defaultBlockState().setValue(hasTE, false).setValue(emitting, false)); } @@ -79,7 +77,6 @@ public class BlockScreen extends BaseEntityBlock { return world.getBlockState(pos.toBlock()).getBlock() != BlockInit.blockScreen.get(); } - @org.jetbrains.annotations.Nullable @Override public BlockState getStateForPlacement(BlockPlaceContext context) { @@ -91,31 +88,6 @@ public class BlockScreen extends BaseEntityBlock { return super.updateShape(state, direction, neighborState, level, currentPos, neighborPos); } - /* @Override - @Nonnull - public BlockState getExtendedState(@Nonnull BlockState ret, Level world, BlockPos bpos) { - Vector3i pos = new Vector3i(bpos); - - for(BlockSide side : BlockSide.values()) { - int icon = 0; - if(isntScreenBlock(world, side.up.clone().add(pos))) icon |= BAR_TOP; - if(isntScreenBlock(world, side.down.clone().add(pos))) icon |= BAR_BOT; - if(isntScreenBlock(world, side.left.clone().add(pos))) icon |= BAR_LEFT; - if(isntScreenBlock(world, side.right.clone().add(pos))) icon |= BAR_RIGHT; - - ret = ret.setValue(sideFlags[side.ordinal()], icon); - } - - return ret; - }*/ - -// @Override -// @Nonnull -// public IBlockState getStateFromMeta(int meta) { -// return getDefaultState().withProperty(hasTE, (meta & 1) != 0).withProperty(emitting, (meta & 2) != 0); -// } -// - public int getMetaFromState(BlockState state) { int ret = 0; if (state.getValue(hasTE)) @@ -216,54 +188,54 @@ public class BlockScreen extends BaseEntityBlock { // return InteractionResult.SUCCESS; // } - Vector2i size = Multiblock.measure(world, pos, side); - if (size.x < 2 && size.y < 2) { - Util.toast(player, "tooSmall"); - return InteractionResult.SUCCESS; - } - - if (size.x > CommonConfig.Screen.maxScreenSizeX || size.y > CommonConfig.Screen.maxScreenSizeY) { - Util.toast(player, "tooBig", CommonConfig.Screen.maxScreenSizeX, CommonConfig.Screen.maxScreenSizeY); - return InteractionResult.SUCCESS; - } - - Vector3i err = Multiblock.check(world, pos, size, side); - if (err != null) { - Util.toast(player, "invalid", err.toString()); - return InteractionResult.SUCCESS; - } - - boolean created = false; - Log.info("Player %s (UUID %s) created a screen at %s of size %dx%d", player.getName(), player.getGameProfile().getId().toString(), pos.toString(), size.x, size.y); - - if (te == null) { - BlockPos bp = pos.toBlock(); - world.setBlockAndUpdate(bp, world.getBlockState(bp).setValue(hasTE, true)); - te = (TileEntityScreen) world.getBlockEntity(bp); - created = true; - } - - te.addScreen(side, size, null, player, true); + Vector2i size = Multiblock.measure(world, pos, side); + if (size.x < 2 && size.y < 2) { + Util.toast(player, "tooSmall"); return InteractionResult.SUCCESS; } - @Override - public void neighborChanged (BlockState state, Level world, BlockPos pos, Block block, BlockPos source, - boolean isMoving){ - if (block != this && !world.isClientSide && !state.getValue(emitting)) { - for (BlockSide side : BlockSide.values()) { - Vector3i vec = new Vector3i(pos); - Multiblock.findOrigin(world, vec, side, null); + if (size.x > CommonConfig.Screen.maxScreenSizeX || size.y > CommonConfig.Screen.maxScreenSizeY) { + Util.toast(player, "tooBig", CommonConfig.Screen.maxScreenSizeX, CommonConfig.Screen.maxScreenSizeY); + return InteractionResult.SUCCESS; + } - TileEntityScreen tes = (TileEntityScreen) world.getBlockEntity(vec.toBlock()); - if (tes != null && tes.hasUpgrade(side, DefaultUpgrade.REDINPUT)) { - Direction facing = Direction.from2DDataValue(side.reverse().ordinal()); //Opposite face - vec.sub(pos.getX(), pos.getY(), pos.getZ()).neg(); - tes.updateJSRedstone(side, new Vector2i(vec.dot(side.right), vec.dot(side.up)), world.getSignal(pos, facing)); - } + Vector3i err = Multiblock.check(world, pos, size, side); + if (err != null) { + Util.toast(player, "invalid", err.toString()); + return InteractionResult.SUCCESS; + } + + boolean created = false; + Log.info("Player %s (UUID %s) created a screen at %s of size %dx%d", player.getName(), player.getGameProfile().getId().toString(), pos.toString(), size.x, size.y); + + if (te == null) { + BlockPos bp = pos.toBlock(); + world.setBlockAndUpdate(bp, world.getBlockState(bp).setValue(hasTE, true)); + te = (TileEntityScreen) world.getBlockEntity(bp); + created = true; + } + + te.addScreen(side, size, null, player, true); + return InteractionResult.SUCCESS; + } + + @Override + public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos source, + boolean isMoving){ + if (block != this && !world.isClientSide && !state.getValue(emitting)) { + for (BlockSide side : BlockSide.values()) { + Vector3i vec = new Vector3i(pos); + Multiblock.findOrigin(world, vec, side, null); + + TileEntityScreen tes = (TileEntityScreen) world.getBlockEntity(vec.toBlock()); + if (tes != null && tes.hasUpgrade(side, DefaultUpgrade.REDINPUT)) { + Direction facing = Direction.from2DDataValue(side.reverse().ordinal()); //Opposite face + vec.sub(pos.getX(), pos.getY(), pos.getZ()).neg(); + tes.updateJSRedstone(side, new Vector2i(vec.dot(side.right), vec.dot(side.up)), world.getSignal(pos, facing)); } } } + } public static boolean hit2pixels(BlockSide side, BlockPos bpos, Vector3i pos, TileEntityScreen.Screen scr, float hitX, float hitY, float hitZ, Vector2i dst) { if(side.right.x < 0) @@ -323,104 +295,98 @@ public class BlockScreen extends BaseEntityBlock { return false; } - @org.jetbrains.annotations.Nullable - @Override - public BlockEntity newBlockEntity (BlockPos pos, BlockState state){ - int meta = getMetaFromState(state); + @org.jetbrains.annotations.Nullable + @Override + public BlockEntity newBlockEntity (BlockPos pos, BlockState state){ + int meta = getMetaFromState(state); - if ((meta & 1) == 0) - return null; + if ((meta & 1) == 0) + return null; - return ((meta & 1) == 0) ? null : new TileEntityScreen(pos, state); + return ((meta & 1) == 0) ? null : new TileEntityScreen(pos, state); + } + + /************************************************* DESTRUCTION HANDLING *************************************************/ + + private void onDestroy (Level world, BlockPos pos, Player ply){ + if (!world.isClientSide) { + Vector3i bp = new Vector3i(pos); + Multiblock.BlockOverride override = new Multiblock.BlockOverride(bp, Multiblock.OverrideAction.SIMULATE); + + for (BlockSide bs : BlockSide.values()) + destroySide(world, bp.clone(), bs, override, ply); } + } - /************************************************* DESTRUCTION HANDLING *************************************************/ + private void destroySide (Level world, Vector3i pos, BlockSide side, Multiblock.BlockOverride override, Player + source){ + Multiblock.findOrigin(world, pos, side, override); + BlockPos bp = pos.toBlock(); + BlockEntity te = world.getBlockEntity(bp); - private void onDestroy (Level world, BlockPos pos, Player ply){ - if (!world.isClientSide) { - Vector3i bp = new Vector3i(pos); - Multiblock.BlockOverride override = new Multiblock.BlockOverride(bp, Multiblock.OverrideAction.SIMULATE); + if (te != null && te instanceof TileEntityScreen) { + ((TileEntityScreen) te).onDestroy(source); + world.setBlock(bp, world.getBlockState(bp).setValue(hasTE, false), Block.UPDATE_ALL_IMMEDIATE); //Destroy tile entity. + } + } + @Override + public boolean onDestroyedByPlayer (BlockState state, Level level, BlockPos pos, Player player, + boolean willHarvest, FluidState fluid){ + onDestroy(level, pos, player); + return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid); + } + + @Override + public void setPlacedBy (Level world, @NotNull BlockPos pos, @NotNull BlockState + state, @org.jetbrains.annotations.Nullable LivingEntity whoDidThisShit, @NotNull ItemStack stack){ + if (world.isClientSide) + return; + + Multiblock.BlockOverride override = new Multiblock.BlockOverride(new Vector3i(pos), Multiblock.OverrideAction.IGNORE); + Vector3i[] neighbors = new Vector3i[6]; + + neighbors[0] = new Vector3i(pos.getX() + 1, pos.getY(), pos.getZ()); + neighbors[1] = new Vector3i(pos.getX() - 1, pos.getY(), pos.getZ()); + neighbors[2] = new Vector3i(pos.getX(), pos.getY() + 1, pos.getZ()); + neighbors[3] = new Vector3i(pos.getX(), pos.getY() - 1, pos.getZ()); + neighbors[4] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() + 1); + neighbors[5] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() - 1); + + for (Vector3i neighbor : neighbors) { + if (world.getBlockState(neighbor.toBlock()).getBlock() instanceof BlockScreen) { for (BlockSide bs : BlockSide.values()) - destroySide(world, bp.clone(), bs, override, ply); + destroySide(world, neighbor.clone(), bs, override, (whoDidThisShit instanceof Player) ? ((Player) whoDidThisShit) : null); } } + } - private void destroySide (Level world, Vector3i pos, BlockSide side, Multiblock.BlockOverride override, Player - source){ - Multiblock.findOrigin(world, pos, side, override); - BlockPos bp = pos.toBlock(); - BlockEntity te = world.getBlockEntity(bp); + @Override + public @NotNull PushReaction getPistonPushReaction (BlockState state){ + return PushReaction.IGNORE; + } - if (te != null && te instanceof TileEntityScreen) { - ((TileEntityScreen) te).onDestroy(source); - world.setBlock(bp, world.getBlockState(bp).setValue(hasTE, false), Block.UPDATE_ALL_IMMEDIATE); //Destroy tile entity. - } + @Override + public int getSignal (BlockState state, BlockGetter level, BlockPos pos, Direction direction){ + return state.getValue(emitting) ? 15 : 0; + } + + @Override + 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 boolean onDestroyedByPlayer (BlockState state, Level level, BlockPos pos, Player player, - boolean willHarvest, FluidState fluid){ - onDestroy(level, pos, player); - return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid); - } - - @Override - public void setPlacedBy (Level world, @NotNull BlockPos pos, @NotNull BlockState - state, @org.jetbrains.annotations.Nullable LivingEntity whoDidThisShit, @NotNull ItemStack stack){ - if (world.isClientSide) - return; - - Multiblock.BlockOverride override = new Multiblock.BlockOverride(new Vector3i(pos), Multiblock.OverrideAction.IGNORE); - Vector3i[] neighbors = new Vector3i[6]; - - neighbors[0] = new Vector3i(pos.getX() + 1, pos.getY(), pos.getZ()); - neighbors[1] = new Vector3i(pos.getX() - 1, pos.getY(), pos.getZ()); - neighbors[2] = new Vector3i(pos.getX(), pos.getY() + 1, pos.getZ()); - neighbors[3] = new Vector3i(pos.getX(), pos.getY() - 1, pos.getZ()); - neighbors[4] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() + 1); - neighbors[5] = new Vector3i(pos.getX(), pos.getY(), pos.getZ() - 1); - - for (Vector3i neighbor : neighbors) { - if (world.getBlockState(neighbor.toBlock()).getBlock() instanceof BlockScreen) { - for (BlockSide bs : BlockSide.values()) - destroySide(world, neighbor.clone(), bs, override, (whoDidThisShit instanceof Player) ? ((Player) whoDidThisShit) : null); - } - } - } - - @Override - public @NotNull PushReaction getPistonPushReaction (BlockState state){ - return PushReaction.IGNORE; - } - - @Override - public int getSignal (BlockState state, BlockGetter level, BlockPos pos, Direction direction){ - return state.getValue(emitting) ? 15 : 0; - } - - @Override - public boolean isSignalSource (BlockState state){ - return state.getValue(emitting); - } - -// @Override //TODO: Add this -// protected BlockItem createItemBlock() { -// return new ItemBlockScreen(this); -// } - - 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(); - } - + 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 index 12873e7..3582f4a 100644 --- a/src/main/java/net/montoyo/wd/block/BlockServer.java +++ b/src/main/java/net/montoyo/wd/block/BlockServer.java @@ -53,44 +53,6 @@ public class BlockServer extends WDBlockContainer{ builder.add(properties); } - // @Nullable TODO: Fix -// @Override -// public BlockState getStateForPlacement(BlockPlaceContext context) { -// Direction rot = Direction.fromYRot(placer.getYHeadRot()); -// return defaultBlockState().setValue(type, DefaultPeripheral.fromMetadata(meta)).setValue(facing, rot); -// -// -// return getStateForPlacement(context); -// } -// -// public BlockState getStateForPlacement(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction nocare, float hitX, -// float hitY, float hitZ, int meta, @Nonnull LivingEntity placer, InteractionHand hand) { -// } - -// @Override -// public void getSubBlocks(CreativeTabs tab, NonNullList list) { -// for(DefaultPeripheral dp : DefaultPeripheral.values()) -// list.add(new ItemStack(getItem(), 1, dp.toMetadata(0))); -// } - -// @Override -// @Nonnull -// public IBlockState getStateFromMeta(int meta) { -// DefaultPeripheral dp = DefaultPeripheral.fromMetadata(meta); -// IBlockState state = getDefaultState().withProperty(type, dp); -// -// if(dp.hasFacing()) -// state = state.withProperty(facing, (meta >> 2) & 3); -// -// return state; -// } -// -// @Override -// public int getMetaFromState(IBlockState state) { -// return state.getValue(type).toMetadata(state.getValue(facing)); -// } - - @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { @@ -102,12 +64,6 @@ public class BlockServer extends WDBlockContainer{ return RenderShape.MODEL; } -// @Override -// public int damageDropped(IBlockState state) { -// return state.getValue(type).toMetadata(0); -// } - - @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if(player.isShiftKeyDown()) @@ -125,31 +81,6 @@ public class BlockServer extends WDBlockContainer{ return InteractionResult.FAIL; } -// @Override -// public boolean isFullCube(IBlockState state) { TODO: FIx. -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isFullBlock(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean isOpaqueCube(IBlockState state) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } -// -// @Override -// public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) { -// return state.getValue(type) != DefaultPeripheral.KEYBOARD; -// } - @Override public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { if(world.isClientSide) @@ -180,7 +111,6 @@ public class BlockServer extends WDBlockContainer{ if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) { world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3); -// dropBlockAsItem(world, pos, state, 0); //TODO Loottable WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } } @@ -190,6 +120,7 @@ public class BlockServer extends WDBlockContainer{ if(!world.isClientSide) { WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos)); } + super.playerDestroy(world, player, pos, state, blockEntity, tool); } @Override @@ -214,5 +145,4 @@ public class BlockServer extends WDBlockContainer{ 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/WDBlockContainer.java b/src/main/java/net/montoyo/wd/block/WDBlockContainer.java index 066a091..c62659f 100644 --- a/src/main/java/net/montoyo/wd/block/WDBlockContainer.java +++ b/src/main/java/net/montoyo/wd/block/WDBlockContainer.java @@ -5,10 +5,7 @@ package net.montoyo.wd.block; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; import net.minecraft.world.level.block.BaseEntityBlock; -import net.minecraft.world.level.block.Block; -import net.montoyo.wd.WebDisplays; public abstract class WDBlockContainer extends BaseEntityBlock { @@ -18,22 +15,6 @@ public abstract class WDBlockContainer extends BaseEntityBlock { super(arg); } - protected void setName(String name) { - // setRegistryName(name); - } - - protected static BlockItem createItemBlock(Block block) { - return new BlockItem(block, new Item.Properties().tab(WebDisplays.CREATIVE_TAB)); - } - - public static void makeItemBlock(Block block) { - if(itemBlock != null) - throw new RuntimeException("WDBlockContainer.makeItemBlock() called twice!"); - - itemBlock = createItemBlock(block); - // itemBlock.setRegistryName(getName().getString()); - } - public BlockItem getItem() { return itemBlock; } diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index 49d06e2..92df13d 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -40,7 +40,6 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderHighlightEvent; @@ -48,6 +47,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.LogicalSide; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.network.NetworkEvent; @@ -533,125 +533,142 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer registerItemMultiModels(wd.itemAdvIcon); } */ - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public void onTick(TickEvent.ClientTickEvent ev) { - if(ev.phase == TickEvent.Phase.END) { - //Help - if(InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_F1)) { - if(!isF1Down) { - isF1Down = true; - - String wikiName = null; - if(mc.screen instanceof WDScreen) - wikiName = ((WDScreen) mc.screen).getWikiPageName(); - else if(mc.screen instanceof ContainerScreen) { - Slot slot = ((ContainerScreen) mc.screen).getSlotUnderMouse(); - - if(slot != null && slot.hasItem() && slot.getItem().getItem() instanceof WDItem) - wikiName = ((WDItem) slot.getItem().getItem()).getWikiName(slot.getItem()); - } - - if(wikiName != null) - mcef.openExampleBrowser("https://montoyo.net/wdwiki/index.php/" + wikiName); - } - } else if(isF1Down) - isF1Down = false; - - //Workaround cuz chat sux - if(nextScreen != null && mc.screen == null) { - mc.setScreen(nextScreen); - nextScreen = null; - } - - //Unload/load screens depending on client player distance - if(mc.player != null && !screenTracking.isEmpty()) { - int id = lastTracked % screenTracking.size(); - lastTracked++; - - TileEntityScreen tes = screenTracking.get(id); - double dist2 = mc.player.distanceToSqr(tes.getBlockPos().getX(), tes.getBlockPos().getY(), tes.getBlockPos().getZ()); - - if(tes.isLoaded()) { - if(dist2 > WebDisplays.INSTANCE.unloadDistance2) - tes.unload(); - else if(ClientConfig.AutoVolumeControl.enableAutoVolume) - tes.updateTrackDistance(dist2, 80); //ToDo find master volume - } else if(dist2 <= WebDisplays.INSTANCE.loadDistance2) - tes.load(); - } - - //Load/unload minePads depending on which item is in the player's hand - if(++minePadTickCounter >= 10) { - minePadTickCounter = 0; - Player ep = mc.player; - - for(PadData pd: padList) - pd.isInHotbar = false; - - if(ep != null) { - updateInventory(ep.getInventory().items, ep.getItemInHand(InteractionHand.MAIN_HAND), 9); - updateInventory(ep.getInventory().offhand, ep.getItemInHand(InteractionHand.OFF_HAND), 1); //Is this okay? - } - - //TODO: Check for GuiContainer.draggedStack - - for(int i = padList.size() - 1; i >= 0; i--) { - PadData pd = padList.get(i); - - if(!pd.isInHotbar) { - pd.view.close(); - pd.view = null; //This is for GuiMinePad, in case the player dies with the GUI open - padList.remove(i); - padMap.remove(pd.id); - } - } - } - - //Laser pointer raycast - if(mc.player != null && mc.level != null && ItemInit.itemLaserPointer.isPresent() && mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.itemLaserPointer.get()) - && mc.options.keyUse.isDown() - && (mc.hitResult == null || mc.hitResult.getType() == HitResult.Type.BLOCK || mc.hitResult.getType() == HitResult.Type.MISS)) { - laserPointerRenderer.isOn = true; - BlockHitResult result = raycast(64.0); //TODO: Make that distance configurable - - BlockPos bpos = result.getBlockPos(); - - if(result.getType() == HitResult.Type.BLOCK && mc.level.getBlockState(bpos).getBlock() == BlockInit.blockScreen.get()) { - Vector3i pos = new Vector3i(result.getBlockPos()); - BlockSide side = BlockSide.values()[result.getDirection().ordinal()]; - - Multiblock.findOrigin(mc.level, pos, side, null); - TileEntityScreen te = (TileEntityScreen) mc.level.getBlockEntity(pos.toBlock()); - - if(te != null && te.hasUpgrade(side, DefaultUpgrade.LASERMOUSE)) { //hasUpgrade returns false is there's no screen on side 'side' - //Since rights aren't synchronized, let the server check them for us... - TileEntityScreen.Screen scr = te.getScreen(side); - - if(scr.browser != null) { - float hitX = ((float) result.getLocation().x) - (float) bpos.getX(); - float hitY = ((float) result.getLocation().y) - (float) bpos.getY(); - float hitZ = ((float) result.getLocation().z) - (float) bpos.getZ(); - Vector2i tmp = new Vector2i(); + @SubscribeEvent + public void onLevelTick(TickEvent.LevelTickEvent ev) { + if (!ev.side.equals(LogicalSide.CLIENT)) return; + if(ev.phase != TickEvent.Phase.END) return; + + //Unload/load screens depending on client player distance + if (mc.player != null || !screenTracking.isEmpty()) + return; + + int id = lastTracked % screenTracking.size(); + + TileEntityScreen tes = screenTracking.get(id); + + if (!tes.getLevel().equals(ev.level)) + return; + + lastTracked++; + if (tes.getLevel() != mc.player.level) { + // TODO: properly handle this + // probably gonna want a helper class for cross-dimensional distances + if (!tes.isLoaded()) + tes.load(); + } else { + double dist2 = mc.player.distanceToSqr(tes.getBlockPos().getX(), tes.getBlockPos().getY(), tes.getBlockPos().getZ()); + + if (tes.isLoaded()) { + if (dist2 > WebDisplays.INSTANCE.unloadDistance2) + tes.unload(); + else if (ClientConfig.AutoVolumeControl.enableAutoVolume) + tes.updateTrackDistance(dist2, 80); //ToDo find master volume + } else if (dist2 <= WebDisplays.INSTANCE.loadDistance2) + tes.load(); + } + } - if(BlockScreen.hit2pixels(side, bpos, new Vector3i(result.getBlockPos()), scr, hitX, hitY, hitZ, tmp)) { - laserClick(te, side, scr, tmp); - } + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent ev) { + if(ev.phase != TickEvent.Phase.END) return; + + //Help + if(InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_F1)) { + if(!isF1Down) { + isF1Down = true; + + String wikiName = null; + if(mc.screen instanceof WDScreen) + wikiName = ((WDScreen) mc.screen).getWikiPageName(); + else if(mc.screen instanceof ContainerScreen) { + Slot slot = ((ContainerScreen) mc.screen).getSlotUnderMouse(); + + if(slot != null && slot.hasItem() && slot.getItem().getItem() instanceof WDItem) + wikiName = ((WDItem) slot.getItem().getItem()).getWikiName(slot.getItem()); + } + + if(wikiName != null) + mcef.openExampleBrowser("https://montoyo.net/wdwiki/index.php/" + wikiName); + } + } else if(isF1Down) + isF1Down = false; + + //Workaround cuz chat sux + if(nextScreen != null && mc.screen == null) { + mc.setScreen(nextScreen); + nextScreen = null; + } + + //Load/unload minePads depending on which item is in the player's hand + if(++minePadTickCounter >= 10) { + minePadTickCounter = 0; + Player ep = mc.player; + + for(PadData pd: padList) + pd.isInHotbar = false; + + if(ep != null) { + updateInventory(ep.getInventory().items, ep.getItemInHand(InteractionHand.MAIN_HAND), 9); + updateInventory(ep.getInventory().offhand, ep.getItemInHand(InteractionHand.OFF_HAND), 1); //Is this okay? + } + + //TODO: Check for GuiContainer.draggedStack + + for(int i = padList.size() - 1; i >= 0; i--) { + PadData pd = padList.get(i); + + if(!pd.isInHotbar) { + pd.view.close(); + pd.view = null; //This is for GuiMinePad, in case the player dies with the GUI open + padList.remove(i); + padMap.remove(pd.id); + } + } + } + + //Laser pointer raycast + if(mc.player != null && mc.level != null && ItemInit.itemLaserPointer.isPresent() && mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.itemLaserPointer.get()) + && mc.options.keyUse.isDown() + && (mc.hitResult == null || mc.hitResult.getType() == HitResult.Type.BLOCK || mc.hitResult.getType() == HitResult.Type.MISS)) { + laserPointerRenderer.isOn = true; + BlockHitResult result = raycast(64.0); //TODO: Make that distance configurable + + BlockPos bpos = result.getBlockPos(); + + if(result.getType() == HitResult.Type.BLOCK && mc.level.getBlockState(bpos).getBlock() == BlockInit.blockScreen.get()) { + Vector3i pos = new Vector3i(result.getBlockPos()); + BlockSide side = BlockSide.values()[result.getDirection().ordinal()]; + + Multiblock.findOrigin(mc.level, pos, side, null); + TileEntityScreen te = (TileEntityScreen) mc.level.getBlockEntity(pos.toBlock()); + + if(te != null && te.hasUpgrade(side, DefaultUpgrade.LASERMOUSE)) { //hasUpgrade returns false is there's no screen on side 'side' + //Since rights aren't synchronized, let the server check them for us... + TileEntityScreen.Screen scr = te.getScreen(side); + + if(scr.browser != null) { + float hitX = ((float) result.getLocation().x) - (float) bpos.getX(); + float hitY = ((float) result.getLocation().y) - (float) bpos.getY(); + float hitZ = ((float) result.getLocation().z) - (float) bpos.getZ(); + Vector2i tmp = new Vector2i(); + + if(BlockScreen.hit2pixels(side, bpos, new Vector3i(result.getBlockPos()), scr, hitX, hitY, hitZ, tmp)) { + laserClick(te, side, scr, tmp); } } } - } else { - laserPointerRenderer.isOn = false; - deselectScreen(); + } + } else { + laserPointerRenderer.isOn = false; + deselectScreen(); - //Handle JS queries - jsDispatcher.handleQueries(); + //Handle JS queries + jsDispatcher.handleQueries(); - //Miniserv - if (msClientStarted && mc.player == null) { - msClientStarted = false; - Client.getInstance().stop(); - } + //Miniserv + if (msClientStarted && mc.player == null) { + msClientStarted = false; + Client.getInstance().stop(); } } } diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java b/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java index 8bb5523..9ec59c9 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java @@ -157,6 +157,7 @@ public class GuiKeyboard extends WDScreen { evStack.add(new TypeData(TypeData.Action.PRESS, keyCode, modifiers)); if (!evStack.isEmpty() && !syncRequested()) requestSync(); + sync(); return super.keyPressed(keyCode, scanCode, modifiers); } @@ -165,6 +166,7 @@ public class GuiKeyboard extends WDScreen { evStack.add(new TypeData(TypeData.Action.TYPE, codePoint, modifiers)); if (!evStack.isEmpty() && !syncRequested()) requestSync(); + sync(); return super.charTyped(codePoint, modifiers); } @@ -173,6 +175,7 @@ public class GuiKeyboard extends WDScreen { evStack.add(new TypeData(TypeData.Action.RELEASE, keyCode, modifiers)); if (!evStack.isEmpty() && !syncRequested()) requestSync(); + sync(); return super.keyPressed(keyCode, scanCode, modifiers); } diff --git a/src/main/java/net/montoyo/wd/item/ItemMinePad2.java b/src/main/java/net/montoyo/wd/item/ItemMinePad2.java index b531886..cf89efb 100644 --- a/src/main/java/net/montoyo/wd/item/ItemMinePad2.java +++ b/src/main/java/net/montoyo/wd/item/ItemMinePad2.java @@ -20,6 +20,8 @@ import net.minecraft.world.level.Level; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.config.CommonConfig; import net.montoyo.wd.core.CraftComponent; +import net.montoyo.wd.net.WDNetworkRegistry; +import net.montoyo.wd.net.server_bound.C2SMinepadUrl; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -59,8 +61,15 @@ public class ItemMinePad2 extends Item implements WDItem { WebDisplays.PROXY.openMinePadGui(is.getTag().getUUID("PadID")); ok = true; - } else - ok = false; + } else { + UUID uuid = UUID.randomUUID(); + String url = CommonConfig.Browser.homepage; + WDNetworkRegistry.INSTANCE.sendToServer(new C2SMinepadUrl(uuid, url)); + is.getOrCreateTag().putUUID("PadID", uuid); + is.getTag().putString("PadURL", url); + + ok = true; + } return new InteractionResultHolder<>(ok ? InteractionResult.SUCCESS : InteractionResult.PASS, is); } diff --git a/src/main/resources/data/webdisplays/loot_tables/blocks/kb_left.json b/src/main/resources/data/webdisplays/loot_tables/blocks/kb_left.json new file mode 100644 index 0000000..1a62020 --- /dev/null +++ b/src/main/resources/data/webdisplays/loot_tables/blocks/kb_left.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "webdisplays:keyboard" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/webdisplays/loot_tables/blocks/kb_right.json b/src/main/resources/data/webdisplays/loot_tables/blocks/kb_right.json new file mode 100644 index 0000000..1a62020 --- /dev/null +++ b/src/main/resources/data/webdisplays/loot_tables/blocks/kb_right.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "webdisplays:keyboard" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/webdisplays/loot_tables/blocks/rctrl.json b/src/main/resources/data/webdisplays/loot_tables/blocks/rctrl.json new file mode 100644 index 0000000..8e1b0ce --- /dev/null +++ b/src/main/resources/data/webdisplays/loot_tables/blocks/rctrl.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "webdisplays:rctrl" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/webdisplays/loot_tables/blocks/redctrl.json b/src/main/resources/data/webdisplays/loot_tables/blocks/redctrl.json new file mode 100644 index 0000000..fa42e22 --- /dev/null +++ b/src/main/resources/data/webdisplays/loot_tables/blocks/redctrl.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "webdisplays:redctrl" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/webdisplays/loot_tables/blocks/screen.json b/src/main/resources/data/webdisplays/loot_tables/blocks/screen.json new file mode 100644 index 0000000..97a81ee --- /dev/null +++ b/src/main/resources/data/webdisplays/loot_tables/blocks/screen.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "webdisplays:screen" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/webdisplays/loot_tables/blocks/server.json b/src/main/resources/data/webdisplays/loot_tables/blocks/server.json new file mode 100644 index 0000000..339d291 --- /dev/null +++ b/src/main/resources/data/webdisplays/loot_tables/blocks/server.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "webdisplays:server" + } + ] + } + ] +} \ No newline at end of file