use of am2.blocks.tileentities.TileEntityLectern in project ArsMagica2 by Mithion.
the class BlockLectern method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
TileEntityLectern te = getTileEntity(world, x, y, z);
if (te == null) {
return true;
}
if (te.hasStack()) {
if (player.isSneaking()) {
if (!world.isRemote && ((player instanceof EntityPlayerMP) && ((EntityPlayerMP) player).theItemInWorldManager.getGameType() != GameType.ADVENTURE)) {
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
ItemStack newItem = new ItemStack(te.getStack().getItem(), 1, te.getStack().getItemDamage());
if (te.getStack().stackTagCompound != null)
newItem.setTagCompound((NBTTagCompound) te.getStack().stackTagCompound.copy());
EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, newItem);
float f3 = 0.05F;
entityitem.motionX = (float) world.rand.nextGaussian() * f3;
entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
world.spawnEntityInWorld(entityitem);
te.setStack(null);
}
} else {
te.getStack().getItem().onItemRightClick(te.getStack(), world, player);
}
} else {
if (player.getCurrentEquippedItem() != null) {
if (te.setStack(player.getCurrentEquippedItem())) {
player.getCurrentEquippedItem().stackSize--;
if (player.getCurrentEquippedItem().stackSize <= 0) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
}
}
}
return true;
}
use of am2.blocks.tileentities.TileEntityLectern in project ArsMagica2 by Mithion.
the class BlockLectern method breakBlock.
@Override
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
TileEntityLectern te = getTileEntity(world, x, y, z);
if (te == null) {
return;
}
if (!world.isRemote) {
if (te.hasStack()) {
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
ItemStack newItem = new ItemStack(te.getStack().getItem(), 1, te.getStack().getItemDamage());
if (te.getStack().stackTagCompound != null)
newItem.setTagCompound((NBTTagCompound) te.getStack().stackTagCompound.copy());
EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, newItem);
float f3 = 0.05F;
entityitem.motionX = (float) world.rand.nextGaussian() * f3;
entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
world.spawnEntityInWorld(entityitem);
}
}
super.breakBlock(world, x, y, z, par5, par6);
}
use of am2.blocks.tileentities.TileEntityLectern in project ArsMagica2 by Mithion.
the class BossSpawnHelper method checkForArcaneGuardianSpawn.
private void checkForArcaneGuardianSpawn(World world, int x, int y, int z) {
List<EntityItem> itemsInRange = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1));
if (itemsInRange.size() != 1)
return;
if (itemsInRange.get(0).getEntityItem().getItem() != ItemsCommonProxy.essence || itemsInRange.get(0).getEntityItem().getItemDamage() != ItemsCommonProxy.essence.META_ARCANE)
return;
boolean hasStructure = false;
TileEntityLectern lectern = null;
//+z check
if (world.getBlock(x - 1, y, z + 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 1, z + 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 2, z + 2) == Blocks.bookshelf && world.getBlock(x + 1, y, z + 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 1, z + 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 2, z + 2) == Blocks.bookshelf) {
if (world.getBlock(x, y, z + 2) == BlocksCommonProxy.blockLectern) {
lectern = (TileEntityLectern) world.getTileEntity(x, y, z + 2);
hasStructure = true;
}
}
//-z check
if (world.getBlock(x - 1, y, z - 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 1, z - 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 2, z - 2) == Blocks.bookshelf && world.getBlock(x + 1, y, z - 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 1, z - 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 2, z - 2) == Blocks.bookshelf) {
if (world.getBlock(x, y, z - 2) == BlocksCommonProxy.blockLectern) {
lectern = (TileEntityLectern) world.getTileEntity(x, y, z - 2);
hasStructure = true;
}
}
//+x check
if (world.getBlock(x + 2, y, z - 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 1, z - 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 2, z - 1) == Blocks.bookshelf && world.getBlock(x + 2, y, z + 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 1, z + 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 2, z + 1) == Blocks.bookshelf) {
if (world.getBlock(x + 2, y, z) == BlocksCommonProxy.blockLectern) {
lectern = (TileEntityLectern) world.getTileEntity(x + 2, y, z);
hasStructure = true;
}
}
//-x check
if (world.getBlock(x - 2, y, z - 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 1, z - 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 2, z - 1) == Blocks.bookshelf && world.getBlock(x - 2, y, z + 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 1, z + 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 2, z + 1) == Blocks.bookshelf) {
if (world.getBlock(x - 2, y, z) == BlocksCommonProxy.blockLectern) {
lectern = (TileEntityLectern) world.getTileEntity(x - 2, y, z);
hasStructure = true;
}
}
if (hasStructure && lectern != null && lectern.hasStack() && lectern.getStack().getItem() == ItemsCommonProxy.arcaneCompendium) {
itemsInRange.get(0).setDead();
EntityArcaneGuardian guardian = new EntityArcaneGuardian(world);
guardian.setPosition(x + 0.5, y + 1, z + 0.5);
queuedBosses.put(guardian, world);
}
}
use of am2.blocks.tileentities.TileEntityLectern in project ArsMagica2 by Mithion.
the class AMPacketProcessorClient method handleLecternData.
private void handleLecternData(byte[] data) {
AMDataReader rdr = new AMDataReader(data, false);
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(rdr.getInt(), rdr.getInt(), rdr.getInt());
if (te == null || !(te instanceof TileEntityLectern))
return;
if (rdr.getBoolean())
((TileEntityLectern) te).setStack(rdr.getItemStack());
else
((TileEntityLectern) te).setStack(null);
}
Aggregations