net.minecraftforge.fluids.FluidStack Java Examples

The following examples show how to use net.minecraftforge.fluids.FluidStack. 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: GT_TileEntity_BioVat.java    From bartworks with MIT License 6 votes vote down vote up
private List<FluidStack> getFluidInputs(){
    ArrayList<FluidStack> tFluidList = this.getStoredFluids();
    int tFluidList_sS = tFluidList.size();
    for (int i = 0; i < tFluidList_sS - 1; i++) {
        for (int j = i + 1; j < tFluidList_sS; j++) {
            if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) {
                if (tFluidList.get(i).amount >= tFluidList.get(j).amount) {
                    tFluidList.remove(j--);
                    tFluidList_sS = tFluidList.size();
                } else {
                    tFluidList.remove(i--);
                    tFluidList_sS = tFluidList.size();
                    break;
                }
            }
        }
    }
    return tFluidList;
}
 
Example #2
Source File: FillerTileEntity.java    From EmergingTechnology with MIT License 6 votes vote down vote up
private void fillAdjacent() {
    for (EnumFacing facing : EnumFacing.VALUES) {
        TileEntity neighbour = this.world.getTileEntity(this.pos.offset(facing));

        // Return if no tile entity or another filler
        if (neighbour == null || neighbour instanceof FillerTileEntity) {
            continue;
        }

        IFluidHandler neighbourFluidHandler = neighbour
                .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());

        // Return if neighbour has no fluid tank
        if (neighbourFluidHandler == null) {
            continue;
        }

        // Fill the neighbour
        neighbourFluidHandler.fill(new FluidStack(FluidRegistry.WATER,
                EmergingTechnologyConfig.HYDROPONICS_MODULE.FILLER.fillerFluidTransferRate), true);
    }
}
 
Example #3
Source File: FluidStackRenderer.java    From YouTubeModdingTutorial with MIT License 6 votes vote down vote up
public static boolean renderFluidStack(FluidStack fluidStack, int x, int y) {
    Fluid fluid = fluidStack.getFluid();
    if (fluid == null) {
        return false;
    }

    Minecraft mc = Minecraft.getMinecraft();
    TextureMap textureMapBlocks = mc.getTextureMapBlocks();
    ResourceLocation fluidStill = fluid.getStill();
    TextureAtlasSprite fluidStillSprite = null;
    if (fluidStill != null) {
        fluidStillSprite = textureMapBlocks.getTextureExtry(fluidStill.toString());
    }
    if (fluidStillSprite == null) {
        fluidStillSprite = textureMapBlocks.getMissingSprite();
    }

    int fluidColor = fluid.getColor(fluidStack);
    mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    setGLColorFromInt(fluidColor);
    drawFluidTexture(x, y, fluidStillSprite);

    return true;
}
 
Example #4
Source File: TileEntityPoweredInventoryFluid.java    From BigReactors with MIT License 6 votes vote down vote up
/**
 * Fills fluid into internal tanks, distribution is left to the ITankContainer.
 * @param from Orientation the fluid is pumped in from.
 * @param resource FluidStack representing the maximum amount of fluid filled into the ITankContainer
 * @param doFill If false filling will only be simulated.
 * @return Amount of resource that was filled into internal tanks.
 */
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
	int tankToFill = FLUIDTANK_NONE;
	if(from != ForgeDirection.UNKNOWN) {
		tankToFill = getExposedTankFromSide(from.ordinal());
	}
	else {
		tankToFill = getDefaultTankForFluid(resource.getFluid());
	}

	if(tankToFill <= FLUIDTANK_NONE) {
		return 0;
	} else {
		return fill(tankToFill, resource, doFill);
	}
}
 
Example #5
Source File: FluidUtils.java    From CodeChickenCore with MIT License 6 votes vote down vote up
public static boolean fillTankWithContainer(IFluidHandler tank, EntityPlayer player) {
    ItemStack stack = player.getCurrentEquippedItem();
    FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);

    if (liquid == null)
        return false;

    if (tank.fill(null, liquid, false) != liquid.amount && !player.capabilities.isCreativeMode)
        return false;

    tank.fill(null, liquid, true);

    if (!player.capabilities.isCreativeMode)
        InventoryUtils.consumeItem(player.inventory, player.inventory.currentItem);

    player.inventoryContainer.detectAndSendChanges();
    return true;
}
 
