Make autosaw respect walls

Previously the blade always phased through solid walls. Now, if colliding with one, it will retract forcibly. In case there are valid targets behind a wall, it will ignore them for the next 5 degrees of rotation
This commit is contained in:
abel1502 2025-06-03 19:03:19 +03:00
parent 79d510aefb
commit f8d827d6cd
No known key found for this signature in database
GPG Key ID: 076926596A536338

View File

@ -63,6 +63,7 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
private int state = 0; private int state = 0;
private int turnProgress; private int turnProgress;
private int forceSkip = 0;
public float spin; public float spin;
public float lastSpin; public float lastSpin;
@ -126,6 +127,9 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
this.rotationYaw -= 360; this.rotationYaw -= 360;
} }
if(forceSkip > 0) {
forceSkip--;
} else {
final double CUT_ANGLE = Math.toRadians(5); final double CUT_ANGLE = Math.toRadians(5);
double rotationYawRads = Math.toRadians((rotationYaw + 270) % 360); double rotationYawRads = Math.toRadians((rotationYaw + 270) % 360);
@ -156,13 +160,12 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
if(shouldIgnore(worldObj, x, y, z, b, meta)) if(shouldIgnore(worldObj, x, y, z, b, meta))
continue; continue;
// com.hbm.main.MainRegistry.logger.info("[Abel] found target at " + x + ", " + y + ", " + z + ", angle=" + rotationYaw);
state = 1; state = 1;
break outer; break outer;
} }
} }
} }
}
int hitY = (int) Math.floor(cY); int hitY = (int) Math.floor(cY);
int hitX0 = (int) Math.floor(cX - 0.5); int hitX0 = (int) Math.floor(cX - 0.5);
@ -247,16 +250,10 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
int meta = worldObj.getBlockMetadata(x, y, z); int meta = worldObj.getBlockMetadata(x, y, z);
if(shouldIgnore(worldObj, x, y, z, b, meta)) { if(!shouldIgnore(worldObj, x, y, z, b, meta)) {
return;
}
if(b.getMaterial() == Material.leaves || b.getMaterial() == Material.plants) { if(b.getMaterial() == Material.leaves || b.getMaterial() == Material.plants) {
cutCrop(x, y, z); cutCrop(x, y, z);
return; } else if(b.getMaterial() == Material.wood) {
}
if(b.getMaterial() == Material.wood) {
fellTree(x, y, z); fellTree(x, y, z);
if(state == 1) { if(state == 1) {
state = 2; state = 2;
@ -264,6 +261,13 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
} }
} }
// Return when hitting a wall
if(state == 1 && worldObj.getBlock(x, y, z).isNormalCube(worldObj, x, y, z)) {
state = 2;
forceSkip = 5;
}
}
protected void cutCrop(int x, int y, int z) { protected void cutCrop(int x, int y, int z) {
Block soil = worldObj.getBlock(x, y - 1, z); Block soil = worldObj.getBlock(x, y - 1, z);