forked from ChomeNS/chipmunkmod
CLAMP CORE Y (YES It is now DYNAMIC)
This commit is contained in:
parent
e4b1f66bb3
commit
40c9f94293
2 changed files with 28 additions and 6 deletions
|
@ -4,6 +4,7 @@ import land.chipmunk.chipmunkmod.ChipmunkMod;
|
|||
import land.chipmunk.chipmunkmod.data.BlockArea;
|
||||
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||
import land.chipmunk.chipmunkmod.util.MathUtilities;
|
||||
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
|
@ -28,11 +29,11 @@ public class CommandCore {
|
|||
|
||||
public boolean runFillCommand = true;
|
||||
|
||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance(), ChipmunkMod.CONFIG.core.relativeArea);
|
||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance());
|
||||
|
||||
public CommandCore (MinecraftClient client, BlockArea relativeArea) {
|
||||
public CommandCore (MinecraftClient client) {
|
||||
this.client = client;
|
||||
this.relativeArea = relativeArea;
|
||||
reloadRelativeArea();
|
||||
}
|
||||
|
||||
public void init () {
|
||||
|
@ -56,20 +57,37 @@ public class CommandCore {
|
|||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
if (networkHandler == null) cleanup();
|
||||
|
||||
reloadRelativeArea();
|
||||
}
|
||||
|
||||
public void reloadRelativeArea () {
|
||||
relativeArea = ChipmunkMod.CONFIG.core.relativeArea;
|
||||
// makes a copy
|
||||
relativeArea = new BlockArea(
|
||||
new BlockPos(ChipmunkMod.CONFIG.core.relativeArea.start),
|
||||
new BlockPos(ChipmunkMod.CONFIG.core.relativeArea.end)
|
||||
);
|
||||
|
||||
relativeArea.start = new BlockPos(
|
||||
relativeArea.start.getX(),
|
||||
(int) MathUtilities.clamp(relativeArea.start.getY(), client.world.getDimension().minY(), client.world.getDimension().height()),
|
||||
relativeArea.start.getZ()
|
||||
);
|
||||
relativeArea.end = new BlockPos(
|
||||
relativeArea.end.getX(),
|
||||
(int) MathUtilities.clamp(relativeArea.end.getY(), client.world.getDimension().minY(), client.world.getDimension().height()),
|
||||
relativeArea.end.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
public void move (Vec3d position) {
|
||||
origin = new BlockPos(
|
||||
((int) position.getX() / 16) * 16,
|
||||
0, // TODO: Use the actual bottom of the world instead of hardcoding to 0
|
||||
0,
|
||||
((int) position.getZ() / 16) * 16
|
||||
);
|
||||
|
||||
if (currentBlockRelative == null) currentBlockRelative = new BlockPos(relativeArea.start);
|
||||
currentBlockRelative = new BlockPos(relativeArea.start);
|
||||
refill();
|
||||
|
||||
for (Listener listener : ListenerManager.listeners) listener.coreMoved();
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package land.chipmunk.chipmunkmod.util;
|
||||
|
||||
public class MathUtilities {
|
||||
public static double clamp (double value, double min, double max) {
|
||||
return Math.max(Math.min(value, max), min);
|
||||
}
|
||||
|
||||
public static float clamp (float value, float min, float max) {
|
||||
return Math.max(Math.min(value, max), min);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue