Skip to content

Commit

Permalink
Merge branch 'printing_1.17' into printing
Browse files Browse the repository at this point in the history
1.16 compatibility
  • Loading branch information
aleksilassila committed Dec 17, 2021
2 parents 62d2080 + 2d64f8f commit 22aeab0
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 120 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}


sourceCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_1_8 // For that 1.16 compatibility
targetCompatibility = JavaVersion.VERSION_17


Expand Down Expand Up @@ -80,4 +80,4 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IConfigBase> getConfigList() {
List<IConfigBase> list = new java.util.ArrayList<>(List.copyOf(Configs.Generic.OPTIONS));
List<IConfigBase> list = new java.util.ArrayList<>(Configs.Generic.OPTIONS);
list.add(PRINT_INTERVAL);
list.add(PRINTING_RANGE);
// list.add(PRINT_IN_AIR);
Expand All @@ -32,13 +32,13 @@ public static ImmutableList<IConfigBase> 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<ConfigHotkey> getHotkeyList() {
List<ConfigHotkey> list = new java.util.ArrayList<>(List.copyOf(Hotkeys.HOTKEY_LIST));
List<ConfigHotkey> list = new java.util.ArrayList<>(Hotkeys.HOTKEY_LIST);
list.add(PRINT);
list.add(TOGGLE_PRINTING_MODE);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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) {
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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),
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 22aeab0

Please sign in to comment.