Show Channel Usage for smart and dense cable in Waila.

Waila Plugin now works when parts are in FMP Tiles.
This commit is contained in:
AlgorithmX2 2014-07-22 00:47:24 -05:00
parent 92171d36d3
commit 6aab1c2e35
3 changed files with 119 additions and 23 deletions

View file

@ -9,7 +9,7 @@ public enum WailaText
Locked, Unlocked, Showing,
Contains;
Contains, Channels;
String root;

View file

@ -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<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
{
return currenttip;
}
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> 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<String> getWailaBody(ItemStack itemStack, List<String> 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<String> getBody(ItemStack itemStack, List<String> 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,9 +131,26 @@ public class Waila extends BaseModule implements IWailaDataProvider
}
}
try
{
if ( ThingOfInterest instanceof PartCableSmart || ThingOfInterest instanceof PartDenseCable )
{
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 = accessor.getNBTData();
NBTTagCompound c = nbt;
if ( c != null && c.hasKey( "internalCurrentPower" ) )
{
TileEnergyCell tec = (TileEnergyCell) ThingOfInterest;
@ -105,6 +159,11 @@ public class Waila extends BaseModule implements IWailaDataProvider
+ 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<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
{
return currenttip;
}
@Override
public List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
{
@ -163,4 +229,16 @@ public class Waila extends BaseModule implements IWailaDataProvider
return currenttip;
}
@Override
public List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config)
{
return currenttip;
}
@Override
public List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config)
{
return currenttip;
}
}

View file

@ -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
{