if (item.getMaterial().equals(VanillaMaterials.TNT)) {
//Place Activated TNT entity at direction of Dispenser
if (facingBlock.getMaterial().getShape() != null) {
World world = facingBlock.getWorld();
Tnt tnt = world.createEntity(facingBlock.getPosition(), Tnt.class).add(Tnt.class);
tnt.getOwner().getPhysics().force(new Vector3f(0.5D, 0.5D, 0.5D));
world.spawnEntity(tnt.getOwner());
slot.addAmount(-1);
return true;
}
} else if (item.getMaterial() instanceof SpawnEgg) {
if (facingBlock.getMaterial().getShape() != null) {
Entity entity = facingBlock.getWorld().createEntity(facingBlock.getPosition(), ((SpawnEgg) item.getMaterial()).getSpawnedComponent());
entity.getPhysics().translate(new Vector3f(0.5D, 0.5D, 0.5D));
facingBlock.getWorld().spawnEntity(entity);
slot.addAmount(-1);
return true;
}
} else if (item.getMaterial() instanceof FullBucket) {
//Attempt to place any FullBucket with it's placement material
if (facingBlock.getMaterial().getShape() != null) {
facingBlock.setMaterial(((FullBucket) item.getMaterial()).getPlacedMaterial());
item.setMaterial(VanillaMaterials.BUCKET);
//TODO: update physics properly after block has been changed to the liquid
return true;
}
} else if (item.getMaterial().equals(VanillaMaterials.FLINT_AND_STEEL)) {
if (facingBlock.getMaterial().equals(VanillaMaterials.TNT)) {
// Detonate TntBlock
VanillaMaterials.TNT.onIgnite(block, new BlockCause(block));
slot.addData(1);
return true;
} else {
// Default fire placement
if (VanillaMaterials.FIRE.canCreate(facingBlock, (short) 0, new BlockCause(block))) {
VanillaMaterials.FIRE.onCreate(facingBlock, (short) 0, new BlockCause(block));
slot.addData(1);
return true;
}
}
} else if (item.getMaterial().equals(VanillaMaterials.BUCKET)) {
if (facingBlock.getMaterial() instanceof Liquid) {
Liquid liquid = (Liquid) facingBlock.getMaterial();
if (liquid.isSource(facingBlock)) {
item.setMaterial(liquid.getContainerMaterial());
facingBlock.setMaterial(VanillaMaterials.AIR);
//TODO: physics update necessary here
return true;
}
}
} else if (item.getMaterial() instanceof Armor) {
for (Player player : block.getWorld().getNearbyPlayers(block.getPosition(), 2)) {
if (player.getPhysics().getPosition().getBlock().equals(facingBlock)) {
PlayerInventory inv = player.get(PlayerInventory.class);
int armorSlot = ((Armor) item.getMaterial()).getEquipableSlot();
if (inv.getArmor().get(armorSlot) != null) {
return false;
}
boolean canSet = inv.getArmor().canSet(armorSlot, item);
InventoryCanSetEvent event = player.getEngine().getEventManager().callEvent(new InventoryCanSetEvent(inv.getArmor(), new BlockCause(block), armorSlot, item, !canSet));
if (event.isCancelled()) {
return false;
}
inv.getArmor().set(armorSlot, item, true);
slot.addAmount(-1);
return true;
}
}
} else if (item.getMaterial().equals(Dye.BONE_MEAL)) {
if (facingBlock.getMaterial() instanceof Growing && ((Growing) facingBlock.getMaterial()).grow(facingBlock, Dye.BONE_MEAL)) {
slot.addAmount(-1);
return true;
}
} else if (item.getMaterial() instanceof MinecartItem) {
if (facingBlock.getMaterial() instanceof RailBase) {
MinecartItem<?> mineItem = (MinecartItem<?>) item.getMaterial();
mineItem.spawnEntity(facingBlock, Vector3f.ZERO);
slot.addAmount(-1);
return true;
}
} else if (item.getMaterial() instanceof BoatItem) {
Point placePos;
if (facingBlock.getMaterial() instanceof Water) {
placePos = facingBlock.getPosition().add(.5f, 1f, .5f);
} else if (facingBlock.getMaterial().equals(VanillaMaterials.AIR) && facingBlock.translate(BlockFace.BOTTOM).getMaterial() instanceof Water) {
placePos = facingBlock.getPosition().add(.5f, 0f, .5f);
} else {
return false;
}
Boat boat = ((BoatItem) item.getMaterial()).spawnEntity(placePos);
block.getWorld().spawnEntity(boat.getOwner());
slot.addAmount(-1);
return true;
} else {
// Try to shoot the item selected if we can't do anything else with it
final Random rand = GenericMath.getRandom();
Vector3f direction = this.getFacing(block).getOffset();
// Calculate position to shoot from
Point position = block.getPosition().add(direction.mul(0.6));
VanillaEntityComponent toLaunch = null;
// Calculate shooting velocity using facing direction
Vector3f velocity = direction.mul(rand.nextDouble() * 0.1 + 0.2);
// Set velocity y to above (0.2)
velocity = velocity.mul(1.0, 0.0, 1.0).add(0.0, 0.2, 0.0);
velocity = velocity.add(0.045 * rand.nextGaussian(), 0.045 * rand.nextGaussian(), 0.045 * rand.nextGaussian());
Effect shootEffect;
Material material = item.getMaterial();
//TODO: Implement the following 'special' shoot cases:
// - eggs, arrows, fireballs and snowballs