From c6f232ab6388c8a7c7d47383664817a43dc5b406 Mon Sep 17 00:00:00 2001 From: thatsIch Date: Fri, 19 Dec 2014 19:01:51 +0100 Subject: [PATCH] Fixes #304 WAILA Integration updated and fixed WAILA offers a new interface to sync the server data to the client. --- build.properties | 2 +- .../parts/IPartStorageMonitor.java | 2 +- .../appeng/core/localization/WailaText.java | 1 + .../java/appeng/integration/BaseModule.java | 6 +- .../integration/IIntegrationModule.java | 4 +- .../appeng/integration/IntegrationNode.java | 4 +- .../appeng/integration/IntegrationType.java | 2 +- .../java/appeng/integration/modules/BC.java | 10 +- .../integration/modules/BetterStorage.java | 4 +- .../appeng/integration/modules/CLApi.java | 6 +- .../integration/modules/CraftGuide.java | 4 +- .../java/appeng/integration/modules/DSU.java | 6 +- .../java/appeng/integration/modules/FMP.java | 4 +- .../java/appeng/integration/modules/FZ.java | 4 +- .../java/appeng/integration/modules/IC2.java | 6 +- .../modules/ImmibisMicroblocks.java | 10 +- .../appeng/integration/modules/InvTweaks.java | 4 +- .../java/appeng/integration/modules/MFR.java | 6 +- .../java/appeng/integration/modules/MJ5.java | 6 +- .../java/appeng/integration/modules/MJ6.java | 10 +- .../appeng/integration/modules/Mekanism.java | 6 +- .../java/appeng/integration/modules/NEI.java | 12 +- .../java/appeng/integration/modules/RB.java | 6 +- .../java/appeng/integration/modules/RC.java | 8 +- .../java/appeng/integration/modules/RF.java | 12 +- .../appeng/integration/modules/RFItem.java | 6 +- .../integration/modules/RotaryCraft.java | 6 +- .../appeng/integration/modules/Waila.java | 231 ++---------------- .../modules/waila/BaseWailaDataProvider.java | 74 ++++++ .../modules/waila/PartWailaDataProvider.java | 173 +++++++++++++ .../modules/waila/TileWailaDataProvider.java | 117 +++++++++ .../waila/part/BasePartWailaDataProvider.java | 67 +++++ .../waila/part/ChannelWailaDataProvider.java | 162 ++++++++++++ .../waila/part/IPartWailaDataProvider.java | 51 ++++ .../modules/waila/part/PartAccessor.java | 69 ++++++ .../part/PowerStateWailaDataProvider.java | 91 +++++++ .../part/StorageMonitorWailaDataProvider.java | 81 ++++++ .../modules/waila/part/Tracer.java | 96 ++++++++ .../waila/tile/ChargerWailaDataProvider.java | 78 ++++++ .../CraftingMonitorWailaDataProvider.java | 74 ++++++ .../tile/PowerStateWailaDataProvider.java | 82 +++++++ .../tile/PowerStorageWailaDataProvider.java | 169 +++++++++++++ .../tile/networking/TileEnergyAcceptor.java | 71 +++--- .../appliedenergistics2/lang/en_US.lang | 1 + 44 files changed, 1514 insertions(+), 330 deletions(-) create mode 100644 src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/part/ChannelWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/part/IPartWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/part/PartAccessor.java create mode 100644 src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/part/Tracer.java create mode 100644 src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/tile/PowerStateWailaDataProvider.java create mode 100644 src/main/java/appeng/integration/modules/waila/tile/PowerStorageWailaDataProvider.java diff --git a/build.properties b/build.properties index 3ef5e5a9..7c0aeeab 100644 --- a/build.properties +++ b/build.properties @@ -18,7 +18,7 @@ fmp_version=1.1.0.311 code_chicken_lib_version=1.1.1.105 code_chicken_core_version=1.0.4.29 nei_version=1.0.3.66 -waila_version=1.5.5_1.7.10 +waila_version=1.5.7a_1.7.10 ######################################################### # API Stubs # diff --git a/src/api/java/appeng/api/implementations/parts/IPartStorageMonitor.java b/src/api/java/appeng/api/implementations/parts/IPartStorageMonitor.java index bb411efe..acafc256 100644 --- a/src/api/java/appeng/api/implementations/parts/IPartStorageMonitor.java +++ b/src/api/java/appeng/api/implementations/parts/IPartStorageMonitor.java @@ -39,7 +39,7 @@ public interface IPartStorageMonitor extends IPartMonitor, IPart, IGridHost, INe * IAEFluidStack the quantity is important remember to use getStackSize() on the IAEStack, and not on the * FluidStack/ItemStack acquired from it. */ - IAEStack getDisplayed(); + IAEStack getDisplayed(); /** * @return the current locked state of the Storage Monitor diff --git a/src/main/java/appeng/core/localization/WailaText.java b/src/main/java/appeng/core/localization/WailaText.java index 0a197c78..d1b8a653 100644 --- a/src/main/java/appeng/core/localization/WailaText.java +++ b/src/main/java/appeng/core/localization/WailaText.java @@ -22,6 +22,7 @@ import net.minecraft.util.StatCollector; public enum WailaText { + Crafting, DeviceOnline, DeviceOffline, DeviceMissingChannel, diff --git a/src/main/java/appeng/integration/BaseModule.java b/src/main/java/appeng/integration/BaseModule.java index 6e5da650..cf40b35f 100644 --- a/src/main/java/appeng/integration/BaseModule.java +++ b/src/main/java/appeng/integration/BaseModule.java @@ -20,15 +20,15 @@ package appeng.integration; public abstract class BaseModule implements IIntegrationModule { - protected void TestClass( Class clz ) + protected void testClassExistence( Class clz ) { clz.isInstance(this); } @Override - public abstract void Init() throws Throwable; + public abstract void init() throws Throwable; @Override - public abstract void PostInit(); + public abstract void postInit(); } diff --git a/src/main/java/appeng/integration/IIntegrationModule.java b/src/main/java/appeng/integration/IIntegrationModule.java index 9a88e8e1..37dd08c7 100644 --- a/src/main/java/appeng/integration/IIntegrationModule.java +++ b/src/main/java/appeng/integration/IIntegrationModule.java @@ -21,8 +21,8 @@ package appeng.integration; public interface IIntegrationModule { - void Init() throws Throwable; + void init() throws Throwable; - void PostInit(); + void postInit(); } diff --git a/src/main/java/appeng/integration/IntegrationNode.java b/src/main/java/appeng/integration/IntegrationNode.java index 107f4283..51da5c52 100644 --- a/src/main/java/appeng/integration/IntegrationNode.java +++ b/src/main/java/appeng/integration/IntegrationNode.java @@ -96,12 +96,12 @@ public class IntegrationNode break; case INIT: - this.mod.Init(); + this.mod.init(); this.state = IntegrationStage.POST_INIT; break; case POST_INIT: - this.mod.PostInit(); + this.mod.postInit(); this.state = IntegrationStage.READY; break; diff --git a/src/main/java/appeng/integration/IntegrationType.java b/src/main/java/appeng/integration/IntegrationType.java index f79a3b5b..fd31eaf1 100644 --- a/src/main/java/appeng/integration/IntegrationType.java +++ b/src/main/java/appeng/integration/IntegrationType.java @@ -48,7 +48,7 @@ public enum IntegrationType CLApi(IntegrationSide.BOTH, "Colored Lights Core", "coloredlightscore"), - Waila(IntegrationSide.CLIENT, "Waila", "Waila"), + Waila(IntegrationSide.BOTH, "Waila", "Waila"), InvTweaks(IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks"), diff --git a/src/main/java/appeng/integration/modules/BC.java b/src/main/java/appeng/integration/modules/BC.java index 16a73f2b..52d3bab2 100644 --- a/src/main/java/appeng/integration/modules/BC.java +++ b/src/main/java/appeng/integration/modules/BC.java @@ -64,9 +64,9 @@ public class BC extends BaseModule implements IBC public static BC instance; public BC() { - this.TestClass( IPipeConnection.class ); - this.TestClass( ItemFacade.class ); - this.TestClass( IToolWrench.class ); + this.testClassExistence( IPipeConnection.class ); + this.testClassExistence( ItemFacade.class ); + this.testClassExistence( IToolWrench.class ); } @Override @@ -225,7 +225,7 @@ public class BC extends BaseModule implements IBC } @Override - public void Init() + public void init() { AEApi.instance().partHelper().registerNewLayer( "appeng.parts.layers.LayerIPipeConnection", "buildcraft.api.transport.IPipeConnection" ); AEApi.instance().registries().externalStorage().addExternalStorageInterface( new BCPipeHandler() ); @@ -292,7 +292,7 @@ public class BC extends BaseModule implements IBC } @Override - public void PostInit() + public void postInit() { this.registerPowerP2P(); this.registerItemP2P(); diff --git a/src/main/java/appeng/integration/modules/BetterStorage.java b/src/main/java/appeng/integration/modules/BetterStorage.java index 6455c1fe..038a038e 100644 --- a/src/main/java/appeng/integration/modules/BetterStorage.java +++ b/src/main/java/appeng/integration/modules/BetterStorage.java @@ -50,13 +50,13 @@ public class BetterStorage implements IIntegrationModule, IBetterStorage } @Override - public void Init() + public void init() { } @Override - public void PostInit() + public void postInit() { AEApi.instance().registries().externalStorage().addExternalStorageInterface( new BSCrateHandler() ); } diff --git a/src/main/java/appeng/integration/modules/CLApi.java b/src/main/java/appeng/integration/modules/CLApi.java index e2303dc2..c25b3683 100644 --- a/src/main/java/appeng/integration/modules/CLApi.java +++ b/src/main/java/appeng/integration/modules/CLApi.java @@ -28,13 +28,13 @@ public class CLApi extends BaseModule implements ICLApi public static CLApi instance; @Override - public void Init() throws Throwable + public void init() throws Throwable { - this.TestClass( coloredlightscore.src.api.CLApi.class ); + this.testClassExistence( coloredlightscore.src.api.CLApi.class ); } @Override - public void PostInit() + public void postInit() { // :P } diff --git a/src/main/java/appeng/integration/modules/CraftGuide.java b/src/main/java/appeng/integration/modules/CraftGuide.java index d936ca5b..2ef9f4b1 100644 --- a/src/main/java/appeng/integration/modules/CraftGuide.java +++ b/src/main/java/appeng/integration/modules/CraftGuide.java @@ -375,13 +375,13 @@ public class CraftGuide extends CraftGuideAPIObject implements IIntegrationModul } @Override - public void Init() throws Throwable + public void init() throws Throwable { StackInfo.addSource( this ); } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/DSU.java b/src/main/java/appeng/integration/modules/DSU.java index 28028e55..2f6e45ab 100644 --- a/src/main/java/appeng/integration/modules/DSU.java +++ b/src/main/java/appeng/integration/modules/DSU.java @@ -48,13 +48,13 @@ public class DSU extends BaseModule implements IDSU } @Override - public void Init() + public void init() { - this.TestClass( IDeepStorageUnit.class ); + this.testClassExistence( IDeepStorageUnit.class ); } @Override - public void PostInit() + public void postInit() { AEApi.instance().registries().externalStorage().addExternalStorageInterface( new MFRDSUHandler() ); } diff --git a/src/main/java/appeng/integration/modules/FMP.java b/src/main/java/appeng/integration/modules/FMP.java index 7b6e4a1a..7bf34bab 100644 --- a/src/main/java/appeng/integration/modules/FMP.java +++ b/src/main/java/appeng/integration/modules/FMP.java @@ -84,7 +84,7 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF } @Override - public void Init() throws Throwable + public void init() throws Throwable { this.createAndRegister( AEApi.instance().blocks().blockQuartz.block(), 0 ); this.createAndRegister( AEApi.instance().blocks().blockQuartzPillar.block(), 0 ); @@ -113,7 +113,7 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF } @Override - public void PostInit() + public void postInit() { MinecraftForge.EVENT_BUS.register( new FMPEvent() ); } diff --git a/src/main/java/appeng/integration/modules/FZ.java b/src/main/java/appeng/integration/modules/FZ.java index 22d0e49e..3ae80106 100644 --- a/src/main/java/appeng/integration/modules/FZ.java +++ b/src/main/java/appeng/integration/modules/FZ.java @@ -161,7 +161,7 @@ public class FZ implements IFZ, IIntegrationModule } @Override - public void Init() throws Throwable + public void init() throws Throwable { day_BarrelClass = Class.forName( "factorization.weird.TileEntityDayBarrel" ); @@ -172,7 +172,7 @@ public class FZ implements IFZ, IIntegrationModule } @Override - public void PostInit() + public void postInit() { AEApi.instance().registries().externalStorage().addExternalStorageInterface( new FactorizationHandler() ); } diff --git a/src/main/java/appeng/integration/modules/IC2.java b/src/main/java/appeng/integration/modules/IC2.java index cbb7db20..eae7cd7d 100644 --- a/src/main/java/appeng/integration/modules/IC2.java +++ b/src/main/java/appeng/integration/modules/IC2.java @@ -37,16 +37,16 @@ public class IC2 extends BaseModule implements IIC2 public static IC2 instance; public IC2() { - this.TestClass( IEnergyTile.class ); + this.testClassExistence( IEnergyTile.class ); } @Override - public void Init() + public void init() { } @Override - public void PostInit() + public void postInit() { IP2PTunnelRegistry reg = AEApi.instance().registries().p2pTunnel(); reg.addNewAttunement( this.getItem( "copperCableItem" ), TunnelType.IC2_POWER ); diff --git a/src/main/java/appeng/integration/modules/ImmibisMicroblocks.java b/src/main/java/appeng/integration/modules/ImmibisMicroblocks.java index d6d5dabe..70425fca 100644 --- a/src/main/java/appeng/integration/modules/ImmibisMicroblocks.java +++ b/src/main/java/appeng/integration/modules/ImmibisMicroblocks.java @@ -50,11 +50,11 @@ public class ImmibisMicroblocks extends BaseModule implements IImmibisMicroblock private Method mergeIntoMicroblockContainer; @Override - public void Init() throws Throwable + public void init() throws Throwable { - this.TestClass( IMultipartTile.class ); - this.TestClass( ICoverSystem.class ); - this.TestClass( IPartContainer.class ); + this.testClassExistence( IMultipartTile.class ); + this.testClassExistence( ICoverSystem.class ); + this.testClassExistence( IPartContainer.class ); try { @@ -70,7 +70,7 @@ public class ImmibisMicroblocks extends BaseModule implements IImmibisMicroblock } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/InvTweaks.java b/src/main/java/appeng/integration/modules/InvTweaks.java index a42b7ac4..6d57932f 100644 --- a/src/main/java/appeng/integration/modules/InvTweaks.java +++ b/src/main/java/appeng/integration/modules/InvTweaks.java @@ -35,13 +35,13 @@ public class InvTweaks extends BaseModule implements IInvTweaks static InvTweaksAPI api; @Override - public void Init() + public void init() { api = (InvTweaksAPI) Loader.instance().getIndexedModList().get( "inventorytweaks" ).getMod(); } @Override - public void PostInit() + public void postInit() { if ( api == null ) throw new RuntimeException( "InvTweaks API Instance Failed." ); diff --git a/src/main/java/appeng/integration/modules/MFR.java b/src/main/java/appeng/integration/modules/MFR.java index a639671f..c6a5cede 100644 --- a/src/main/java/appeng/integration/modules/MFR.java +++ b/src/main/java/appeng/integration/modules/MFR.java @@ -28,17 +28,17 @@ public class MFR extends BaseModule public static MFR instance; public MFR() { - this.TestClass( IRedNetConnection.class ); + this.testClassExistence( IRedNetConnection.class ); } @Override - public void Init() throws Throwable + public void init() throws Throwable { } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/MJ5.java b/src/main/java/appeng/integration/modules/MJ5.java index fd506040..884c9c8e 100644 --- a/src/main/java/appeng/integration/modules/MJ5.java +++ b/src/main/java/appeng/integration/modules/MJ5.java @@ -30,7 +30,7 @@ public class MJ5 extends BaseModule implements IMJ5 public static MJ5 instance; public MJ5() { - this.TestClass( IPowerReceptor.class ); + this.testClassExistence( IPowerReceptor.class ); } @Override @@ -42,13 +42,13 @@ public class MJ5 extends BaseModule implements IMJ5 } @Override - public void Init() throws Throwable + public void init() throws Throwable { } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/MJ6.java b/src/main/java/appeng/integration/modules/MJ6.java index d283c48f..ebeaa4fc 100644 --- a/src/main/java/appeng/integration/modules/MJ6.java +++ b/src/main/java/appeng/integration/modules/MJ6.java @@ -39,18 +39,18 @@ public class MJ6 extends BaseModule implements IMJ6 public static MJ6 instance; public MJ6() { - this.TestClass( IBatteryObject.class ); - this.TestClass( IBatteryProvider.class ); - this.TestClass( ISidedBatteryProvider.class ); + this.testClassExistence( IBatteryObject.class ); + this.testClassExistence( IBatteryProvider.class ); + this.testClassExistence( ISidedBatteryProvider.class ); } @Override - public void Init() throws Throwable + public void init() throws Throwable { } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/Mekanism.java b/src/main/java/appeng/integration/modules/Mekanism.java index d50661bf..7aade3ee 100644 --- a/src/main/java/appeng/integration/modules/Mekanism.java +++ b/src/main/java/appeng/integration/modules/Mekanism.java @@ -31,13 +31,13 @@ public class Mekanism extends BaseModule implements IMekanism public static Mekanism instance; @Override - public void Init() throws Throwable + public void init() throws Throwable { - this.TestClass( mekanism.api.energy.IStrictEnergyAcceptor.class ); + this.testClassExistence( mekanism.api.energy.IStrictEnergyAcceptor.class ); } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/NEI.java b/src/main/java/appeng/integration/modules/NEI.java index 8a011d54..8c9b3d23 100644 --- a/src/main/java/appeng/integration/modules/NEI.java +++ b/src/main/java/appeng/integration/modules/NEI.java @@ -56,16 +56,16 @@ public class NEI extends BaseModule implements INEI, IContainerTooltipHandler public static NEI instance; - Class API; + Class API; // recipe handler... Method registerRecipeHandler; Method registerUsageHandler; public NEI() throws ClassNotFoundException { - this.TestClass( GuiContainerManager.class ); - this.TestClass( codechicken.nei.recipe.ICraftingHandler.class ); - this.TestClass( codechicken.nei.recipe.IUsageHandler.class ); + this.testClassExistence( GuiContainerManager.class ); + this.testClassExistence( codechicken.nei.recipe.ICraftingHandler.class ); + this.testClassExistence( codechicken.nei.recipe.IUsageHandler.class ); this.API = Class.forName( "codechicken.nei.api.API" ); } @@ -76,7 +76,7 @@ public class NEI extends BaseModule implements INEI, IContainerTooltipHandler } @Override - public void Init() throws Throwable + public void init() throws Throwable { this.registerRecipeHandler = this.API.getDeclaredMethod( "registerRecipeHandler", codechicken.nei.recipe.ICraftingHandler.class ); this.registerUsageHandler = this.API.getDeclaredMethod( "registerUsageHandler", codechicken.nei.recipe.IUsageHandler.class ); @@ -108,7 +108,7 @@ public class NEI extends BaseModule implements INEI, IContainerTooltipHandler } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/RB.java b/src/main/java/appeng/integration/modules/RB.java index 4dd8c1fc..18d16b58 100644 --- a/src/main/java/appeng/integration/modules/RB.java +++ b/src/main/java/appeng/integration/modules/RB.java @@ -67,13 +67,13 @@ public class RB extends BaseModule implements IRB public static RB instance; @Override - public void Init() throws Throwable + public void init() throws Throwable { - this.TestClass( IOrientable.class ); + this.testClassExistence( IOrientable.class ); } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/RC.java b/src/main/java/appeng/integration/modules/RC.java index 5f09bb58..4f1ed514 100644 --- a/src/main/java/appeng/integration/modules/RC.java +++ b/src/main/java/appeng/integration/modules/RC.java @@ -39,19 +39,19 @@ public class RC extends BaseModule implements IRC } public RC() { - this.TestClass( RailcraftCraftingManager.class ); - this.TestClass( IRockCrusherRecipe.class ); + this.testClassExistence( RailcraftCraftingManager.class ); + this.testClassExistence( IRockCrusherRecipe.class ); } @Override - public void Init() + public void init() { // TODO Auto-generated method stub } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/RF.java b/src/main/java/appeng/integration/modules/RF.java index f8bc71fc..58e3df6d 100644 --- a/src/main/java/appeng/integration/modules/RF.java +++ b/src/main/java/appeng/integration/modules/RF.java @@ -33,14 +33,14 @@ public class RF extends BaseModule public static RF instance; public RF() { - this.TestClass( cofh.api.energy.IEnergyReceiver.class ); - this.TestClass( cofh.api.energy.IEnergyProvider.class ); - this.TestClass( cofh.api.energy.IEnergyHandler.class ); - this.TestClass( cofh.api.energy.IEnergyConnection.class ); + this.testClassExistence( cofh.api.energy.IEnergyReceiver.class ); + this.testClassExistence( cofh.api.energy.IEnergyProvider.class ); + this.testClassExistence( cofh.api.energy.IEnergyHandler.class ); + this.testClassExistence( cofh.api.energy.IEnergyConnection.class ); } @Override - public void Init() + public void init() { } @@ -55,7 +55,7 @@ public class RF extends BaseModule } @Override - public void PostInit() + public void postInit() { this.RFStack( "ExtraUtilities", "extractor_base", 12 ); this.RFStack( "ExtraUtilities", "pipes", 11 ); diff --git a/src/main/java/appeng/integration/modules/RFItem.java b/src/main/java/appeng/integration/modules/RFItem.java index 741a04f6..e232e29f 100644 --- a/src/main/java/appeng/integration/modules/RFItem.java +++ b/src/main/java/appeng/integration/modules/RFItem.java @@ -26,17 +26,17 @@ public class RFItem extends BaseModule public static RFItem instance; public RFItem() { - this.TestClass( cofh.api.energy.IEnergyContainerItem.class ); + this.testClassExistence( cofh.api.energy.IEnergyContainerItem.class ); } @Override - public void Init() + public void init() { } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/RotaryCraft.java b/src/main/java/appeng/integration/modules/RotaryCraft.java index 93692a26..0792b957 100644 --- a/src/main/java/appeng/integration/modules/RotaryCraft.java +++ b/src/main/java/appeng/integration/modules/RotaryCraft.java @@ -26,17 +26,17 @@ public class RotaryCraft extends BaseModule public static RotaryCraft instance; public RotaryCraft() { - this.TestClass( Reika.RotaryCraft.API.ShaftPowerReceiver.class ); + this.testClassExistence( Reika.RotaryCraft.API.ShaftPowerReceiver.class ); } @Override - public void Init() throws Throwable + public void init() throws Throwable { } @Override - public void PostInit() + public void postInit() { } diff --git a/src/main/java/appeng/integration/modules/Waila.java b/src/main/java/appeng/integration/modules/Waila.java index 6277fa90..94d4cfe4 100644 --- a/src/main/java/appeng/integration/modules/Waila.java +++ b/src/main/java/appeng/integration/modules/Waila.java @@ -19,241 +19,46 @@ package appeng.integration.modules; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; - import cpw.mods.fml.common.event.FMLInterModComms; -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 appeng.api.implementations.IPowerChannelState; -import appeng.api.implementations.parts.IPartStorageMonitor; -import appeng.api.parts.IPartHost; -import appeng.api.parts.SelectedPart; -import appeng.api.storage.data.IAEFluidStack; -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.integration.IntegrationType; -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 appeng.integration.modules.waila.PartWailaDataProvider; +import appeng.integration.modules.waila.TileWailaDataProvider; +import appeng.tile.AEBaseTile; -public class Waila extends BaseModule implements IWailaDataProvider, IWailaFMPProvider + +public class Waila extends BaseModule { - public static Waila instance; - public static void register(IWailaRegistrar registrar) + public static void register( IWailaRegistrar registrar ) { - Waila w = (Waila) AppEng.instance.getIntegration( IntegrationType.Waila ); + final IWailaDataProvider partHost = new PartWailaDataProvider(); - registrar.registerBodyProvider( w, AEBaseBlock.class ); - registrar.registerBodyProvider( w, "ae2_cablebus" ); + registrar.registerBodyProvider( partHost, AEBaseTile.class ); + registrar.registerNBTProvider( partHost, AEBaseTile.class ); - registrar.registerSyncedNBTKey( "internalCurrentPower", TileEnergyCell.class ); - registrar.registerSyncedNBTKey( "extra:6.usedChannels", TileCableBus.class ); + final IWailaDataProvider tile = new TileWailaDataProvider(); + + registrar.registerBodyProvider( tile, AEBaseTile.class ); + registrar.registerNBTProvider( tile, AEBaseTile.class ); } @Override - public void Init() throws Throwable + public void init() throws Throwable { - this.TestClass( IWailaDataProvider.class ); - this.TestClass( IWailaRegistrar.class ); + this.testClassExistence( IWailaDataProvider.class ); + this.testClassExistence( IWailaRegistrar.class ); + FMLInterModComms.sendMessage( "Waila", "register", this.getClass().getName() + ".register" ); } @Override - public void PostInit() + public void postInit() { // :P } - - @Override - public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) - { - return null; - } - - @Override - public List getWailaBody(ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) - { - TileEntity te = accessor.getTileEntity(); - MovingObjectPosition mop = accessor.getPosition(); - - NBTTagCompound nbt = null; - - try - { - nbt = accessor.getNBTData(); - } - catch (NullPointerException ignored) - { - } - - return this.getBody( itemStack, currentToolTip, accessor.getPlayer(), nbt, te, mop ); - } - - @Override - public List getWailaBody(ItemStack itemStack, List currentToolTip, IWailaFMPAccessor accessor, IWailaConfigHandler config) - { - TileEntity te = accessor.getTileEntity(); - MovingObjectPosition mop = accessor.getPosition(); - - NBTTagCompound nbt = null; - - try - { - nbt = accessor.getNBTData(); - } - catch (NullPointerException ignored) - { - } - - return this.getBody( itemStack, currentToolTip, accessor.getPlayer(), nbt, te, mop ); - } - - public List getBody(ItemStack itemStack, List currentToolTip, EntityPlayer player, NBTTagCompound nbt, TileEntity te, MovingObjectPosition mop) - { - - Object ThingOfInterest = te; - if ( te instanceof IPartHost ) - { - Vec3 Pos = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ); - SelectedPart sp = ((IPartHost) te).selectPart( Pos ); - if ( sp.facade != null ) - { - ThingOfInterest = sp.facade; - } - else if ( sp.part != null ) - { - ThingOfInterest = sp.part; - } - } - - try - { - if ( ThingOfInterest instanceof PartCableSmart || ThingOfInterest instanceof PartDenseCable ) - { - if ( nbt != null && nbt.hasKey( "extra:6" ) ) - { - NBTTagCompound ic = nbt.getCompoundTag( "extra:6" ); - if ( ic != null && ic.hasKey( "usedChannels" ) ) - { - int channels = ic.getByte( "usedChannels" ); - currentToolTip.add( channels + " " + GuiText.Of.getLocal() + ' ' + (ThingOfInterest instanceof PartDenseCable ? 32 : 8) + ' ' - + WailaText.Channels.getLocal() ); - } - } - } - - if ( ThingOfInterest instanceof TileEnergyCell ) - { - if ( nbt != null && nbt.hasKey( "internalCurrentPower" ) ) - { - TileEnergyCell tec = (TileEnergyCell) ThingOfInterest; - long power = (long) (100 * nbt.getDouble( "internalCurrentPower" )); - currentToolTip.add( WailaText.Contains + ": " + Platform.formatPowerLong( power, false ) + " / " - + Platform.formatPowerLong( (long) (100 * tec.getAEMaxPower()), false ) ); - } - } - } - catch (NullPointerException ex) - { - // :P - } - - if ( ThingOfInterest instanceof IPartStorageMonitor ) - { - IPartStorageMonitor psm = (IPartStorageMonitor) ThingOfInterest; - IAEStack stack = psm.getDisplayed(); - boolean isLocked = psm.isLocked(); - - if ( stack instanceof IAEItemStack ) - { - IAEItemStack ais = (IAEItemStack) stack; - currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() ); - } - - if ( stack instanceof IAEFluidStack ) - { - IAEFluidStack ais = (IAEFluidStack) stack; - currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getFluid().getLocalizedName( ais.getFluidStack() ) ); - } - - if ( isLocked ) - currentToolTip.add( WailaText.Locked.getLocal() ); - else - currentToolTip.add( WailaText.Unlocked.getLocal() ); - } - - if ( ThingOfInterest instanceof TileCharger ) - { - TileCharger tc = (TileCharger) ThingOfInterest; - IInventory inv = tc.getInternalInventory(); - ItemStack is = inv.getStackInSlot( 0 ); - if ( is != null ) - { - currentToolTip.add( WailaText.Contains + ": " + is.getDisplayName() ); - is.getItem().addInformation( is, player, currentToolTip, true ); - } - } - - if ( ThingOfInterest instanceof IPowerChannelState ) - { - IPowerChannelState pbs = (IPowerChannelState) ThingOfInterest; - if ( pbs.isActive() && pbs.isPowered() ) - currentToolTip.add( WailaText.DeviceOnline.getLocal() ); - else if ( pbs.isPowered() ) - currentToolTip.add( WailaText.DeviceMissingChannel.getLocal() ); - else - currentToolTip.add( WailaText.DeviceOffline.getLocal() ); - } - - return currentToolTip; - } - - @Override - public List getWailaHead(ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) - { - return currentToolTip; - } - - @Override - public List getWailaTail(ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) - { - return currentToolTip; - } - - @Override - public List getWailaHead(ItemStack itemStack, List currentToolTip, IWailaFMPAccessor accessor, IWailaConfigHandler config) - { - return currentToolTip; - } - - @Override - public List getWailaTail(ItemStack itemStack, List currentToolTip, IWailaFMPAccessor accessor, IWailaConfigHandler config) - { - return currentToolTip; - } - } diff --git a/src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java new file mode 100644 index 00000000..c2c83ddd --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java @@ -0,0 +1,74 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import mcp.mobius.waila.api.IWailaDataProvider; + + +/** + * Base implementation for {@link mcp.mobius.waila.api.IWailaDataProvider} + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public abstract class BaseWailaDataProvider implements IWailaDataProvider +{ + @Override + public ItemStack getWailaStack( IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return null; + } + + @Override + public List getWailaHead( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaBody( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaTail( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z ) + { + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java new file mode 100644 index 00000000..bc021c38 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java @@ -0,0 +1,173 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +import com.google.common.base.Optional; +import com.google.common.collect.Lists; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import mcp.mobius.waila.api.IWailaDataProvider; + +import appeng.api.parts.IPart; +import appeng.integration.modules.waila.part.ChannelWailaDataProvider; +import appeng.integration.modules.waila.part.IPartWailaDataProvider; +import appeng.integration.modules.waila.part.PartAccessor; +import appeng.integration.modules.waila.part.PowerStateWailaDataProvider; +import appeng.integration.modules.waila.part.StorageMonitorWailaDataProvider; +import appeng.integration.modules.waila.part.Tracer; + + +/** + * Delegation provider for parts through {@link appeng.integration.modules.waila.part.IPartWailaDataProvider} + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class PartWailaDataProvider implements IWailaDataProvider +{ + /** + * Contains all providers + */ + private final List providers; + + /** + * Can access parts through view-hits + */ + private final PartAccessor accessor = new PartAccessor(); + + /** + * Traces views hit on blocks + */ + private final Tracer tracer = new Tracer(); + + /** + * Initializes the provider list with all wanted providers + */ + public PartWailaDataProvider() + { + final IPartWailaDataProvider channel = new ChannelWailaDataProvider(); + final IPartWailaDataProvider storageMonitor = new StorageMonitorWailaDataProvider(); + final IPartWailaDataProvider powerState = new PowerStateWailaDataProvider(); + + this.providers = Lists.newArrayList( channel, storageMonitor, powerState ); + } + + @Override + public ItemStack getWailaStack( IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return null; + } + + @Override + public List getWailaHead( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + final MovingObjectPosition mop = accessor.getPosition(); + + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if ( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for ( IPartWailaDataProvider provider : this.providers ) + { + provider.getWailaHead( part, currentToolTip, accessor, config ); + } + } + + return currentToolTip; + } + + @Override + public List getWailaBody( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + final MovingObjectPosition mop = accessor.getPosition(); + + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if ( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for ( IPartWailaDataProvider provider : this.providers ) + { + provider.getWailaBody( part, currentToolTip, accessor, config ); + } + } + + return currentToolTip; + } + + @Override + public List getWailaTail( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + final MovingObjectPosition mop = accessor.getPosition(); + + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if ( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for ( IPartWailaDataProvider provider : this.providers ) + { + provider.getWailaTail( part, currentToolTip, accessor, config ); + } + } + + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z ) + { + final MovingObjectPosition mop = this.tracer.retraceBlock( world, player, x, y, z ); + + if ( mop != null ) + { + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if ( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for ( IPartWailaDataProvider provider : this.providers ) + { + provider.getNBTData( player, part, te, tag, world, x, y, z ); + } + } + } + + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java new file mode 100644 index 00000000..5ce333fd --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java @@ -0,0 +1,117 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import com.google.common.collect.Lists; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import mcp.mobius.waila.api.IWailaDataProvider; + +import appeng.integration.modules.waila.tile.ChargerWailaDataProvider; +import appeng.integration.modules.waila.tile.CraftingMonitorWailaDataProvider; +import appeng.integration.modules.waila.tile.PowerStateWailaDataProvider; +import appeng.integration.modules.waila.tile.PowerStorageWailaDataProvider; + + +/** + * Delegation provider for tiles through {@link mcp.mobius.waila.api.IWailaDataProvider} + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class TileWailaDataProvider implements IWailaDataProvider +{ + /** + * Contains all providers + */ + private final List providers; + + /** + * Initializes the provider list with all wanted providers + */ + public TileWailaDataProvider() + { + final IWailaDataProvider charger = new ChargerWailaDataProvider(); + final IWailaDataProvider energyCell = new PowerStorageWailaDataProvider(); + final IWailaDataProvider craftingBlock = new PowerStateWailaDataProvider(); + final IWailaDataProvider craftingMonitor = new CraftingMonitorWailaDataProvider(); + + this.providers = Lists.newArrayList( charger, energyCell, craftingBlock, craftingMonitor ); + } + + @Override + public ItemStack getWailaStack( IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return null; + } + + @Override + public List getWailaHead( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + for ( IWailaDataProvider provider : this.providers ) + { + provider.getWailaHead( itemStack, currentToolTip, accessor, config ); + } + + return currentToolTip; + } + + @Override + public List getWailaBody( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + for ( IWailaDataProvider provider : this.providers ) + { + provider.getWailaBody( itemStack, currentToolTip, accessor, config ); + } + + return currentToolTip; + } + + @Override + public List getWailaTail( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + for ( IWailaDataProvider provider : this.providers ) + { + provider.getWailaTail( itemStack, currentToolTip, accessor, config ); + } + + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z ) + { + for ( IWailaDataProvider provider : this.providers ) + { + provider.getNBTData( player, te, tag, world, x, y, z ); + } + + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java new file mode 100644 index 00000000..00394a97 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java @@ -0,0 +1,67 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.part; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.parts.IPart; + + +/** + * Default implementation of {@link appeng.integration.modules.waila.part.IPartWailaDataProvider} + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public abstract class BasePartWailaDataProvider implements IPartWailaDataProvider +{ + @Override + public List getWailaHead( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaBody( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaTail( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z ) + { + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/part/ChannelWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/ChannelWailaDataProvider.java new file mode 100644 index 00000000..dcc16dd7 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/part/ChannelWailaDataProvider.java @@ -0,0 +1,162 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.part; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import gnu.trove.map.TObjectByteMap; +import gnu.trove.map.hash.TObjectByteHashMap; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.parts.IPart; +import appeng.core.localization.GuiText; +import appeng.core.localization.WailaText; +import appeng.parts.networking.PartCableSmart; +import appeng.parts.networking.PartDenseCable; + + +/** + * Channel-information provider for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class ChannelWailaDataProvider extends BasePartWailaDataProvider +{ + /** + * Channel key used for the transferred {@link net.minecraft.nbt.NBTTagCompound} + */ + private static final String ID_USED_CHANNELS = "usedChannels"; + + /** + * Used cache for channels if the channel was not transmitted through the server. + *

