Skip to content

Commit

Permalink
misc cleanup + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursivePineapple committed Dec 16, 2024
1 parent f87e8f0 commit 5da0049
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 74 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public final double charge(ItemStack stack, double toCharge, int voltageTier, bo
boolean simulate) {
NBTTagCompound tag = getOrCreateNbtData(stack);

double maxTransfer = ignoreTransferLimit ? toCharge : Math.min(toCharge, V[tier.voltageTier]);
double maxTransfer = ignoreTransferLimit ? toCharge : Math.min(toCharge, getTransferLimit(stack));
double currentCharge = tag.getDouble("charge");
double remainingSpace = tier.maxCharge - currentCharge;

Expand All @@ -260,7 +260,7 @@ public final double discharge(ItemStack stack, double toDischarge, int voltageTi

NBTTagCompound tag = getOrCreateNbtData(stack);

double maxTransfer = ignoreTransferLimit ? toDischarge : Math.min(toDischarge, V[tier.voltageTier]);
double maxTransfer = ignoreTransferLimit ? toDischarge : Math.min(toDischarge, getTransferLimit(stack));
double currentCharge = tag.getDouble("charge");

double toConsume = Math.min(maxTransfer, currentCharge);
Expand Down Expand Up @@ -565,6 +565,8 @@ private <T> void addInfoLine(List<String> desc, String format, T value, Function

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (player.getItemInUse() != null) return stack;

MMState state = getState(stack);

if (state.config.action != null) {
Expand Down Expand Up @@ -1763,7 +1765,7 @@ private Row makeCoordinateEditor(EntityPlayer player, int coord, int component)
} else if (GuiScreen.isCtrlKeyDown()) {
MMState currState = getState(player.getHeldItem());

Vector3i size = currState.config.getPasteVisualDeltas(null).size();
Vector3i size = currState.config.getPasteVisualDeltas(null, false).size();

offset = switch (component) {
case 0 -> size.x;
Expand All @@ -1787,7 +1789,7 @@ private Row makeCoordinateEditor(EntityPlayer player, int coord, int component)
} else if (GuiScreen.isCtrlKeyDown()) {
MMState currState = getState(player.getHeldItem());

Vector3i size = currState.config.getPasteVisualDeltas(null).size();
Vector3i size = currState.config.getPasteVisualDeltas(null, false).size();

offset = switch (component) {
case 0 -> size.x;
Expand Down Expand Up @@ -1840,7 +1842,7 @@ private Row makeCoordinateEditor(EntityPlayer player, int coord, int component)
} else if (GuiScreen.isCtrlKeyDown()) {
MMState currState = getState(player.getHeldItem());

Vector3i size = currState.config.getPasteVisualDeltas(null).size();
Vector3i size = currState.config.getPasteVisualDeltas(null, false).size();

offset = switch (component) {
case 0 -> size.x;
Expand All @@ -1864,7 +1866,7 @@ private Row makeCoordinateEditor(EntityPlayer player, int coord, int component)
} else if (GuiScreen.isCtrlKeyDown()) {
MMState currState = getState(player.getHeldItem());

Vector3i size = currState.config.getPasteVisualDeltas(null).size();
Vector3i size = currState.config.getPasteVisualDeltas(null, false).size();

offset = switch (component) {
case 0 -> size.x;
Expand Down Expand Up @@ -1957,6 +1959,9 @@ public void onKeyPressed() {
}
if (InteractionConfig.pasteAutoClear) {
Messages.ClearCoords.sendToServer();
if (InteractionConfig.resetTransform) {
Messages.ClearTransform.sendToServer();
}
}
Messages.MarkCut.sendToServer();
} else if (COPY.isPressed()) {
Expand All @@ -1965,6 +1970,9 @@ public void onKeyPressed() {
}
if (InteractionConfig.pasteAutoClear) {
Messages.ClearCoords.sendToServer();
if (InteractionConfig.resetTransform) {
Messages.ClearTransform.sendToServer();
}
}
Messages.MarkCopy.sendToServer();
} else if (PASTE.isPressed()) {
Expand All @@ -1975,6 +1983,9 @@ public void onKeyPressed() {
Messages.MarkPaste.sendToServer();
} else if (RESET.isPressed()) {
Messages.ClearCoords.sendToServer();
if (InteractionConfig.resetTransform) {
Messages.ClearTransform.sendToServer();
}
}
}
}
Expand Down Expand Up @@ -2223,16 +2234,12 @@ private void renderRegions(RenderWorldLastEvent event, MMState state, EntityPlay
if (isPasteValid) {
Objects.requireNonNull(paste);

pasteDeltas = state.config.getPasteVisualDeltas(player.worldObj);
pasteDeltas = state.config.getPasteVisualDeltas(player.worldObj, true);

if (pasteDeltas == null) {
pasteDeltas = new VoxelAABB(paste.toVec(), paste.toVec());
}

if (state.config.transform != null) {
state.config.transform.apply(pasteDeltas);
}

BoxRenderer.INSTANCE.drawAround(pasteDeltas.toBoundingBox(), new Vector3f(0.75f, 0.5f, 0.15f));

Location playerLocation = new Location(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,34 @@ public Location getCoordC(World world, Vector3i lookingAt) {

public static class VoxelAABB {

public Vector3i origin, bounds;
public Vector3i origin, a, b;

public VoxelAABB() {
origin = new Vector3i();
bounds = new Vector3i();
a = new Vector3i();
b = new Vector3i();
}

public VoxelAABB(Vector3i a, Vector3i b) {
origin = new Vector3i(a);
bounds = new Vector3i(b);
this.origin = new Vector3i(a);
this.a = new Vector3i(a);
this.b = new Vector3i(b);
}

public Vector3i min() {
return new Vector3i(origin).min(bounds);
return new Vector3i(a).min(b);
}

public Vector3i max() {
return new Vector3i(origin).max(bounds);
return new Vector3i(a).max(b);
}

public VoxelAABB union(Vector3i v) {
Vector3i min = min(), max = max();

origin.set(v)
a.set(v)
.min(min);
bounds.set(v)
b.set(v)
.max(max);

return this;
Expand All @@ -157,26 +159,26 @@ public VoxelAABB union(Vector3i v) {
public VoxelAABB union(VoxelAABB other) {
Vector3i min = min(), max = max();

origin.set(min)
a.set(min)
.min(other.min());
bounds.set(max)
b.set(max)
.max(other.max());

return this;
}

public VoxelAABB moveOrigin(Vector3i newOrigin) {
bounds.sub(origin)
.add(newOrigin);
b.sub(origin).add(newOrigin);
a.sub(origin).add(newOrigin);
origin.set(newOrigin);

return this;
}

public VoxelAABB scale(int x, int y, int z) {
int dirX = bounds.x < origin.x ? -1 : 1;
int dirY = bounds.y < origin.y ? -1 : 1;
int dirZ = bounds.z < origin.z ? -1 : 1;
int dirX = b.x < a.x ? -1 : 1;
int dirY = b.y < a.y ? -1 : 1;
int dirZ = b.z < a.z ? -1 : 1;

Vector3i size = size();

Expand All @@ -196,7 +198,8 @@ public VoxelAABB scale(int x, int y, int z) {
public VoxelAABB clone() {
VoxelAABB dup = new VoxelAABB();
dup.origin = new Vector3i(origin);
dup.bounds = new Vector3i(bounds);
dup.a = new Vector3i(a);
dup.b = new Vector3i(b);
return dup;
}

Expand Down Expand Up @@ -254,18 +257,24 @@ public Vector3i getArrayMult(World world, Location sourceA, Location sourceB, Lo
return array;
}

public VoxelAABB getPasteVisualDeltas(World world) {
public VoxelAABB getPasteVisualDeltas(World world, boolean transform) {
if (!Location.areCompatible(coordA, coordB, coordC)) return null;
if (world != null && coordA.worldId != world.provider.dimensionId) return null;

VoxelAABB aabb = new VoxelAABB(coordA.toVec(), coordB.toVec());

aabb.moveOrigin(coordC.toVec());
aabb.moveOrigin(new Vector3i(0));

if (arraySpan != null) {
aabb.scale(arraySpan.x, arraySpan.y, arraySpan.z);
}

if (transform) {
this.transform.apply(aabb);
}

aabb.moveOrigin(coordC.toVec());

return aabb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ private List<PendingBlock> getCableBlocks(World world) {
ItemStack stack = config.getCables();

if (stack == null) {
TileAnalysisResult noop = new TileAnalysisResult();

for (Vector3i voxel : getLineVoxels(a.x, a.y, a.z, b.x, b.y, b.z)) {
PendingBlock pendingBlock = new PendingBlock(
world.provider.dimensionId,
Expand All @@ -474,7 +472,7 @@ private List<PendingBlock> getCableBlocks(World world) {
voxel.z,
null);

pendingBlock.tileData = noop;
pendingBlock.tileData = new TileAnalysisResult();

out.add(pendingBlock);
}
Expand Down Expand Up @@ -526,29 +524,33 @@ public static boolean isAECable(ItemStack stack) {
@Optional(Names.GREG_TECH)
private void getGTCables(Vector3i a, Vector3i b, List<PendingBlock> out, Block block, World world, ItemStack cableStack) {
if (block instanceof BlockMachines) {
int start = 0, end = 0;
int end = 0, start = 0;

// calculate the start & end mConnections flags
switch (new Vector3i(b).sub(a)
.maxComponent()) {
case 0: {
start = b.x > 0 ? ForgeDirection.WEST.flag : ForgeDirection.EAST.flag;
end = b.x < 0 ? ForgeDirection.WEST.flag : ForgeDirection.EAST.flag;
start = b.x < 0 ? ForgeDirection.WEST.flag : ForgeDirection.EAST.flag;
end = b.x > 0 ? ForgeDirection.WEST.flag : ForgeDirection.EAST.flag;
break;
}
case 1: {
start = b.y > 0 ? ForgeDirection.DOWN.flag : ForgeDirection.UP.flag;
end = b.y < 0 ? ForgeDirection.DOWN.flag : ForgeDirection.UP.flag;
start = b.y < 0 ? ForgeDirection.DOWN.flag : ForgeDirection.UP.flag;
end = b.y > 0 ? ForgeDirection.DOWN.flag : ForgeDirection.UP.flag;
break;
}
case 2: {
start = b.z > 0 ? ForgeDirection.NORTH.flag : ForgeDirection.SOUTH.flag;
end = b.z < 0 ? ForgeDirection.NORTH.flag : ForgeDirection.SOUTH.flag;
start = b.z < 0 ? ForgeDirection.NORTH.flag : ForgeDirection.SOUTH.flag;
end = b.z > 0 ? ForgeDirection.NORTH.flag : ForgeDirection.SOUTH.flag;
break;
}
}

for (Vector3i voxel : getLineVoxels(a.x, a.y, a.z, b.x, b.y, b.z)) {
List<Vector3i> voxels = getLineVoxels(a.x, a.y, a.z, b.x, b.y, b.z);

for (int i = 0; i < voxels.size(); i++) {
Vector3i voxel = voxels.get(i);

byte existingConnections = 0;

// respect existing connections if possible
Expand All @@ -569,19 +571,19 @@ private void getGTCables(Vector3i a, Vector3i b, List<PendingBlock> out, Block b
cableStack);

GTAnalysisResult gt = new GTAnalysisResult();
gt.mConnections = (byte) (existingConnections | start | end);

byte conn = existingConnections;

if (i > 0) conn |= start;
if (i < voxels.size() - 1) conn |= end;

gt.mConnections = conn;

pendingBlock.tileData = new TileAnalysisResult();
pendingBlock.tileData.gt = gt;

out.add(pendingBlock);
}

// stop the ends from connecting to nothing
if (!out.isEmpty()) {
((GTAnalysisResult) out.get(0).tileData.gt).mConnections &= ~start;
((GTAnalysisResult) out.get(out.size() - 1).tileData.gt).mConnections &= ~end;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public PendingBlock setBlock(ItemStack stack) {

public Block getBlock() {
if (block == null) {
block = blockId == null ? Blocks.air : GameRegistry.findBlock(blockId.modId, blockId.name);
if (blockId != null) block = GameRegistry.findBlock(blockId.modId, blockId.name);

if (block == null) block = Blocks.air;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ public Vector3i apply(Vector3i v) {
}

public VoxelAABB apply(VoxelAABB bb) {
Vector3i deltas = new Vector3i(
bb.bounds.x - bb.origin.x,
bb.bounds.y - bb.origin.y,
bb.bounds.z - bb.origin.z);
bb.a.sub(bb.origin);
apply(bb.a);
bb.a.add(bb.origin);

apply(deltas);

bb.bounds.x = deltas.x + bb.origin.x;
bb.bounds.y = deltas.y + bb.origin.y;
bb.bounds.z = deltas.z + bb.origin.z;
bb.b.sub(bb.origin);
apply(bb.b);
bb.b.add(bb.origin);

return bb;
}
Expand Down
Loading

0 comments on commit 5da0049

Please sign in to comment.