Skip to content

Commit

Permalink
Fixed following placements:
Browse files Browse the repository at this point in the history
 - Dripleaf stems
 - Flower pots (partly)
 - Farmland in survival
 - Stripped logs
 - Note block correct notes
 - End portal frame ender eye placement
 - Unlit campfires
 - Dirt paths
  • Loading branch information
aleksilassila committed Jan 10, 2022
1 parent f65318a commit 9ea3177
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import fi.dy.masa.malilib.config.options.ConfigBoolean;
import fi.dy.masa.malilib.config.options.ConfigHotkey;
import fi.dy.masa.malilib.config.options.ConfigInteger;
import fi.dy.masa.malilib.gui.GuiKeybindSettings;
import fi.dy.masa.malilib.hotkeys.KeyCallbackToggleBooleanConfigWithMessage;
import fi.dy.masa.malilib.hotkeys.KeybindSettings;
import net.fabricmc.api.ModInitializer;

import java.util.List;
Expand All @@ -18,24 +20,26 @@ 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", true, "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 final ConfigBoolean STRIP_LOGS = new ConfigBoolean("stripLogs", false, "Whether or not the printer should use normal logs if stripped\nversions are not available and then strip them with an axe.");

public static ImmutableList<IConfigBase> getConfigList() {
List<IConfigBase> list = new java.util.ArrayList<>(Configs.Generic.OPTIONS);
list.add(PRINT_MODE);
list.add(PRINT_INTERVAL);
list.add(PRINTING_RANGE);
// list.add(PRINT_IN_AIR);
list.add(PRINT_MODE);
list.add(PRINT_IN_AIR);
list.add(REPLACE_FLUIDS);
list.add(STRIP_LOGS);

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 final ConfigHotkey PRINT = new ConfigHotkey("print", "V", KeybindSettings.PRESS_ALLOWEXTRA_EMPTY, "Prints while pressed");
public static final ConfigHotkey TOGGLE_PRINTING_MODE = new ConfigHotkey("togglePrintingMode", "CAPS_LOCK", KeybindSettings.PRESS_ALLOWEXTRA_EMPTY, "Allows quickly toggling on/off Printing mode");

public static List<ConfigHotkey> getHotkeyList() {
List<ConfigHotkey> list = new java.util.ArrayList<>(Hotkeys.HOTKEY_LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void rightClickBlock(BlockPos pos, Direction side, Vec3d hitVec)
interactBlock(client.player, client.world, Hand.MAIN_HAND,
new BlockHitResult(hitVec, side, pos, false));
interactItem(client.player, client.world, Hand.MAIN_HAND);
System.out.println("Printer interactBlock: pos: (" + pos.toShortString() + "), side: " + side.getName() + ", vector: " + hitVec.toString());
// System.out.println("Printer interactBlock: pos: (" + pos.toShortString() + "), side: " + side.getName() + ", vector: " + hitVec.toString());
}

@Shadow
Expand All @@ -42,8 +42,8 @@ public abstract ActionResult interactBlock(
public abstract ActionResult interactItem(PlayerEntity playerEntity_1,
World world_1, Hand hand_1);

@Inject(at = @At("HEAD"), method = "interactBlock")
public void interactBlock(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
System.out.println("Player interactBlock: pos: (" + hitResult.getBlockPos().toShortString() + "), side: " + hitResult.getSide().getName() + ", vector: " + hitResult.getPos().toString());
}
// @Inject(at = @At("HEAD"), method = "interactBlock")
// public void interactBlock(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
// System.out.println("Player interactBlock: pos: (" + hitResult.getBlockPos().toShortString() + "), side: " + hitResult.getSide().getName() + ", vector: " + hitResult.getPos().toString());
// }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.aleksilassila.litematica.printer.printer;

import me.aleksilassila.litematica.printer.interfaces.Implementation;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.fabricmc.fabric.mixin.content.registry.AxeItemAccessor;
import net.minecraft.block.*;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
Expand All @@ -18,6 +20,10 @@ public enum ClickGuide {
DOOR(DoorBlock.class),
PICKLES(SeaPickleBlock.class),
FENCE(FenceGateBlock.class),
NOTE_BLOCK(NoteBlock.class),
CAMPFIRE(CampfireBlock.class),
PILLAR(PillarBlock.class),
END_PORTAL_FRAME(EndPortalFrameBlock.class),
DEFAULT;

private final Class<?>[] matchClasses;
Expand Down Expand Up @@ -95,6 +101,40 @@ public static Click shouldClickBlock(BlockState requiredState, BlockState curren
if (requiredState.get(FenceGateBlock.OPEN) != currentState.get(FenceGateBlock.OPEN))
return new Click(true);

break;
}
case NOTE_BLOCK: {
if (!Objects.equals(requiredState.get(NoteBlock.NOTE), currentState.get(NoteBlock.NOTE)))
return new Click(true);

break;
}
case CAMPFIRE: {
if (requiredState.get(CampfireBlock.LIT) != currentState.get(CampfireBlock.LIT))
return new Click(true, FabricToolTags.SHOVELS.values().toArray(Item[]::new));

break;
}
case PILLAR: {
Block stripped = AxeItemAccessor.getStrippedBlocks().get(currentState.getBlock());
if (stripped != null && stripped == requiredState.getBlock()) {
return new Click(true, FabricToolTags.AXES.values().toArray(Item[]::new));
}
break;
}
case END_PORTAL_FRAME: {
if (requiredState.get(EndPortalFrameBlock.EYE) && !currentState.get(EndPortalFrameBlock.EYE))
return new Click(true, Items.ENDER_EYE);

break;
}
case DEFAULT: {
if (currentState.getBlock().equals(Blocks.DIRT) && requiredState.getBlock().equals(Blocks.FARMLAND)) {
return new Click(true, FabricToolTags.HOES.values().toArray(Item[]::new));
} else if (currentState.getBlock().equals(Blocks.DIRT) && requiredState.getBlock().equals(Blocks.DIRT_PATH)) {
return new Click(true, FabricToolTags.SHOVELS.values().toArray(Item[]::new));
}

break;
}
}
Expand All @@ -105,11 +145,11 @@ public static Click shouldClickBlock(BlockState requiredState, BlockState curren
public static class Click {
public final boolean click;
@Nullable
public final Item item;
public final Item[] items;

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

public Click(boolean click) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package me.aleksilassila.litematica.printer.printer;

import me.aleksilassila.litematica.printer.LitematicaMixinMod;
import me.aleksilassila.litematica.printer.interfaces.Implementation;
import net.fabricmc.fabric.api.tag.FabricTag;
import net.fabricmc.fabric.mixin.content.registry.AxeItemAccessor;
import net.minecraft.block.*;
import net.minecraft.block.enums.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.AxeItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Property;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public enum PlacementGuide {
Expand All @@ -20,7 +28,7 @@ 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),
Expand All @@ -32,11 +40,14 @@ public enum PlacementGuide {
OBSERVER(ObserverBlock.class),
WALLSKULL(WallSkullBlock.class),
SKIP(SkullBlock.class, GrindstoneBlock.class, SignBlock.class, Implementation.NewBlocks.LICHEN.clazz, VineBlock.class),
FARMLAND(FarmlandBlock.class),
FLOWER_POT(FlowerPotBlock.class),
BIG_DRIPLEAF_STEM(BigDripleafStemBlock.class),
DEFAULT;

private final Class<?>[] matchClasses;

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

Expand All @@ -52,7 +63,12 @@ private static PlacementGuide getGuide(BlockState requiredState) {
return DEFAULT;
}

public static Placement getPlacement(BlockState requiredState) {
public static Placement getPlacement(BlockState requiredState, MinecraftClient client) {
Placement placement = _getPlacement(requiredState, client);
return placement.setItem(placement.item == null ? requiredState.getBlock().asItem() : placement.item);
}

private static Placement _getPlacement(BlockState requiredState, MinecraftClient client) {
switch (getGuide(requiredState)) {
case WALLTORCH:
case ROD:
Expand All @@ -79,9 +95,28 @@ public static Placement getPlacement(BlockState requiredState) {
requiredState.get(StairsBlock.FACING).getOpposite());
}
case PILLAR: {
return new Placement(PrinterUtils.axisToDirection(requiredState.get(PillarBlock.AXIS)),
Placement placement = new Placement(PrinterUtils.axisToDirection(requiredState.get(PillarBlock.AXIS)),
null,
null, true);
null).setSideIsAxis(true);

// If is stripped log && should use normal log instead
if (AxeItemAccessor.getStrippedBlocks().containsValue(requiredState.getBlock()) &&
LitematicaMixinMod.STRIP_LOGS.getBooleanValue()) {
Block stripped = requiredState.getBlock();

for (Block log : AxeItemAccessor.getStrippedBlocks().keySet()) {
if (AxeItemAccessor.getStrippedBlocks().get(log) != stripped) continue;

if (!PrinterUtils.playerHasAccessToItem(client.player, stripped.asItem()) &&
PrinterUtils.playerHasAccessToItem(client.player, log.asItem())) {
placement.item = log.asItem();
}
break;

}
}

return placement;
}
case ANVIL: {
return new Placement(null,
Expand Down Expand Up @@ -133,6 +168,7 @@ public static Placement getPlacement(BlockState requiredState) {
// look);
// }
case GATE:
case OBSERVER:
case CAMPFIRE: {
return new Placement(null,
null,
Expand Down Expand Up @@ -189,6 +225,18 @@ public static Placement getPlacement(BlockState requiredState) {
case SKIP: {
return new Placement();
}
case FARMLAND: {
if (!PrinterUtils.playerHasAccessToItem(client.player, requiredState.getBlock().asItem())) {
return new Placement(null, null, null).setItem(Items.DIRT);
}
break;
}
case FLOWER_POT: {
return new Placement(null, null, null).setItem(Items.FLOWER_POT);
}
case BIG_DRIPLEAF_STEM: {
return new Placement(null, null, null).setItem(Items.BIG_DRIPLEAF);
}
default: { // Try to guess how the rest of the blocks are placed.
Direction look = null;

Expand All @@ -198,13 +246,20 @@ public static Placement getPlacement(BlockState requiredState) {
}
}

return new Placement(null, null, look);
Placement placement = new Placement(null, null, look);

// If required == dirt path place dirt
if (requiredState.getBlock().equals(Blocks.DIRT_PATH) && !PrinterUtils.playerHasAccessToItem(client.player, requiredState.getBlock().asItem())) {
placement.setItem(Items.DIRT);
}

return placement;
}
}
}

public static class Placement {
@Nullable
@NotNull
public final Direction side;
@Nullable
public final Vec3d hitModifier;
Expand All @@ -216,21 +271,18 @@ public static class Placement {
boolean cantPlaceInAir = false;
boolean skip;

public Placement(@Nullable Direction side, @Nullable Vec3d hitModifier, @Nullable Direction look, boolean sideIsAxis) {
this.side = side;
Item item = null;

public Placement(@Nullable Direction side, @Nullable Vec3d hitModifier, @Nullable Direction look) {
this.side = side == null ? Direction.DOWN : side;
this.hitModifier = hitModifier;
this.look = look;

this.sideIsAxis = sideIsAxis;
this.skip = false;
}

public Placement(@Nullable Direction side, @Nullable Vec3d hitModifier, @Nullable Direction look) {
this(side, hitModifier, look, false);
}

public Placement() {
this(null, null, null, false);
this(null, null, null);
this.skip = true;
}

Expand All @@ -244,5 +296,10 @@ public Placement setCantPlaceInAir(boolean cantPlaceInAir) {
this.cantPlaceInAir = cantPlaceInAir;
return this;
}

public Placement setItem(Item item) {
this.item = item;
return this;
}
}
}
Loading

0 comments on commit 9ea3177

Please sign in to comment.