I'm trying to make an Australian Animals mod for Minecraft, and in this mod the wombat digs burrows. This works by obtaining coordinates in an array and setting the block with those coordinates to air. The problem is, the wombat keeps trying to obtain the coordinates from the next array item even after it has finished digging the burrow. Here is my code:
The problem lies with this line:
The wombat tries to obtain a value that is outside the bounds of the coordinate arrays, despite the fact that I have code to ensure that the wombat stops digging before that happens. The arrays hold 23 items, and the wombat is supposed to only obtain the "var4" block as long as digProgressActual (the variable used to obtain the array value) is under 23. I have tried lowering the digProgressActual limit, but the wombat just keeps on digging until it crashes the game.
Can someone please tell me what I'm doing wrong?
public void onLivingUpdate() { if (!this.worldObj.isClient && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing") && !this.getClipped()) { Block var4; if (this.rand.nextInt(1000) < 100) { if (digProgress <= -1) { burrowX = MathHelper.floor_double(this.posX); burrowY = MathHelper.floor_double(this.posY); burrowZ = MathHelper.floor_double(this.posZ); digProgress = 0; } } if (digProgress >= 0) { int digProgressActual = digProgress / 20; if (digProgressActual < 23); { var4 = this.worldObj.getBlock(burrowX + digPositionsX[digProgressActual], burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual]); if (carriableBlocks[Block.getIdFromBlock(var4)]) { if (digFailures < 2) { if (digProgressActual == 2) { if (!firstFailure) { worldObj.setBlock(burrowX + digPositionsX[digProgressActual], burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual], Blocks.air); setPositionAndUpdate(burrowX + digPositionsX[digProgressActual] + 0.5D, burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual] + 0.5D); } else { digFailures = 0; firstFailure = false; secondFailure = false; digProgress = -1; burrowX = 0; burrowY = 0; burrowZ = 0; } } else if (digProgressActual == 4) { if (!secondFailure) { worldObj.setBlock(burrowX + digPositionsX[digProgressActual], burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual], Blocks.air); setPositionAndUpdate(burrowX + digPositionsX[digProgressActual] + 0.5D, burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual] + 0.5D); } else { digFailures = 0; firstFailure = false; secondFailure = false; digProgress = -1; burrowX = 0; burrowY = 0; burrowZ = 0; } } else { worldObj.setBlock(burrowX + digPositionsX[digProgressActual], burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual], Blocks.air); setPositionAndUpdate(burrowX + digPositionsX[digProgressActual] + 0.5D, burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual] + 0.5D); } } else { digFailures = 0; firstFailure = false; secondFailure = false; digProgress = -1; burrowX = 0; burrowY = 0; burrowZ = 0; } } else if (var4 != Blocks.air) { if (digProgressActual == 1 && !firstFailure) { digFailures++; firstFailure = true; } if (digProgressActual == 3 && !secondFailure) { digFailures++; firstFailure = true; } } digProgress++; } } } if (this.nailTimer > 0) { --this.nailTimer; setClipped(true); } else { setClipped(false); } super.onLivingUpdate(); }
var4 = this.worldObj.getBlock(burrowX + digPositionsX[digProgressActual], burrowY + digPositionsY[digProgressActual], burrowZ + digPositionsZ[digProgressActual]);