use of net.minecraftforge.fluids.FluidActionResult in project Ceramics by KnightMiner.
the class ItemClayBucket method onFillBucket.
@SubscribeEvent(priority = EventPriority.LOW)
public void onFillBucket(FillBucketEvent event) {
if (event.getResult() != Event.Result.DEFAULT) {
// event was already handled
return;
}
// not for us to handle
ItemStack emptyBucket = event.getEmptyBucket();
if (emptyBucket == null || !emptyBucket.getItem().equals(this)) {
return;
}
// needs to target a block or entity
ItemStack singleBucket = emptyBucket.copy();
singleBucket.setCount(1);
RayTraceResult target = event.getTarget();
if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) {
return;
}
World world = event.getWorld();
BlockPos pos = target.getBlockPos();
IBlockState state = world.getBlockState(pos);
// first, try cauldrons (as long as the player is not sneaking
EntityPlayer player = event.getEntityPlayer();
if (state.getBlock() == Blocks.CAULDRON && (player == null || !player.isSneaking())) {
// if full, fill the bucket
if (state.getValue(BlockCauldron.LEVEL).intValue() == 3) {
// fill the bucket
event.setResult(Event.Result.ALLOW);
event.setFilledBucket(withFluid(FluidRegistry.WATER));
if (!world.isRemote) {
Blocks.CAULDRON.setWaterLevel(world, pos, state, 0);
}
// sound
if (player != null) {
SoundEvent soundevent = FluidRegistry.WATER.getFillSound(new FluidStack(FluidRegistry.WATER, 1000));
player.playSound(soundevent, 1f, 1f);
player.addStat(StatList.CAULDRON_USED);
}
} else {
event.setCanceled(true);
}
return;
}
FluidActionResult result = FluidUtil.tryPickUpFluid(singleBucket, player, world, pos, target.sideHit);
// if we have a bucket from the fluid, use that
if (result.isSuccess()) {
event.setResult(Event.Result.ALLOW);
event.setFilledBucket(result.getResult());
} else // otherwise, try gravel/sand
{
SpecialFluid fluid = SpecialFluid.fromState(state);
if (fluid != null) {
// fill the bucket
event.setFilledBucket(setSpecialFluid(singleBucket, fluid));
// play sound
world.playSound(player, pos, state.getBlock().getSoundType(state, world, pos, player).getBreakSound(), SoundCategory.BLOCKS, 1.0F, 0.8F);
// set air
if (!world.isRemote) {
world.setBlockToAir(pos);
}
// and allow
event.setResult(Event.Result.ALLOW);
} else {
// cancel event, otherwise the vanilla minecraft ItemBucket would
// convert it into a water/lava bucket depending on the blocks
// material
event.setCanceled(true);
}
}
}
use of net.minecraftforge.fluids.FluidActionResult in project pnc-repressurized by TeamPneumatic.
the class FluidUtils method tryFluidExtraction.
/**
* Attempt to extract fluid from the given fluid handler into the given fluid-containing item.
*
* @param srcHandler fluid handler into which to place the fluid
* @param destStack the fluid container item to extract from
* @param returnedItems the modified fluid container after extraction
* @return true if any fluid was moved, false otherwise
*/
public static boolean tryFluidExtraction(IFluidHandler srcHandler, ItemStack destStack, NonNullList<ItemStack> returnedItems) {
FluidActionResult result = FluidUtil.tryFillContainer(destStack, srcHandler, 1000, null, true);
if (result.isSuccess()) {
returnedItems.add(result.getResult());
destStack.shrink(1);
return true;
} else {
return false;
}
}
use of net.minecraftforge.fluids.FluidActionResult in project MorePlanets by SteveKunG.
the class BlockDummy method onNuclearTankActivated.
private boolean onNuclearTankActivated(World world, BlockPos pos, BlockPos detectPos, EntityPlayer player, ItemStack heldStack) {
if (world.getTileEntity(detectPos) instanceof TileEntityNuclearWasteTank && world.getBlockState(detectPos) == MPBlocks.NUCLEAR_WASTE_TANK.getDefaultState()) {
TileEntityNuclearWasteTank tank = (TileEntityNuclearWasteTank) world.getTileEntity(detectPos);
if (!heldStack.isEmpty()) {
if (tank.hasRod && !tank.createRod) {
if (heldStack.getItem() == MPItems.WASTE_ROD_PICKER) {
if (!player.capabilities.isCreativeMode) {
heldStack.damageItem(1, player);
}
Block.spawnAsEntity(world, pos, new ItemStack(MPItems.NUCLEAR_WASTE_ROD));
tank.hasRod = false;
return true;
}
} else {
int slot = player.inventory.currentItem;
FluidActionResult result = FluidUtil.interactWithFluidHandler(player.inventory.getCurrentItem(), tank.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null), player);
if (result.isSuccess()) {
tank.createRod = true;
tank.setTime();
player.inventory.setInventorySlotContents(slot, result.result);
if (player.inventoryContainer != null) {
player.inventoryContainer.detectAndSendChanges();
}
return true;
}
}
}
}
return false;
}
use of net.minecraftforge.fluids.FluidActionResult in project MorePlanets by SteveKunG.
the class BlockBlackHoleStorage method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
} else {
TileEntity tile = world.getTileEntity(pos);
int slot = player.inventory.currentItem;
if (tile instanceof TileEntityBlackHoleStorage) {
TileEntityBlackHoleStorage storage = (TileEntityBlackHoleStorage) tile;
FluidActionResult result = FluidUtil.interactWithFluidHandler(player.inventory.getCurrentItem(), storage.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null), player);
if (result.isSuccess()) {
player.inventory.setInventorySlotContents(slot, result.result);
if (player.inventoryContainer != null) {
player.inventoryContainer.detectAndSendChanges();
}
return true;
} else {
if (player.getGameProfile().getId().toString().equals(storage.ownerUUID)) {
if (player.isSneaking() && storage.fluidTank.getFluidAmount() > 0) {
Random rand = world.rand;
storage.drainExp(player);
world.playSound(null, player.getPosition(), SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.1F, 0.5F * ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.8F));
} else {
player.openGui(MorePlanetsMod.MOD_ID, -1, world, pos.getX(), pos.getY(), pos.getZ());
}
} else {
player.sendMessage(JsonUtils.create(LangUtils.translate("gui.bh_storage_not_owner.message")).setStyle(JsonUtils.red()));
}
}
}
return true;
}
}
use of net.minecraftforge.fluids.FluidActionResult in project GregTech by GregTechCE.
the class MetaTileEntity method fillContainerFromInternalTank.
public boolean fillContainerFromInternalTank(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, int inputSlot, int outputSlot) {
ItemStack emptyContainer = importItems.extractItem(inputSlot, 1, true);
FluidActionResult result = FluidUtil.tryFillContainer(emptyContainer, exportFluids, Integer.MAX_VALUE, null, false);
if (result.isSuccess()) {
ItemStack remainingItem = result.getResult();
if (!remainingItem.isEmpty() && !exportItems.insertItem(outputSlot, remainingItem, true).isEmpty())
return false;
FluidUtil.tryFillContainer(emptyContainer, exportFluids, Integer.MAX_VALUE, null, true);
importItems.extractItem(inputSlot, 1, false);
exportItems.insertItem(outputSlot, remainingItem, false);
return true;
}
return false;
}
Aggregations