Skip to content

Commit

Permalink
Fix LCE/ECE obstruction check (#2346)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss authored Jan 16, 2024
1 parent 06a31af commit b86e268
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
29 changes: 29 additions & 0 deletions src/main/java/gregtech/api/util/RelativeDirection.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,33 @@ public static EnumFacing simulateAxisRotation(EnumFacing newFrontFacing, EnumFac
return upwardsFacing.getOpposite();
}
}

/**
* Offset a BlockPos relatively in any direction by any amount. Pass negative values to offset down, right or
* backwards.
*/
public static BlockPos offsetPos(BlockPos pos, EnumFacing frontFacing, EnumFacing upwardsFacing, boolean isFlipped,
int upOffset, int leftOffset, int forwardOffset) {
if (upOffset == 0 && leftOffset == 0 && forwardOffset == 0) {
return pos;
}

int oX = 0, oY = 0, oZ = 0;
final EnumFacing relUp = UP.getRelativeFacing(frontFacing, upwardsFacing, isFlipped);
oX += relUp.getXOffset() * upOffset;
oY += relUp.getYOffset() * upOffset;
oZ += relUp.getZOffset() * upOffset;

final EnumFacing relLeft = LEFT.getRelativeFacing(frontFacing, upwardsFacing, isFlipped);
oX += relLeft.getXOffset() * leftOffset;
oY += relLeft.getYOffset() * leftOffset;
oZ += relLeft.getZOffset() * leftOffset;

final EnumFacing relForward = FRONT.getRelativeFacing(frontFacing, upwardsFacing, isFlipped);
oX += relForward.getXOffset() * forwardOffset;
oY += relForward.getYOffset() * forwardOffset;
oZ += relForward.getZOffset() * forwardOffset;

return pos.add(oX, oY, oZ);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.recipes.RecipeMaps;
import gregtech.api.unification.material.Materials;
import gregtech.api.util.RelativeDirection;
import gregtech.api.util.TextComponentUtil;
import gregtech.api.util.TextFormattingUtil;
import gregtech.client.renderer.ICubeRenderer;
Expand All @@ -28,7 +29,6 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
Expand Down Expand Up @@ -192,18 +192,19 @@ protected void formStructure(PatternMatchContext context) {
}

private boolean checkIntakesObstructed() {
EnumFacing facing = this.getFrontFacing();
boolean permuteXZ = facing.getAxis() == EnumFacing.Axis.Z;
BlockPos centerPos = this.getPos().offset(facing);
for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) {
// Skip the controller block itself
if (x == 0 && y == 0)
for (int left = -1; left <= 1; left++) {
for (int up = -1; up <= 1; up++) {
if (left == 0 && up == 0) {
// Skip the controller block itself
continue;
BlockPos blockPos = centerPos.add(permuteXZ ? x : 0, y, permuteXZ ? 0 : x);
IBlockState blockState = this.getWorld().getBlockState(blockPos);
if (!blockState.getBlock().isAir(blockState, this.getWorld(), blockPos))
}

final BlockPos checkPos = RelativeDirection.offsetPos(
getPos(), getFrontFacing(), getUpwardsFacing(), isFlipped(), up, left, 1);
final IBlockState state = getWorld().getBlockState(checkPos);
if (!state.getBlock().isAir(state, getWorld(), checkPos)) {
return true;
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.util.RelativeDirection;
import gregtech.client.renderer.texture.Textures;
import gregtech.common.items.behaviors.AbstractMaterialPartBehavior;
import gregtech.common.items.behaviors.TurbineRotorBehavior;
Expand Down Expand Up @@ -163,14 +164,17 @@ public boolean isFrontFaceFree() {
}

private boolean checkTurbineFaceFree() {
EnumFacing facing = getFrontFacing();
boolean permuteXZ = facing.getAxis() == EnumFacing.Axis.Z;
BlockPos centerPos = getPos().offset(facing);
for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) {
BlockPos blockPos = centerPos.add(permuteXZ ? x : 0, y, permuteXZ ? 0 : x);
IBlockState blockState = getWorld().getBlockState(blockPos);
if (!blockState.getBlock().isAir(blockState, getWorld(), blockPos)) {
final EnumFacing front = getFrontFacing();
// this can be anything really, as long as it is not up/down when on Y axis
final EnumFacing upwards = front.getAxis() == EnumFacing.Axis.Y ? EnumFacing.NORTH : EnumFacing.UP;

for (int left = -1; left <= 1; left++) {
for (int up = -1; up <= 1; up++) {
// flip doesn't affect anything here since we are checking a square anyway
final BlockPos checkPos = RelativeDirection.offsetPos(
getPos(), front, upwards, false, up, left, 1);
final IBlockState state = getWorld().getBlockState(checkPos);
if (!state.getBlock().isAir(state, getWorld(), checkPos)) {
return false;
}
}
Expand Down

0 comments on commit b86e268

Please sign in to comment.