if (this.createBlock) {
lastDeleteBlock = this.deleteBlock;
this.createBlock = false;
if (!this.inventory.hasBlock(this.blockToPlace))
return null;
Vector3i closestBlock = this.thingBridge
.getClosestEmptyBlockOnVector(
new Vector3d(getCameraX(), getCameraY(),
getCameraZ()), dir);
if (closestBlock != null) {
AddBlock ab = new AddBlock();
ab.x = closestBlock.x;
ab.y = closestBlock.y;
ab.z = closestBlock.z;
ab.block = getBlockToPlace();
return ab;
} else {
return null;
}
} else if (this.deleteBlock) {
boolean justClickedDelete = this.deleteBlock != lastDeleteBlock;
lastDeleteBlock = this.deleteBlock;
this.deleteBlock = false;
ArrayList<Vector3i> blocksAttacking = this.thingBridge.getNonEmptyBlocksOnVector(
new Vector3d(getCameraX(), getCameraY(), getCameraZ()), dir);
Set<Thing> things = this.thingBridge.getIntersectingThings(blocksAttacking);
things.remove(this);
if (things.size() > 0){
if (justClickedDelete){
for (Thing thing : things){
if (thing instanceof Zombie){
Long lastAttackTime = lastAttack.get(thing);
lastAttack.put(thing, System.currentTimeMillis());
Zombie zombie = (Zombie)thing;
if (lastAttackTime == null || System.currentTimeMillis() - lastAttackTime > 100){
zombie.health -= .25;
zombie.hurt = 10;
break;
}
}
else if (thing instanceof Deer){
Long lastAttackTime = lastAttack.get(thing);
lastAttack.put(thing, System.currentTimeMillis());
Deer deer = (Deer)thing;
if (lastAttackTime == null || System.currentTimeMillis() - lastAttackTime > 100){
deer.health -= .25;
deer.lastHurt = deer.step;
if (deer.health <= 0)
this.hunger = 1;
break;
}
}
}
}
}
else {
Vector3i closestBlock = blocksAttacking.get(blocksAttacking.size()-1);
Vector3i tmp3i = new Vector3i();
Block b = thingBridge.engine.chunks.getBlock(closestBlock.x, closestBlock.y, closestBlock.z, tmp3i, (Chunk)null);
if (!(b instanceof BlockEmpty || b instanceof BlockWater)){
if (closestBlock != null) {
RemoveBlock ab = new RemoveBlock();
ab.x = closestBlock.x;