Example #6
Source File: RecipeSteroidSyringe.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	boolean foundSyringe = false;
	boolean foundMana = false;
	boolean foundNacre = false;
	boolean foundLava = false;
	boolean foundDevilDust = false;

	ItemStack mana = FluidUtil.getFilledBucket(new FluidStack(ModFluids.MANA.getActual(), 1));
	ItemStack nacre = FluidUtil.getFilledBucket(new FluidStack(ModFluids.NACRE.getActual(), 1));

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) foundSyringe = true;
		if (ItemStack.areItemStacksEqual(mana, stack)) foundMana = true;
		if (ItemStack.areItemStacksEqual(nacre, stack)) foundNacre = true;
		if (stack.getItem() == Items.LAVA_BUCKET) foundLava = true;
		if (stack.getItem() == ModItems.DEVIL_DUST) foundDevilDust = true;
	}
	return foundSyringe && foundMana && foundDevilDust && foundLava && foundNacre;
}
 
Example #7
Source File: FluidHelper.java    From BigReactors with MIT License 6 votes vote down vote up
public FluidStack drain(int idx, FluidStack resource,
		boolean doDrain) {
	if(resource == null || resource.amount <= 0 || idx < 0 || idx >= fluids.length) { return null; }
	
	Fluid existingFluid = getFluidType(idx);
	if(existingFluid == null || existingFluid.getID() != resource.getFluid().getID()) { return null; }
	
	FluidStack drained = resource.copy();
	if(!doDrain) {
		drained.amount = Math.min(resource.amount, getFluidAmount(idx));
	}
	else {
		drained.amount = drainFluidFromStack(idx, resource.amount);
	}

	return drained;
}
 
Example #8
Source File: TileEntityAerialInterface.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill){
    if(resource != null && canFill(from, resource.getFluid())) {
        EntityPlayer player = getPlayer();
        if(player != null) {
            int liquidToXP = PneumaticCraftAPIHandler.getInstance().liquidXPs.get(resource.getFluid());
            int xpPoints = resource.amount / liquidToXP;
            if(doFill) {
                player.addExperience(xpPoints);
                curXpFluid = resource.getFluid();
            }
            return xpPoints * liquidToXP;
        }
    }
    return 0;
}
 
Example #9
Source File: ModFluidProvider.java    From EmergingTechnology with MIT License 6 votes vote down vote up
public static int getSpecificPlantGrowthBoostFromFluidStack(FluidStack fluidStack, String plantName) {

        if (fluidStack == null) return 0;

        if (fluidStack.getFluid() == null) return 0;

        ModFluid fluid = getFluidByFluidStack(fluidStack);

        if (fluid == null) {
            return 0;
        }

        if (fluid.allPlants == true) {
            return 0;
        }

        for (String plant : fluid.plants) {
            if (plantName.equalsIgnoreCase(plant)) {
                return fluid.boostModifier;
            }
        }

        return 0;
    }
 
Example #10
Source File: PacketUpdateGui.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public static Object readField(ByteBuf buf, int type){
    switch(type){
        case 0:
            return buf.readInt();
        case 1:
            return buf.readFloat();
        case 2:
            return buf.readDouble();
        case 3:
            return buf.readBoolean();
        case 4:
            return ByteBufUtils.readUTF8String(buf);
        case 5:
            return buf.readByte();
        case 6:
            return ByteBufUtils.readItemStack(buf);
        case 7:
            if(!buf.readBoolean()) return null;
            return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
    }
    throw new IllegalArgumentException("Invalid sync type! " + type);
}
 
Example #11
Source File: SplitFluidStorageHandler.java    From EmergingTechnology with MIT License 6 votes vote down vote up
@Override
public int fill(FluidStack resource, boolean doFill) {
    Fluid fluid = resource.getFluid();

    if (fluid == null) return 0;

    for (String fluidName : fluidNames) {
        if (fluid.getName().equalsIgnoreCase(fluidName)) {
            return fluidTank.fill(resource, doFill);
        }
    }
    
    for (String gasName : gasNames) {
        if (fluid.getName().equalsIgnoreCase(gasName)) {
            return gasTank.fill(resource, doFill);
        }
    }

    return 0;
}
 
