use of net.minecraftforge.fluids.FluidStack in project Railcraft by Railcraft.
the class SteamBoiler method convertSteam.
public int convertSteam(int numTanks) {
if (!isBoiling())
return 0;
partialConversions += numTanks * getHeatLevel();
int waterCost = (int) partialConversions;
if (waterCost <= 0)
return 0;
partialConversions -= waterCost;
FluidStack water = tankWater.drainInternal(waterCost, false);
if (water == null)
return 0;
waterCost = Math.min(waterCost, water.amount);
FluidStack steam = Fluids.STEAM.get(Steam.STEAM_PER_UNIT_WATER * waterCost);
if (steam == null)
return 0;
tankWater.drainInternal(waterCost, true);
tankSteam.fillInternal(steam, true);
return steam.amount;
}
use of net.minecraftforge.fluids.FluidStack in project Railcraft by Railcraft.
the class EntityCartTank method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
if (Game.isClient(worldObj)) {
return;
}
FluidStack fluidStack = tank.getFluid();
if (!Fluids.areIdentical(fluidStack, getFluidStack()))
setFluidStack(fluidStack);
update++;
ItemStack topSlot = invLiquids.getStackInSlot(SLOT_INPUT);
if (!InvTools.isEmpty(topSlot) && !FluidItemHelper.isContainer(topSlot)) {
invLiquids.setInventorySlotContents(SLOT_INPUT, null);
entityDropItem(topSlot, 1);
}
ItemStack bottomSlot = invLiquids.getStackInSlot(SLOT_OUTPUT);
if (!InvTools.isEmpty(bottomSlot) && !FluidItemHelper.isContainer(bottomSlot)) {
invLiquids.setInventorySlotContents(SLOT_OUTPUT, null);
entityDropItem(bottomSlot, 1);
}
//FIXME
// if (update % FluidTools.BUCKET_FILL_TIME == 0)
// FluidTools.processContainers(tank, invLiquids, SLOT_INPUT, SLOT_OUTPUT);
}
use of net.minecraftforge.fluids.FluidStack in project Witchworks by Um-Mitternacht.
the class TileKettle method useKettle.
@SuppressWarnings("ConstantConditions")
public boolean useKettle(EntityPlayer player, EnumHand hand, ItemStack heldItem) {
if (!world.isRemote) {
if (heldItem.isEmpty()) {
if (!getContainer().isEmpty()) {
giveItem(player, hand, ItemStack.EMPTY, getContainer());
setContainer(ItemStack.EMPTY);
} else if (inv.isFull() && hasIngredients() && mode != Mode.RITUAL) {
itemRitualLogic();
}
return true;
}
//Held Item is not empty
if (heldItem.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.UP)) {
handleLiquid(heldItem.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.UP));
} else if (heldItem.getItem() == Items.POTIONITEM && PotionUtils.getEffectsFromStack(heldItem).isEmpty()) {
int level = inv.getFluidAmount();
if (level < BUCKET_VOLUME && (inv.getFluid() == null || inv.hasFluid(FluidRegistry.WATER))) {
play(SoundEvents.ITEM_BUCKET_FILL, 1F, 1F);
giveItem(player, hand, heldItem, new ItemStack(Items.GLASS_BOTTLE));
FluidStack fluidStack = new FluidStack(FluidRegistry.WATER, 250);
inv.fill(fluidStack, true);
}
} else if (heldItem.getItem() == Items.GLASS_BOTTLE) {
if (mode == Mode.POTION) {
potionRecipeLogic(player, hand, heldItem);
} else if (mode == Mode.CUSTOM) {
potionCustomLogic(player, hand, heldItem);
}
} else if (getContainer().isEmpty()) {
ItemStack copy = heldItem.copy();
copy.setCount(1);
setContainer(copy);
giveItem(player, hand, heldItem, ItemStack.EMPTY);
}
}
return true;
}
use of net.minecraftforge.fluids.FluidStack in project Witchworks by Um-Mitternacht.
the class TileKettle method tryTurnLiquid.
private void tryTurnLiquid() {
if (!isBoiling() && hasIngredients() && inv.isFull()) {
Map<Item, FluidStack> fluids = KettleRegistry.getFluidItems();
Item item = ingredients[0].getItem();
if (fluids.containsKey(item)) {
int count = 8;
for (ItemStack ingredient : ingredients) {
if (ingredient.isEmpty())
break;
if (item == ingredient.getItem()) {
if (ingredient.getCount() > 1) {
while (ingredient.getCount() > 0 && count > 0) {
ingredient.shrink(1);
--count;
}
} else if (--count <= 0)
break;
} else
return;
}
if (count <= 0) {
FluidStack fluid = fluids.get(item).copy();
play(fluid.getFluid().getFillSound(), 1F, 1F);
inv.setFluid(fluid);
onLiquidChange();
}
}
}
}
use of net.minecraftforge.fluids.FluidStack in project Witchworks by Um-Mitternacht.
the class TileKettle method handleLiquid.
private void handleLiquid(IFluidHandlerItem handler) {
if (inv.isEmpty()) {
FluidStack drain = handler.drain(BUCKET_VOLUME, false);
if (drain != null && drain.amount <= BUCKET_VOLUME) {
handler.drain(drain.amount, true);
inv.setFluid(drain);
onLiquidChange();
play(drain.getFluid().getEmptySound(), 1F, 1F);
}
} else {
if (inv.isFull()) {
FluidStack fill = inv.drain(BUCKET_VOLUME, false);
FluidStack compare = handler.drain(BUCKET_VOLUME, false);
int filled = handler.fill(fill, false);
if (fill != null && (compare == null || fill.isFluidEqual(compare)) && filled <= BUCKET_VOLUME) {
handler.fill(fill, true);
inv.drain(filled, true);
play(fill.getFluid().getEmptySound(), 1F, 1F);
}
} else {
FluidStack drain = handler.drain(BUCKET_VOLUME, false);
if (drain != null && drain.isFluidEqual(inv.getFluid()) && drain.amount <= BUCKET_VOLUME) {
handler.drain(drain.amount, true);
inv.fill(drain, true);
play(drain.getFluid().getFillSound(), 1F, 1F);
}
}
}
}
Aggregations