mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
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:
parent
79d510aefb
commit
f8d827d6cd
@ -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,40 +127,42 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
|||||||
this.rotationYaw -= 360;
|
this.rotationYaw -= 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
final double CUT_ANGLE = Math.toRadians(5);
|
if(forceSkip > 0) {
|
||||||
double rotationYawRads = Math.toRadians((rotationYaw + 270) % 360);
|
forceSkip--;
|
||||||
|
} else {
|
||||||
|
final double CUT_ANGLE = Math.toRadians(5);
|
||||||
|
double rotationYawRads = Math.toRadians((rotationYaw + 270) % 360);
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for(int dx = -9; dx <= 9; dx++) {
|
for(int dx = -9; dx <= 9; dx++) {
|
||||||
for(int dz = -9; dz <= 9; dz++) {
|
for(int dz = -9; dz <= 9; dz++) {
|
||||||
int sqrDst = dx * dx + dz * dz;
|
int sqrDst = dx * dx + dz * dz;
|
||||||
|
|
||||||
if(sqrDst <= 4 || sqrDst > 81)
|
if(sqrDst <= 4 || sqrDst > 81)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
double angle = Math.atan2(dz, dx);
|
double angle = Math.atan2(dz, dx);
|
||||||
double relAngle = Math.abs(angle - rotationYawRads);
|
double relAngle = Math.abs(angle - rotationYawRads);
|
||||||
relAngle = Math.abs((relAngle + Math.PI) % (2 * Math.PI) - Math.PI);
|
relAngle = Math.abs((relAngle + Math.PI) % (2 * Math.PI) - Math.PI);
|
||||||
|
|
||||||
if(relAngle > CUT_ANGLE)
|
if(relAngle > CUT_ANGLE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int x = xCoord + dx;
|
int x = xCoord + dx;
|
||||||
int y = yCoord + 1;
|
int y = yCoord + 1;
|
||||||
int z = zCoord + dz;
|
int z = zCoord + dz;
|
||||||
|
|
||||||
Block b = worldObj.getBlock(x, y, z);
|
Block b = worldObj.getBlock(x, y, z);
|
||||||
if(!(b.getMaterial() == Material.wood || b.getMaterial() == Material.leaves || b.getMaterial() == Material.plants))
|
if(!(b.getMaterial() == Material.wood || b.getMaterial() == Material.leaves || b.getMaterial() == Material.plants))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
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))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// com.hbm.main.MainRegistry.logger.info("[Abel] found target at " + x + ", " + y + ", " + z + ", angle=" + rotationYaw);
|
state = 1;
|
||||||
|
break outer;
|
||||||
state = 1;
|
}
|
||||||
break outer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,21 +250,22 @@ 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) {
|
||||||
}
|
cutCrop(x, y, z);
|
||||||
|
} else if(b.getMaterial() == Material.wood) {
|
||||||
if(b.getMaterial() == Material.leaves || b.getMaterial() == Material.plants) {
|
fellTree(x, y, z);
|
||||||
cutCrop(x, y, z);
|
if(state == 1) {
|
||||||
return;
|
state = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(b.getMaterial() == Material.wood) {
|
|
||||||
fellTree(x, y, z);
|
|
||||||
if(state == 1) {
|
|
||||||
state = 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user