Example #12
Source File: PhantomFluidWidget.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    if (id == 1) {
        ItemStack itemStack = gui.entityPlayer.inventory.getItemStack().copy();
        if (!itemStack.isEmpty()) {
            itemStack.setCount(1);
            IFluidHandlerItem fluidHandler = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
            if (fluidHandler != null) {
                FluidStack resultFluid = fluidHandler.drain(Integer.MAX_VALUE, false);
                fluidStackUpdater.accept(resultFluid);
            }
        } else {
            fluidStackUpdater.accept(null);
        }
    } else if (id == 2) {
        FluidStack fluidStack;
        try {
            fluidStack = FluidStack.loadFluidStackFromNBT(buffer.readCompoundTag());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        fluidStackUpdater.accept(fluidStack);
    }
}
 
Example #13
Source File: BarrelFluidHandler.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@Override
public int fill(FluidStack resource, boolean doFill) {
	if (barrel.getMode() != null && !barrel.getMode().canFillWithFluid(barrel))
		return 0;
	
	int amount = super.fill(resource, doFill);
	if (amount > 0) {
		PacketHandler.sendToAllAround(new MessageFluidUpdate(fluid, barrel.getPos()), barrel);
    	if (this.fluid != null && this.barrel.getMode() == null) {
    		this.barrel.setMode("fluid");
    		PacketHandler.sendToAllAround(new MessageBarrelModeUpdate(barrel.getMode().getName(), barrel.getPos()), barrel);
    	}
	}
	return amount;
}
 
Example #14
Source File: GTItemFluidTube.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull EntityPlayer player,
		@Nonnull EnumHand hand) {
	ItemStack itemstack = player.getHeldItem(hand);
	FluidStack fluidStack = FluidUtil.getFluidContained(itemstack);
	if (fluidStack == null) {
		return tryPickUpFluid(world, player, hand, itemstack, fluidStack);
	}
	return tryPlaceFluid(world, player, hand, itemstack, fluidStack);
}
 
Example #15
Source File: GuiLiquidCompressor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private List<String> getAllFuels(){
    List<String> fuels = new ArrayList<String>();
    fuels.add("L/Bucket | Fluid");
    for(Map.Entry<String, Integer> map : sortByValue(PneumaticCraftAPIHandler.getInstance().liquidFuels).entrySet()) {
        String value = map.getValue() / 1000 + "";
        while(fontRendererObj.getStringWidth(value) < 25) {
            value = value + " ";
        }
        Fluid fluid = FluidRegistry.getFluid(map.getKey());
        fuels.add(value + "| " + fluid.getLocalizedName(new FluidStack(fluid, 1)));
    }
    return fuels;
}
 
Example #16
Source File: GT_TileEntity_MegaDistillTower.java    From bartworks with MIT License 5 votes vote down vote up
@Override
protected void addFluidOutputs(FluidStack[] mOutputFluids2) {
    for (int i = 0; i < mOutputFluids2.length; i++) {
        for (int j = 0; j < LAYERMAP.get(i).size(); j++) {
            LAYERMAP.get(i).get(j).fill(new FluidStack(mOutputFluids2[i],mOutputFluids2[i].amount/LAYERMAP.get(i).size()), true);
        }
    }
}
 
Example #17
Source File: FluidHelper.java    From BigReactors with MIT License 5 votes vote down vote up
protected NBTTagCompound writeToNBT(NBTTagCompound destination) {
	String[] tankNames = getNBTTankNames();
	
	if(tankNames.length != fluids.length) { throw new IllegalArgumentException("getNBTTankNames must return the same number of strings as there are fluid stacks"); }

	FluidStack stack;
	for(int i = 0; i < tankNames.length; i++) {
		stack = fluids[i];
		if(stack != null) {
			destination.setTag(tankNames[i], stack.writeToNBT(new NBTTagCompound()));
		}
	}
	
	return destination;
}
 
