use of net.minecraftforge.fluids.FluidStack in project SimplyJetpacks by Tonius.
the class ItemJetpackFueller method onUsingTick.
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
if (blockPos == null || blockPos.sideHit < 0) {
player.setItemInUse(null, 1);
} else {
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
if (player.worldObj.isRemote) {
return;
}
ItemStack chestplate = player.getCurrentArmor(2);
if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
return;
}
ItemPack packItem = (ItemPack) chestplate.getItem();
PackBase pack = packItem.getPack(chestplate);
if (pack == null) {
return;
}
FuelType fuelType = pack.fuelType;
ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
int pulled = 0;
if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
IEnergyProvider energyTile = (IEnergyProvider) tile;
pulled = energyTile.extractEnergy(pullSide, toPull, false);
} else if (fuelType == FuelType.FLUID) {
if (tile instanceof IFluidHandler) {
IFluidHandler fluidTile = (IFluidHandler) tile;
FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
return;
}
fluid = fluidTile.drain(pullSide, toPull, true);
pulled = fluid.amount;
}
}
if (pulled > 0) {
packItem.addFuel(chestplate, pulled, false);
}
}
}
use of net.minecraftforge.fluids.FluidStack in project SimplyJetpacks by Tonius.
the class ItemPack method drain.
@Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
T pack = this.getPack(container);
if (pack == null || pack.fuelType != FuelType.FLUID || pack.fuelFluid == null) {
return null;
}
FluidStack fluid = this.getFluid(container);
int amount = fluid != null ? fluid.amount : 0;
int fluidExtracted = Math.min(amount, Math.min(maxDrain, pack.fuelPerTickOut));
if (doDrain) {
amount -= fluidExtracted;
NBTHelper.getNBT(container).setInteger(TAG_FLUID, amount);
}
return fluidExtracted > 0 ? new FluidStack(FluidRegistry.getFluid(pack.fuelFluid), fluidExtracted) : null;
}
use of net.minecraftforge.fluids.FluidStack in project SimplyJetpacks by Tonius.
the class ItemPack method useFuel.
public int useFuel(ItemStack stack, int maxUse, boolean simulate) {
T pack = this.getPack(stack);
switch(pack.fuelType) {
case ENERGY:
default:
int energy = this.getEnergyStored(stack);
int energyExtracted = Math.min(energy, maxUse);
if (!simulate) {
energy -= energyExtracted;
NBTHelper.getNBT(stack).setInteger(TAG_ENERGY, energy);
}
return energyExtracted;
case FLUID:
if (pack.fuelFluid == null) {
return 0;
}
FluidStack fluid = this.getFluid(stack);
int amount = fluid != null ? fluid.amount : 0;
int fluidExtracted = Math.min(amount, maxUse);
if (!simulate) {
amount -= fluidExtracted;
NBTHelper.getNBT(stack).setInteger(TAG_FLUID, amount);
}
return fluidExtracted;
}
}
use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.
the class GuiAerialInterface method getLiquidXPText.
private List<String> getLiquidXPText() {
List<String> liquidXpText = new ArrayList<String>();
liquidXpText.add("gui.tab.info.aerialInterface.liquidXp.info");
for (Fluid fluid : PneumaticCraftAPIHandler.getInstance().liquidXPs.keySet()) {
liquidXpText.add(EnumChatFormatting.DARK_AQUA + new FluidStack(fluid, 1).getLocalizedName() + " (" + fluid.getName() + ")");
}
return liquidXpText;
}
use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.
the class GuiLogisticsBase method actionPerformed.
@Override
public void actionPerformed(IGuiWidget widget) {
super.actionPerformed(widget);
if (widget instanceof WidgetFluidStack) {
boolean leftClick = Mouse.isButtonDown(0);
boolean middleClick = Mouse.isButtonDown(2);
boolean shift = PneumaticCraft.proxy.isSneakingInGui();
IFluidTank tank = logistics.getTankFilter(widget.getID());
if (tank.getFluidAmount() > 0) {
if (middleClick) {
logistics.setFilter(widget.getID(), (FluidStack) null);
} else if (leftClick) {
tank.drain(shift ? tank.getFluidAmount() / 2 : 1000, true);
if (tank.getFluidAmount() < 1000) {
tank.drain(1000, true);
}
} else {
tank.fill(new FluidStack(tank.getFluid().getFluid(), shift ? tank.getFluidAmount() : 1000), true);
}
NetworkHandler.sendToServer(new PacketSetLogisticsFluidFilterStack(logistics, tank.getFluid(), widget.getID()));
} else {
fluidSearchGui = new GuiLogisticsLiquidFilter(this);
editingSlot = widget.getID();
mc.displayGuiScreen(fluidSearchGui);
}
}
}
Aggregations