Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Dec 6, 2022
1 parent ad67ee4 commit 93e8cc6
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import me.aleksilassila.litematica.printer.v1_19.actions.PrepareAction;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.Direction;

import java.util.LinkedList;
import java.util.List;
Expand All @@ -25,7 +24,7 @@ public ActionHandler(MinecraftClient client, ClientPlayerEntity player) {
private int tick = 0;

public void onGameTick() {
int tickRate = LitematicaMixinMod.PRINT_INTERVAL.getIntegerValue();
int tickRate = LitematicaMixinMod.PRINTING_INTERVAL.getIntegerValue();

tick = tick % tickRate == tickRate - 1 ? 0 : tick + 1;
if (tick % tickRate != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
public class LitematicaMixinMod implements ModInitializer {

public static Printer printer;
public static boolean DEBUG = true;
public static boolean DEBUG = false;
// Config settings
public static final ConfigInteger PRINT_INTERVAL = new ConfigInteger("printInterval", 12, 1, 40, "Printing interval. Lower values mean faster printing speed.\nIf the printer creates \"ghost blocks\" or blocks are facing the wrong way, raise this value.");
public static final ConfigInteger PRINTING_INTERVAL = new ConfigInteger("printingInterval", 12, 1, 40, "Printing interval. Lower values mean faster printing speed.\nIf the printer creates \"ghost blocks\" or blocks are facing the wrong way, raise this value.");
public static final ConfigDouble PRINTING_RANGE = new ConfigDouble("printingRange", 2, 1, 5, "Printing block place range\nLower values are recommended for servers.");
// public static final ConfigBoolean PRINT_WATER = new ConfigBoolean("printWater", false, "Whether the printer should place water\n source blocks or make blocks waterlogged.");
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_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_SOURCE_BLOCKS = new ConfigBoolean("replaceFluidSourceBlocks", true, "Whether or not fluid source blocks should be replaced by the printer.");
public static final ConfigBoolean STRIP_LOGS = new ConfigBoolean("stripLogs", true, "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_INTERVAL);
list.add(PRINTING_RANGE);
list.add(PRINT_IN_AIR);
// list.add(PRINT_IN_AIR);
list.add(REPLACE_FLUIDS_SOURCE_BLOCKS);
list.add(STRIP_LOGS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class PrinterPlacementContext extends ItemPlacementContext {
public final @Nullable Direction lookDirection;
public final boolean shouldSneak;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.ComparatorBlock;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.property.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import java.util.List;

/**
* Guide that clicks the current block to change its state.
* A guide that clicks the current block to change its state.
*/

public abstract class InteractionGuide extends Guide {
public InteractionGuide(SchematicBlockState state) {
super(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import net.minecraft.block.*;
import net.minecraft.block.enums.SlabType;

public class BlockIndifferentGuesserGuide extends GuesserGuide {
public BlockIndifferentGuesserGuide(SchematicBlockState state) {
Expand Down Expand Up @@ -38,10 +37,6 @@ protected boolean statesEqual(BlockState resultState, BlockState targetState) {
TripwireBlock.EAST, TripwireBlock.SOUTH, TripwireBlock.WEST);
}

// if (getProperty(targetState, SlabBlock.TYPE).orElse(null) == SlabType.DOUBLE && resultBlock instanceof SlabBlock) {
// return statesEqualIgnoreProperties(resultState, targetState, SlabBlock.TYPE);
// }

return super.statesEqual(resultState, targetState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Also that reversing chest connection logic is an enormous pain in the ass. I spent way too long on this.
* Thanks for coming to my ted talk
*/
public class ChestGuide extends BlockPlacementGuide {
public class ChestGuide extends GeneralPlacementGuide {
public ChestGuide(SchematicBlockState state) {
super(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Arrays;
import java.util.List;

public class FarmlandGuide extends BlockPlacementGuide {
public class FarmlandGuide extends GeneralPlacementGuide {
public static final Block[] TILLABLE_BLOCKS = new Block[]{
Blocks.DIRT,
Blocks.GRASS_BLOCK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Collections;
import java.util.List;

public class FlowerPotGuide extends BlockPlacementGuide {
public class FlowerPotGuide extends GeneralPlacementGuide {
public FlowerPotGuide(SchematicBlockState state) {
super(state);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.aleksilassila.litematica.printer.v1_19.guides.placement;

import me.aleksilassila.litematica.printer.v1_19.LitematicaMixinMod;
import me.aleksilassila.litematica.printer.v1_19.PrinterPlacementContext;
import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import net.minecraft.block.SlabBlock;
Expand All @@ -17,8 +16,12 @@
import java.util.List;
import java.util.Optional;

public class BlockPlacementGuide extends PlacementGuide {
public BlockPlacementGuide(SchematicBlockState state) {
/**
* An old school guide where there are defined specific conditions
* for player state depending on the block being placed.
*/
public class GeneralPlacementGuide extends PlacementGuide {
public GeneralPlacementGuide(SchematicBlockState state) {
super(state);
}

Expand All @@ -42,16 +45,8 @@ protected Vec3d getHitModifier(Direction validSide) {
return new Vec3d(0, 0, 0);
}

// @Override
// protected int getStackSlot(ClientPlayerEntity player) {
// List<ItemStack> requiredItems = getRequiredItems();
// if (requiredItems.isEmpty() || requiredItems.get(0) == ItemStack.EMPTY) return -1;
//
// return super.getStackSlot(player);
// }

private Optional<Direction> getValidSide(SchematicBlockState state) {
boolean printInAir = LitematicaMixinMod.PRINT_IN_AIR.getBooleanValue();
boolean printInAir = false; // LitematicaMixinMod.PRINT_IN_AIR.getBooleanValue();

List<Direction> sides = getPossibleSides();

Expand All @@ -71,15 +66,6 @@ private Optional<Direction> getValidSide(SchematicBlockState state) {
continue;
}

// if (getProperty(neighborState.currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE) != SlabType.DOUBLE)
// continue;
//
// // If neighbor is half slab
// if (!(state.targetState.getBlock() instanceof SlabBlock)
// && getProperty(neighborState.currentState, SlabBlock.TYPE).orElse(SlabType.DOUBLE) != SlabType.DOUBLE) {
// continue;
// }

if (canBeClicked(neighborState.world, neighborState.blockPos) && // Handle unclickable grass for example
!neighborState.currentState.getMaterial().isReplaceable())
validSides.add(side);
Expand All @@ -97,7 +83,7 @@ private Optional<Direction> getValidSide(SchematicBlockState state) {

protected boolean getUseShift(SchematicBlockState state) {
if (getRequiresExplicitShift()) return true;
// if (interactionDir == null) return false;

Direction clickSide = getValidSide(state).orElse(null);
if (clickSide == null) return false;
return isInteractive(state.offset(clickSide).currentState.getBlock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* It will try to predict the correct player state for producing the right blockState
* by brute forcing the correct hit vector and look direction.
*/
public class GuesserGuide extends BlockPlacementGuide {
public class GuesserGuide extends GeneralPlacementGuide {
private PrinterPlacementContext contextCache = null;

protected static Direction[] directionsToTry = new Direction[]{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Collections;
import java.util.List;

public class LogGuide extends BlockPlacementGuide {
public class LogGuide extends GeneralPlacementGuide {
public LogGuide(SchematicBlockState state) {
super(state);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package me.aleksilassila.litematica.printer.v1_19.guides.placement;

import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import net.minecraft.block.AbstractRailBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.enums.RailShape;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Direction;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class RailGuesserGuide extends GuesserGuide {
static final RailShape[] STRAIGHT_RAIL_SHAPES = new RailShape[]{
Expand All @@ -30,6 +30,13 @@ public boolean skipOtherGuides() {
protected boolean statesEqual(BlockState resultState, BlockState targetState) {
if (!wouldConnectCorrectly()) return false;
// if (wouldBlockAnotherConnection()) return false;
/*TODO: Fully working rail guesser
* If has a neighbor that:
* - Has not been placed yet
* - OR Has been placed but can change shape
* - AND this placement should connect to only one rail, that is not the neighbor
* Then return false
* */

if (getRailShape(resultState).isPresent()) {
if (Arrays.stream(STRAIGHT_RAIL_SHAPES).anyMatch(shape -> shape == getRailShape(resultState).orElse(null))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.List;
import java.util.Optional;

public class RotatingBlockGuide extends BlockPlacementGuide {
public class RotatingBlockGuide extends GeneralPlacementGuide {
public RotatingBlockGuide(SchematicBlockState state) {
super(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.enums.SlabType;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

import java.util.Arrays;
import java.util.List;

public class SlabGuide extends BlockPlacementGuide {
public class SlabGuide extends GeneralPlacementGuide {
public SlabGuide(SchematicBlockState state) {
super(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;
import java.util.Optional;

public class TorchGuide extends BlockPlacementGuide {
public class TorchGuide extends GeneralPlacementGuide {
public TorchGuide(SchematicBlockState state) {
super(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import me.aleksilassila.litematica.printer.v1_19.LitematicaMixinMod;
import me.aleksilassila.litematica.printer.v1_19.Printer;
import me.aleksilassila.litematica.printer.v1_19.actions.Action;
import me.aleksilassila.litematica.printer.v1_19.actions.PrepareAction;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.Direction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
Expand Down

0 comments on commit 93e8cc6

Please sign in to comment.