public static void consumeAmmo(EntityPlayer player, Predicate<ItemStack> ammoFunc) { ItemStack ammo = getAmmo(player, ammoFunc); if(!ammo.isEmpty()) { ammo.shrink(1); } }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { if(!player.capabilities.isCreativeMode) player.getHeldItem(hand).shrink(1); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if(!world.isRemote) { EntityVineBall ball = new EntityVineBall(player, true); ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F); world.spawnEntity(ball); } return ActionResult.newResult(EnumActionResult.SUCCESS, player.getHeldItem(hand)); }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) { if(!world.isRemote && pos.getY() < 160 && !world.provider.doesWaterVaporize()) { world.playSound(null, pos, ModSounds.laputaStart, SoundCategory.BLOCKS, 1.0F + world.rand.nextFloat(), world.rand.nextFloat() * 0.7F + 1.3F); ItemStack stack = player.getHeldItem(hand); spawnBurstFirst(world, pos, stack); UseItemSuccessTrigger.INSTANCE.trigger((EntityPlayerMP) player, stack, (WorldServer) world, pos.getX(), pos.getY(), pos.getZ()); stack.shrink(1); } return EnumActionResult.SUCCESS; }
@Override public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity e) { if(!world.isRemote && e instanceof EntityItem) { EntityItem item = (EntityItem) e; ItemStack stack = item.getItem(); if(isSunflower(stack) && removeRain(world) || isBlueOrchid(stack) && startRain(world)) { stack.shrink(1); } } }
@Override public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase target, EnumHand hand) { if(target instanceof EntitySheep) { EntitySheep entitysheep = (EntitySheep)target; EnumDyeColor i = EnumDyeColor.byMetadata(stack.getItemDamage()); if(!entitysheep.getSheared() && entitysheep.getFleeceColor() != i) { entitysheep.setFleeceColor(i); stack.shrink(1); } return true; } return false; }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if(stack.getItemDamage() == 15) { if(!player.capabilities.isCreativeMode) stack.shrink(1); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if(!world.isRemote) { EntityEnderAirBottle b = new EntityEnderAirBottle(world, player); b.shoot(player, player.rotationPitch, player.rotationYaw, 0F, 1.5F, 1F); world.spawnEntity(b); } else player.swingArm(hand); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } return ActionResult.newResult(EnumActionResult.PASS, stack); }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if(!world.isRemote) { ItemStack copy = stack.copy(); copy.setCount(1); EntityThornChakram c = new EntityThornChakram(world, player, copy); c.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F); c.setFire(stack.getItemDamage() != 0); world.spawnEntity(c); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); stack.shrink(1); } return ActionResult.newResult(EnumActionResult.SUCCESS, stack); }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing s, float xs, float ys, float zs) { ItemStack stack = player.getHeldItem(hand); if(!stack.isEmpty() && (isSunflower(stack) && removeRain(world) || isBlueOrchid(stack) && startRain(world))) { if(!player.capabilities.isCreativeMode) stack.shrink(1); return true; } return false; }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); BlockPos coords = world.getSpawnPoint(); if(MathHelper.pointDistanceSpace(coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, player.posX, player.posY, player.posZ) > 24) { player.rotationPitch = 0F; player.rotationYaw = 0F; player.setPositionAndUpdate(coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5); while(!world.getCollisionBoxes(player, player.getEntityBoundingBox()).isEmpty()) player.setPositionAndUpdate(player.posX, player.posY + 1, player.posZ); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1F, 1F); for(int i = 0; i < 50; i++) Botania.proxy.sparkleFX(player.posX + Math.random() * player.width, player.posY - 1.6 + Math.random() * player.height, player.posZ + Math.random() * player.width, 0.25F, 1F, 0.25F, 1F, 10); stack.shrink(1); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } return ActionResult.newResult(EnumActionResult.PASS, stack); }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xs, float ys, float zs) { ItemStack stack = player.getHeldItem(hand); if(getSound(stack) != null) { Block block = world.getBlockState(pos).getBlock(); if(block == Blocks.NOTEBLOCK) { world.setBlockState(pos, ModBlocks.cacophonium.getDefaultState()); ((TileCacophonium) world.getTileEntity(pos)).stack = stack.copy(); stack.shrink(1); return EnumActionResult.SUCCESS; } } return EnumActionResult.PASS; }
private boolean addStack(World world, BlockPos pos, ItemStack stack, boolean creative) { TileCocoon cocoon = (TileCocoon) world.getTileEntity(pos); Item item = stack.getItem(); if(cocoon != null && (item == Items.EMERALD || item == Items.CHORUS_FRUIT)) { if(!world.isRemote) { if(item == Items.EMERALD && cocoon.emeraldsGiven < TileCocoon.MAX_EMERALDS) { if(!creative) stack.shrink(1); cocoon.emeraldsGiven++; ((WorldServer) world).spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0, 0, 0, 0.5); } else if(item == Items.CHORUS_FRUIT && cocoon.chorusFruitGiven < TileCocoon.MAX_CHORUS_FRUITS) { if(!creative) stack.shrink(1); cocoon.chorusFruitGiven++; ((WorldServer) world).spawnParticle(EnumParticleTypes.PORTAL, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 32, 0, 0, 0, 0.5); } } return true; } return false; }
@Nonnull @Override public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { EnumFacing facing = par1IBlockSource.getBlockState().getValue(BlockDispenser.FACING); BlockPos pos = par1IBlockSource.getBlockPos().offset(facing); World world = par1IBlockSource.getWorld(); if(world.isAirBlock(pos) && block.canPlaceBlockAt(world, pos)) { world.setBlockState(pos, block.getDefaultState()); par2ItemStack.shrink(1); return par2ItemStack; } return super.dispenseStack(par1IBlockSource, par2ItemStack); }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); int range = 16; List<EntityWither> withers = world.getEntitiesWithinAABB(EntityWither.class, new AxisAlignedBB(player.posX - range, player.posY - range, player.posZ - range, player.posX + range, player.posY + range, player.posZ + range)); for(EntityWither wither : withers) if(!world.isRemote && !wither.isDead && !(wither instanceof EntityPinkWither)) { wither.setDead(); EntityPinkWither pink = new EntityPinkWither(world); pink.setLocationAndAngles(wither.posX, wither.posY, wither.posZ, wither.rotationYaw, wither.rotationPitch); pink.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(pink)), null); world.spawnEntity(pink); pink.spawnExplosionParticle(); pink.playSound(SoundEvents.ENTITY_GENERIC_EXPLODE, 4F, (1F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F) * 0.7F); UseItemSuccessTrigger.INSTANCE.trigger((EntityPlayerMP) player, stack, (WorldServer) world, player.posX, player.posY, player.posZ); stack.shrink(1); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } return ActionResult.newResult(EnumActionResult.PASS, stack); }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xs, float ys, float zs) { IBlockState state = world.getBlockState(pos); if(Item.getItemFromBlock(state.getBlock()) == Items.AIR) return EnumActionResult.PASS; ItemStack blockStack = new ItemStack(state.getBlock()); int[] ids = OreDictionary.getOreIDs(blockStack); for(int i : ids) { String name = OreDictionary.getOreName(i); if(name.equals("grass")) { world.playEvent(2001, pos, Block.getStateId(state)); world.setBlockState(pos, ModBlocks.enchantedSoil.getDefaultState()); player.getHeldItem(hand).shrink(1); return EnumActionResult.SUCCESS; } } return EnumActionResult.PASS; }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing s, float xs, float ys, float zs) { if(Botania.gardenOfGlassLoaded) { ItemStack stack = player.getHeldItem(hand); if(!stack.isEmpty() && stack.getItem() == Item.getItemFromBlock(Blocks.SAPLING) && !player.inventory.hasItemStack(new ItemStack(ModItems.lexicon))) { if(!world.isRemote) { stack.shrink(1); ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.lexicon)); } return true; } } return false; }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if(BlockRailBase.isRailBlock(world.getBlockState(pos))) { if(!world.isRemote) { EntityMinecart entityminecart = new EntityPoolMinecart(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); if(stack.hasDisplayName()) entityminecart.setCustomNameTag(stack.getDisplayName()); world.spawnEntity(entityminecart); } stack.shrink(1); return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
@Override public void onDissolveTick(IManaPool pool, ItemStack stack, EntityItem item) { if(pool.isFull() || pool.getCurrentMana() == 0) return; TileEntity tile = (TileEntity) pool; boolean t2 = stack.getItemDamage() > 0; if(!item.world.isRemote) { pool.recieveMana(t2 ? MANA_PER_T2 : MANA_PER); stack.shrink(1); VanillaPacketDispatcher.dispatchTEToNearbyPlayers(item.world, tile.getPos()); PacketHandler.sendToNearby(item.world, item, new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.BLACK_LOTUS_DISSOLVE, item.posX, tile.getPos().getY() + 0.5, item.posZ)); } item.playSound(ModSounds.blackLotus, 0.5F, t2 ? 0.1F : 1F); }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xv, float yv, float zv) { TileEntity tile = world.getTileEntity(pos); if(tile != null && (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP) || tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) && !CorporeaHelper.doesBlockHaveSpark(world, pos)) { ItemStack stack = player.getHeldItem(hand); stack.shrink(1); if(!world.isRemote) { EntityCorporeaSpark spark = new EntityCorporeaSpark(world); if(stack.getItemDamage() == 1) spark.setMaster(true); spark.setPosition(pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5); world.spawnEntity(spark); world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 0); } return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
@Nonnull @Override public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { if(par2ItemStack.getItemDamage() == EnumDyeColor.BROWN.getDyeDamage()) { Block block = Blocks.COCOA; EnumFacing facing = par1IBlockSource.getBlockState().getValue(BlockDispenser.FACING); BlockPos pos = par1IBlockSource.getBlockPos().offset(facing); World world = par1IBlockSource.getWorld(); BlockPos logPos = pos.offset(facing); IBlockState logState = world.getBlockState(logPos); if(logState.getBlock() == Blocks.LOG && logState.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.JUNGLE && world.isAirBlock(pos) && block.canPlaceBlockAt(world, pos)) { world.setBlockState(pos, block.getDefaultState().withProperty(BlockHorizontal.FACING, facing)); par2ItemStack.shrink(1); return par2ItemStack; } } return vanillaBehaviour.dispense(par1IBlockSource, par2ItemStack); }
@SubscribeEvent public void onPlayerInteract(PlayerInteractEvent.RightClickBlock event) { ItemStack stack = event.getItemStack(); boolean correctStack = !stack.isEmpty() && stack.getItem() == Items.GLASS_BOTTLE; boolean ender = event.getWorld().provider instanceof WorldProviderEnd; if(correctStack && ender) { if (event.getWorld().isRemote) { event.getEntityPlayer().swingArm(event.getHand()); } else { ItemStack stack1 = new ItemStack(this, 1, 15); ItemHandlerHelper.giveItemToPlayer(event.getEntityPlayer(), stack1); stack.shrink(1); event.getWorld().playSound(null, event.getPos(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.5F, 1F); } event.setCanceled(true); event.setCancellationResult(EnumActionResult.SUCCESS); } }