Example #18
Source File: ItemBlockFluidTank.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void addInformation(ItemStack stack, World player,
		List list, ITooltipFlag bool) {
	super.addInformation(stack, player, list, bool);

	FluidStack fluidStack = getFluid(stack);

	if(fluidStack == null) {
		list.add("Empty");
	}
	else {
		list.add(fluidStack.getLocalizedName() + ": " + fluidStack.amount + "/64000mb");
	}
}
 
Example #19
Source File: TileRocketFluidUnloader.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void update() {

	//Move a stack of items
	if( !world.isRemote && rocket != null ) {

		boolean isAllowToOperate = (inputstate == RedstoneState.OFF || isStateActive(inputstate, getStrongPowerForSides(world, getPos())));

		List<TileEntity> tiles = rocket.storage.getFluidTiles();
		boolean rocketContainsItems = false;
		//Function returns if something can be moved
		for(TileEntity tile : tiles) {
			IFluidHandler handler = (IFluidHandler)tile;

			if(handler.drain( 1, false) != null)
				rocketContainsItems = true;

			if(isAllowToOperate) {
				FluidStack stack = fluidTank.getFluid();
				if(stack == null) {
					this.fill(handler.drain(fluidTank.getCapacity(), true), true);
				}
				else {
					stack = stack.copy();
					stack.amount = fluidTank.getCapacity() - fluidTank.getFluidAmount();

					if(stack.amount != 0) {
						this.fill(handler.drain( stack, true), true);
					}
				}
			}
		}

		//Update redstone state
		setRedstoneState(!rocketContainsItems);

	}
}
 
Example #20
Source File: FluidBusInventoryHandler.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public IAEItemStack addItems(IAEItemStack input)
{
	IAEItemStack addedStack = input.copy();

	if (input.getItem() == ItemEnum.FLUIDDISPLAY.getItemInstance() && (!isPreformatted() || (isPreformatted() && isItemInPreformattedItems(input.getItemStack()))))
	{
		if (tank != null)
		{

			if (getTankInfo(tank) == null || getTankInfo(tank)[0].fluid == null || FluidRegistry.getFluid(input.getItemDamage()) == tank.getTankInfo(facing)[0].fluid.getFluid())
			{

				int filled = 0;

				for (long i = 0; i < input.getStackSize() / 25; i++)
				{
					filled += tank.fill(facing, new FluidStack(input.getItemDamage(), 25), true);
				}
				int remainder = (int) (input.getStackSize() - ((input.getStackSize() / 25) * 25));
				if (remainder > 0)
				{
					filled += tank.fill(facing, new FluidStack(input.getItemDamage(), remainder), true);
				}

				addedStack.setStackSize(input.getStackSize() - filled);

				((TileEntity) tank).onInventoryChanged();

				if (addedStack != null && addedStack.getStackSize() == 0)
					addedStack = null;

				return addedStack;
			}
		}
	}
	return addedStack;
}
 
Example #21
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean addFluidsToFluidHandler(IFluidHandler handler, boolean simulate, List<FluidStack> items) {
    boolean filledAll = true;
    for (FluidStack stack : items) {
        int filled = handler.fill(stack, !simulate);
        filledAll &= filled == stack.amount;
        if (!filledAll && simulate) return false;
    }
    return filledAll;
}
 
Example #22
Source File: StaticRecipeChangeLoaders.java    From bartworks with MIT License 5 votes vote down vote up
private static void replaceWrongFluidOutput(Werkstoff werkstoff, GT_Recipe recipe, FluidStack wrongNamedFluid) {
    for (int i = 0; i < recipe.mFluidOutputs.length; i++) {
        if (GT_Utility.areFluidsEqual(recipe.mFluidOutputs[i], wrongNamedFluid)) {
            recipe.mFluidOutputs[i] = werkstoff.getFluidOrGas(recipe.mFluidOutputs[i].amount);
        }
    }
}
 
Example #23
Source File: MachineRecipeOutputImpl.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<FluidStack> getResultFluids()
{
    return outputFluids.stream()
                       .map(FluidStack::copy)
                       .collect(Collectors.toList());
}
 
Example #24
Source File: TileEntityDistillation.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public boolean canFillFluidType(FluidStack fluid) {
	if (!canFill() || fluid.getFluid().isGaseous(fluid) || fluid.getFluid().isLighterThanAir()) {
		return false;
	}
	return fluid.getFluid().getTemperature(fluid) < 500;
}
 
