Lambda
Members-
Posts
486 -
Joined
-
Last visited
Everything posted by Lambda
-
Hello, So I created an enchantment that I want to have the ability for the player to fly, however I do not know how to check if the player is wearing boots with the enchantment, thus allowing them to fly. Would I have to create a separate event in which its constantly checking if the player is wearing boots? Or is there one within enchantments I could use? I have the code for the enchantment here: And the event handler here: Thanks!
-
Thanks, but ehrm.. How would I delete this post?
-
Hey there! So I need to access the items within a crafting table (or any table that uses the vanilla recipe system) so I can assign it to the ItemBlock just before its crafted.. here is my hoping result: You craft the original block, no special flags, nothing.. Then when you put a 'battery' with 'the block' in the the crafting table, it yields you a block with +1 battery or 2, just whatever amount you put it (where I need the crafting result).. the TE updates and notices the battery count has increased (via nbt) and sets the capacity respectively. Figured it out. I seriously do not know how to delete post anymore. Thanks.
-
No, he is not properly assigning names I beleive, this: #tabs itemGroup.tab_WeaponTab=Weapons Tab #Items item.NightGem.name=Night Gem #Blocks tile.NightOre.name=Night Ore Should be: #tabs itemGroup.MODID.tab_WeaponTab=Weapons Tab #Items item.MODID.NightGem.name=Night Gem #Blocks tile.MODID.NightOre.name=Night Ore
-
Hey there, So I have this basic conduit that transfer RF, however it seems that if the line of conduits are connected to multiple energy acceptors, it only supplies the closet one.. Can someone point me to how to do this? Here is the code I have so far: @Override public void updateEntity() { super.updateEntity(); if(!world.isRemote) { int energyStored = getEnergyStored(EnumFacing.DOWN); for (EnumFacing facing : EnumFacing.values()) { BlockPos pos = getPos().offset(facing); TileEntity te = world.getTileEntity(pos); if (te instanceof IEnergyHandler || (te != null && te.hasCapability(CapabilityEnergy.ENERGY, null))) { EnumFacing opposite = facing.getOpposite(); int rfToGive = SENDPERTICK <= energyStored ? SENDPERTICK : energyStored; int received; if (te instanceof IEnergyConnection) { IEnergyConnection connection = (IEnergyConnection) te; if (connection.canConnectEnergy(opposite)) { received = receiveEnergy(te, opposite, rfToGive); } else { received = 0; } } else { received = receiveEnergy(te, opposite, rfToGive); } energyStored -= storage.extractEnergy(received, false); if (energyStored <= 0) { break; } } } } } public static int receiveEnergy(TileEntity tileEntity, EnumFacing from, int maxReceive) { if (tileEntity instanceof IEnergyReceiver) { return ((IEnergyReceiver) tileEntity).receiveEnergy(from, maxReceive, false); } else if (tileEntity != null && tileEntity.hasCapability(CapabilityEnergy.ENERGY, from)) { net.minecraftforge.energy.IEnergyStorage capability = tileEntity.getCapability(CapabilityEnergy.ENERGY, from); if (capability.canReceive()) { return capability.receiveEnergy(maxReceive, false); } } return 0; } Thanks!
-
Is it your display not updating? Try doing this in the update function: System.out.println(energyStorage.getEnergyStored()); And see if it increments with the energy production.
-
Is the generate method being called?
-
I believe the mod has to support it.. Due to the fact the API is not an capability and class conventions are also different, so capability checks on a block or item would be return false for CoFH items/blocks. Usually mods just support both, but more recently people are moving away from this API. Here is an example of supporting both, if my statements above do not make sense. if (this.storage.getEnergyStored() > 0) { int received = 0; boolean canTakeUp = false; if (slotStack.getItem() instanceof IEnergyContainerItem) { //Checking CoFH Items IEnergyContainerItem item = (IEnergyContainerItem) slotStack.getItem(); received = (item.receiveEnergy(slotStack, this.storage.getEnergyStored(), false)); canTakeUp = item.getEnergyStored(slotStack) >= item.getMaxEnergyStored(slotStack); } else if (slotStack.hasCapability(CapabilityEnergy.ENERGY, null)) { //Checking Forge Energy Items IEnergyStorage cap = slotStack.getCapability(CapabilityEnergy.ENERGY, null); if (cap != null) { received = cap.receiveEnergy(this.storage.getEnergyStored(), false); canTakeUp = cap.getEnergyStored() >= cap.getMaxEnergyStored(); } } } But honestly, just use forges energy system.
-
We CANNOT help you if you show us nothing and complain about something is broke.. 0 code, your github hasn't been updated for a day, so I'm guessing its out of date. Take some time and think about what your doing and please get github working... It has great integration with IDEA and its easy to setup..
-
[1.11] [TESR] Weird shadow overlay on rendered item.
Lambda replied to Lambda's topic in Modder Support
Ah, yes that is what I thought, but it still doesn't seem to make a very big difference.. However it did lightening up a little bit... Maybe its because of the enchantment effect? (cannot connect to the website to copy the image, thanks ISP) http://prntscr.com/dzxdhb -
Hey there, As the title says I'm having this render issue with my TESR, the item displayed has this weird gloomy shadow overlay, even though I'm disabling said shadows, here is what it looks like: Here is the TESR: public class TileEntityRenderInscriber extends TileEntitySpecialRenderer<TileEntityInscriber> { @Override public void renderTileEntityAt(TileEntityInscriber te, double x, double y, double z, float partialTicks, int destroyStage) { if(te == null) return; ItemStack infStone = te.slots.getStackInSlot(0); if(StackUtil.isValid(infStone)) { GlStateManager.pushMatrix(); GlStateManager.translate((float) x + .5f, (float) y + 1.225f, (float) z + .5f); double spinRate = Minecraft.getSystemTime()/800d; GlStateManager.rotate((float)(((spinRate*40D)%360)), 0, 1, 0); GlStateManager.scale(.25, .25, .25); try { ResourceUtil.renderItemInWorld(infStone); } catch (Exception e) { ModUtil.LOGGER.error("A player tried to display an item on a 'inscriber' but failed!", e); } GlStateManager.popMatrix(); } } } Here is the code for 'renderItemInWorld': @SideOnly(Side.CLIENT) public static void renderItemInWorld(ItemStack stack){ if(StackUtil.isValid(stack)){ GlStateManager.pushMatrix(); GlStateManager.disableLighting(); GlStateManager.pushAttrib(); RenderHelper.enableStandardItemLighting(); Minecraft.getMinecraft().getRenderItem().renderItem(stack, TransformType.FIXED); RenderHelper.disableStandardItemLighting(); GlStateManager.popAttrib(); GlStateManager.enableLighting(); GlStateManager.popMatrix(); } } Thanks,
-
Maybe show us some code so we can see what your doing..?
-
Hey there, So I'm in need of setting a max size of a slot, say I want to make the slot size only 1, how would I do this?
-
Look at the vanilla code?
-
Yeah, I derped there, I had an original idea that only used 6 slots, but changed partway though... Thanks for pointing that out.
-
Hey there! So updating my mod to the latest forge version, I seem to get this crash when I open up my containers: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Slot 6 not in valid range - [0,6) at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_91] at net.minecraft.util.Util.runTask(Util.java:27) [util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91] Caused by: java.lang.RuntimeException: Slot -1 not in valid range - [0,6) at net.minecraftforge.items.ItemStackHandler.validateSlotIndex(ItemStackHandler.java:209) ~[itemStackHandler.class:?] at net.minecraftforge.items.ItemStackHandler.getStackInSlot(ItemStackHandler.java:75) ~[itemStackHandler.class:?] at com.github.dynamicgenerators.inventory.slot.SlotCustomItemHandler.getStack(SlotCustomItemHandler.java:39) ~[slotCustomItemHandler.class:?] at net.minecraft.inventory.Container.getInventory(Container.java:64) ~[Container.class:?] at net.minecraft.inventory.Container.addListener(Container.java:53) ~[Container.class:?] at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:100) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2733) ~[EntityPlayer.class:?] at com.github.dynamicgenerators.blocks.BlockInfuser.onBlockActivated(BlockInfuser.java:47) ~[blockInfuser.class:?] at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:474) ~[PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:712) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_91] at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?] ... 5 more Here is the code for the container: public class ContainerInfuser extends Container { public final TileEntityInfuser infuser; public ContainerInfuser(InventoryPlayer inventoryPlayer, TileEntityBase tileEntityBase) { this.infuser = (TileEntityInfuser)tileEntityBase; this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_INPUT, 80, 20)); //todo forloop this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD, 100, 20)); this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_1, 120, 20)); this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_2, 140, 20)); this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_3, 160, 20)); this.addSlotToContainer(new SlotCustomItemHandler(this.infuser.slots, TileEntityInfuser.SLOT_MOD_4, 180, 20)); this.addSlotToContainer(new SlotOutput(this.infuser.slots, TileEntityInfuser.SLOT_OUTPUT, 80, 5)); for(int i = 0; i < 3; i++){ for(int j = 0; j < 9; j++){ this.addSlotToContainer(new Slot(inventoryPlayer, j+i*9+9, 8+j*18, 97+i*18)); } } for(int i = 0; i < 9; i++){ this.addSlotToContainer(new Slot(inventoryPlayer, i, 8+i*18, 155)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot){ int inventoryStart = 7; int inventoryEnd = inventoryStart+26; int hotbarStart = inventoryEnd+1; int hotbarEnd = hotbarStart+8; Slot theSlot = this.inventorySlots.get(slot); if(theSlot != null && theSlot.getHasStack()){ ItemStack newStack = theSlot.getStack(); ItemStack currentStack = newStack.copy(); if(slot == TileEntityInfuser.SLOT_OUTPUT){ if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){ return StackUtil.getNull(); } theSlot.onSlotChange(newStack, currentStack); } else if(slot >= inventoryStart){ if(InfuserRecipeHandler.getRecipeFromInputs(newStack, newStack, newStack, newStack, newStack, newStack) != null){ if(!this.mergeItemStack(newStack, TileEntityInfuser.SLOT_INPUT, TileEntityInfuser.SLOT_INPUT+1, false)){ { return StackUtil.getNull(); } } } else if(slot >= inventoryStart && slot <= inventoryEnd){ if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){ return StackUtil.getNull(); } } else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){ return StackUtil.getNull(); } } else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){ return StackUtil.getNull(); } if(!StackUtil.isValid(newStack)){ theSlot.putStack(StackUtil.getNull()); } else{ theSlot.onSlotChanged(); } if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){ return StackUtil.getNull(); } theSlot.onTake(player, newStack); return currentStack; } return StackUtil.getNull(); } @Override public boolean canInteractWith(EntityPlayer playerIn) { return infuser.canPlayerUse(playerIn); } } And here is the 'CustomSlot' public class SlotCustomItemHandler extends SlotItemHandler{ private final ItemStackHandlerCustom handler; public SlotCustomItemHandler(ItemStackHandlerCustom handler, int index, int xPosition, int yPosition){ super(handler, index, xPosition, yPosition); this.handler = handler; } @Override public boolean isItemValid(ItemStack stack){ if(StackUtil.isValid(stack)){ ItemStack currentStack = this.handler.getStackInSlot(this.getSlotIndex()); this.handler.setStackInSlot(this.getSlotIndex(), ItemStack.EMPTY); ItemStack remainder = this.handler.insertItemInternal(this.getSlotIndex(), stack, true); this.handler.setStackInSlot(this.getSlotIndex(), currentStack); return remainder == null || remainder.getCount() < stack.getCount(); } return false; } @Override @Nonnull public ItemStack getStack(){ return this.handler.getStackInSlot(this.getSlotIndex()); } @Override public void putStack(ItemStack stack){ this.handler.setStackInSlot(this.getSlotIndex(), stack); this.onSlotChanged(); } @Override public int getItemStackLimit(ItemStack stack){ ItemStack maxAdd = stack.copy(); maxAdd.setCount(stack.getMaxStackSize()); ItemStack currentStack = this.handler.getStackInSlot(this.getSlotIndex()); this.handler.setStackInSlot(this.getSlotIndex(), ItemStack.EMPTY); ItemStack remainder = this.handler.insertItemInternal(this.getSlotIndex(), maxAdd, true); this.handler.setStackInSlot(this.getSlotIndex(), currentStack); return stack.getMaxStackSize()-remainder.getCount(); } @Override public boolean canTakeStack(EntityPlayer playerIn){ return !this.handler.extractItemInternal(this.getSlotIndex(), 1, true).isEmpty(); } @Override public ItemStack decrStackSize(int amount){ return this.handler.extractItemInternal(this.getSlotIndex(), amount, false); } } And it crashes at: @Override @Nonnull public ItemStack getStack(){ return this.handler.getStackInSlot(this.getSlotIndex()); } Thanks.
-
public class PacketServerToClient implements IMessage{ private NBTTagCompound data; private IDataHandler handler; public PacketServerToClient(){ //NOOP } public PacketServerToClient(NBTTagCompound data, IDataHandler handler){ this.data = data; this.handler = handler; } @Override public void fromBytes(ByteBuf buf){ PacketBuffer buffer = new PacketBuffer(buf); try{ this.data = buffer.readCompoundTag(); int handlerId = buffer.readInt(); if(handlerId >= 0 && handlerId < PacketHandler.DATA_HANDLERS.size()){ this.handler = PacketHandler.DATA_HANDLERS.get(handlerId); } } catch(Exception e){ ModUtil.LOGGER.error("Something went wrong trying to receive a client packet!", e); } } @Override public void toBytes(ByteBuf buf){ PacketBuffer buffer = new PacketBuffer(buf); buffer.writeCompoundTag(this.data); buffer.writeInt(PacketHandler.DATA_HANDLERS.indexOf(this.handler)); } public static class Handler implements IMessageHandler<PacketServerToClient, IMessage>{ @Override @SideOnly(Side.CLIENT) public IMessage onMessage(final PacketServerToClient message, final MessageContext ctx){ Minecraft.getMinecraft().addScheduledTask(new Runnable(){ @Override public void run(){ if(message.data != null && message.handler != null){ message.handler.handleData(message.data, ctx); } } }); return null; } } } With the IDataHandeler being: public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler() { @Override @SideOnly(Side.CLIENT) public void handleData(NBTTagCompound compound, MessageContext context) { World world = Minecraft.getMinecraft().world; if (world != null) { TileEntity tile = world.getTileEntity(new BlockPos(compound.getInteger("X"), compound.getInteger("Y"), compound.getInteger("Z"))); if (tile instanceof TileEntityBase) { ((TileEntityBase) tile).readSyncableNBT(compound.getCompoundTag("Data"), TileEntityBase.NBTType.SYNC); } } } };
-
It is.
-
@SubscribeEvent public void onGameOverlay(RenderGameOverlayEvent.Post event) { if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null) { Minecraft minecraft = Minecraft.getMinecraft(); EntityPlayer player = minecraft.player; RayTraceResult posHit = minecraft.objectMouseOver; FontRenderer font = minecraft.fontRendererObj; ItemStack stack = player.getHeldItemMainhand(); if (StackUtil.isValid(stack)) { if (stack.getItem() instanceof IHudDisplay) { ((IHudDisplay) stack.getItem()).displayHud(minecraft, player, stack, posHit, event.getResolution()); } } if (posHit != null && posHit.getBlockPos() != null) { Block blockHit = minecraft.world.getBlockState(posHit.getBlockPos()).getBlock(); TileEntity tileHit = minecraft.world.getTileEntity(posHit.getBlockPos()); if (blockHit instanceof IHudDisplay) { ((IHudDisplay) blockHit).displayHud(minecraft, player, stack, posHit, event.getResolution()); } if (tileHit instanceof TileEntityBase) { TileEntityBase base = (TileEntityBase) tileHit; if (base.isRedstoneToggle()) { String strg = "Activation Mode: " + TextFormatting.DARK_RED + (base.isPulseMode ? "Pulse" : "Deactivation") + TextFormatting.RESET; font.drawStringWithShadow(strg, event.getResolution().getScaledWidth() / 2 + 5, event.getResolution().getScaledHeight() / 2 + 5, StringUtil.DECIMAL_COLOR_WHITE); String expl; if (StackUtil.isValid(stack) && stack.getItem() == InitItems.itemJAWrench) { expl = TextFormatting.GREEN + "Right-Click to adjust!"; } else { expl = TextFormatting.GRAY.toString() + TextFormatting.ITALIC + "Hold a " + TextFormatting.BLUE + "Wrench " + TextFormatting.GRAY + " to Adjust"; } font.drawStringWithShadow(expl, event.getResolution().getScaledWidth() / 2 + 5, event.getResolution().getScaledHeight() / 2 + 15, StringUtil.DECIMAL_COLOR_WHITE); } } if (tileHit instanceof IEnergyDisplay) { IEnergyDisplay display = (IEnergyDisplay) tileHit; if (!display.needsHoldShift() || player.isSneaking()) { if (energyDisplay == null) { energyDisplay = new EnergyDisplay(0, 0, null); } energyDisplay.setData(2, event.getResolution().getScaledHeight() - 96, display.getEnergyStorage(), true, true); GlStateManager.pushMatrix(); GlStateManager.color(1F, 1F, 1F, 1F); energyDisplay.draw(); GlStateManager.popMatrix(); } } }
-
Oh man, this happened again, I went though and checked for previous mistakes, but its definitely something different. The TE Overlay does not update util I relog, which is interesting considering I'm almost sure that everything is in the right place (but obviously something is wrong) Here is the TE base: Here is the TE itself: public class TileEntitySterlingEngine extends TileEntityInventoryBase implements IEnergyDisplay { public final FluidTank lava = new FluidTank(8* Util.BUCKET); public final FluidTank water = new FluidTank(8* Util.BUCKET); public final CustomEnergyStorage storage = new CustomEnergyStorage(250000, 0, 50); public static final int FLUID_USE = 1; public static final int PRODUCE = 35; private int lastEnergy; private int lastLava; private int lastWater; public TileEntitySterlingEngine() { super(1, "sterlingGenerator"); } @Override public void updateEntity() { super.updateEntity(); if(!world.isRemote) { if(slots.getStackInSlot(0).getItem() == Items.WATER_BUCKET) { water.fillInternal(new FluidStack(FluidRegistry.WATER, Util.BUCKET), true); slots.setStackInSlot(0, new ItemStack(Items.BUCKET)); }else if(slots.getStackInSlot(0).getItem() == Items.LAVA_BUCKET) { lava.fillInternal(new FluidStack(FluidRegistry.LAVA, Util.BUCKET), true); slots.setStackInSlot(0, new ItemStack(Items.BUCKET)); } if(lava.getFluidAmount() - FLUID_USE >= 0 && water.getFluidAmount() - FLUID_USE >= 0) { lava.drainInternal(new FluidStack(FluidRegistry.LAVA, FLUID_USE), true); water.drainInternal(new FluidStack(FluidRegistry.WATER, FLUID_USE), true); storage.receiveEnergyInternal(PRODUCE, false); } if (this.lastEnergy != this.storage.getEnergyStored() || this.lava.getFluidAmount() != this.lastLava || this.water.getFluidAmount() != this.lastWater && this.sendUpdateWithInterval()) { this.lastEnergy = this.storage.getEnergyStored(); this.lastWater = this.water.getFluidAmount(); this.lastLava = this.lava.getFluidAmount(); } } } @Override public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { super.writeSyncableNBT(compound, type); this.storage.writeToNBT(compound); this.water.writeToNBT(compound); this.lava.writeToNBT(compound); } @Override public void readSyncableNBT(NBTTagCompound compound, NBTType type) { super.readSyncableNBT(compound, type); this.storage.readFromNBT(compound); this.lava.readFromNBT(compound); this.water.readFromNBT(compound); } @Override public CustomEnergyStorage getEnergyStorage() { return storage; } @Override public boolean needsHoldShift() { return false; } @Override public IEnergyStorage getEnergyStorage(EnumFacing facing) { return storage; } } My sendUpdate() function is being called this time!
-
Hey there! So I have a block here that accepts lava and water, however I have it bound so that the player must be sneaking to put it in, I want it to stay this way if possible.. However while sneaking and clicking on the machine it seems to place the lava instead of 'putting' it into the machine. Is there a work around to this? Thanks.
-
I don't like doing this.. bump
-
[1.11]Making Ore gen causes freeze on world loading {FIXED}
Lambda replied to Vitro Static's topic in Modder Support
We need that said error, look in your run folder>crashreports. -
Okay, an update: So now I've got a lot of this working, however it seems sometimes it gives energy to tiles that have 'MaxReceive' to 0 and sometimes no power is taken / received into the tether.. Is there a better way of coding this? public class TileEntityNetworkTethers extends TileEntityBase implements ISharingEnergyHandler, IEnergyDisplay { public CustomEnergyStorage storage = new CustomEnergyStorage(50000, 50, 50); public static final int MAX_SEND = 50; public ConcurrentHashMap<TileEntity, EnumFacing> energyUsers = new ConcurrentHashMap<>(); private int oldEnergy; public TileEntityNetworkTethers() { super("networkTethers"); } @Override public void updateEntity() { super.updateEntity(); if(!world.isRemote) { Iterable<BlockPos> blockPos = BlockPos.getAllInBox(pos.add(-5, -5, -5), pos.add(+5, +5, +5)); for(BlockPos bPos : blockPos) { TileEntity te = world.getTileEntity(bPos); for(EnumFacing facing : EnumFacing.VALUES) { if(te != null) { energyUsers.put(te, facing); } } } for(TileEntity tileEntity : energyUsers.keySet()) { for(EnumFacing facing : energyUsers.values()) { if(tileEntity.hasCapability(CapabilityEnergy.ENERGY, facing)) { IEnergyStorage cap = tileEntity.getCapability(CapabilityEnergy.ENERGY, facing); if(cap != null) { handleEnergy(tileEntity, cap); } } } } validateMap(); if (this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) { this.oldEnergy = this.storage.getEnergyStored(); } } } public void handleEnergy(TileEntity te, IEnergyStorage cap) { if (te instanceof TileEntityNetworkTethers) { IEnergyStorage theirStorage = ((TileEntityNetworkTethers) te).getEnergyStorage(); if(theirStorage.getEnergyStored() + MAX_SEND <= theirStorage.getMaxEnergyStored() || storage.getEnergyStored() + MAX_SEND <= storage.getMaxEnergyStored()) { if (theirStorage.getEnergyStored() != storage.getEnergyStored()) { solveDifference(theirStorage, storage); } } } if (cap.canExtract()) { int theirEnergyStored = cap.getEnergyStored(); if (theirEnergyStored - MAX_SEND >= 0) { cap.extractEnergy(MAX_SEND, false); this.storage.receiveEnergy(MAX_SEND, false); } } if (cap.canReceive()) { int theirEnergyStored = cap.getEnergyStored(); int theirMaxEnergyStored = cap.getMaxEnergyStored(); if (theirEnergyStored + MAX_SEND <= theirMaxEnergyStored) { if(storage.getEnergyStored() - MAX_SEND >= 0) { storage.extractEnergyInternal(MAX_SEND, false); cap.receiveEnergy(MAX_SEND, false); } } } } public void validateMap() { for(TileEntity te : energyUsers.keySet()) { if(te != null) { if(te.isInvalid()) { energyUsers.remove(te); } } } } public void solveDifference(IEnergyStorage theirStorage, IEnergyStorage thisStorage) { int difference = Math.abs(theirStorage.getEnergyStored()-thisStorage.getEnergyStored()); System.out.println(difference); if(theirStorage.receiveEnergy(difference/2, false) <= theirStorage.getMaxEnergyStored() && thisStorage.extractEnergy(difference / 2, false) >= 0) { theirStorage.receiveEnergy(difference / 2, false); thisStorage.extractEnergy(difference / 2, false); } } @Override public IEnergyStorage getEnergyStorage(EnumFacing facing) { return storage; } @Override public int getEnergyToSplitShare() { return storage.getEnergyStored(); } @Override public boolean doesShareEnergy() { return true; } @Override public EnumFacing[] getEnergyShareSides() { return EnumFacing.VALUES; } @Override public boolean canShareTo(TileEntity tile) { return true; } @Override public CustomEnergyStorage getEnergyStorage() { return storage; } @Override public boolean needsHoldShift() { return false; } } Also, my github is updated.. Thanks.
-
Hey there! So I'm in need in of somehow accessing a TE that extends the Energy Capability and find out if it is Energy Producer or Receiver.. However I cannot seem to find a way of doing this, especially a way that is compatible with other mods. Thanks.