From 6aab1c2e356f2eda6fa03b359010f0dca819c4aa Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Tue, 22 Jul 2014 00:47:24 -0500 Subject: [PATCH] Show Channel Usage for smart and dense cable in Waila. Waila Plugin now works when parts are in FMP Tiles. --- core/localization/WailaText.java | 2 +- integration/modules/Waila.java | 122 +++++++++++++++++++++++++------ parts/networking/PartCable.java | 18 +++++ 3 files changed, 119 insertions(+), 23 deletions(-) diff --git a/core/localization/WailaText.java b/core/localization/WailaText.java index ff4fdc31..6b8de3fe 100644 --- a/core/localization/WailaText.java +++ b/core/localization/WailaText.java @@ -9,7 +9,7 @@ public enum WailaText Locked, Unlocked, Showing, - Contains; + Contains, Channels; String root; diff --git a/integration/modules/Waila.java b/integration/modules/Waila.java index 506e350d..12ff7304 100644 --- a/integration/modules/Waila.java +++ b/integration/modules/Waila.java @@ -5,7 +5,10 @@ import java.util.List; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import mcp.mobius.waila.api.IWailaDataProvider; +import mcp.mobius.waila.api.IWailaFMPAccessor; +import mcp.mobius.waila.api.IWailaFMPProvider; import mcp.mobius.waila.api.IWailaRegistrar; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -23,24 +26,31 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.block.AEBaseBlock; import appeng.core.AppEng; +import appeng.core.localization.GuiText; import appeng.core.localization.WailaText; import appeng.integration.BaseModule; +import appeng.parts.networking.PartCableSmart; +import appeng.parts.networking.PartDenseCable; import appeng.tile.misc.TileCharger; +import appeng.tile.networking.TileCableBus; import appeng.tile.networking.TileEnergyCell; import appeng.util.Platform; import cpw.mods.fml.common.event.FMLInterModComms; -public class Waila extends BaseModule implements IWailaDataProvider +public class Waila extends BaseModule implements IWailaDataProvider, IWailaFMPProvider { public static Waila instance; public static void register(IWailaRegistrar registrar) { - // registrar.registerHeadProvider( (Waila) AppEng.instance.getIntegration( "Waila" ), AEBaseBlock.class ); - registrar.registerBodyProvider( (Waila) AppEng.instance.getIntegration( "Waila" ), AEBaseBlock.class ); + Waila w = (Waila) AppEng.instance.getIntegration( "Waila" ); + + registrar.registerBodyProvider( w, AEBaseBlock.class ); + registrar.registerBodyProvider( w, "ae2_cablebus" ); + registrar.registerSyncedNBTKey( "internalCurrentPower", TileEnergyCell.class ); - // registrar.registerTailProvider( (Waila) AppEng.instance.getIntegration( "Waila" ), AEBaseBlock.class ); + registrar.registerSyncedNBTKey( "extra:6.usedChannels", TileCableBus.class ); } @Override @@ -60,26 +70,53 @@ public class Waila extends BaseModule implements IWailaDataProvider @Override public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) { - return null; } - @Override - public List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) - { - - return currenttip; - } - @Override public List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { TileEntity te = accessor.getTileEntity(); + MovingObjectPosition mop = accessor.getPosition(); + + NBTTagCompound nbt = null; + + try + { + nbt = accessor.getNBTData(); + } + catch (NullPointerException npe) + { + } + + return getBody( itemStack, currenttip, accessor.getPlayer(), nbt, te, mop ); + } + + @Override + public List getWailaBody(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) + { + TileEntity te = accessor.getTileEntity(); + MovingObjectPosition mop = accessor.getPosition(); + + NBTTagCompound nbt = null; + + try + { + nbt = accessor.getNBTData(); + } + catch (NullPointerException npe) + { + } + + return getBody( itemStack, currenttip, accessor.getPlayer(), nbt, te, mop ); + } + + public List getBody(ItemStack itemStack, List currenttip, EntityPlayer player, NBTTagCompound nbt, TileEntity te, MovingObjectPosition mop) + { Object ThingOfInterest = te; if ( te instanceof IPartHost ) { - MovingObjectPosition mop = accessor.getPosition(); Vec3 Pos = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ); SelectedPart sp = ((IPartHost) te).selectPart( Pos ); if ( sp.facade != null ) @@ -94,16 +131,38 @@ public class Waila extends BaseModule implements IWailaDataProvider } } - if ( ThingOfInterest instanceof TileEnergyCell ) + try { - NBTTagCompound c = accessor.getNBTData(); - if ( c != null && c.hasKey( "internalCurrentPower" ) ) + if ( ThingOfInterest instanceof PartCableSmart || ThingOfInterest instanceof PartDenseCable ) { - TileEnergyCell tec = (TileEnergyCell) ThingOfInterest; - long power = (long) (100 * c.getDouble( "internalCurrentPower" )); - currenttip.add( WailaText.Contains + ": " + Platform.formatPowerLong( power, false ) + " / " - + Platform.formatPowerLong( (long) (100 * tec.getAEMaxPower()), false ) ); + NBTTagCompound c = nbt; + if ( c != null && c.hasKey( "extra:6" ) ) + { + NBTTagCompound ic = c.getCompoundTag( "extra:6" ); + if ( ic != null && ic.hasKey( "usedChannels" ) ) + { + int channels = ic.getByte( "usedChannels" ); + currenttip.add( channels + " " + GuiText.Of.getLocal() + " " + (ThingOfInterest instanceof PartDenseCable ? 32 : 8) + " " + + WailaText.Channels.getLocal() ); + } + } } + + if ( ThingOfInterest instanceof TileEnergyCell ) + { + NBTTagCompound c = nbt; + if ( c != null && c.hasKey( "internalCurrentPower" ) ) + { + TileEnergyCell tec = (TileEnergyCell) ThingOfInterest; + long power = (long) (100 * c.getDouble( "internalCurrentPower" )); + currenttip.add( WailaText.Contains + ": " + Platform.formatPowerLong( power, false ) + " / " + + Platform.formatPowerLong( (long) (100 * tec.getAEMaxPower()), false ) ); + } + } + } + catch (NullPointerException ex) + { + // :P } if ( ThingOfInterest instanceof IPartStorageMonitor ) @@ -121,7 +180,7 @@ public class Waila extends BaseModule implements IWailaDataProvider if ( stack instanceof IAEFluidStack ) { IAEFluidStack ais = (IAEFluidStack) stack; - currenttip.add( WailaText.Showing.getLocal() + ": " + ais.getFluid().getLocalizedName() ); + currenttip.add( WailaText.Showing.getLocal() + ": " + ais.getFluid().getLocalizedName( ais.getFluidStack() ) ); } if ( isLocked ) @@ -138,7 +197,7 @@ public class Waila extends BaseModule implements IWailaDataProvider if ( is != null ) { currenttip.add( WailaText.Contains + ": " + is.getDisplayName() ); - is.getItem().addInformation( is, accessor.getPlayer(), currenttip, true ); + is.getItem().addInformation( is, player, currenttip, true ); } } @@ -156,6 +215,13 @@ public class Waila extends BaseModule implements IWailaDataProvider return currenttip; } + @Override + public List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) + { + + return currenttip; + } + @Override public List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { @@ -163,4 +229,16 @@ public class Waila extends BaseModule implements IWailaDataProvider return currenttip; } + @Override + public List getWailaHead(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) + { + return currenttip; + } + + @Override + public List getWailaTail(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) + { + return currenttip; + } + } diff --git a/parts/networking/PartCable.java b/parts/networking/PartCable.java index 17d05ab1..2c2a7820 100644 --- a/parts/networking/PartCable.java +++ b/parts/networking/PartCable.java @@ -9,6 +9,7 @@ import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraftforge.common.util.ForgeDirection; @@ -222,6 +223,23 @@ public class PartCable extends AEBasePart implements IPartCable getHost().markForUpdate(); } + @Override + public void writeToNBT(NBTTagCompound data) + { + super.writeToNBT( data ); + + if ( Platform.isServer() ) + { + int howMany = 0; + + for (IGridConnection gc : getGridNode().getConnections()) + howMany = Math.max( gc.getUsedChannels(), howMany ); + + data.setByte( "usedChannels", (byte) howMany ); + } + + } + @Override public void writeToStream(ByteBuf data) throws IOException {