Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Autodetect build limits.
Browse files Browse the repository at this point in the history
Automatically detect the build limits. It detects it only once, when the world is loaded. This should improve performance and make this mod compatible with data packs that modifies the build limits. Thanks to @aria1th!
  • Loading branch information
jensvh committed Jul 22, 2021
1 parent 849dc07 commit cb39dd3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ To set this up just add the latest litematica version to your mods folder as wel
`easyPlaceActivation`:&emsp; "When the easyPlaceMode is enabled, this key must be held to enable placing the blocks when using the vanilla Use key"<br/>
`easyPlaceToggle`:&emsp; "Allows quickly toggling on/off the Easy Place mode"<br/>

`easyPlaceLimitMinY`:&emsp; "it will allow printer's acting y minimum range. for 1.17 datapacks"<br/>
`easyPlaceLimitMaxY`:&emsp; "it will allow printer's acting y maximum range. for 1.17 datapacks"<br/>
## Support
If you have any issues with this mod **DO NOT** contact and bother masa with it. Please message me in discord, I am usually around Scicraft, Mechanists, and Hekate.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class LitematicaMixinMod implements ModInitializer {
public static final ConfigInteger EASY_PLACE_MODE_RANGE_X = new ConfigInteger("easyPlaceModeRangeX", 3, 0, 1024, "X Range for EasyPlace");
public static final ConfigInteger EASY_PLACE_MODE_RANGE_Y = new ConfigInteger("easyPlaceModeRangeY", 3, 0, 1024, "Y Range for EasyPlace");
public static final ConfigInteger EASY_PLACE_MODE_RANGE_Z = new ConfigInteger("easyPlaceModeRangeZ", 3, 0, 1024, "Z Range for EasyPlace");
public static final ConfigInteger EASY_PLACE_Y_MIN = new ConfigInteger("easyplaceLimitMinY", 0, -256, 1024, "Limits or allows easy place acting Y range");
public static final ConfigInteger EASY_PLACE_Y_MAX = new ConfigInteger("easyplaceLimitMaxY", 255, -256, 1024, "Limits or allows easy place acting Y range");
public static final ConfigInteger EASY_PLACE_MODE_MAX_BLOCKS = new ConfigInteger("easyPlaceModeMaxBlocks", 3, 1, 1000000, "Max block interactions per cycle");
public static final ConfigBoolean EASY_PLACE_MODE_BREAK_BLOCKS = new ConfigBoolean("easyPlaceModeBreakBlocks", false, "Automatically breaks blocks.");
public static final ConfigDouble EASY_PLACE_MODE_DELAY = new ConfigDouble( "easyPlaceModeDelay", 0.2, 0.0, 1.0, "Delay between printing blocks.\nDo not set to 0 if you are playing on a server.");
Expand Down Expand Up @@ -48,8 +46,6 @@ public class LitematicaMixinMod implements ModInitializer {
EASY_PLACE_MODE_RANGE_X,
EASY_PLACE_MODE_RANGE_Y,
EASY_PLACE_MODE_RANGE_Z,
EASY_PLACE_Y_MIN,
EASY_PLACE_Y_MAX,
EASY_PLACE_MODE_MAX_BLOCKS,
EASY_PLACE_MODE_BREAK_BLOCKS,
EASY_PLACE_MODE_DELAY,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.eatmyvenom.litematicin.mixin.Litematica;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import io.github.eatmyvenom.litematicin.utils.Printer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;


@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {

// On join a new world/server
@Inject(at = @At("HEAD"), method = "joinWorld")
public void joinWorld(ClientWorld world, CallbackInfo ci) {
Printer.worldBottomY = world.getBottomY();
Printer.worldTopY = world.getTopY();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.EASY_PLACE_MODE_RANGE_X;
import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.EASY_PLACE_MODE_RANGE_Y;
import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.EASY_PLACE_MODE_RANGE_Z;
import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.EASY_PLACE_Y_MIN;
import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.EASY_PLACE_Y_MAX;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -229,6 +227,9 @@ public static ActionResult doAccuratePlacePrinter(MinecraftClient mc) {
// For printing delay
public static long lastPlaced = new Date().getTime();
public static Breaker breaker = new Breaker();

public static int worldBottomY = 0;
public static int worldTopY = 256;

@Environment(EnvType.CLIENT)
public static ActionResult doPrinterAction(MinecraftClient mc) {
Expand Down Expand Up @@ -302,8 +303,6 @@ public static ActionResult doPrinterAction(MinecraftClient mc) {
int rangeY = EASY_PLACE_MODE_RANGE_Y.getIntegerValue();
int rangeZ = EASY_PLACE_MODE_RANGE_Z.getIntegerValue();
int MaxReach = Math.max(Math.max(rangeX,rangeY),rangeZ);
int LimitMinY = EASY_PLACE_Y_MIN.getIntegerValue();
int LimitMaxY = EASY_PLACE_Y_MAX.getIntegerValue();
boolean breakBlocks = EASY_PLACE_MODE_BREAK_BLOCKS.getBooleanValue();
Direction[] facingSides = Direction.getEntityFacingOrder(mc.player);
Direction primaryFacing = facingSides[0];
Expand Down Expand Up @@ -335,8 +334,8 @@ public static ActionResult doPrinterAction(MinecraftClient mc) {
int toY = Math.min(posY + rangeY, maxY);
int toZ = Math.min(posZ + rangeZ, maxZ);

toY = Math.max(Math.max(LimitMinY, Math.min(Math.min(toY, LimitMaxY),world.getTopY())),world.getBottomY());
fromY = Math.max(Math.max(LimitMinY, Math.min(Math.min(fromY, LimitMaxY),world.getTopY())),world.getBottomY());
toY = Math.max(Math.min(toY,worldTopY),worldBottomY);
fromY = Math.max(Math.min(fromY, worldTopY),worldBottomY);

fromX = Math.max(fromX,(int)mc.player.getX() - rangeX);
fromY = Math.max(fromY,(int)mc.player.getY() - rangeY);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/litematica-printer.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"client": [
"Litematica.ConfigsMixin",
"Litematica.GuiConfigsMixin",
"Litematica.WorldUtilsMixin"
"Litematica.WorldUtilsMixin",
"Litematica.MinecraftClientMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit cb39dd3

Please sign in to comment.