@Override protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) { return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) { @Override protected boolean evaluate(BlockPos pos) { TileEntity te = drone.world().getTileEntity(pos); int count = 0; if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null) ) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); for (IFluidTankProperties prop : handler.getTankProperties()) { FluidStack stack = prop.getContents(); if (stack != null) { if (ProgWidgetLiquidFilter.isLiquidValid(stack.getFluid(), widget, 1)) { count += stack.amount; } } } } else { Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.world().getBlockState(pos).getBlock()); if (fluid != null && ProgWidgetLiquidFilter.isLiquidValid(fluid, widget, 1) && FluidUtils.isSourceBlock(drone.world(), pos)) { count += 1000; } } return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount(); } }; }
@Override @Optional.Method(modid = "theoneprobe") public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) { TileEntity te = world.getTileEntity(data.getPos()); if(te instanceof IInfoForwarder){ te = ((IInfoForwarder)te).getInfoTileEntity(); } if (te instanceof IPneumaticMachine) { TOPCallback.handlePneumatic(mode, probeInfo, (IPneumaticMachine)te); } if (te instanceof IHeatExchanger) { TOPCallback.handleHeat(mode, probeInfo, (IHeatExchanger) te); } if (ConfigHandler.client.topShowsFluids && te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit())) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit()); TOPCallback.handleFluidTanks(mode, probeInfo, handler); } if (te instanceof TileEntityBase) { TOPCallback.handleRedstoneMode(mode, probeInfo, (TileEntityBase) te); } if (te instanceof TileEntityPressureTube) { TOPCallback.handlePressureTube(mode, probeInfo, (TileEntityPressureTube) te, data.getSideHit()); } }
private static boolean doFluidInteraction(TileEntity te, EnumFacing face, EntityPlayer player, EnumHand hand, boolean isInserting) { ItemStack stack = player.getHeldItem(hand); IFluidHandlerItem stackHandler = FluidUtil.getFluidHandler(stack); if (stackHandler != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face)) { int capacity = stackHandler.getTankProperties()[0].getCapacity(); IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face); PlayerInvWrapper invWrapper = new PlayerInvWrapper(player.inventory); FluidActionResult result = isInserting ? FluidUtil.tryEmptyContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player) : FluidUtil.tryFillContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player); if (result.isSuccess()) { player.setHeldItem(hand, result.getResult()); return true; } } return false; }
@Subscribe public void preInit(FMLPreInitializationEvent evt) { CapabilityItemHandler.register(); CapabilityFluidHandler.register(); CapabilityAnimation.register(); CapabilityEnergy.register(); MinecraftForge.EVENT_BUS.register(MinecraftForge.INTERNAL_HANDLER); ForgeChunkManager.captureConfig(evt.getModConfigurationDirectory()); MinecraftForge.EVENT_BUS.register(this); if (!ForgeModContainer.disableVersionCheck) { ForgeVersion.startVersionCheck(); } // Add and register the forge universal bucket, if it's enabled if(FluidRegistry.isUniversalBucketEnabled()) { universalBucket = new UniversalBucket(); universalBucket.setUnlocalizedName("forge.bucketFilled"); GameRegistry.registerItem(universalBucket, "bucketFilled"); MinecraftForge.EVENT_BUS.register(universalBucket); } }
@Nullable @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (facing == null) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler); switch (facing) { case UP: return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerArmorInvHandler); case DOWN: return super.getCapability(capability, facing); default: return dispenserUpgradeInserted ? CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerFoodHandler) : CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler); } } else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && dispenserUpgradeInserted) { return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(playerExperienceHandler); } else if (capability == CapabilityEnergy.ENERGY) { return CapabilityEnergy.ENERGY.cast(energyRF); } return super.getCapability(capability, facing); }
@Override public int amountRequested(FluidStack stack) { int totalRequestingAmount = getTotalRequestedAmount(stack); if (totalRequestingAmount > 0) { TileEntity te = getTileEntity(); int count = 0; for (EnumFacing facing : EnumFacing.VALUES) { if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing); for (IFluidTankProperties properties : handler.getTankProperties()) { FluidStack contents = properties.getContents(); if (contents != null && contents.getFluid() == stack.getFluid()) { count += contents.amount; } } if (count > 0) break; } } if (count == 0) return 0; count += getIncomingFluid(stack.getFluid()); return Math.max(0, Math.min(stack.amount, totalRequestingAmount - count)); } return 0; }
@Override public IFluidTankProperties[] getTankProperties() { if(properties == null) { //Fingers crossed ArrayList<IFluidTankProperties> importedProperties = new ArrayList<>(); if (tile != null) for (EnumFacing facing : EnumFacing.HORIZONTALS) { if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) { IFluidHandler capability = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing); IFluidTankProperties[] faceProperties = capability.getTankProperties(); importedProperties.addAll(Arrays.asList(faceProperties)); } } properties = importedProperties.toArray(new IFluidTankProperties[importedProperties.size()]); } return properties; }
@Nullable @Override public FluidStack drain(FluidStack resource, boolean doDrain) { FluidStack drained = null; if(tile != null) for (EnumFacing facing : EnumFacing.HORIZONTALS) { if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing)) { IFluidHandler capability = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing); drained = capability.drain(resource,doDrain); if(drained != null) break; } } return drained; }
@Nullable @Override public FluidStack drain(int maxDrain, boolean doDrain) { FluidStack drained = null; if(tile != null) for (EnumFacing facing : EnumFacing.HORIZONTALS) { if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing)) { IFluidHandler capability = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing); drained = capability.drain(maxDrain,doDrain); if(drained != null) break; } } return drained; }
@Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { super.drawGuiContainerForegroundLayer(mouseX, mouseY); int[] data = ((ContainerBarrel) inventorySlots).data_a; this.renderHoveredToolTip(mouseX - guiLeft, mouseY - guiTop); if (mouseX > guiLeft + 62 && mouseX < guiLeft + 114 && mouseY > guiTop + 17 && mouseY < guiTop + 33) { FluidStack fstack = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).drain(1000, false); if (fstack != null) { ArrayList<String> tooltip = new ArrayList<String>(2); String color = fstack.getFluid().getTemperature() > 600 ? TextFormatting.GOLD.toString() : fstack.getFluid().getTemperature() < 150 ? TextFormatting.AQUA.toString() : TextFormatting.DARK_AQUA.toString(); tooltip.add(color + fstack.getLocalizedName()); tooltip.add(TextFormatting.GRAY + I18n.format("fluid.quantity.mB", fstack.amount)); drawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop); } else { drawHoveringText(I18n.format("fluid.none"), mouseX - guiLeft, mouseY - guiTop); } } else if (mouseX > guiLeft + 134 && mouseX < guiLeft + 150 && mouseY > guiTop + 20 && mouseY < guiTop + 36) { String text = TextFormatting.YELLOW + I18n.format("tile.barrel.altar.working"); if (data[3] == 0) text = TextFormatting.GREEN + I18n.format("tile.barrel.altar.none_required"); else if (te.getAltar(false) == null) text = TextFormatting.DARK_RED + I18n.format("tile.barrel.altar.no_altar"); else if (data[3] == data[1]) text = TextFormatting.GREEN + I18n.format("tile.barrel.altar.done"); drawHoveringText(text, mouseX - guiLeft, mouseY - guiTop); } }
@SuppressWarnings("ConstantConditions") @Override public void onFinish(TileCauldron tile, World world, BlockPos pos) { for (int i = 0; i < 20; i++) { final float x = pos.getX() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F); final float y = pos.getY() + 0.2F + world.rand.nextFloat(); final float z = pos.getZ() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F); PacketHandler.spawnParticle(ParticleF.STEAM, world, x, y, z, 10, 0, 0, 0); } if (!stack.isEmpty()) { if (tile.getContainer().isEmpty()) { tile.setContainer(stack); } else { spawnItem(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); } } world.playSound(null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1F, 1F); IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); handler.drain(1000, true); }
@Nullable @Override public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){ IItemHandler inventory = getInventory(facing); if(inventory != null){ return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory); } } if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){ IFluidHandler tank = getTank(facing); if(tank != null){ return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank); } } if(capability == CapabilityEnergy.ENERGY){ IEnergyStorage energy = getEnergy(facing); if(energy != null){ return CapabilityEnergy.ENERGY.cast(energy); } } return null; }
protected void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side){ IItemHandler inventory = this.getInventory(side); if(inventory != null && inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")){ for(int i = 0; i < inventory.getSlots(); i++){ // clear the inventory, otherwise empty stacks doesn't get overriden while syncing. Forge Bug? ((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY); } CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory")); } IFluidHandler tank = getTank(side); if(tank != null && tank instanceof IFluidTank && nbt.hasKey("FluidTank")){ CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank")); } IEnergyStorage energy = getEnergy(side); if(energy != null && energy instanceof EnergyStorage && nbt.hasKey("Energy")){ CapabilityEnergy.ENERGY.readNBT(energy, side, nbt.getTag("Energy")); } }
private boolean interactWithFluidItem(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing) { if (getContent().canInteractWithFluidItem.get(getSubtype(state)).orElse(true)) { TileEntity tile = worldIn.getTileEntity(pos); if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) { if (worldIn.isRemote) { return true; } if (FluidUtil.interactWithFluidHandler(playerIn, hand, worldIn, pos, facing)) { playerIn.inventoryContainer.detectAndSendChanges(); return true; } } } return false; }
public TileEntityPotStill() { inputTank.listen(this::markDirty); outputTank.listen(this::markDirty); itemStorage.listen(this::markDirty); heat.listen(this::markDirty); //Always inputTank.setCanDrain(false); outputTank.setCanFill(false); //Most of the time setTanksLocked(false); capabilities.registerForAllSides(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, ()->new ValidatedItemHandlerView(itemStorage), ()->itemStorage); capabilities.registerForAllSides(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ()->cap); capabilities.registerForAllSides(Thermionics.CAPABILITY_HEATSTORAGE, ()->HeatStorageView.insertOnlyOf(heat)); }
@Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); if (tag.hasKey("inputtank")) { CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(inputTank, null, tag.getTag("inputtank")); } if (tag.hasKey("outputtank")) { CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(outputTank, null, tag.getTag("outputtank")); } if (tag.hasKey("heatstorage")) { Thermionics.CAPABILITY_HEATSTORAGE.readNBT(heat, null, tag.getTag("heatstorage")); } if (tag.hasKey("inventory")) { CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(itemStorage, null, tag.getTag("inventory")); } if (tag.hasKey("locked")) { tanksLocked = tag.getByte("locked")!=0; } }
@Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); if (tag.hasKey("inputtank")) { CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(inputTank, null, tag.getTag("inputtank")); } if (tag.hasKey("outputtank")) { CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(outputTank, null, tag.getTag("outputtank")); } if (tag.hasKey("heatstorage")) { Thermionics.CAPABILITY_HEATSTORAGE.readNBT(heat, null, tag.getTag("heatstorage")); } if (tag.hasKey("inventory")) { CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(items, null, tag.getTag("inventory")); } if (tag.hasKey("cooldown")) { cooldown = tag.getInteger("cooldown"); } }
/** * Helper method to get an IFluidHandler for at a block position. * * Returns null if there is no valid fluid handler. */ @Nullable public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side) { IBlockState state = world.getBlockState(blockPos); Block block = state.getBlock(); if (block.hasTileEntity(state)) { TileEntity tileEntity = world.getTileEntity(blockPos); if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); } } else if (block instanceof IFluidBlock) { return new FluidBlockWrapper((IFluidBlock) block, world, blockPos); } else if (block instanceof BlockLiquid) { return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos); } return null; }
@Override public void addProblems(List<String> curInfo) { super.addProblems(curInfo); IFluidHandler fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); if (!te.isProducing && (fluidHandler == null || fluidHandler.getTankProperties()[0].getContents() == null)) { curInfo.add("gui.tab.problems.liquidCompressor.noFuel"); } }
@Override public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || capability == CapabilityEnergy.ENERGY || super.hasCapability(capability, facing); }
@Nullable @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory); } else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank); } else if (capability == CapabilityEnergy.ENERGY) { return CapabilityEnergy.ENERGY.cast(energy); } return super.getCapability(capability, facing); }
private boolean emptyTank(BlockPos pos, boolean simulate) { if (drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) { drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank"); abort(); return false; } else { TileEntity te = drone.world().getTileEntity(pos); if (te != null) { for (int i = 0; i < 6; i++) { if (((ISidedWidget) widget).getSides()[i] && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i))) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i)); FluidStack importedFluid = handler.drain(Integer.MAX_VALUE, false); if (importedFluid != null && ((ILiquidFiltered) widget).isFluidValid(importedFluid.getFluid())) { int filledAmount = drone.getTank().fill(importedFluid, false); if (filledAmount > 0) { if (((ICountWidget) widget).useCount()) filledAmount = Math.min(filledAmount, getRemainingCount()); if (!simulate) { decreaseCount(drone.getTank().fill(handler.drain(filledAmount, true), true)); } return true; } } } } drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos); } else if (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000) { Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.world().getBlockState(pos).getBlock()); if (fluid != null && ((ILiquidFiltered) widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.world(), pos)) { if (!simulate) { decreaseCount(1000); drone.getTank().fill(new FluidStack(fluid, 1000), true); drone.world().setBlockToAir(pos); } return true; } } return false; } }
@Nullable @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank); } else { return super.getCapability(capability, facing); } }
@Override public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { return ((isConnectedToPlayer && (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && dispenserUpgradeInserted) || capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)) || capability == CapabilityEnergy.ENERGY || super.hasCapability(capability, facing); }
@SuppressWarnings("unchecked") @Nullable @Override public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) return (T) energyStorage; else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return (T) fluidTank; else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) itemHandler; else return super.getCapability(capability, facing); }
private void tryTransferFluid(TileEntity inputTE, TileEntity outputTE){ IFluidHandler input = inputTE.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing); IFluidHandler output = outputTE.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite()); if(input != null && output != null){ FluidUtil.tryFluidTransfer(output, input, 100, true); } }
public void doAlchemicMixing(TileEntityMixerBottomImproved bottom, List<IUpgradeProvider> upgrades) { if(!(tile instanceof TileEntityAlchemyGlobe)) return; TileEntityAlchemyGlobe globe = (TileEntityAlchemyGlobe) this.tile; World world = bottom.getWorld(); TileEntityMixerTop top = (TileEntityMixerTop) world.getTileEntity(bottom.getPos().up()); if (top != null) { double emberCost = 2.0 * UpgradeUtil.getTotalEmberFuelEfficiency(bottom,upgrades); if (top.capability.getEmber() >= emberCost) { ArrayList<FluidStack> fluids = bottom.getFluids(); RecipeAlchemicalMixer recipe = CraftingRegistry.getAlchemicalMixingRecipe(fluids); if (recipe != null) { AlchemyResult result = recipe.matchAshes(globe.getAspects(), world); if(result.getAccuracy() == 1.0) { IFluidHandler tank = top.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidStack output = UpgradeUtil.transformOutput(bottom, recipe.output, upgrades); int amount = tank.fill(output, false); if (amount != 0) { tank.fill(output, true); bottom.consumeFluids(fluids, recipe); top.capability.removeAmount(emberCost * UpgradeUtil.getTotalEmberFuelEfficiency(bottom, upgrades), true); bottom.markDirty(); top.markDirty(); } } else if(result.getTotal() > 0) //That's not fair if we just void fluid without any ash { ItemStack failure = result.createFailure(); BlockPos topPos = top.getPos(); ejectFailure(world, topPos,failure,EnumFacing.HORIZONTALS); bottom.consumeFluids(fluids, recipe); top.capability.removeAmount(emberCost * UpgradeUtil.getTotalEmberFuelEfficiency(bottom, upgrades), true); fail(world.rand.nextInt(100)+200); } } } } }
@Override public void update() { World world = getWorld(); BlockPos pos = getPos(); TileEntityMixerTop top = (TileEntityMixerTop) world.getTileEntity(pos.up()); if (top != null) { List<IUpgradeProvider> upgrades = UpgradeUtil.getUpgrades(world,pos.up(),EnumFacing.values()); //TODO: Cache both of these calls UpgradeUtil.verifyUpgrades(this,upgrades); boolean cancel = UpgradeUtil.doWork(this,upgrades); if(cancel) return; double emberCost = 2.0 * UpgradeUtil.getTotalEmberFuelEfficiency(this,upgrades); if (top.capability.getEmber() >= emberCost) { ArrayList<FluidStack> fluids = getFluids(); FluidMixingRecipe recipe = RecipeRegistry.getMixingRecipe(fluids); if (recipe != null) { IFluidHandler tank = top.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidStack output = UpgradeUtil.transformOutput(this,recipe.output,upgrades); int amount = tank.fill(output, false); if (amount != 0) { tank.fill(output, true); consumeFluids(fluids, recipe); top.capability.removeAmount(emberCost, true); markDirty(); top.markDirty(); } } } } }
public ItemStack getFilled(CaskLiquid liquid) { ItemStack filled = new ItemStack(this); IFluidHandlerItem tank = filled.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY,null); if(tank != null) tank.fill(new FluidStack(liquid.fluid,capacity),true); return filled; }
public boolean hasOnlyOneFluid() { Fluid tankFluid = tank.getFluid() != null ? tank.getFluid().getFluid() : null; List<Fluid> fluids = new ArrayList<>(); for (ItemStack stack : crafting.getFilter()) { if (stack.isEmpty()) continue; if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); FluidStack fluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false); if (fluid != null && !fluids.contains(fluid.getFluid())) fluids.add(fluid.getFluid()); } } if (tankFluid != null) fluids.remove(tankFluid); return fluids.size() <= 1; }
@Override @Nullable public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY) { return CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY.cast(this); } return null; }
@Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { this.drawDefaultBackground(); if (te != null) { FluidStack fstack = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).drain(1000, false); Minecraft.getMinecraft().renderEngine.bindTexture(texture); drawTexturedModalRect(guiLeft + 62, guiTop + 17, 176, 32, 52, 16); if (fstack == null) { drawTexturedModalRect(guiLeft + 80, guiTop + 17, xSize, 0, 16, 16); } else { TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); TextureAtlasSprite sprite = map.getTextureExtry(fstack.getFluid().getStill().toString()); Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); for (int i = 0; i < 4; i++) drawTexturedModalRect(guiLeft + 62 + (16 * i), guiTop + 17, sprite, 16, 16); } } Minecraft.getMinecraft().renderEngine.bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); if (te != null) { int[] data = ((ContainerBarrel) inventorySlots).data_a; if (data[2] > 0) { double progress = (double) data[0] / (double) data[2]; if (progress > 1) progress = 1; int dy = (int) Math.ceil(31 * progress); drawTexturedModalRect(guiLeft + 29, guiTop + 27 + 31 - dy, 0, ySize + 31 - dy, 11, dy); } float absorption = 1; if (data[3] > 0) absorption = (float) data[1] / (float) data[3]; GlStateManager.pushMatrix(); { GlStateManager.color(2 * (1f - absorption), 2 * absorption, 0f); drawTexturedModalRect(guiLeft + 134, guiTop + 20, xSize, 16, 16, 16); GlStateManager.color(1f, 1f, 1f); } GlStateManager.popMatrix(); } }
@SuppressWarnings("unchecked") @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return (T) internalTank; if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) inv; return super.getCapability(capability, facing); }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) return true; TileEntityBarrel barrel = (TileEntityBarrel) world.getTileEntity(pos); world.notifyBlockUpdate(pos, state, state, 3); ItemStack stack = player.getHeldItem(hand); if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem itemHandler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); IFluidHandler barrelHandler = barrel.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidStack fluidInItem = itemHandler.drain(Fluid.BUCKET_VOLUME, false); FluidStack fluidInBarrel = barrelHandler.drain(Fluid.BUCKET_VOLUME, false); if ((fluidInBarrel != null && fluidInBarrel.amount > 0) && (fluidInItem == null || fluidInItem.amount == 0 || (fluidInItem.isFluidEqual(fluidInBarrel) && fluidInItem.amount < Fluid.BUCKET_VOLUME))) { itemHandler.fill(barrelHandler.drain(Fluid.BUCKET_VOLUME, true), true); player.setHeldItem(hand, itemHandler.getContainer()); } else if (fluidInItem != null && fluidInItem.amount > 0 && fluidInItem.getFluid() != null && (fluidInBarrel == null || fluidInBarrel.amount == 0 || (fluidInBarrel.amount < Fluid.BUCKET_VOLUME && fluidInBarrel.isFluidEqual(fluidInItem)))) { FluidStack fsin = itemHandler.drain(Fluid.BUCKET_VOLUME, true); if (fsin != null && fsin.amount > 0 && fsin.getFluid() != null) { barrelHandler.fill(fsin, true); player.setHeldItem(hand, itemHandler.getContainer()); player.inventory.markDirty(); } } return true; } player.openGui(Bewitchment.instance, LibGui.BARREL.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); return true; }
protected void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side){ IItemHandler inventory = this.getInventory(side); if(inventory != null && inventory instanceof IItemHandlerModifiable){ nbt.setTag("Inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side)); } IFluidHandler tank = getTank(side); if(tank != null && tank instanceof IFluidTank){ nbt.setTag("FluidTank", CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side)); } IEnergyStorage energy = getEnergy(side); if(energy != null && energy instanceof EnergyStorage){ nbt.setTag("Energy", CapabilityEnergy.ENERGY.writeNBT(energy, side)); } }
@Override public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) { init(stack); if (getFluidStored(stack) >= FLUID_CAPACITY) { return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } RayTraceResult ray = rayTrace(worldIn, playerIn, true); if (ray == null || ray.typeOfHit == null || hand == null) { return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } if (ray.typeOfHit == RayTraceResult.Type.BLOCK && hand == EnumHand.MAIN_HAND && !worldIn.isRemote) { BlockPos blockpos = ray.getBlockPos(); IBlockState iblockstate = worldIn.getBlockState(blockpos); Material material = iblockstate.getMaterial(); if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) { worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11); playerIn.addStat(StatList.getObjectUseStats(this)); playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F); addFluid(stack, 1000); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } else if (iblockstate.getBlock().hasTileEntity(iblockstate) && worldIn.getTileEntity(blockpos).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit)) { IFluidHandler fluidHandler = worldIn.getTileEntity(blockpos).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit); for (IFluidTankProperties property : fluidHandler.getTankProperties()) { if (property.getContents().getFluid() == FluidRegistry.WATER && property.getContents().amount >= 1000 && property.canDrain()) { fluidHandler.drain(new FluidStack(FluidRegistry.WATER, 1000), true); addFluid(stack, 1000); } } } } return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); }