use of blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver in project ImmersiveEngineering by BluSunrize.
the class TileEntityLightningrod method update.
@Override
public void update() {
if (!worldObj.isRemote && formed && pos == 13) {
if (energyStorage.getEnergyStored() > 0) {
TileEntity tileEntity;
for (EnumFacing f : EnumFacing.HORIZONTALS) {
tileEntity = worldObj.getTileEntity(getPos().offset(f, 2));
if (tileEntity instanceof IFluxReceiver) {
IFluxReceiver ifr = (IFluxReceiver) tileEntity;
int accepted = ifr.receiveEnergy(f.getOpposite(), energyStorage.getEnergyStored(), true);
int extracted = energyStorage.extractEnergy(accepted, false);
ifr.receiveEnergy(f.getOpposite(), extracted, false);
}
}
}
if (worldObj.getTotalWorldTime() % 256 == ((getPos().getX() ^ getPos().getZ()) & 255))
fenceNet = null;
if (fenceNet == null)
fenceNet = this.getFenceNet();
if (fenceNet != null && worldObj.getTotalWorldTime() % 128 == ((getPos().getX() ^ getPos().getZ()) & 127) && (worldObj.isThundering() || (worldObj.isRaining() && worldObj.rand.nextInt(10) == 0))) {
int i = this.height + this.fenceNet.size();
if (worldObj.rand.nextInt(4096 * worldObj.getHeight()) < i * (getPos().getY() + i)) {
this.energyStorage.setEnergy(IEConfig.Machines.lightning_output);
BlockPos pos = fenceNet.get(worldObj.rand.nextInt(fenceNet.size()));
EntityLightningBolt entityLightningBolt = new EntityLightningBolt(worldObj, pos.getX(), pos.getY(), pos.getZ(), true);
worldObj.addWeatherEffect(entityLightningBolt);
worldObj.spawnEntityInWorld(entityLightningBolt);
}
}
}
}
use of blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver in project ImmersiveEngineering by BluSunrize.
the class ItemIETool method onItemUseFirst.
// @Override
// public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack)
// {
// return stack.getItemDamage()!=0;
// }
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
TileEntity tileEntity = world.getTileEntity(pos);
if (stack.getItemDamage() == 0) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return EnumActionResult.PASS;
String[] permittedMultiblocks = null;
String[] interdictedMultiblocks = null;
if (ItemNBTHelper.hasKey(stack, "multiblockPermission")) {
NBTTagList list = stack.getTagCompound().getTagList("multiblockPermission", 8);
permittedMultiblocks = new String[list.tagCount()];
for (int i = 0; i < permittedMultiblocks.length; i++) permittedMultiblocks[i] = list.getStringTagAt(i);
}
if (ItemNBTHelper.hasKey(stack, "multiblockInterdiction")) {
NBTTagList list = stack.getTagCompound().getTagList("multiblockInterdiction", 8);
interdictedMultiblocks = new String[list.tagCount()];
for (int i = 0; i < interdictedMultiblocks.length; i++) interdictedMultiblocks[i] = list.getStringTagAt(i);
}
for (IMultiblock mb : MultiblockHandler.getMultiblocks()) if (mb.isBlockTrigger(world.getBlockState(pos))) {
boolean b = permittedMultiblocks == null;
if (permittedMultiblocks != null)
for (String s : permittedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
b = true;
continue;
}
if (!b)
break;
if (interdictedMultiblocks != null)
for (String s : interdictedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
b = false;
continue;
}
if (!b)
break;
if (MultiblockHandler.postMultiblockFormationEvent(player, mb, pos, stack).isCanceled())
continue;
if (mb.createStructure(world, pos, side, player))
return EnumActionResult.SUCCESS;
}
TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof IDirectionalTile) && !(tile instanceof IHammerInteraction) && !(tile instanceof IConfigurableSides))
return RotationUtil.rotateBlock(world, pos, side) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
} else if (stack.getItemDamage() == 1 && tileEntity instanceof IImmersiveConnectable && !world.isRemote) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(null, target);
tileEntity = world.getTileEntity(masterPos);
if (!(tileEntity instanceof IImmersiveConnectable))
return EnumActionResult.PASS;
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
boolean cut = ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(nodeHere), world, target);
IESaveData.setDirty(world.provider.getDimension());
if (cut) {
int nbtDamage = ItemNBTHelper.getInt(stack, "cutterDmg") + 1;
if (nbtDamage < cutterMaxDamage)
ItemNBTHelper.setInt(stack, "cutterDmg", nbtDamage);
else {
player.renderBrokenItemStack(stack);
player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);
}
}
return EnumActionResult.SUCCESS;
} else if (stack.getItemDamage() == 2 && !world.isRemote) {
if (!player.isSneaking() && (tileEntity instanceof IFluxReceiver || tileEntity instanceof IFluxProvider)) {
int max = 0;
int stored = 0;
if (tileEntity instanceof IFluxReceiver) {
max = ((IFluxReceiver) tileEntity).getMaxEnergyStored(side);
stored = ((IFluxReceiver) tileEntity).getEnergyStored(side);
} else {
max = ((IFluxProvider) tileEntity).getMaxEnergyStored(side);
stored = ((IFluxProvider) tileEntity).getEnergyStored(side);
}
if (max > 0)
ChatUtils.sendServerNoSpamMessages(player, new TextComponentTranslation(Lib.CHAT_INFO + "energyStorage", stored, max));
return EnumActionResult.SUCCESS;
}
if (player.isSneaking() && tileEntity instanceof IImmersiveConnectable) {
if (!ItemNBTHelper.hasKey(stack, "linkingPos"))
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ() });
else {
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
if (array[0] == world.provider.getDimension()) {
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
if (nodeLink != null) {
Set<AbstractConnection> connections = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(Utils.toCC(nodeLink), world, true);
for (AbstractConnection con : connections) if (Utils.toCC(nodeHere).equals(con.end))
player.addChatComponentMessage(new TextComponentTranslation(Lib.CHAT_INFO + "averageLoss", Utils.formatDouble(con.getAverageLossRate() * 100, "###.000")));
}
}
ItemNBTHelper.remove(stack, "linkingPos");
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
use of blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver 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