use of net.minecraftforge.fluids.capability.IFluidHandler in project MinecraftForge by MinecraftForge.
the class FluidHandlerConcatenate method drain.
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
if (resource == null || resource.amount <= 0)
return null;
resource = resource.copy();
FluidStack totalDrained = null;
for (IFluidHandler handler : subHandlers) {
FluidStack drain = handler.drain(resource, doDrain);
if (drain != null) {
if (totalDrained == null)
totalDrained = drain;
else
totalDrained.amount += drain.amount;
resource.amount -= drain.amount;
if (resource.amount <= 0)
break;
}
}
return totalDrained;
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project Overloaded by CJ-MC-Mods.
the class BlockInfiniteTank method onBlockActivated.
@Override
public boolean onBlockActivated(@Nonnull World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.isEmpty() && hand == EnumHand.MAIN_HAND) {
LongFluidStack storedFluid = ((TileInfiniteTank) worldIn.getTileEntity(pos)).getStorage().getFluidStack();
if (storedFluid == null || storedFluid.fluidStack == null) {
playerIn.sendStatusMessage(new TextComponentString("Fluid: EMPTY"), false);
} else {
playerIn.sendStatusMessage(new TextComponentString(String.format("Fluid: %s Amount %,d", storedFluid.fluidStack.getLocalizedName(), storedFluid.amount)), false);
}
} else {
TileEntity te = worldIn.getTileEntity(pos);
if (te != null && te instanceof TileInfiniteTank) {
IFluidHandler handler = te.getCapability(FLUID_HANDLER_CAPABILITY, side);
// FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), te.getCapability(FLUID_HANDLER_CAPABILITY, facing), playerIn);
FluidActionResult result = FluidUtil.interactWithFluidHandler(heldItem, handler, playerIn);
if (result.isSuccess())
playerIn.setHeldItem(hand, result.getResult());
}
}
}
return true;
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project ImmersiveEngineering by BluSunrize.
the class TileEntitySqueezer method update.
@Override
public void update() {
super.update();
if (isDummy() || isRSDisabled())
return;
if (worldObj.isRemote) {
if (this.processQueue.isEmpty() && animation_piston < .6875)
animation_piston = Math.min(.6875f, animation_piston + .03125f);
else if (shouldRenderAsActive()) {
if (animation_down)
animation_piston = Math.max(0, animation_piston - .03125f);
else
animation_piston = Math.min(.6875f, animation_piston + .03125f);
if (animation_piston <= 0 && animation_down)
animation_down = false;
else if (animation_piston >= .6875 && !animation_down)
animation_down = true;
}
} else {
boolean update = false;
if (energyStorage.getEnergyStored() > 0 && processQueue.size() < this.getProcessQueueMaxLength()) {
final int[] usedInvSlots = new int[8];
for (MultiblockProcess process : processQueue) if (process instanceof MultiblockProcessInMachine)
for (int i : ((MultiblockProcessInMachine) process).inputSlots) usedInvSlots[i]++;
Integer[] preferredSlots = new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7 };
Arrays.sort(preferredSlots, 0, 8, new Comparator<Integer>() {
@Override
public int compare(Integer arg0, Integer arg1) {
return Integer.compare(usedInvSlots[arg0], usedInvSlots[arg1]);
}
});
for (int slot : preferredSlots) {
ItemStack stack = this.getInventory()[slot];
if (stack != null) {
stack = stack.copy();
stack.stackSize -= usedInvSlots[slot];
}
if (stack != null && stack.stackSize > 0) {
SqueezerRecipe recipe = this.findRecipeForInsertion(stack);
if (recipe != null) {
MultiblockProcessInMachine<SqueezerRecipe> process = new MultiblockProcessInMachine(recipe, slot);
if (this.addProcessToQueue(process, true)) {
this.addProcessToQueue(process, false);
update = true;
}
}
}
}
}
EnumFacing fw = mirrored ? facing.rotateYCCW() : facing.rotateY();
if (this.tanks[0].getFluidAmount() > 0) {
FluidStack out = Utils.copyFluidStackWithAmount(this.tanks[0].getFluid(), Math.min(this.tanks[0].getFluidAmount(), 80), false);
BlockPos outputPos = this.getPos().add(0, -1, 0).offset(fw, 2);
IFluidHandler output = FluidUtil.getFluidHandler(worldObj, outputPos, fw.getOpposite());
if (output != null) {
int accepted = output.fill(out, false);
if (accepted > 0) {
int drained = output.fill(Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true);
this.tanks[0].drain(drained, true);
update = true;
}
}
ItemStack empty = getInventory()[9];
if (empty != null && tanks[0].getFluidAmount() > 0) {
ItemStack full = Utils.fillFluidContainer(tanks[0], empty, getInventory()[10], null);
if (full != null) {
if (getInventory()[10] != null && OreDictionary.itemMatches(full, getInventory()[10], true))
getInventory()[10].stackSize += full.stackSize;
else
getInventory()[10] = full;
if (--inventory[9].stackSize <= 0)
inventory[9] = null;
}
}
}
if (inventory[8] != null && worldObj.getTotalWorldTime() % 8 == 0) {
BlockPos outputPos = this.getPos().offset(fw);
TileEntity outputTile = this.worldObj.getTileEntity(outputPos);
if (outputTile != null) {
ItemStack stack = Utils.copyStackWithAmount(inventory[8], 1);
stack = Utils.insertStackIntoInventory(outputTile, stack, fw.getOpposite());
if (stack == null)
if ((--this.inventory[8].stackSize) <= 0)
this.inventory[8] = null;
}
}
if (update) {
this.markDirty();
this.markContainingBlockForUpdate(null);
}
}
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project ImmersiveEngineering by BluSunrize.
the class TileEntityRefinery method update.
@Override
public void update() {
super.update();
if (worldObj.isRemote || isDummy())
return;
boolean update = false;
if (energyStorage.getEnergyStored() > 0 && processQueue.size() < this.getProcessQueueMaxLength()) {
if (tanks[0].getFluidAmount() > 0 || tanks[1].getFluidAmount() > 0) {
RefineryRecipe recipe = RefineryRecipe.findRecipe(tanks[0].getFluid(), tanks[1].getFluid());
if (recipe != null) {
MultiblockProcessInMachine<RefineryRecipe> process = new MultiblockProcessInMachine(recipe).setInputTanks((tanks[0].getFluidAmount() > 0 && tanks[1].getFluidAmount() > 0) ? new int[] { 0, 1 } : tanks[0].getFluidAmount() > 0 ? new int[] { 0 } : new int[] { 1 });
if (this.addProcessToQueue(process, true)) {
this.addProcessToQueue(process, false);
update = true;
}
}
}
}
if (this.tanks[2].getFluidAmount() > 0) {
ItemStack filledContainer = Utils.fillFluidContainer(tanks[2], inventory[4], inventory[5], null);
if (filledContainer != null) {
if (inventory[5] != null && OreDictionary.itemMatches(inventory[5], filledContainer, true))
inventory[5].stackSize += filledContainer.stackSize;
else if (inventory[5] == null)
inventory[5] = filledContainer.copy();
if (--inventory[4].stackSize <= 0)
inventory[4] = null;
update = true;
}
if (this.tanks[2].getFluidAmount() > 0) {
FluidStack out = Utils.copyFluidStackWithAmount(this.tanks[2].getFluid(), Math.min(this.tanks[2].getFluidAmount(), 80), false);
BlockPos outputPos = this.getPos().add(0, -1, 0).offset(facing.getOpposite());
IFluidHandler output = FluidUtil.getFluidHandler(worldObj, outputPos, facing);
if (output != null) {
int accepted = output.fill(out, false);
if (accepted > 0) {
int drained = output.fill(Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true);
this.tanks[2].drain(drained, true);
update = true;
}
}
}
}
ItemStack emptyContainer = Utils.drainFluidContainer(tanks[0], inventory[0], inventory[1], null);
if (emptyContainer != null && emptyContainer.stackSize > 0) {
if (inventory[1] != null && OreDictionary.itemMatches(inventory[1], emptyContainer, true))
inventory[1].stackSize += emptyContainer.stackSize;
else if (inventory[1] == null)
inventory[1] = emptyContainer.copy();
if (--inventory[0].stackSize <= 0)
inventory[0] = null;
update = true;
}
emptyContainer = Utils.drainFluidContainer(tanks[1], inventory[2], inventory[3], null);
if (emptyContainer != null && emptyContainer.stackSize > 0) {
if (inventory[3] != null && OreDictionary.itemMatches(inventory[3], emptyContainer, true))
inventory[3].stackSize += emptyContainer.stackSize;
else if (inventory[3] == null)
inventory[3] = emptyContainer.copy();
if (--inventory[2].stackSize <= 0)
inventory[2] = null;
update = true;
}
if (update) {
this.markDirty();
this.markContainingBlockForUpdate(null);
}
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project ImmersiveEngineering by BluSunrize.
the class ClientEventHandler method onRenderOverlayPost.
@SubscribeEvent()
public void onRenderOverlayPost(RenderGameOverlayEvent.Post event) {
if (ClientUtils.mc().thePlayer != null && event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
EntityPlayer player = ClientUtils.mc().thePlayer;
for (EnumHand hand : EnumHand.values()) if (player.getHeldItem(hand) != null) {
ItemStack equipped = player.getHeldItem(hand);
if (OreDictionary.itemMatches(new ItemStack(IEContent.itemTool, 1, 2), equipped, false) || equipped.getItem() instanceof IWireCoil) {
if (ItemNBTHelper.hasKey(equipped, "linkingPos")) {
int[] link = ItemNBTHelper.getIntArray(equipped, "linkingPos");
if (link != null && link.length > 3) {
String s = I18n.format(Lib.DESC_INFO + "attachedTo", link[1], link[2], link[3]);
int col = WireType.ELECTRUM.getColour(null);
if (equipped.getItem() instanceof IWireCoil) {
RayTraceResult rtr = ClientUtils.mc().objectMouseOver;
double d = rtr != null && rtr.getBlockPos() != null ? rtr.getBlockPos().distanceSq(link[1], link[2], link[3]) : player.getDistanceSq(link[1], link[2], link[3]);
int max = ((IWireCoil) equipped.getItem()).getWireType(equipped).getMaxLength();
if (d > max * max)
col = 0xdd3333;
}
ClientUtils.font().drawString(s, event.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, event.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, col, true);
}
}
} else if (OreDictionary.itemMatches(equipped, new ItemStack(IEContent.itemFluorescentTube), false)) {
String s = I18n.format("desc.ImmersiveEngineering.info.colour", "#" + ItemFluorescentTube.hexColorString(equipped));
ClientUtils.font().drawString(s, event.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, event.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, ItemFluorescentTube.getRGBInt(equipped), true);
} else if (equipped.getItem() instanceof ItemRevolver && equipped.getItemDamage() != 2) {
ClientUtils.bindTexture("immersiveengineering:textures/gui/revolver.png");
ItemStack[] bullets = ((ItemRevolver) equipped.getItem()).getBullets(equipped);
int bulletAmount = bullets.length;
EnumHandSide side = hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite();
float dx = side == EnumHandSide.RIGHT ? event.getResolution().getScaledWidth() - 32 - 48 : 48;
float dy = event.getResolution().getScaledHeight() - 64;
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.translate(dx, dy, 0);
GlStateManager.scale(.5f, .5f, 1);
GlStateManager.color(1, 1, 1, 1);
ClientUtils.drawTexturedRect(0, 1, 74, 74, 0 / 256f, 74 / 256f, 51 / 256f, 125 / 256f);
if (bulletAmount >= 18)
ClientUtils.drawTexturedRect(47, 1, 103, 74, 74 / 256f, 177 / 256f, 51 / 256f, 125 / 256f);
else if (bulletAmount > 8)
ClientUtils.drawTexturedRect(57, 1, 79, 39, 57 / 256f, 136 / 256f, 12 / 256f, 51 / 256f);
RenderItem ir = ClientUtils.mc().getRenderItem();
int[][] slots = ContainerRevolver.slotPositions[bulletAmount >= 18 ? 2 : bulletAmount > 8 ? 1 : 0];
for (int i = 0; i < bulletAmount; i++) {
if (bullets[i] != null) {
int x = 0;
int y = 0;
if (i == 0) {
x = 29;
y = 3;
} else if (i - 1 < slots.length) {
x = slots[i - 1][0];
y = slots[i - 1][1];
} else {
int ii = i - (slots.length + 1);
x = ii == 0 ? 48 : ii == 1 ? 29 : ii == 3 ? 2 : 10;
y = ii == 1 ? 57 : ii == 3 ? 30 : ii == 4 ? 11 : 49;
}
ir.renderItemIntoGUI(bullets[i], x, y);
}
}
RenderHelper.disableStandardItemLighting();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
} else if (equipped.getItem() instanceof ItemRailgun) {
int duration = 72000 - player.getItemInUseCount();
int chargeTime = ((ItemRailgun) equipped.getItem()).getChargeTime(equipped);
int chargeLevel = duration < 72000 ? Math.min(99, (int) (duration / (float) chargeTime * 100)) : 0;
float scale = 2f;
GlStateManager.pushMatrix();
GlStateManager.translate(event.getResolution().getScaledWidth() - 80, event.getResolution().getScaledHeight() - 30, 0);
GlStateManager.scale(scale, scale, 1);
ClientProxy.nixieFont.drawString((chargeLevel < 10 ? "0" : "") + chargeLevel, 0, 0, Lib.colour_nixieTubeText, false);
GlStateManager.scale(1 / scale, 1 / scale, 1);
GlStateManager.popMatrix();
} else if ((equipped.getItem() instanceof ItemDrill && equipped.getItemDamage() == 0) || equipped.getItem() instanceof ItemChemthrower) {
boolean drill = equipped.getItem() instanceof ItemDrill;
ClientUtils.bindTexture("immersiveengineering:textures/gui/hudElements.png");
GL11.glColor4f(1, 1, 1, 1);
float dx = event.getResolution().getScaledWidth() - 16;
float dy = event.getResolution().getScaledHeight();
GL11.glPushMatrix();
GL11.glTranslated(dx, dy, 0);
int w = 31;
int h = 62;
double uMin = 179 / 256f;
double uMax = 210 / 256f;
double vMin = 9 / 256f;
double vMax = 71 / 256f;
ClientUtils.drawTexturedRect(-24, -68, w, h, uMin, uMax, vMin, vMax);
GL11.glTranslated(-23, -37, 0);
IFluidHandler handler = FluidUtil.getFluidHandler(equipped);
int capacity = -1;
if (handler != null) {
IFluidTankProperties[] props = handler.getTankProperties();
if (props != null && props.length > 0)
capacity = props[0].getCapacity();
}
if (capacity > -1) {
FluidStack fuel = FluidUtil.getFluidContained(equipped);
int amount = fuel != null ? fuel.amount : 0;
if (!drill && player.isHandActive()) {
int use = player.getItemInUseMaxCount();
amount -= use * IEConfig.Tools.chemthrower_consumption;
}
float cap = (float) capacity;
float angle = 83 - (166 * amount / cap);
GL11.glRotatef(angle, 0, 0, 1);
ClientUtils.drawTexturedRect(6, -2, 24, 4, 91 / 256f, 123 / 256f, 80 / 256f, 87 / 256f);
GL11.glRotatef(-angle, 0, 0, 1);
// for(int i=0; i<=8; i++)
// {
// float angle = 83-(166/8f)*i;
// GL11.glRotatef(angle, 0, 0, 1);
// ClientUtils.drawTexturedRect(6,-2, 24,4, 91/256f,123/256f, 80/96f,87/96f);
// GL11.glRotatef(-angle, 0, 0, 1);
// }
GL11.glTranslated(23, 37, 0);
if (drill) {
ClientUtils.drawTexturedRect(-54, -73, 66, 72, 108 / 256f, 174 / 256f, 4 / 256f, 76 / 256f);
RenderItem ir = ClientUtils.mc().getRenderItem();
ItemStack head = ((ItemDrill) equipped.getItem()).getHead(equipped);
if (head != null) {
ir.renderItemIntoGUI(head, -51, -45);
ir.renderItemOverlayIntoGUI(head.getItem().getFontRenderer(head), head, -51, -45, null);
RenderHelper.disableStandardItemLighting();
}
} else {
ClientUtils.drawTexturedRect(-41, -73, 53, 72, 8 / 256f, 61 / 256f, 4 / 256f, 76 / 256f);
boolean ignite = ItemNBTHelper.getBoolean(equipped, "ignite");
ClientUtils.drawTexturedRect(-32, -43, 12, 12, 66 / 256f, 78 / 256f, (ignite ? 21 : 9) / 256f, (ignite ? 33 : 21) / 256f);
}
GL11.glPopMatrix();
}
}
// else if(equipped.getItem() instanceof ItemRailgun)
// {
// float dx = event.getResolution().getScaledWidth()-32-48;
// float dy = event.getResolution().getScaledHeight()-40;
// ClientUtils.bindTexture("immersiveengineering:textures/gui/hudElements.png");
// GL11.glColor4f(1, 1, 1, 1);
// GL11.glPushMatrix();
// GL11.glEnable(GL11.GL_BLEND);
// GL11.glTranslated(dx, dy, 0);
//
// int duration = player.getItemInUseDuration();
// int chargeTime = ((ItemRailgun)equipped.getItem()).getChargeTime(equipped);
// int chargeLevel = Math.min(99, (int)(duration/(float)chargeTime*100));
// // ClientUtils.drawTexturedRect(0,0, 64,32, 0/256f,64/256f, 96/256f,128/256f);
//
// GL11.glScalef(1.5f,1.5f,1.5f);
// int col = Config.getBoolean("nixietubeFont")?Lib.colour_nixieTubeText:0xffffff;
// ClientProxy.nixieFont.setDrawTubeFlag(false);
// // ClientProxy.nixieFont.drawString((chargeLevel<10?"0"+chargeLevel:""+chargeLevel), 19,3, col);
// ClientProxy.nixieFont.setDrawTubeFlag(true);
//
// GL11.glPopMatrix();
// }
RayTraceResult mop = ClientUtils.mc().objectMouseOver;
if (mop != null && mop.getBlockPos() != null) {
TileEntity tileEntity = player.worldObj.getTileEntity(mop.getBlockPos());
if (OreDictionary.itemMatches(new ItemStack(IEContent.itemTool, 1, 2), equipped, true)) {
int col = IEConfig.nixietubeFont ? Lib.colour_nixieTubeText : 0xffffff;
String[] text = null;
if (tileEntity instanceof IFluxReceiver) {
int maxStorage = ((IFluxReceiver) tileEntity).getMaxEnergyStored(mop.sideHit);
int storage = ((IFluxReceiver) tileEntity).getEnergyStored(mop.sideHit);
if (maxStorage > 0)
text = I18n.format(Lib.DESC_INFO + "energyStored", "<br>" + Utils.toScientificNotation(storage, "0##", 100000) + " / " + Utils.toScientificNotation(maxStorage, "0##", 100000)).split("<br>");
} else // }
if (mop.entityHit instanceof IFluxReceiver) {
int maxStorage = ((IFluxReceiver) mop.entityHit).getMaxEnergyStored(null);
int storage = ((IFluxReceiver) mop.entityHit).getEnergyStored(null);
if (maxStorage > 0)
text = I18n.format(Lib.DESC_INFO + "energyStored", "<br>" + Utils.toScientificNotation(storage, "0##", 100000) + " / " + Utils.toScientificNotation(maxStorage, "0##", 100000)).split("<br>");
}
if (text != null) {
if (player.worldObj.getTotalWorldTime() % 20 == 0) {
ImmersiveEngineering.packetHandler.sendToServer(new MessageRequestBlockUpdate(player.dimension, mop.getBlockPos()));
}
int i = 0;
for (String s : text) if (s != null) {
int w = ClientProxy.nixieFontOptional.getStringWidth(s);
ClientProxy.nixieFontOptional.drawString(s, event.getResolution().getScaledWidth() / 2 - w / 2, event.getResolution().getScaledHeight() / 2 - 4 - text.length * (ClientProxy.nixieFontOptional.FONT_HEIGHT + 2) + (i++) * (ClientProxy.nixieFontOptional.FONT_HEIGHT + 2), col, true);
}
}
}
}
}
if (ClientUtils.mc().objectMouseOver != null) {
boolean hammer = player.getHeldItem(EnumHand.MAIN_HAND) != null && Utils.isHammer(player.getHeldItem(EnumHand.MAIN_HAND));
RayTraceResult mop = ClientUtils.mc().objectMouseOver;
if (mop != null && mop.getBlockPos() != null) {
TileEntity tileEntity = player.worldObj.getTileEntity(mop.getBlockPos());
if (tileEntity instanceof IBlockOverlayText) {
IBlockOverlayText overlayBlock = (IBlockOverlayText) tileEntity;
String[] text = overlayBlock.getOverlayText(ClientUtils.mc().thePlayer, mop, hammer);
boolean useNixie = overlayBlock.useNixieFont(ClientUtils.mc().thePlayer, mop);
if (text != null && text.length > 0) {
FontRenderer font = useNixie ? ClientProxy.nixieFontOptional : ClientUtils.font();
int col = (useNixie && IEConfig.nixietubeFont) ? Lib.colour_nixieTubeText : 0xffffff;
int i = 0;
for (String s : text) if (s != null)
font.drawString(s, event.getResolution().getScaledWidth() / 2 + 8, event.getResolution().getScaledHeight() / 2 + 8 + (i++) * font.FONT_HEIGHT, col, true);
}
}
}
}
}
}
Aggregations