+ * This is useful, when a player just started to look at a tile + * and thus just requested the new information from the server. + *

+ * The cache will be updated from the server. + */ + private final TObjectByteMap cache = new TObjectByteHashMap(); + + /** + * Adds the used and max channel to the tool tip + * + * @param part being looked at part + * @param currentToolTip current tool tip + * @param accessor wrapper for various world information + * @param config config to react to various settings + * + * @return modified tool tip + */ + @Override + public List getWailaBody( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + if ( part instanceof PartCableSmart || part instanceof PartDenseCable ) + { + final NBTTagCompound tag = accessor.getNBTData(); + + final byte usedChannels = this.getUsedChannels( part, tag, this.cache ); + final byte maxChannels = ( byte ) ( ( part instanceof PartDenseCable ) ? 32 : 8 ); + + currentToolTip.add( usedChannels + " " + GuiText.Of.getLocal() + ' ' + maxChannels + ' ' + WailaText.Channels.getLocal() ); + } + + return currentToolTip; + } + + /** + * Determines the source of the channel. + *

+ * If the client received information of the channels on the server, they are used, + * else if the cache contains a previous stored value, this will be used. + * Default value is 0. + * + * @param part part to be looked at + * @param tag tag maybe containing the channel information + * @param cache cache with previous knowledge + * + * @return used channels on the cable + */ + private byte getUsedChannels( IPart part, NBTTagCompound tag, TObjectByteMap cache ) + { + final byte usedChannels; + + if ( tag.hasKey( ID_USED_CHANNELS ) ) + { + usedChannels = tag.getByte( ID_USED_CHANNELS ); + this.cache.put( part, usedChannels ); + } + else if ( this.cache.containsKey( part ) ) + { + usedChannels = this.cache.get( part ); + } + else + { + usedChannels = 0; + } + + return usedChannels; + } + + /** + * Called on server to transfer information from server to client. + *

+ * If the part is a cable, + * it writes the channel information in the {@code #tag} + * using the {@code ID_USED_CHANNELS} key. + * + * @param player player looking at the part + * @param part part being looked at + * @param te host of the part + * @param tag transferred tag which is send to the client + * @param world world of the part + * @param x x pos of the part + * @param y y pos of the part + * @param z z pos of the part + * + * @return tag send to the client + */ + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z ) + { + if ( part instanceof PartCableSmart || part instanceof PartDenseCable ) + { + final NBTTagCompound tempTag = new NBTTagCompound(); + + part.writeToNBT( tempTag ); + + if ( tempTag.hasKey( ID_USED_CHANNELS ) ) + { + final byte usedChannels = tempTag.getByte( ID_USED_CHANNELS ); + + tag.setByte( ID_USED_CHANNELS, usedChannels ); + } + } + + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/part/IPartWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/IPartWailaDataProvider.java new file mode 100644 index 00000000..fa1e9140 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/part/IPartWailaDataProvider.java @@ -0,0 +1,51 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.part; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.parts.IPart; + + +/** + * An abstraction layer of the {@link appeng.integration.modules.waila.part.IPartWailaDataProvider} for {@link appeng.api.parts.IPart}. + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public interface IPartWailaDataProvider +{ + List getWailaHead( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ); + + List getWailaBody( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ); + + List getWailaTail( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ); + + NBTTagCompound getNBTData(EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z); +} diff --git a/src/main/java/appeng/integration/modules/waila/part/PartAccessor.java b/src/main/java/appeng/integration/modules/waila/part/PartAccessor.java new file mode 100644 index 00000000..107e904c --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/part/PartAccessor.java @@ -0,0 +1,69 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.part; + + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; + +import com.google.common.base.Optional; + +import appeng.api.parts.IPart; +import appeng.api.parts.IPartHost; +import appeng.api.parts.SelectedPart; + + +/** + * Accessor to access specific parts for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class PartAccessor +{ + /** + * Hits a {@link appeng.api.parts.IPartHost} with {@link net.minecraft.util.MovingObjectPosition}. + *

+ * You can derive the looked at {@link appeng.api.parts.IPart} by doing that. + * If a facade is being looked at, it is defined as being absent. + * + * @param te being looked at {@link net.minecraft.tileentity.TileEntity} + * @param mop type of raytrace + * + * @return maybe the looked at {@link appeng.api.parts.IPart} + */ + public Optional getMaybePart( TileEntity te, MovingObjectPosition mop ) + { + if ( te instanceof IPartHost ) + { + final Vec3 position = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ); + final IPartHost host = ( IPartHost ) te; + final SelectedPart sp = host.selectPart( position ); + + if ( sp.part != null ) + { + return Optional.of( sp.part ); + } + } + + return Optional.absent(); + } +} diff --git a/src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java new file mode 100644 index 00000000..59bc2fba --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java @@ -0,0 +1,91 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.part; + + +import java.util.List; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.implementations.IPowerChannelState; +import appeng.api.parts.IPart; +import appeng.core.localization.WailaText; + + +/** + * Power state provider for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class PowerStateWailaDataProvider extends BasePartWailaDataProvider +{ + /** + * Adds state to the tooltip + * + * @param part part with state + * @param currentToolTip to be added to tooltip + * @param accessor wrapper for various information + * @param config config settings + * + * @return modified tooltip + */ + @Override + public List getWailaBody( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + if ( part instanceof IPowerChannelState ) + { + final IPowerChannelState state = ( IPowerChannelState ) part; + + currentToolTip.add( this.getToolTip( state.isActive(), state.isPowered() ) ); + } + + return currentToolTip; + } + + /** + * Gets the corresponding tool tip for different values of {@code #isActive} and {@code #isPowered} + * + * @param isActive if part is active + * @param isPowered if part is powered + * + * @return tooltip of the state + */ + private String getToolTip( boolean isActive, boolean isPowered ) + { + final String result; + + if ( isActive && isPowered ) + { + result = WailaText.DeviceOnline.getLocal(); + } + else if ( isPowered ) + { + result = WailaText.DeviceMissingChannel.getLocal(); + } + else + { + result = WailaText.DeviceOffline.getLocal(); + } + + return result; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java new file mode 100644 index 00000000..3743a327 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java @@ -0,0 +1,81 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.part; + + +import java.util.List; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.implementations.parts.IPartStorageMonitor; +import appeng.api.parts.IPart; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStack; +import appeng.core.localization.WailaText; + + +/** + * Storage monitor provider for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class StorageMonitorWailaDataProvider extends BasePartWailaDataProvider +{ + /** + * Displays the stack if present and if the monitor is locked. + * Can handle fluids and items. + * + * @param part maybe storage monitor + * @param currentToolTip to be written to tooltip + * @param accessor information wrapper + * @param config config option + * + * @return modified tooltip + */ + @Override + public List getWailaBody( IPart part, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + if ( part instanceof IPartStorageMonitor ) + { + final IPartStorageMonitor monitor = ( IPartStorageMonitor ) part; + + final IAEStack displayed = monitor.getDisplayed(); + final boolean isLocked = monitor.isLocked(); + + if ( displayed instanceof IAEItemStack ) + { + IAEItemStack ais = ( IAEItemStack ) displayed; + currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() ); + } + else if ( displayed instanceof IAEFluidStack ) + { + IAEFluidStack ais = ( IAEFluidStack ) displayed; + currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getFluid().getLocalizedName( ais.getFluidStack() ) ); + } + + currentToolTip.add( ( isLocked ) ? WailaText.Locked.getLocal() : WailaText.Unlocked.getLocal() ); + } + + return currentToolTip; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/part/Tracer.java b/src/main/java/appeng/integration/modules/waila/part/Tracer.java new file mode 100644 index 00000000..0f2baab7 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/part/Tracer.java @@ -0,0 +1,96 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.part; + + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + + +/** + * Tracer for players hitting blocks + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class Tracer +{ + /** + * Trace view of players to blocks. + * Ignore all which are out of reach. + * + * @param world word of block + * @param player player viewing block + * @param x x pos of block + * @param y y pos of block + * @param z z pos of block + * + * @return trace movement. Can be null + */ + public MovingObjectPosition retraceBlock( World world, EntityPlayerMP player, int x, int y, int z ) + { + Block block = world.getBlock( x, y, z ); + + Vec3 headVec = this.getCorrectedHeadVec( player ); + Vec3 lookVec = player.getLook( 1.0F ); + double reach = this.getBlockReachDistance_server( player ); + Vec3 endVec = headVec.addVector( lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach ); + + return block.collisionRayTrace( world, x, y, z, headVec, endVec ); + } + + /** + * Gets the view point of a player + * + * @param player player with head + * + * @return view point of player + */ + private Vec3 getCorrectedHeadVec( EntityPlayer player ) + { + Vec3 v = Vec3.createVectorHelper( player.posX, player.posY, player.posZ ); + if ( player.worldObj.isRemote ) + { + //compatibility with eye height changing mods + v.yCoord += player.getEyeHeight() - player.getDefaultEyeHeight(); + } + else + { + v.yCoord += player.getEyeHeight(); + if ( player instanceof EntityPlayerMP && player.isSneaking() ) + v.yCoord -= 0.08; + } + return v; + } + + /** + * @param player multi-player player + * + * @return block reach distance of player + */ + private double getBlockReachDistance_server( EntityPlayerMP player ) + { + return player.theItemInWorldManager.getBlockReachDistance(); + } +} diff --git a/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java new file mode 100644 index 00000000..6fb5bcad --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java @@ -0,0 +1,78 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.tile; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.core.localization.WailaText; +import appeng.integration.modules.waila.BaseWailaDataProvider; +import appeng.tile.misc.TileCharger; + + +/** + * Charger provider for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class ChargerWailaDataProvider extends BaseWailaDataProvider +{ + /** + * Displays the holding item and its tooltip + * + * @param itemStack stack of charger + * @param currentToolTip unmodified tooltip + * @param accessor wrapper information + * @param config config option + * + * @return modified tooltip + */ + @Override + public List getWailaBody( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + if ( te instanceof TileCharger ) + { + final TileCharger charger = ( TileCharger ) te; + final IInventory chargerInventory = charger.getInternalInventory(); + final ItemStack chargingItem = chargerInventory.getStackInSlot( 0 ); + + if ( chargingItem != null ) + { + final String currentInventory = chargingItem.getDisplayName(); + final EntityPlayer player = accessor.getPlayer(); + + currentToolTip.add( WailaText.Contains + ": " + currentInventory ); + chargingItem.getItem().addInformation( chargingItem, player, currentToolTip, true ); + } + } + + return currentToolTip; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java new file mode 100644 index 00000000..dd3a24be --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java @@ -0,0 +1,74 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.tile; + + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.storage.data.IAEItemStack; +import appeng.core.localization.WailaText; +import appeng.integration.modules.waila.BaseWailaDataProvider; +import appeng.tile.crafting.TileCraftingMonitorTile; + + +/** + * Crafting-monitor provider for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class CraftingMonitorWailaDataProvider extends BaseWailaDataProvider +{ + /** + * Displays the item currently crafted by the CPU cluster + * + * @param itemStack stack of crafting monitor + * @param currentToolTip unmodified tooltip + * @param accessor information wrapper + * @param config config option + * + * @return modified tooltip + */ + @Override + public List getWailaBody( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + if ( te instanceof TileCraftingMonitorTile ) + { + final TileCraftingMonitorTile monitor = ( TileCraftingMonitorTile ) te; + final IAEItemStack displayStack = monitor.getJobProgress(); + + if ( displayStack != null ) + { + final String currentCrafting = displayStack.getItemStack().getDisplayName(); + + currentToolTip.add( WailaText.Crafting.getLocal() + ": " + currentCrafting ); + } + } + + return currentToolTip; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/tile/PowerStateWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/PowerStateWailaDataProvider.java new file mode 100644 index 00000000..9458ca91 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/tile/PowerStateWailaDataProvider.java @@ -0,0 +1,82 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.tile; + + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.implementations.IPowerChannelState; +import appeng.core.localization.WailaText; +import appeng.integration.modules.waila.BaseWailaDataProvider; + + +/** + * Power state provider for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class PowerStateWailaDataProvider extends BaseWailaDataProvider +{ + /** + * Adds state to the tooltip + * + * @param itemStack stack of power state + * @param currentToolTip to be added to tooltip + * @param accessor wrapper for various information + * @param config config settings + * + * @return modified tooltip + */ + @Override + public List getWailaBody( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + + if ( te instanceof IPowerChannelState ) + { + final IPowerChannelState state = ( IPowerChannelState ) te; + + final boolean isActive = state.isActive(); + final boolean isPowered = state.isPowered(); + + if ( isActive && isPowered ) + { + currentToolTip.add( WailaText.DeviceOnline.getLocal() ); + } + else if ( isPowered ) + { + currentToolTip.add( WailaText.DeviceMissingChannel.getLocal() ); + } + else + { + currentToolTip.add( WailaText.DeviceOffline.getLocal() ); + } + } + + return currentToolTip; + } +} \ No newline at end of file diff --git a/src/main/java/appeng/integration/modules/waila/tile/PowerStorageWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/PowerStorageWailaDataProvider.java new file mode 100644 index 00000000..7f86fa68 --- /dev/null +++ b/src/main/java/appeng/integration/modules/waila/tile/PowerStorageWailaDataProvider.java @@ -0,0 +1,169 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.integration.modules.waila.tile; + + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import gnu.trove.map.TObjectLongMap; +import gnu.trove.map.hash.TObjectLongHashMap; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.networking.energy.IAEPowerStorage; +import appeng.core.localization.WailaText; +import appeng.integration.modules.waila.BaseWailaDataProvider; +import appeng.util.Platform; + + +/** + * Power storage provider for WAILA + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public final class PowerStorageWailaDataProvider extends BaseWailaDataProvider +{ + /** + * Power key used for the transferred {@link net.minecraft.nbt.NBTTagCompound} + */ + private static final String ID_CURRENT_POWER = "currentPower"; + + /** + * Used cache for power if the power was not transmitted through the server. + *

+ * This is useful, when a player just started to look at a tile + * and thus just requested the new information from the server. + *

+ * The cache will be updated from the server. + */ + private final TObjectLongMap cache = new TObjectLongHashMap(); + + /** + * Adds the current and max power to the tool tip + * Will ignore if the tile has an energy buffer ( > 0 ) + * + * @param itemStack stack of power storage + * @param currentToolTip current tool tip + * @param accessor wrapper for various world information + * @param config config to react to various settings + * + * @return modified tool tip + */ + @Override + public List getWailaBody( ItemStack itemStack, List currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + if ( te instanceof IAEPowerStorage ) + { + final IAEPowerStorage storage = ( IAEPowerStorage ) te; + + final double maxPower = storage.getAEMaxPower(); + if ( maxPower > 0 ) + { + final NBTTagCompound tag = accessor.getNBTData(); + + final long internalCurrentPower = this.getInternalCurrentPower( tag, te ); + final long internalMaxPower = ( long ) ( 100 * maxPower ); + + final String formatCurrentPower = Platform.formatPowerLong( internalCurrentPower, false ); + final String formatMaxPower = Platform.formatPowerLong( internalMaxPower, false ); + + currentToolTip.add( WailaText.Contains + ": " + formatCurrentPower + " / " + formatMaxPower ); + } + } + + return currentToolTip; + } + + /** + * Called on server to transfer information from server to client. + *

+ * If the {@link net.minecraft.tileentity.TileEntity} is a {@link appeng.api.networking.energy.IAEPowerStorage}, + * it writes the power information to the {@code #tag} + * using the {@code #ID_CURRENT_POWER} key. + * + * @param player player looking at the power storage + * @param te power storage + * @param tag transferred tag which is send to the client + * @param world world of the power storage + * @param x x pos of the power storage + * @param y y pos of the power storage + * @param z z pos of the power storage + * + * @return tag send to the client + */ + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z ) + { + if ( te instanceof IAEPowerStorage ) + { + final IAEPowerStorage storage = ( IAEPowerStorage ) te; + + if ( storage.getAEMaxPower() > 0 ) + { + final long internalCurrentPower = ( long ) ( 100 * storage.getAECurrentPower() ); + + tag.setLong( ID_CURRENT_POWER, internalCurrentPower ); + } + } + + return tag; + } + + /** + * Determines the current power. + *

+ * If the client received power information on the server, they are used, + * else if the cache contains a previous stored value, this will be used. + * Default value is 0. + * + * @param te te to be looked at + * @param tag tag maybe containing the channel information + * + * @return used channels on the cable + */ + private long getInternalCurrentPower( NBTTagCompound tag, TileEntity te ) + { + final long internalCurrentPower; + + if ( tag.hasKey( ID_CURRENT_POWER ) ) + { + internalCurrentPower = tag.getLong( ID_CURRENT_POWER ); + this.cache.put( te, internalCurrentPower ); + } + else if ( this.cache.containsKey( te ) ) + { + internalCurrentPower = this.cache.get( te ); + } + else + { + internalCurrentPower = 0; + } + + return internalCurrentPower; + } +} diff --git a/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java b/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java index cd00378d..765acf84 100644 --- a/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java +++ b/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java @@ -18,72 +18,71 @@ package appeng.tile.networking; + import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; import appeng.api.networking.energy.IEnergyGrid; import appeng.api.util.AECableType; import appeng.me.GridAccessException; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; import appeng.tile.grid.AENetworkPowerTile; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.InvOperation; + public class TileEnergyAcceptor extends AENetworkPowerTile { + final static AppEngInternalInventory INTERNAL_INVENTORY = new AppEngInternalInventory( null, 0 ); final int[] sides = new int[] { }; - final static AppEngInternalInventory inv = new AppEngInternalInventory( null, 0 ); + + public TileEnergyAcceptor() + { + this.gridProxy.setIdlePowerUsage( 0.0 ); + this.internalMaxPower = 0; + } @Override - public AECableType getCableConnectionType(ForgeDirection dir) + public AECableType getCableConnectionType( ForgeDirection dir ) { return AECableType.COVERED; } - @TileEvent(TileEventType.TICK) - public void Tick_TileEnergyAcceptor() + @Override + public void readFromNBT_AENetwork( NBTTagCompound data ) { - if ( this.internalCurrentPower > 0 ) - { - try - { - IEnergyGrid eg = this.gridProxy.getEnergy(); - double powerRequested = this.internalCurrentPower - eg.injectPower( this.internalCurrentPower, Actionable.SIMULATE ); - - if ( powerRequested > 0 ) - { - eg.injectPower( this.extractAEPower( powerRequested, Actionable.MODULATE, PowerMultiplier.ONE ), Actionable.MODULATE ); - } - } - catch (GridAccessException e) - { - // null net, probably bad. - } - - } + /** + * Does nothing here since the NBT tag in the parent is not needed anymore + */ } @Override - protected double getFunnelPowerDemand(double maxRequired) + public void writeToNBT_AENetwork( NBTTagCompound data ) + { + /** + * Does nothing here since the NBT tag in the parent is not needed anymore + */ + } + + @Override + protected double getFunnelPowerDemand( double maxRequired ) { try { IEnergyGrid grid = this.gridProxy.getEnergy(); return grid.getEnergyDemand( maxRequired ); } - catch (GridAccessException e) + catch ( GridAccessException e ) { - return super.getFunnelPowerDemand( maxRequired ); + return this.internalMaxPower; } } @Override - protected double funnelPowerIntoStorage(double newPower, Actionable mode) + protected double funnelPowerIntoStorage( double newPower, Actionable mode ) { try { @@ -93,33 +92,27 @@ public class TileEnergyAcceptor extends AENetworkPowerTile return leftOver; return 0.0; } - catch (GridAccessException e) + catch ( GridAccessException e ) { return super.funnelPowerIntoStorage( newPower, mode ); } } - public TileEnergyAcceptor() { - this.gridProxy.setIdlePowerUsage( 0.0 ); - this.internalMaxPower = 100; - } - @Override public IInventory getInternalInventory() { - return inv; + return INTERNAL_INVENTORY; } @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) + public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added ) { } @Override - public int[] getAccessibleSlotsBySide(ForgeDirection side) + public int[] getAccessibleSlotsBySide( ForgeDirection side ) { return this.sides; } - } diff --git a/src/main/resources/assets/appliedenergistics2/lang/en_US.lang b/src/main/resources/assets/appliedenergistics2/lang/en_US.lang index 4f4a1546..b48f4e2b 100644 --- a/src/main/resources/assets/appliedenergistics2/lang/en_US.lang +++ b/src/main/resources/assets/appliedenergistics2/lang/en_US.lang @@ -314,6 +314,7 @@ gui.appliedenergistics2.Red=Red gui.appliedenergistics2.Black=Black gui.appliedenergistics2.Fluix=Fluix +waila.appliedenergistics2.Crafting=Crafting waila.appliedenergistics2.DeviceOnline=Device Online waila.appliedenergistics2.DeviceOffline=Device Offline waila.appliedenergistics2.DeviceMissingChannel=Device Missing Channel