Skip to content

Commit

Permalink
Implemented block clicking rules, and wrongly printed blocks wont be …
Browse files Browse the repository at this point in the history
…placed at all

 - Todo: Fix the look packet blocking
  • Loading branch information
aleksilassila committed Dec 16, 2021
1 parent 498320c commit 1c4050d
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class LitematicaMixinMod implements ModInitializer {
public static final ConfigInteger PRINT_INTERVAL = new ConfigInteger( "printInterval", 4, 2, 20, "Print interval in game ticks. Lower values mean faster printing speed.\nIf the printer creates \"ghost blocks\", raise this value.");
public static final ConfigInteger PRINTING_RANGE = new ConfigInteger("printingRange", 2, 1, 6, "Printing block place range\nLower values are recommended for servers.");
// public static final ConfigBoolean PRINT_WATER = new ConfigBoolean("printWater", false, "Whether or not the printer should place water\n source blocks or make blocks waterlogged.");
public static final ConfigBoolean PRINT_IN_AIR = new ConfigBoolean("printInAir", false, "Whether or not the printer should place blocks without anything to build on.\nBe aware that some anti-cheat plugins might notice this.");
// public static final ConfigBoolean PRINT_IN_AIR = new ConfigBoolean("printInAir", false, "Whether or not the printer should place blocks without anything to build on.\nBe aware that some anti-cheat plugins might notice this.");
public static final ConfigBoolean PRINT_MODE = new ConfigBoolean("printingMode", false, "Autobuild / print loaded selection.\nBe aware that some servers and anticheat plugins do not allow printing.");
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.add(PRINT_INTERVAL);
list.add(PRINTING_RANGE);
list.add(PRINT_IN_AIR);
// list.add(PRINT_IN_AIR);
list.add(PRINT_MODE);
list.add(REPLACE_FLUIDS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public void sendPacket(Packet<?> packet, CallbackInfo ci) {
}

return;
} else {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
Expand All @@ -31,13 +30,6 @@ public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {

protected Printer printer;

@Inject(at = @At("RETURN"), method = "isCamera", cancellable = true)
protected void isCamera(CallbackInfoReturnable<Boolean> cir) {
if (printer != null && printer.lockCamera) {
cir.setReturnValue(false); // Fix for placing correctly pistons for example
}
}

@Inject(at = @At("HEAD"), method = "tick")
public void tick(CallbackInfo ci) {
if (!didCheckForUpdates) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package me.aleksilassila.litematica.printer.printer;

import net.minecraft.block.*;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public enum ClickGuide {
SNOW(SnowBlock.class),
CANDLES(AbstractCandleBlock.class),
LEVER(LeverBlock.class),
REPEATER(RepeaterBlock.class),
COMPARATOR(ComparatorBlock.class),
TRAPDOOR(TrapdoorBlock.class),
DOOR(DoorBlock.class),
PICKLES(SeaPickleBlock.class),
FENCE(FenceGateBlock.class),
DEFAULT;

private final Class<?>[] matchClasses;

ClickGuide(Class<?> ... classes) {
matchClasses = classes;
}

private static ClickGuide getGuide(BlockState requiredState, BlockState currentState) {
for (ClickGuide guide : ClickGuide.values()) {
for (Class<?> clazz : guide.matchClasses) {
if (clazz.isInstance(requiredState.getBlock()) &&
clazz.isInstance(currentState.getBlock())) {
return guide;
}
}
}

return DEFAULT;
}

public static Click shouldClickBlock(BlockState requiredState, BlockState currentState) {
switch(getGuide(requiredState, currentState)) {
case SNOW -> {
if (currentState.get(SnowBlock.LAYERS) < requiredState.get(SnowBlock.LAYERS)) {
return new Click(true, Items.SNOW);
}
}
case DOOR -> {
if (requiredState.get(DoorBlock.OPEN) != currentState.get(DoorBlock.OPEN))
return new Click(true);
}
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))
return new Click(true, requiredState.getBlock().asItem());
}
case PICKLES -> {
if (currentState.get(SeaPickleBlock.PICKLES) < requiredState.get(SeaPickleBlock.PICKLES))
return new Click(true, Items.SEA_PICKLE);
}
case REPEATER -> {
if (!Objects.equals(requiredState.get(RepeaterBlock.DELAY), currentState.get(RepeaterBlock.DELAY)))
return new Click(true);
}
case COMPARATOR -> {
if (requiredState.get(ComparatorBlock.MODE) != currentState.get(ComparatorBlock.MODE))
return new Click(true);
}
case TRAPDOOR -> {
if (requiredState.get(TrapdoorBlock.OPEN) != currentState.get(TrapdoorBlock.OPEN))
return new Click(true);
}
case FENCE -> {
if (requiredState.get(FenceGateBlock.OPEN) != currentState.get(FenceGateBlock.OPEN))
return new Click(true);
}
}

return new Click();
}

public static class Click {
public final boolean click;
@Nullable
public final Item item;

public Click(boolean click, @Nullable Item item) {
this.click = click;
this.item = item;
}

public Click(boolean click) {
this(click, null);
}

public Click() {
this(false, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import net.minecraft.state.property.Property;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public enum PlacementGuide {
Expand All @@ -21,14 +19,16 @@ public enum PlacementGuide {
ANVIL(AnvilBlock.class),
HOPPER(HopperBlock.class),
WALLMOUNTED(LeverBlock.class, AbstractButtonBlock.class),
GRINDSTONE(GrindstoneBlock.class),
// GRINDSTONE(GrindstoneBlock.class),
GATE(FenceGateBlock.class),
CAMPFIRE(CampfireBlock.class),
SHULKER(ShulkerBoxBlock.class),
BED(BedBlock.class),
BELL(BellBlock.class),
AMETHYST(AmethystClusterBlock.class),
DOOR(DoorBlock.class),
COCOA(CocoaBlock.class),
SKIP(SkullBlock.class, GrindstoneBlock.class, SignBlock.class, AbstractLichenBlock.class, VineBlock.class),
DEFAULT;

private final Class<?>[] matchClasses;
Expand All @@ -51,7 +51,7 @@ private static PlacementGuide getGuide(BlockState requiredState) {

public static Placement getPlacement(BlockState requiredState) {
switch (getGuide(requiredState)) {
case TORCH, ROD, AMETHYST -> { // FIXME check if the wall exists?
case WALLTORCH, ROD, AMETHYST -> { // FIXME check if the wall exists?
return new Placement(((Direction) getPropertyByName(requiredState, "FACING")).getOpposite(),
null,
null);
Expand Down Expand Up @@ -82,8 +82,8 @@ public static Placement getPlacement(BlockState requiredState) {
null,
requiredState.get(AnvilBlock.FACING).rotateYCounterclockwise());
}
case HOPPER -> {
return new Placement(requiredState.get(HopperBlock.FACING),
case HOPPER, COCOA -> {
return new Placement((Direction) getPropertyByName(requiredState, "FACING"),
null,
null);
}
Expand Down Expand Up @@ -160,6 +160,9 @@ public static Placement getPlacement(BlockState requiredState) {
hitModifier,
requiredState.get(DoorBlock.FACING));
}
case SKIP -> {
return new Placement();
}
default -> { // Try to guess how the rest of the blocks are placed.
Direction look = null;

Expand Down Expand Up @@ -225,39 +228,4 @@ public Placement() {
this.skip = true;
}
}
//
// public enum PlacementSide {
// FORWARD,
// BACKWARDS,
// RIGHT,
// LEFT,
// UP,
// DOWN,
// UNDEFINED;
// }
//
// private enum PlacementHalf {
// TOP,
// BOTTOM,
// UNDEFINED;
// }
//
// public enum PlacementLookDirection {
// FORWARD,
// BACKWARDS,
// RIGHT,
// LEFT,
// UP,
// DOWN,
// UNDEFINED;
// }
}
/*
PlacementGuide.getPlacement(requiredState)
-> requiredState
Block class, State
return where to click
*/
Loading

0 comments on commit 1c4050d

Please sign in to comment.