Skip to content

Commit

Permalink
Ring of Loki support for Cover Copy/Paste Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlamonster committed Feb 13, 2025
1 parent 2e41b0c commit 2876404
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -3798,54 +3798,57 @@ public static float[] getClickedFacingCoords(ForgeDirection side, float aX, floa

/**
* This Function determines the direction a Block gets when being Wrenched. returns -1 if invalid. Even though that
* could never happen.
* could never happen. Normalizes values into the range [0.0f, 1.0f].
*/
public static ForgeDirection determineWrenchingSide(ForgeDirection side, float aX, float aY, float aZ) {
float modX = (aX % 1.0f + 1.0f) % 1.0f;
float modY = (aY % 1.0f + 1.0f) % 1.0f;
float modZ = (aZ % 1.0f + 1.0f) % 1.0f;
ForgeDirection tBack = side.getOpposite();
switch (side) {
case DOWN, UP -> {
if (aX < 0.25) {
if (aZ < 0.25) return tBack;
if (aZ > 0.75) return tBack;
if (modX < 0.25) {
if (modZ < 0.25) return tBack;
if (modZ > 0.75) return tBack;
return WEST;
}
if (aX > 0.75) {
if (aZ < 0.25) return tBack;
if (aZ > 0.75) return tBack;
if (modX > 0.75) {
if (modZ < 0.25) return tBack;
if (modZ > 0.75) return tBack;
return EAST;
}
if (aZ < 0.25) return NORTH;
if (aZ > 0.75) return SOUTH;
if (modZ < 0.25) return NORTH;
if (modZ > 0.75) return SOUTH;
return side;
}
case NORTH, SOUTH -> {
if (aX < 0.25) {
if (aY < 0.25) return tBack;
if (aY > 0.75) return tBack;
if (modX < 0.25) {
if (modY < 0.25) return tBack;
if (modY > 0.75) return tBack;
return WEST;
}
if (aX > 0.75) {
if (aY < 0.25) return tBack;
if (aY > 0.75) return tBack;
if (modX > 0.75) {
if (modY < 0.25) return tBack;
if (modY > 0.75) return tBack;
return EAST;
}
if (aY < 0.25) return DOWN;
if (aY > 0.75) return UP;
if (modY < 0.25) return DOWN;
if (modY > 0.75) return UP;
return side;
}
case WEST, EAST -> {
if (aZ < 0.25) {
if (aY < 0.25) return tBack;
if (aY > 0.75) return tBack;
if (modZ < 0.25) {
if (modY < 0.25) return tBack;
if (modY > 0.75) return tBack;
return NORTH;
}
if (aZ > 0.75) {
if (aY < 0.25) return tBack;
if (aY > 0.75) return tBack;
if (modZ > 0.75) {
if (modY < 0.25) return tBack;
if (modY > 0.75) return tBack;
return SOUTH;
}
if (aY < 0.25) return DOWN;
if (aY > 0.75) return UP;
if (modY < 0.25) return DOWN;
if (modY > 0.75) return UP;
return side;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public class BehaviourCoverTool extends BehaviourNone {
private int mCoverType;
private int mTickRateAddition = 0;

@Override
public boolean shouldInterruptBlockActivation(final EntityPlayer player, final TileEntity tileEntity,
final ForgeDirection side) {
return tileEntity instanceof ICoverable;
}

@Override
// Included for Ring of Loki support.
public boolean onItemUse(final MetaBaseItem aItem, final ItemStack aStack, final EntityPlayer aPlayer,
final World aWorld, final int aX, final int aY, final int aZ, final int ordinalSide, final float hitX,
final float hitY, final float hitZ) {
if (aWorld.getTileEntity(aX, aY, aZ) instanceof ICoverable) {
final ForgeDirection side = ForgeDirection.getOrientation(ordinalSide);
return onItemUseFirst(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, side, hitX, hitY, hitZ);
}
return false;
}

@Override
public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX,
int aY, int aZ, ForgeDirection side, float hitX, float hitY, float hitZ) {
Expand Down

0 comments on commit 2876404

Please sign in to comment.