@Override public void onBlockPlacedBy( World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int orientation = BlockPistonBase.determineOrientation(par1World, par2, par3, par4, par5EntityLivingBase); TileSpreader spreader = (TileSpreader) par1World.getTileEntity(par2, par3, par4); par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage(), 1 | 2); switch (orientation) { case 0: spreader.rotationY = -90F; break; case 1: spreader.rotationY = 90F; break; case 2: spreader.rotationX = 270F; break; case 3: spreader.rotationX = 90F; break; case 4: break; default: spreader.rotationX = 180F; break; } }
@Override public boolean onBlockActivated( World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { TileEntity tile = par1World.getTileEntity(par2, par3, par4); if (!(tile instanceof TileSpreader)) return false; TileSpreader spreader = (TileSpreader) tile; ItemStack lens = spreader.getStackInSlot(0); ItemStack heldItem = par5EntityPlayer.getCurrentEquippedItem(); boolean isHeldItemLens = heldItem != null && heldItem.getItem() instanceof ILens; if (heldItem != null) if (heldItem.getItem() == ModItems.twigWand) return false; if (lens == null && isHeldItemLens) { par5EntityPlayer.inventory.setInventorySlotContents( par5EntityPlayer.inventory.currentItem, null); spreader.setInventorySlotContents(0, heldItem.copy()); spreader.markDirty(); } else if (lens != null) { ItemStack add = lens.copy(); if (!par5EntityPlayer.inventory.addItemStackToInventory(add)) par5EntityPlayer.dropPlayerItemWithRandomChoice(add, false); spreader.setInventorySlotContents(0, null); spreader.markDirty(); } return true; }
@Override public boolean onItemUse( ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { Block block = par3World.getBlock(par4, par5, par6); ChunkCoordinates boundSpreader = getBoundSpreader(par1ItemStack); if (boundSpreader.posY != -1 && par2EntityPlayer.isSneaking() && (boundSpreader.posX != par4 || boundSpreader.posY != par5 || boundSpreader.posZ != par6)) { TileEntity tile = par3World.getTileEntity(boundSpreader.posX, boundSpreader.posY, boundSpreader.posZ); if (tile instanceof TileSpreader) { TileSpreader spreader = (TileSpreader) tile; Vector3 spreaderVec = Vector3.fromTileEntityCenter(spreader); Vector3 blockVec = new Vector3(par4 + 0.5, par5 + 0.5, par6 + 0.5); AxisAlignedBB axis = par3World .getBlock(par4, par5, par6) .getCollisionBoundingBoxFromPool(par3World, par4, par5, par6); if (axis == null) axis = AxisAlignedBB.getBoundingBox(par4, par5, par6, par4 + 1, par5 + 1, par6 + 1); if (!blockVec.isInside(axis)) blockVec = new Vector3( axis.minX + (axis.maxX - axis.minX) / 2, axis.minY + (axis.maxY - axis.minY) / 2, axis.minZ + (axis.maxZ - axis.minZ) / 2); Vector3 diffVec = blockVec.copy().sub(spreaderVec); Vector3 diffVec2D = new Vector3(diffVec.x, diffVec.z, 0); Vector3 rotVec = new Vector3(0, 1, 0); double angle = rotVec.angle(diffVec2D) / Math.PI * 180.0; if (blockVec.x < spreaderVec.x) angle = -angle; spreader.rotationX = (float) angle + 90; rotVec = new Vector3(diffVec.x, 0, diffVec.z); angle = diffVec.angle(rotVec) * 180F / Math.PI; if (blockVec.y < spreaderVec.y) angle = -angle; spreader.rotationY = (float) angle; spreader.checkForReceiver(); par3World.markBlockForUpdate(boundSpreader.posX, boundSpreader.posY, boundSpreader.posZ); return true; } else setBoundSpreader(par1ItemStack, 0, -1, 0); } else if (par2EntityPlayer.isSneaking()) { block.rotateBlock(par3World, par4, par5, par6, ForgeDirection.getOrientation(par7)); if (par3World.isRemote) par2EntityPlayer.swingItem(); } if (block == Blocks.lapis_block && ConfigHandler.enchanterEnabled) { int meta = -1; if (TileEnchanter.canEnchanterExist(par3World, par4, par5, par6, 0)) meta = 0; else if (TileEnchanter.canEnchanterExist(par3World, par4, par5, par6, 1)) meta = 1; if (meta != -1 && !par3World.isRemote) { par3World.setBlock(par4, par5, par6, ModBlocks.enchanter, meta, 1 | 2); par3World.playSoundEffect(par4, par5, par6, "botania:enchanterBlock", 0.5F, 0.6F); for (int i = 0; i < 50; i++) { float red = (float) Math.random(); float green = (float) Math.random(); float blue = (float) Math.random(); double x = (Math.random() - 0.5) * 6; double y = (Math.random() - 0.5) * 6; double z = (Math.random() - 0.5) * 6; float velMul = 0.07F; Botania.proxy.wispFX( par3World, par4 + 0.5 + x, par5 + 0.5 + y, par6 + 0.5 + z, red, green, blue, (float) Math.random() * 0.15F + 0.15F, (float) -x * velMul, (float) -y * velMul, (float) -z * velMul); } } } else if (block instanceof IWandable) { boolean spreader = par3World.getTileEntity(par4, par5, par6) instanceof TileSpreader; int ticks = getTicksSinceSpreaderUse(par1ItemStack); boolean wanded = false; if (spreader && ticks == 5 && par2EntityPlayer.isSneaking()) { if (boundSpreader.posX == par4 && boundSpreader.posY == par5 && boundSpreader.posZ == par6) setBoundSpreader(par1ItemStack, 0, -1, 0); else setBoundSpreader(par1ItemStack, par4, par5, par6); if (par3World.isRemote) par2EntityPlayer.swingItem(); par3World.playSoundAtEntity(par2EntityPlayer, "botania:ding", 0.1F, 1F); setTicksSinceSpreaderUse(par1ItemStack, 0); wanded = true; } else { wanded = ((IWandable) block) .onUsedByWand(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6, par7); if (wanded) { if (par3World.isRemote) par2EntityPlayer.swingItem(); if (spreader) setTicksSinceSpreaderUse(par1ItemStack, 0); } } return wanded; } else if (BlockPistonRelay.playerPositions.containsKey( par2EntityPlayer.getCommandSenderName())) { String bindPos = BlockPistonRelay.playerPositions.get(par2EntityPlayer.getCommandSenderName()); String currentPos = BlockPistonRelay.getCoordsAsString(par3World.provider.dimensionId, par4, par5, par6); BlockPistonRelay.playerPositions.remove(par2EntityPlayer.getCommandSenderName()); BlockPistonRelay.mappedPositions.put(bindPos, currentPos); BlockPistonRelay.WorldData.get(par3World).markDirty(); if (par3World.isRemote) par2EntityPlayer.swingItem(); } return false; }