diff --git a/build.gradle b/build.gradle index e0094369f..a8c4aab94 100644 --- a/build.gradle +++ b/build.gradle @@ -80,4 +80,4 @@ publishing { // The repositories here will be used for publishing your artifact, not for // retrieving dependencies. } -} \ No newline at end of file +} diff --git a/src/main/java/me/aleksilassila/litematica/printer/LitematicaMixinMod.java b/src/main/java/me/aleksilassila/litematica/printer/LitematicaMixinMod.java index e26f79544..67ab63963 100644 --- a/src/main/java/me/aleksilassila/litematica/printer/LitematicaMixinMod.java +++ b/src/main/java/me/aleksilassila/litematica/printer/LitematicaMixinMod.java @@ -23,7 +23,7 @@ public class LitematicaMixinMod implements ModInitializer { public static final ConfigBoolean REPLACE_FLUIDS = new ConfigBoolean("replaceFluids", false, "Whether or not fluid source blocks should be replaced by the printer."); public static ImmutableList getConfigList() { - List list = new java.util.ArrayList<>(List.copyOf(Configs.Generic.OPTIONS)); + List list = new java.util.ArrayList<>(Configs.Generic.OPTIONS); list.add(PRINT_INTERVAL); list.add(PRINTING_RANGE); // list.add(PRINT_IN_AIR); @@ -32,13 +32,13 @@ public static ImmutableList getConfigList() { return ImmutableList.copyOf(list); } - + // Hotkeys public static final ConfigHotkey PRINT = new ConfigHotkey("print", "V", "Prints while pressed"); public static final ConfigHotkey TOGGLE_PRINTING_MODE = new ConfigHotkey("togglePrintingMode", "CAPS_LOCK", "Allows quickly toggling on/off Printing mode"); public static List getHotkeyList() { - List list = new java.util.ArrayList<>(List.copyOf(Hotkeys.HOTKEY_LIST)); + List list = new java.util.ArrayList<>(Hotkeys.HOTKEY_LIST); list.add(PRINT); list.add(TOGGLE_PRINTING_MODE); diff --git a/src/main/java/me/aleksilassila/litematica/printer/interfaces/Implementation.java b/src/main/java/me/aleksilassila/litematica/printer/interfaces/Implementation.java index 1989f3426..c9f4d22f6 100644 --- a/src/main/java/me/aleksilassila/litematica/printer/interfaces/Implementation.java +++ b/src/main/java/me/aleksilassila/litematica/printer/interfaces/Implementation.java @@ -1,6 +1,7 @@ package me.aleksilassila.litematica.printer.interfaces; import me.aleksilassila.litematica.printer.printer.Printer; +import net.minecraft.block.*; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.player.PlayerAbilities; import net.minecraft.entity.player.PlayerInventory; @@ -47,30 +48,6 @@ public static boolean isLookPacket(Packet packet) { } public static Packet getMoveOnlyPacket(ClientPlayerEntity playerEntity, Packet packet) { -// try { -// if (packet instanceof PlayerMoveC2SPacket.LookOnly) { -// return null; -// } else if (packet instanceof PlayerMoveC2SPacket) { -// Field xField = PlayerMoveC2SPacket.class.getDeclaredField("x"); -// Field yField = PlayerMoveC2SPacket.class.getDeclaredField("y"); -// Field zField = PlayerMoveC2SPacket.class.getDeclaredField("z"); -// -// xField.setAccessible(true); -// yField.setAccessible(true); -// zField.setAccessible(true); -// -// double x = xField.getDouble(packet); -// double y = yField.getDouble(packet); -// double z = zField.getDouble(packet); -// -// return new PlayerMoveC2SPacket.PositionOnly(x, y, z, ((PlayerMoveC2SPacket) packet).isOnGround()); -// } -// -// return packet; -// } catch (NoSuchFieldException | IllegalAccessException e) { -// e.printStackTrace(); -// return packet; -// } if (Printer.Queue.playerShouldBeFacing == null) return packet; try { Field yawField = PlayerMoveC2SPacket.class.getDeclaredField("yaw"); @@ -87,26 +64,6 @@ public static Packet getMoveOnlyPacket(ClientPlayerEntity playerEntity, Packe e.printStackTrace(); return packet; } - -// try { -// Field xField = PlayerMoveC2SPacket.class.getDeclaredField("x"); -// Field yField = PlayerMoveC2SPacket.class.getDeclaredField("y"); -// Field zField = PlayerMoveC2SPacket.class.getDeclaredField("z"); -// -// xField.setAccessible(true); -// yField.setAccessible(true); -// zField.setAccessible(true); -// -// double x = xField.getDouble(packet); -// double y = yField.getDouble(packet); -// double z = zField.getDouble(packet); -// -// PlayerMoveC2SPacket moveC2SPacket = (PlayerMoveC2SPacket) packet; -// return new PlayerMoveC2SPacket.PositionOnly(x, y, z, moveC2SPacket.isOnGround()); -// } catch (NoSuchFieldException | IllegalAccessException e) { -// e.printStackTrace(); -// return packet; -// } } protected static float getRequiredYaw(ClientPlayerEntity playerEntity, Direction playerShouldBeFacing) { @@ -125,4 +82,17 @@ protected static float getRequiredPitch(ClientPlayerEntity playerEntity, Directi return Math.abs(pitch) < 40 ? pitch : pitch / Math.abs(pitch) * 40; } } + + public enum NewBlocks { + LICHEN(AbstractLichenBlock.class), + ROD(RodBlock.class), + CANDLES(CandleBlock.class), + AMETHYST(AmethystClusterBlock.class); + + public Class clazz; + + NewBlocks(Class clazz) { + this.clazz = clazz; + } + } } diff --git a/src/main/java/me/aleksilassila/litematica/printer/printer/ClickGuide.java b/src/main/java/me/aleksilassila/litematica/printer/printer/ClickGuide.java index 0441d56a3..ab9a4ab43 100644 --- a/src/main/java/me/aleksilassila/litematica/printer/printer/ClickGuide.java +++ b/src/main/java/me/aleksilassila/litematica/printer/printer/ClickGuide.java @@ -1,5 +1,6 @@ package me.aleksilassila.litematica.printer.printer; +import me.aleksilassila.litematica.printer.interfaces.Implementation; import net.minecraft.block.*; import net.minecraft.item.Item; import net.minecraft.item.Items; @@ -9,7 +10,7 @@ public enum ClickGuide { SNOW(SnowBlock.class), - CANDLES(AbstractCandleBlock.class), + CANDLES(Implementation.NewBlocks.CANDLES.clazz), LEVER(LeverBlock.class), REPEATER(RepeaterBlock.class), COMPARATOR(ComparatorBlock.class), @@ -28,7 +29,8 @@ public enum ClickGuide { private static ClickGuide getGuide(BlockState requiredState, BlockState currentState) { for (ClickGuide guide : ClickGuide.values()) { for (Class clazz : guide.matchClasses) { - if (clazz.isInstance(requiredState.getBlock()) && + if (clazz != null && + clazz.isInstance(requiredState.getBlock()) && clazz.isInstance(currentState.getBlock())) { return guide; } @@ -40,41 +42,41 @@ private static ClickGuide getGuide(BlockState requiredState, BlockState currentS public static Click shouldClickBlock(BlockState requiredState, BlockState currentState) { switch(getGuide(requiredState, currentState)) { - case SNOW -> { + case SNOW: { if (currentState.get(SnowBlock.LAYERS) < requiredState.get(SnowBlock.LAYERS)) { return new Click(true, Items.SNOW); } } - case DOOR -> { + case DOOR: { if (requiredState.get(DoorBlock.OPEN) != currentState.get(DoorBlock.OPEN)) return new Click(true); } - case LEVER -> { + case LEVER: { System.out.println("Caught lever, required: " + requiredState.get(LeverBlock.POWERED) + ", current: " + currentState.get(LeverBlock.POWERED)); if (requiredState.get(LeverBlock.POWERED) != currentState.get(LeverBlock.POWERED)) return new Click(true); } - case CANDLES -> { - if (currentState.get(CandleBlock.CANDLES) < requiredState.get(CandleBlock.CANDLES)) + case CANDLES: { + if ((Integer) PrinterUtils.getPropertyByName(currentState, "CANDLES") < (Integer) PrinterUtils.getPropertyByName(requiredState, "CANDLES")) return new Click(true, requiredState.getBlock().asItem()); } - case PICKLES -> { + case PICKLES: { if (currentState.get(SeaPickleBlock.PICKLES) < requiredState.get(SeaPickleBlock.PICKLES)) return new Click(true, Items.SEA_PICKLE); } - case REPEATER -> { + case REPEATER: { if (!Objects.equals(requiredState.get(RepeaterBlock.DELAY), currentState.get(RepeaterBlock.DELAY))) return new Click(true); } - case COMPARATOR -> { + case COMPARATOR: { if (requiredState.get(ComparatorBlock.MODE) != currentState.get(ComparatorBlock.MODE)) return new Click(true); } - case TRAPDOOR -> { + case TRAPDOOR: { if (requiredState.get(TrapdoorBlock.OPEN) != currentState.get(TrapdoorBlock.OPEN)) return new Click(true); } - case FENCE -> { + case FENCE: { if (requiredState.get(FenceGateBlock.OPEN) != currentState.get(FenceGateBlock.OPEN)) return new Click(true); } diff --git a/src/main/java/me/aleksilassila/litematica/printer/printer/PlacementGuide.java b/src/main/java/me/aleksilassila/litematica/printer/printer/PlacementGuide.java index f9f11eba1..06e7ed556 100644 --- a/src/main/java/me/aleksilassila/litematica/printer/printer/PlacementGuide.java +++ b/src/main/java/me/aleksilassila/litematica/printer/printer/PlacementGuide.java @@ -1,5 +1,6 @@ package me.aleksilassila.litematica.printer.printer; +import me.aleksilassila.litematica.printer.interfaces.Implementation; import net.minecraft.block.*; import net.minecraft.block.enums.*; import net.minecraft.state.property.DirectionProperty; @@ -9,7 +10,7 @@ import org.jetbrains.annotations.Nullable; public enum PlacementGuide { - ROD(RodBlock.class), + ROD(Implementation.NewBlocks.ROD.clazz), WALLTORCH(WallTorchBlock.class), TORCH(TorchBlock.class), SLAB(SlabBlock.class), @@ -25,12 +26,12 @@ public enum PlacementGuide { SHULKER(ShulkerBoxBlock.class), BED(BedBlock.class), BELL(BellBlock.class), - AMETHYST(AmethystClusterBlock.class), + AMETHYST(Implementation.NewBlocks.AMETHYST.clazz), DOOR(DoorBlock.class), COCOA(CocoaBlock.class), OBSERVER(ObserverBlock.class), WALLSKULL(WallSkullBlock.class), - SKIP(SkullBlock.class, GrindstoneBlock.class, SignBlock.class, AbstractLichenBlock.class, VineBlock.class), + SKIP(SkullBlock.class, GrindstoneBlock.class, SignBlock.class, Implementation.NewBlocks.LICHEN.clazz, VineBlock.class), DEFAULT; private final Class[] matchClasses; @@ -42,7 +43,7 @@ public enum PlacementGuide { private static PlacementGuide getGuide(BlockState requiredState) { for (PlacementGuide guide : PlacementGuide.values()) { for (Class clazz : guide.matchClasses) { - if (clazz.isInstance(requiredState.getBlock())) { + if (clazz != null && clazz.isInstance(requiredState.getBlock())) { return guide; } } @@ -53,51 +54,65 @@ private static PlacementGuide getGuide(BlockState requiredState) { public static Placement getPlacement(BlockState requiredState) { switch (getGuide(requiredState)) { - case WALLTORCH, ROD, AMETHYST, SHULKER -> { - return new Placement(((Direction) getPropertyByName(requiredState, "FACING")).getOpposite(), + case WALLTORCH: + case ROD: + case AMETHYST: + case SHULKER: { + return new Placement(((Direction) PrinterUtils.getPropertyByName(requiredState, "FACING")).getOpposite(), null, null); } - case SLAB -> { + case SLAB: { Direction half = requiredState.get(SlabBlock.TYPE) == SlabType.BOTTOM ? Direction.DOWN : Direction.UP; return new Placement(half, null, null); } - case STAIR -> { + case STAIR: { return new Placement(requiredState.get(StairsBlock.FACING), // FIXME before shipping - Vec3d.of(getHalf(requiredState.get(StairsBlock.HALF)).getVector()).multiply(0.25), //getHalf(requiredState.get(StairsBlock.HALF)), + Vec3d.of(PrinterUtils.getHalf(requiredState.get(StairsBlock.HALF)).getVector()).multiply(0.25), //getHalf(requiredState.get(StairsBlock.HALF)), requiredState.get(StairsBlock.FACING)); } - case TRAPDOOR -> { - return new Placement(getHalf(requiredState.get(TrapdoorBlock.HALF)), + case TRAPDOOR: { + return new Placement(PrinterUtils.getHalf(requiredState.get(TrapdoorBlock.HALF)), null, //getHalf(requiredState.get(TrapdoorBlock.HALF)), requiredState.get(StairsBlock.FACING).getOpposite()); } - case PILLAR -> { - return new Placement(axisToDirection(requiredState.get(PillarBlock.AXIS)), + case PILLAR: { + return new Placement(PrinterUtils.axisToDirection(requiredState.get(PillarBlock.AXIS)), null, null, true); } - case ANVIL -> { + case ANVIL: { return new Placement(null, null, requiredState.get(AnvilBlock.FACING).rotateYCounterclockwise()); } - case HOPPER, COCOA -> { - return new Placement((Direction) getPropertyByName(requiredState, "FACING"), + case HOPPER: + case COCOA: { + return new Placement((Direction) PrinterUtils.getPropertyByName(requiredState, "FACING"), null, null); } - case WALLMOUNTED -> { - Direction side = switch ((WallMountLocation) getPropertyByName(requiredState, "FACE")) { - case FLOOR -> Direction.DOWN; - case CEILING -> Direction.UP; - default -> ((Direction) getPropertyByName(requiredState, "FACING")).getOpposite(); - }; + case WALLMOUNTED: { + Direction side; + switch ((WallMountLocation) PrinterUtils.getPropertyByName(requiredState, "FACE")) { + case FLOOR: { + side = Direction.DOWN; + break; + } + case CEILING: { + side = Direction.UP; + break; + } + default: { + side = ((Direction) PrinterUtils.getPropertyByName(requiredState, "FACING")).getOpposite(); + break; + } + } - Direction look = getPropertyByName(requiredState, "FACE") == WallMountLocation.WALL ? - null : (Direction) getPropertyByName(requiredState, "FACING"); + Direction look = PrinterUtils.getPropertyByName(requiredState, "FACE") == WallMountLocation.WALL ? + null : (Direction) PrinterUtils.getPropertyByName(requiredState, "FACING"); return new Placement(side, null, @@ -117,24 +132,35 @@ public static Placement getPlacement(BlockState requiredState) { // Vec3d.of(side.getVector()).multiply(0.5), // look); // } - case GATE, CAMPFIRE -> { + case GATE: + case CAMPFIRE: { return new Placement(null, null, - (Direction) getPropertyByName(requiredState, "FACING")); + (Direction) PrinterUtils.getPropertyByName(requiredState, "FACING")); } - case BED -> { + case BED: { if (requiredState.get(BedBlock.PART) != BedPart.FOOT) { return new Placement(); } else { return new Placement(null, null, requiredState.get(BedBlock.FACING)); } } - case BELL -> { - Direction side = switch (requiredState.get(BellBlock.ATTACHMENT)) { - case FLOOR -> Direction.DOWN; - case CEILING -> Direction.UP; - default -> requiredState.get(BellBlock.FACING); - }; + case BELL: { + Direction side; + switch (requiredState.get(BellBlock.ATTACHMENT)) { + case FLOOR: { + side = Direction.DOWN; + break; + } + case CEILING: { + side = Direction.UP; + break; + } + default: { + side = requiredState.get(BellBlock.FACING); + break; + } + } Direction look = requiredState.get(BellBlock.ATTACHMENT) != Attachment.SINGLE_WALL && requiredState.get(BellBlock.ATTACHMENT) != Attachment.DOUBLE_WALL ? @@ -144,7 +170,7 @@ public static Placement getPlacement(BlockState requiredState) { null, look); } - case DOOR -> { + case DOOR: { Direction hinge = requiredState.get(DoorBlock.FACING); if (requiredState.get(DoorBlock.HINGE) == DoorHinge.RIGHT) { hinge = hinge.rotateYClockwise(); @@ -157,13 +183,13 @@ public static Placement getPlacement(BlockState requiredState) { hitModifier, requiredState.get(DoorBlock.FACING)); } - case WALLSKULL -> { + case WALLSKULL: { return new Placement(requiredState.get(WallSkullBlock.FACING).getOpposite(), null, null); } - case SKIP -> { + case SKIP: { return new Placement(); } - default -> { // Try to guess how the rest of the blocks are placed. + default: { // Try to guess how the rest of the blocks are placed. Direction look = null; for (Property prop : requiredState.getProperties()) { @@ -177,28 +203,6 @@ public static Placement getPlacement(BlockState requiredState) { } } - private static Direction getHalf(BlockHalf half) { - return half == BlockHalf.TOP ? Direction.UP : Direction.DOWN; - } - - private static Direction axisToDirection(Direction.Axis axis) { - for (Direction direction : Direction.values()) { - if (direction.getAxis() == axis) return direction; - } - - return Direction.DOWN; - } - - private static Comparable getPropertyByName(BlockState state, String name) { - for (Property prop : state.getProperties()) { - if (prop.getName().equalsIgnoreCase(name)) { - return state.get(prop); - } - } - - return null; - } - public static class Placement { @Nullable public final Direction side; diff --git a/src/main/java/me/aleksilassila/litematica/printer/printer/PrinterUtils.java b/src/main/java/me/aleksilassila/litematica/printer/printer/PrinterUtils.java index ef9937b4c..3d66a1923 100644 --- a/src/main/java/me/aleksilassila/litematica/printer/printer/PrinterUtils.java +++ b/src/main/java/me/aleksilassila/litematica/printer/printer/PrinterUtils.java @@ -154,4 +154,26 @@ protected static boolean isDoubleSlab(BlockState state) { protected static boolean isHalfSlab(BlockState state) { return state.contains(SlabBlock.TYPE) && state.get(SlabBlock.TYPE) != SlabType.DOUBLE; } + + public static Direction getHalf(BlockHalf half) { + return half == BlockHalf.TOP ? Direction.UP : Direction.DOWN; + } + + public static Direction axisToDirection(Direction.Axis axis) { + for (Direction direction : Direction.values()) { + if (direction.getAxis() == axis) return direction; + } + + return Direction.DOWN; + } + + public static Comparable getPropertyByName(BlockState state, String name) { + for (Property prop : state.getProperties()) { + if (prop.getName().equalsIgnoreCase(name)) { + return state.get(prop); + } + } + + return null; + } }