Java Code Examples for net.minecraftforge.event.entity.player.FillBucketEvent#setResult()
The following examples show how to use
net.minecraftforge.event.entity.player.FillBucketEvent#setResult() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BucketHandler.java From AdvancedRocketry with MIT License | 6 votes |
@SubscribeEvent public void onBucketFill(FillBucketEvent event) { if(event.getTarget() == null || Type.BLOCK != event.getTarget().typeOfHit) return; IBlockState state = event.getWorld().getBlockState(new BlockPos(event.getTarget().getBlockPos())); Block block = state.getBlock(); Item bucket = bucketMap.get(block); if(bucket != null && state.equals(block.getDefaultState())) { event.getWorld().setBlockToAir(new BlockPos(event.getTarget().getBlockPos())); event.setFilledBucket(new ItemStack(bucket)); bucket.hasContainerItem(event.getFilledBucket()); event.setResult(Result.ALLOW); } }
Example 2
Source File: SingleFluidBucketFillHandler.java From OpenModsLib with MIT License | 6 votes |
@SubscribeEvent(priority = EventPriority.HIGH) public void onBucketFill(FillBucketEvent evt) { if (evt.getResult() != Result.DEFAULT) return; if (evt.getEmptyBucket().getItem() != EMPTY_BUCKET) return; final RayTraceResult target = evt.getTarget(); if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) return; final TileEntity te = evt.getWorld().getTileEntity(target.getBlockPos()); if (te == null) return; if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) { final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit); final FluidStack drained = source.drain(containedFluid, false); if (containedFluid.isFluidStackIdentical(drained)) { source.drain(containedFluid, true); evt.setFilledBucket(filledBucket.copy()); evt.setResult(Result.ALLOW); } } }
Example 3
Source File: PLEvent.java From Production-Line with MIT License | 5 votes |
@SubscribeEvent public void onBucketFill(FillBucketEvent event) { if (event.getEntityPlayer() != null) { Biome biome = event.getWorld().getBiomeForCoordsBody(event.getTarget().getBlockPos()); if (biome == Biomes.OCEAN || biome == Biomes.DEEP_OCEAN || biome == Biomes.FROZEN_OCEAN) { event.setResult(Event.Result.ALLOW); event.setFilledBucket(new ItemStack(PLItems.saltWaterBucket)); } } }
Example 4
Source File: EventHandlerPneumaticCraft.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@SubscribeEvent public void FillBucket(FillBucketEvent event){ MovingObjectPosition p = event.target; if(event.current == null || event.current.getItem() != Items.bucket || event.world.getBlockMetadata(p.blockX, p.blockY, p.blockZ) != 0) return; ItemStack result = attemptFill(event.world, event.target); if(result != null) { event.result = result; AchievementHandler.giveAchievement(event.entityPlayer, result); event.setResult(Result.ALLOW); } }
Example 5
Source File: BRLoader.java From BigReactors with MIT License | 5 votes |
@SubscribeEvent public void onBucketFill(FillBucketEvent e) { if(e.current.getItem() != Items.bucket) { return; } ItemStack filledBucket = fillBucket(e.world, e.target); if(filledBucket != null) { e.world.setBlockToAir(e.target.blockX, e.target.blockY, e.target.blockZ); e.result = filledBucket; e.setResult(Result.ALLOW); } }
Example 6
Source File: ContainerBucketFillHandler.java From OpenModsLib with MIT License | 5 votes |
@SubscribeEvent public void onBucketFill(FillBucketEvent evt) { if (evt.getResult() != Result.DEFAULT) return; if (evt.getEmptyBucket().getItem() != EMPTY_BUCKET) return; final RayTraceResult target = evt.getTarget(); if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) return; final TileEntity te = evt.getWorld().getTileEntity(target.getBlockPos()); if (te == null) return; if (!canFill(evt.getWorld(), target.getBlockPos(), te)) { return; } if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) { final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit); final FluidStack fluidInContainer = source.drain(Fluid.BUCKET_VOLUME, false); if (fluidInContainer != null) { final ItemStack filledBucket = getFilledBucket(fluidInContainer); if (!filledBucket.isEmpty()) { final IFluidHandlerItem container = FluidUtil.getFluidHandler(filledBucket); if (container != null) { final FluidStack fluidInBucket = container.drain(Integer.MAX_VALUE, false); if (fluidInBucket != null && fluidInBucket.isFluidStackIdentical(source.drain(fluidInBucket, false))) { source.drain(fluidInBucket, true); evt.setFilledBucket(filledBucket.copy()); evt.setResult(Result.ALLOW); } } } } } }