Example #25
Source File: MetaTileEntityCokeOven.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    this.isActive = data.getBoolean("Active");
    this.wasActiveAndNeedUpdate = data.getBoolean("WasActive");
    this.maxProgressDuration = data.getInteger("MaxProgress");
    if (maxProgressDuration > 0) {
        this.currentProgress = data.getInteger("Progress");
        this.outputStack = new ItemStack(data.getCompoundTag("OutputItem"));
        this.outputFluid = FluidStack.loadFluidStackFromNBT(data.getCompoundTag("OutputFluid"));
    }
}
 
Example #26
Source File: SimpleFluidFilter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void writeToNBT(NBTTagCompound tagCompound) {
    NBTTagList filterSlots = new NBTTagList();
    for (int i = 0; i < this.fluidFilterSlots.length; ++i) {
        FluidStack fluidStack = this.fluidFilterSlots[i];
        if (fluidStack != null) {
            NBTTagCompound stackTag = new NBTTagCompound();
            fluidStack.writeToNBT(stackTag);
            stackTag.setInteger("Slot", i);
            filterSlots.appendTag(stackTag);
        }
    }
    tagCompound.setTag("FluidFilter", filterSlots);
}
 
Example #27
Source File: RecipeHandlerFermenter.java    From NEI-Integration with MIT License 5 votes vote down vote up
@Override
public void loadCraftingRecipes(FluidStack result) {
    for (MachineFermenter.Recipe recipe : MachineFermenter.RecipeManager.recipes) {
        if (Utils.areFluidsSameType(recipe.output, result)) {
            this.arecipes.addAll(this.getCachedRecipes(recipe, true));
        }
    }
}
 
Example #28
Source File: TileEntityAerialInterface.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain){
    if(resource != null && canDrain(from, resource.getFluid())) {
        EntityPlayer player = getPlayer();
        if(player != null) {
            int liquidToXP = PneumaticCraftAPIHandler.getInstance().liquidXPs.get(resource.getFluid());
            int pointsDrained = Math.min(getPlayerXP(player), resource.amount / liquidToXP);
            if(doDrain) addPlayerXP(player, -pointsDrained);
            return new FluidStack(resource.getFluid(), pointsDrained * liquidToXP);
        }
    }
    return null;
}
 
Example #29
Source File: StaticRecipeChangeLoaders.java    From bartworks with MIT License 5 votes vote down vote up
private static void editEBFMaterialRecipes(SubTag GasTag, GT_Recipe recipe, Materials mat, HashSet<GT_Recipe> toAdd) {
    for (Materials materials : Materials.values()) {
        if (materials.contains(GasTag)) {
            int time = (int) ((double) recipe.mDuration / 200D * (200D + (materials.getProtons() >= mat.getProtons() ? (double) mat.getProtons() - (double) materials.getProtons() : (double) mat.getProtons() * 2.75D - (double) materials.getProtons())));
            toAdd.add(new BWRecipes.DynamicGTRecipe(false, recipe.mInputs, recipe.mOutputs, recipe.mSpecialItems, recipe.mChances, new FluidStack[]{materials.getGas(recipe.mFluidInputs[0].amount)}, recipe.mFluidOutputs, time, recipe.mEUt, recipe.mSpecialValue));
        }
    }
}
 
Example #30
Source File: FluidNetTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int fill(FluidStack resource, boolean doFill) {
    Preconditions.checkNotNull(resource, "resource");
    FluidStack copyStack = resource.copy();
    copyStack.amount = Math.min(copyStack.amount, getMaxThroughput());
    FluidPipeProperties properties = handle.getNodeData();
    boolean isLeakingPipe = copyStack.getFluid().isGaseous(copyStack) && !properties.gasProof;
    boolean isBurningPipe = copyStack.getFluid().getTemperature(copyStack) > properties.maxFluidTemperature;
    if (isLeakingPipe || isBurningPipe) {
        handle.destroyNetwork(isLeakingPipe, isBurningPipe);
        return copyStack.amount;
    }
    return super.fill(copyStack, doFill);
}