Skip to content

Commit

Permalink
Fixed options not working and added sign autofill
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Dec 5, 2022
1 parent 25e6fdc commit 33e40b0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@
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 ConfigDouble PRINTING_RANGE = new ConfigDouble("printingRange", 2, 1, 6, "Printing block place range\nLower values are recommended for servers.");
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_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 boolean shouldPrintInAir = PRINT_IN_AIR.getBooleanValue();
public static boolean shouldReplaceFluids = REPLACE_FLUIDS.getBooleanValue();
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_RANGE);
list.add(PRINT_IN_AIR);
list.add(REPLACE_FLUIDS);
list.add(REPLACE_FLUIDS_SOURCE_BLOCKS);
list.add(STRIP_LOGS);

return ImmutableList.copyOf(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean onGameTick() {

private List<BlockPos> getReachablePositions() {
int maxReach = (int) Math.ceil(LitematicaMixinMod.PRINTING_RANGE.getDoubleValue());
int maxReachSquared = (int) MathHelper.square(LitematicaMixinMod.PRINTING_RANGE.getDoubleValue());
double maxReachSquared = MathHelper.square(LitematicaMixinMod.PRINTING_RANGE.getDoubleValue());

ArrayList<BlockPos> positions = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 me.aleksilassila.litematica.printer.v1_19.actions.AbstractAction;
Expand Down Expand Up @@ -73,15 +74,14 @@ public boolean canExecute(ClientPlayerEntity player) {
ItemPlacementContext ctx = getPlacementContext(player);
if (ctx == null || !ctx.canPlace()) return false;
// if (!state.currentState.getMaterial().isReplaceable()) return false;
if (state.currentState.contains(FluidBlock.LEVEL) && state.currentState.get(FluidBlock.LEVEL) == 0)
if (!LitematicaMixinMod.REPLACE_FLUIDS_SOURCE_BLOCKS.getBooleanValue()
&& getProperty(state.currentState, FluidBlock.LEVEL).orElse(1) == 0)
return false;

BlockState resultState = getRequiredItemAsBlock(player)
.orElse(targetState.getBlock())
.getPlacementState(ctx);

// if (resultState != null && !canPlaceInWater(resultState)) return false;

if (resultState != null) {
if (!resultState.canPlaceAt(state.world, state.blockPos)) return false;
return !(currentState.getBlock() instanceof FluidBlock) || canPlaceInWater(resultState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public SlabGuide(SchematicBlockState state) {
super(state);
}

@Override
public boolean skipOtherGuides() {
return false;
}

@Override
protected List<Direction> getPossibleSides() {
return Arrays.stream(Direction.values())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package me.aleksilassila.litematica.printer.v1_19.implementation.mixin;

import com.mojang.authlib.GameProfile;
import fi.dy.masa.litematica.world.SchematicWorldHandler;
import fi.dy.masa.litematica.world.WorldSchematic;
import me.aleksilassila.litematica.printer.v1_19.LitematicaMixinMod;
import me.aleksilassila.litematica.printer.v1_19.Printer;
import me.aleksilassila.litematica.printer.v1_19.SchematicBlockState;
import me.aleksilassila.litematica.printer.v1_19.UpdateChecker;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.network.encryption.PlayerPublicKey;
import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -17,12 +24,16 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Optional;

@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
private static boolean didCheckForUpdates = false;

@Shadow
protected MinecraftClient client;
@Shadow
public ClientPlayNetworkHandler networkHandler;

public MixinClientPlayerEntity(ClientWorld world, GameProfile profile, @Nullable PlayerPublicKey publicKey) {
super(world, profile, publicKey);
Expand Down Expand Up @@ -62,4 +73,30 @@ public void checkForUpdates() {
}
}).start();
}

@Inject(method = "openEditSignScreen", at = @At("HEAD"), cancellable = true)
public void openEditSignScreen(SignBlockEntity sign, CallbackInfo ci) {
getTargetSignEntity(sign).ifPresent(signBlockEntity -> {
UpdateSignC2SPacket packet = new UpdateSignC2SPacket(sign.getPos(),
signBlockEntity.getTextOnRow(0, false).getString(),
signBlockEntity.getTextOnRow(1, false).getString(),
signBlockEntity.getTextOnRow(2, false).getString(),
signBlockEntity.getTextOnRow(3, false).getString());
this.networkHandler.sendPacket(packet);
ci.cancel();
});
}

private Optional<SignBlockEntity> getTargetSignEntity(SignBlockEntity sign) {
WorldSchematic worldSchematic = SchematicWorldHandler.getSchematicWorld();
SchematicBlockState state = new SchematicBlockState(sign.getWorld(), worldSchematic, sign.getPos());

BlockEntity targetBlockEntity = worldSchematic.getBlockEntity(state.blockPos);

if (targetBlockEntity instanceof SignBlockEntity targetSignEntity) {
return Optional.of(targetSignEntity);
}

return Optional.empty();
}
}

This file was deleted.

0 comments on commit 33e40b0

Please sign in to comment.