diff --git a/gradle.properties b/gradle.properties index 31d254c0d..55843b0f9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ forge_version=14.21.1.2412 ######################################################### # Installable # ######################################################### -waila_version=1.7.0-B3_1.9.4 +hwyla_version=1.8.19-B33_1.12 ######################################################### # Provided APIs # diff --git a/gradle/scripts/dependencies.gradle b/gradle/scripts/dependencies.gradle index 469e39b83..3a9883953 100644 --- a/gradle/scripts/dependencies.gradle +++ b/gradle/scripts/dependencies.gradle @@ -53,6 +53,11 @@ repositories { name 'mcjty' url "http://maven.k-4u.nl/" } + + maven { // Hwyla + name 'tehnut' + url "http://tehnut.info/maven" + } } configurations { @@ -61,18 +66,19 @@ configurations { dependencies { // installable runtime dependencies - //mods "mcp.mobius.waila:Waila:${waila_version}" - //mods "net.industrial-craft:industrialcraft-2:${ic2_version}:dev" + mods "mcp.mobius.waila:Hwyla:${hwyla_version}" + mods "net.industrial-craft:industrialcraft-2:${ic2_version}:dev" mods "mcjty.theoneprobe:TheOneProbe-${minecraft_version}:${top_version}" // mods "com.github.mcjty:compatlayer:${compatlayer_version}" // compile against provided APIs compileOnly "mezz.jei:jei_${minecraft_version}:${jei_version}:api" - //compileOnly "mcp.mobius.waila:Waila:${waila_version}" + compileOnly "mcp.mobius.waila:Hwyla:${hwyla_version}" compileOnly "net.darkhax.tesla:Tesla-${minecraft_version}:${tesla_version}" - //compileOnly "net.industrial-craft:industrialcraft-2:${ic2_version}:api" + compileOnly "net.industrial-craft:industrialcraft-2:${ic2_version}:api" compileOnly "mcjty.theoneprobe:TheOneProbe-1.12:${top_version}:api" +// deobfCompile "mcp.mobius.waila:Hwyla:${hwyla_version}" deobfCompile "cofh:RedstoneFlux:${minecraft_version}-${rf_version}:universal" // at runtime, use the full JEI jar diff --git a/gradle/scripts/optional.gradle b/gradle/scripts/optional.gradle index b3c6af624..046613679 100644 --- a/gradle/scripts/optional.gradle +++ b/gradle/scripts/optional.gradle @@ -20,15 +20,15 @@ task wrapper(type: Wrapper) { gradleVersion = "2.14" } -// WAILA -task installWaila(type: Copy, dependsOn: "deinstallWaila") { +// HWYLA +task installHwyla(type: Copy, dependsOn: "deinstallHwyla") { from { configurations.mods } - include "**/*Waila*.jar" + include "**/*Hwyla*.jar" into file(minecraft.runDir + "/mods") } -task deinstallWaila(type: Delete) { - delete fileTree(dir: minecraft.runDir + "/mods", include: "*Waila*.jar") +task deinstallHwyla(type: Delete) { + delete fileTree(dir: minecraft.runDir + "/mods", include: "*Hwyla*.jar") } // IC2 diff --git a/src/main/java/appeng/integration/IntegrationType.java b/src/main/java/appeng/integration/IntegrationType.java index 315f229d6..9ca3bf946 100644 --- a/src/main/java/appeng/integration/IntegrationType.java +++ b/src/main/java/appeng/integration/IntegrationType.java @@ -19,43 +19,58 @@ package appeng.integration; -// import appeng.integration.modules.ic2.IC2Module; +import appeng.integration.modules.ic2.IC2Module; import appeng.integration.modules.jei.JEIModule; +import appeng.integration.modules.rf.RFModule; import appeng.integration.modules.theoneprobe.TheOneProbeModule; -// import appeng.integration.modules.waila.WailaModule; +import appeng.integration.modules.waila.WailaModule; public enum IntegrationType { -// IC2( IntegrationSide.BOTH, "Industrial Craft 2", "IC2" ) -// { -// @Override -// public IIntegrationModule createInstance() -// { -// return Integrations.setIc2( new IC2Module() ); -// } -// }, + IC2( IntegrationSide.BOTH, "Industrial Craft 2", "ic2" ) + { + @Override + public IIntegrationModule createInstance() + { + return Integrations.setIc2( new IC2Module() ); + } + }, - RC( IntegrationSide.BOTH, "Railcraft", "Railcraft" ), + RC( IntegrationSide.BOTH, "Railcraft", "railcraft" ), - RF( IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", "CoFHAPI" ), + RF( IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", "redstoneflux" ) + { + @Override + public IIntegrationModule createInstance() + { + return new RFModule(); + } + }, - RFItem( IntegrationSide.BOTH, "RedstoneFlux Power - Items", "CoFHAPI" ), + RFItem( IntegrationSide.BOTH, "RedstoneFlux Power - Items", "redstoneflux" ) + { + @Override + public IIntegrationModule createInstance() + { + return new RFModule(); + } + }, - MFR( IntegrationSide.BOTH, "Mine Factory Reloaded", "MineFactoryReloaded" ), + MFR( IntegrationSide.BOTH, "Mine Factory Reloaded", "minefactoryreloaded" ), -// Waila( IntegrationSide.BOTH, "Waila", "Waila" ) -// { -// @Override -// public IIntegrationModule createInstance() -// { -// return new WailaModule(); -// } -// }, + Waila( IntegrationSide.BOTH, "Waila", "waila" ) + { + @Override + public IIntegrationModule createInstance() + { + return new WailaModule(); + } + }, InvTweaks( IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks" ), - JEI( IntegrationSide.CLIENT, "Just Enough Items", "JEI" ) + JEI( IntegrationSide.CLIENT, "Just Enough Items", "jei" ) { @Override public IIntegrationModule createInstance() @@ -64,9 +79,9 @@ public enum IntegrationType } }, - Mekanism( IntegrationSide.BOTH, "Mekanism", "Mekanism" ), + Mekanism( IntegrationSide.BOTH, "Mekanism", "mekanism" ), - OpenComputers( IntegrationSide.BOTH, "OpenComputers", "OpenComputers" ), + OpenComputers( IntegrationSide.BOTH, "OpenComputers", "opencomputers" ), THE_ONE_PROBE( IntegrationSide.BOTH, "TheOneProbe", "theoneprobe" ) { @@ -90,7 +105,9 @@ public enum IntegrationType public IIntegrationModule createInstance() { - throw new UnsupportedOperationException(); + return new IIntegrationModule() + { + }; } } diff --git a/src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java index 842d006b9..42cb8ec71 100644 --- a/src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/BaseWailaDataProvider.java @@ -1,74 +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.math.BlockPos; -//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( final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return null; -// } -// -// @Override -// public List getWailaHead( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return currentToolTip; -// } -// -// @Override -// public List getWailaBody( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return currentToolTip; -// } -// -// @Override -// public List getWailaTail( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return currentToolTip; -// } -// -// @Override -// public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) -// { -// return tag; -// } -//} +/* + * 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.math.BlockPos; +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( final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return ItemStack.EMPTY; + } + + @Override + public List getWailaHead( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaBody( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaTail( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) + { + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java index 9937b1fd0..cff75a214 100644 --- a/src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/PartWailaDataProvider.java @@ -1,198 +1,198 @@ -///* -// * 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 java.util.Optional; -// -//import com.google.common.collect.Lists; -// -//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.math.BlockPos; -//import net.minecraft.util.math.RayTraceResult; -//import net.minecraft.world.World; -// -//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.P2PStateWailaDataProvider; -//import appeng.integration.modules.waila.part.PartAccessor; -//import appeng.integration.modules.waila.part.PartStackWailaDataProvider; -//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 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(); -// final IPartWailaDataProvider p2pState = new P2PStateWailaDataProvider(); -// final IPartWailaDataProvider partStack = new PartStackWailaDataProvider(); -// -// this.providers = Lists.newArrayList( channel, storageMonitor, powerState, partStack, p2pState ); -// } -// -// @Override -// public ItemStack getWailaStack( final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// final TileEntity te = accessor.getTileEntity(); -// final RayTraceResult mop = accessor.getMOP(); -// -// -// final Optional maybePart = this.accessor.getMaybePart( te, mop ); -// -// if( maybePart.isPresent() ) -// { -// final IPart part = maybePart.get(); -// -// ItemStack wailaStack = null; -// -// for( final IPartWailaDataProvider provider : this.providers ) -// { -// wailaStack = provider.getWailaStack( part, config, wailaStack ); -// } -// return wailaStack; -// } -// -// return null; -// } -// -// @Override -// public List getWailaHead( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// final TileEntity te = accessor.getTileEntity(); -// final RayTraceResult mop = accessor.getMOP(); -// -// final Optional maybePart = this.accessor.getMaybePart( te, mop ); -// -// if( maybePart.isPresent() ) -// { -// final IPart part = maybePart.get(); -// -// for( final IPartWailaDataProvider provider : this.providers ) -// { -// provider.getWailaHead( part, currentToolTip, accessor, config ); -// } -// } -// -// return currentToolTip; -// } -// -// @Override -// public List getWailaBody( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// final TileEntity te = accessor.getTileEntity(); -// final RayTraceResult mop = accessor.getMOP(); -// -// final Optional maybePart = this.accessor.getMaybePart( te, mop ); -// -// if( maybePart.isPresent() ) -// { -// final IPart part = maybePart.get(); -// -// for( final IPartWailaDataProvider provider : this.providers ) -// { -// provider.getWailaBody( part, currentToolTip, accessor, config ); -// } -// } -// -// return currentToolTip; -// } -// -// @Override -// public List getWailaTail( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// final TileEntity te = accessor.getTileEntity(); -// final RayTraceResult mop = accessor.getMOP(); -// -// final Optional maybePart = this.accessor.getMaybePart( te, mop ); -// -// if( maybePart.isPresent() ) -// { -// final IPart part = maybePart.get(); -// -// for( final IPartWailaDataProvider provider : this.providers ) -// { -// provider.getWailaTail( part, currentToolTip, accessor, config ); -// } -// } -// -// return currentToolTip; -// } -// -// @Override -// public NBTTagCompound getNBTData( final EntityPlayerMP player, final TileEntity te, final NBTTagCompound tag, final World world, BlockPos pos ) -// { -// final RayTraceResult mop = this.tracer.retraceBlock( world, player, pos ); -// -// if( mop != null ) -// { -// final Optional maybePart = this.accessor.getMaybePart( te, mop ); -// -// if( maybePart.isPresent() ) -// { -// final IPart part = maybePart.get(); -// -// for( final IPartWailaDataProvider provider : this.providers ) -// { -// provider.getNBTData( player, part, te, tag, world, pos ); -// } -// } -// } -// -// return tag; -// } -//} +/* + * 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 java.util.Optional; + +import com.google.common.collect.Lists; + +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.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.world.World; + +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.P2PStateWailaDataProvider; +import appeng.integration.modules.waila.part.PartAccessor; +import appeng.integration.modules.waila.part.PartStackWailaDataProvider; +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 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(); + final IPartWailaDataProvider p2pState = new P2PStateWailaDataProvider(); + final IPartWailaDataProvider partStack = new PartStackWailaDataProvider(); + + this.providers = Lists.newArrayList( channel, storageMonitor, powerState, partStack, p2pState ); + } + + @Override + public ItemStack getWailaStack( final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + final RayTraceResult mop = accessor.getMOP(); + + + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + ItemStack wailaStack = ItemStack.EMPTY; + + for( final IPartWailaDataProvider provider : this.providers ) + { + wailaStack = provider.getWailaStack( part, config, wailaStack ); + } + return wailaStack; + } + + return ItemStack.EMPTY; + } + + @Override + public List getWailaHead( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + final RayTraceResult mop = accessor.getMOP(); + + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for( final IPartWailaDataProvider provider : this.providers ) + { + provider.getWailaHead( part, currentToolTip, accessor, config ); + } + } + + return currentToolTip; + } + + @Override + public List getWailaBody( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + final RayTraceResult mop = accessor.getMOP(); + + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for( final IPartWailaDataProvider provider : this.providers ) + { + provider.getWailaBody( part, currentToolTip, accessor, config ); + } + } + + return currentToolTip; + } + + @Override + public List getWailaTail( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + final TileEntity te = accessor.getTileEntity(); + final RayTraceResult mop = accessor.getMOP(); + + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for( final IPartWailaDataProvider provider : this.providers ) + { + provider.getWailaTail( part, currentToolTip, accessor, config ); + } + } + + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( final EntityPlayerMP player, final TileEntity te, final NBTTagCompound tag, final World world, BlockPos pos ) + { + final RayTraceResult mop = this.tracer.retraceBlock( world, player, pos ); + + if( mop != null ) + { + final Optional maybePart = this.accessor.getMaybePart( te, mop ); + + if( maybePart.isPresent() ) + { + final IPart part = maybePart.get(); + + for( final IPartWailaDataProvider provider : this.providers ) + { + provider.getNBTData( player, part, te, tag, world, pos ); + } + } + } + + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java index ac386f267..070cf5665 100644 --- a/src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/TileWailaDataProvider.java @@ -1,119 +1,119 @@ -///* -// * 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 com.google.common.collect.Lists; -// -//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.math.BlockPos; -//import net.minecraft.world.World; -// -//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( final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return null; -// } -// -// @Override -// public List getWailaHead( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// for( final IWailaDataProvider provider : this.providers ) -// { -// provider.getWailaHead( itemStack, currentToolTip, accessor, config ); -// } -// -// return currentToolTip; -// } -// -// @Override -// public List getWailaBody( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// for( final IWailaDataProvider provider : this.providers ) -// { -// provider.getWailaBody( itemStack, currentToolTip, accessor, config ); -// } -// -// return currentToolTip; -// } -// -// @Override -// public List getWailaTail( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// for( final IWailaDataProvider provider : this.providers ) -// { -// provider.getWailaTail( itemStack, currentToolTip, accessor, config ); -// } -// -// return currentToolTip; -// } -// -// @Override -// public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) -// { -// for( final IWailaDataProvider provider : this.providers ) -// { -// provider.getNBTData( player, te, tag, world, pos ); -// } -// -// return tag; -// } -//} +/* + * 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 com.google.common.collect.Lists; + +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.math.BlockPos; +import net.minecraft.world.World; + +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( final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return ItemStack.EMPTY; + } + + @Override + public List getWailaHead( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + for( final IWailaDataProvider provider : this.providers ) + { + provider.getWailaHead( itemStack, currentToolTip, accessor, config ); + } + + return currentToolTip; + } + + @Override + public List getWailaBody( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + for( final IWailaDataProvider provider : this.providers ) + { + provider.getWailaBody( itemStack, currentToolTip, accessor, config ); + } + + return currentToolTip; + } + + @Override + public List getWailaTail( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + for( final IWailaDataProvider provider : this.providers ) + { + provider.getWailaTail( itemStack, currentToolTip, accessor, config ); + } + + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) + { + for( final IWailaDataProvider provider : this.providers ) + { + provider.getNBTData( player, te, tag, world, pos ); + } + + return tag; + } +} diff --git a/src/main/java/appeng/integration/modules/waila/WailaModule.java b/src/main/java/appeng/integration/modules/waila/WailaModule.java index 94da07c1a..efa350f0d 100644 --- a/src/main/java/appeng/integration/modules/waila/WailaModule.java +++ b/src/main/java/appeng/integration/modules/waila/WailaModule.java @@ -1,64 +1,64 @@ -///* -// * 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 net.minecraftforge.fml.common.event.FMLInterModComms; -// -//import mcp.mobius.waila.api.IWailaDataProvider; -//import mcp.mobius.waila.api.IWailaRegistrar; -// -//import appeng.integration.IIntegrationModule; -//import appeng.integration.IntegrationHelper; -//import appeng.tile.AEBaseTile; -// -// -//public class WailaModule implements IIntegrationModule -//{ -// -// public WailaModule() -// { -// IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaDataProvider.class ); -// IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaRegistrar.class ); -// IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaConfigHandler.class ); -// IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaDataAccessor.class ); -// IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.ITaggedList.class ); -// } -// -// public static void register( final IWailaRegistrar registrar ) -// { -// final IWailaDataProvider partHost = new PartWailaDataProvider(); -// -// registrar.registerStackProvider( partHost, AEBaseTile.class ); -// registrar.registerBodyProvider( partHost, AEBaseTile.class ); -// registrar.registerNBTProvider( partHost, AEBaseTile.class ); -// -// final IWailaDataProvider tile = new TileWailaDataProvider(); -// -// registrar.registerBodyProvider( tile, AEBaseTile.class ); -// registrar.registerNBTProvider( tile, AEBaseTile.class ); -// } -// -// @Override -// public void init() throws Throwable -// { -// FMLInterModComms.sendMessage( "Waila", "register", this.getClass().getName() + ".register" ); -// } -// -//} +/* + * 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 net.minecraftforge.fml.common.event.FMLInterModComms; + +import mcp.mobius.waila.api.IWailaDataProvider; +import mcp.mobius.waila.api.IWailaRegistrar; + +import appeng.integration.IIntegrationModule; +import appeng.integration.IntegrationHelper; +import appeng.tile.AEBaseTile; + + +public class WailaModule implements IIntegrationModule +{ + + public WailaModule() + { + IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaDataProvider.class ); + IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaRegistrar.class ); + IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaConfigHandler.class ); + IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.IWailaDataAccessor.class ); + IntegrationHelper.testClassExistence( this, mcp.mobius.waila.api.ITaggedList.class ); + } + + public static void register( final IWailaRegistrar registrar ) + { + final IWailaDataProvider partHost = new PartWailaDataProvider(); + + registrar.registerStackProvider( partHost, AEBaseTile.class ); + registrar.registerBodyProvider( partHost, AEBaseTile.class ); + registrar.registerNBTProvider( partHost, AEBaseTile.class ); + + final IWailaDataProvider tile = new TileWailaDataProvider(); + + registrar.registerBodyProvider( tile, AEBaseTile.class ); + registrar.registerNBTProvider( tile, AEBaseTile.class ); + } + + @Override + public void init() throws Throwable + { + FMLInterModComms.sendMessage( "waila", "register", this.getClass().getName() + ".register" ); + } + +} diff --git a/src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java index 09aaba2ff..ac51d200c 100644 --- a/src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/BasePartWailaDataProvider.java @@ -1,75 +1,75 @@ -///* -// * 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.item.ItemStack; -//import net.minecraft.nbt.NBTTagCompound; -//import net.minecraft.tileentity.TileEntity; -//import net.minecraft.util.math.BlockPos; -//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 ItemStack getWailaStack( final IPart part, final IWailaConfigHandler config, final ItemStack partStack ) -// { -// return null; -// } -// -// @Override -// public List getWailaHead( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return currentToolTip; -// } -// -// @Override -// public List getWailaBody( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return currentToolTip; -// } -// -// @Override -// public List getWailaTail( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// return currentToolTip; -// } -// -// @Override -// public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) -// { -// return tag; -// } -//} +/* + * 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.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +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 ItemStack getWailaStack( final IPart part, final IWailaConfigHandler config, final ItemStack partStack ) + { + return ItemStack.EMPTY; + } + + @Override + public List getWailaHead( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaBody( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public List getWailaTail( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) + { + 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 index 22303f8ed..6064daf44 100644 --- a/src/main/java/appeng/integration/modules/waila/part/ChannelWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/ChannelWailaDataProvider.java @@ -1,163 +1,163 @@ -///* -// * 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.util.math.BlockPos; -//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.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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// if( part instanceof PartCableSmart || part instanceof PartDenseCable ) -// { -// final NBTTagCompound tag = accessor.getNBTData(); -// -// final byte usedChannels = this.getUsedChannels( part, tag, this.cache ); -// -// if( usedChannels >= 0 ) -// { -// final byte maxChannels = (byte) ( ( part instanceof PartDenseCable ) ? 32 : 8 ); -// -// final String formattedToolTip = String.format( WailaText.Channels.getLocal(), usedChannels, maxChannels ); -// currentToolTip.add( formattedToolTip ); -// } -// } -// -// 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( final IPart part, final NBTTagCompound tag, final 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 = -1; -// } -// -// 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 pos pos of the part -// * -// * @return tag send to the client -// */ -// @Override -// public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) -// { -// 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; -// } -//} +/* + * 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.util.math.BlockPos; +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.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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + if( part instanceof PartCableSmart || part instanceof PartDenseCable ) + { + final NBTTagCompound tag = accessor.getNBTData(); + + final byte usedChannels = this.getUsedChannels( part, tag, this.cache ); + + if( usedChannels >= 0 ) + { + final byte maxChannels = (byte) ( ( part instanceof PartDenseCable ) ? 32 : 8 ); + + final String formattedToolTip = String.format( WailaText.Channels.getLocal(), usedChannels, maxChannels ); + currentToolTip.add( formattedToolTip ); + } + } + + 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( final IPart part, final NBTTagCompound tag, final 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 = -1; + } + + 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 pos pos of the part + * + * @return tag send to the client + */ + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) + { + 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 index 0e1d7ee76..51126ea52 100644 --- a/src/main/java/appeng/integration/modules/waila/part/IPartWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/IPartWailaDataProvider.java @@ -1,56 +1,56 @@ -///* -// * 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.item.ItemStack; -//import net.minecraft.nbt.NBTTagCompound; -//import net.minecraft.tileentity.TileEntity; -//import net.minecraft.util.math.BlockPos; -//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 -//{ -// ItemStack getWailaStack( IPart part, IWailaConfigHandler config, ItemStack partStack ); -// -// 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, BlockPos pos ); -//} +/* + * 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.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +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 +{ + ItemStack getWailaStack( IPart part, IWailaConfigHandler config, ItemStack partStack ); + + 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, BlockPos pos ); +} diff --git a/src/main/java/appeng/integration/modules/waila/part/P2PStateWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/P2PStateWailaDataProvider.java index cf0e16239..a9e77fbd3 100644 --- a/src/main/java/appeng/integration/modules/waila/part/P2PStateWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/P2PStateWailaDataProvider.java @@ -1,158 +1,158 @@ -///* -// * 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 com.google.common.collect.Iterators; -// -//import net.minecraft.entity.player.EntityPlayerMP; -//import net.minecraft.nbt.NBTTagCompound; -//import net.minecraft.tileentity.TileEntity; -//import net.minecraft.util.math.BlockPos; -//import net.minecraft.world.World; -// -//import mcp.mobius.waila.api.IWailaConfigHandler; -//import mcp.mobius.waila.api.IWailaDataAccessor; -// -//import appeng.api.parts.IPart; -//import appeng.core.localization.WailaText; -//import appeng.me.GridAccessException; -//import appeng.parts.p2p.PartP2PTunnel; -// -// -///** -// * Provides information about a P2P tunnel to WAILA. -// */ -//public final class P2PStateWailaDataProvider extends BasePartWailaDataProvider -//{ -// -// private static final int STATE_UNLINKED = 0; -// private static final int STATE_OUTPUT = 1; -// private static final int STATE_INPUT = 2; -// public static final String TAG_P2P_STATE = "p2p_state"; -// -// /** -// * 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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// if( part instanceof PartP2PTunnel ) -// { -// NBTTagCompound nbtData = accessor.getNBTData(); -// if( nbtData.hasKey( TAG_P2P_STATE ) ) -// { -// int[] stateArr = nbtData.getIntArray( TAG_P2P_STATE ); -// if( stateArr.length == 2 ) -// { -// int state = stateArr[0]; -// int outputs = stateArr[1]; -// -// switch( state ) -// { -// case STATE_UNLINKED: -// currentToolTip.add( WailaText.P2PUnlinked.getLocal() ); -// break; -// case STATE_OUTPUT: -// currentToolTip.add( WailaText.P2POutput.getLocal() ); -// break; -// case STATE_INPUT: -// currentToolTip.add( getOutputText( outputs ) ); -// break; -// } -// } -// } -// } -// -// return currentToolTip; -// } -// -// @Override -// public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) -// { -// if( part instanceof PartP2PTunnel ) -// { -// PartP2PTunnel tunnel = (PartP2PTunnel) part; -// -// // The default state -// int state = STATE_UNLINKED; -// int outputCount = 0; -// -// if( !tunnel.isOutput() ) -// { -// outputCount = getOutputCount( tunnel ); -// if( outputCount > 0 ) -// { -// // Only set it to INPUT if we know there are any outputs -// state = STATE_INPUT; -// } -// } -// else -// { -// PartP2PTunnel input = tunnel.getInput(); -// if( input != null ) -// { -// state = STATE_OUTPUT; -// } -// } -// -// tag.setIntArray( TAG_P2P_STATE, new int[] { -// state, -// outputCount -// } ); -// } -// -// return tag; -// } -// -// private static int getOutputCount( PartP2PTunnel tunnel ) -// { -// try -// { -// return Iterators.size( tunnel.getOutputs().iterator() ); -// } -// catch( GridAccessException e ) -// { -// // Well... unknown size it is! -// return 0; -// } -// } -// -// private static String getOutputText( int outputs ) -// { -// if( outputs <= 1 ) -// { -// return WailaText.P2PInputOneOutput.getLocal(); -// } -// else -// { -// return String.format( WailaText.P2PInputManyOutputs.getLocal(), outputs ); -// } -// } -// -//} +/* + * 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 com.google.common.collect.Iterators; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +import appeng.api.parts.IPart; +import appeng.core.localization.WailaText; +import appeng.me.GridAccessException; +import appeng.parts.p2p.PartP2PTunnel; + + +/** + * Provides information about a P2P tunnel to WAILA. + */ +public final class P2PStateWailaDataProvider extends BasePartWailaDataProvider +{ + + private static final int STATE_UNLINKED = 0; + private static final int STATE_OUTPUT = 1; + private static final int STATE_INPUT = 2; + public static final String TAG_P2P_STATE = "p2p_state"; + + /** + * 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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + if( part instanceof PartP2PTunnel ) + { + NBTTagCompound nbtData = accessor.getNBTData(); + if( nbtData.hasKey( TAG_P2P_STATE ) ) + { + int[] stateArr = nbtData.getIntArray( TAG_P2P_STATE ); + if( stateArr.length == 2 ) + { + int state = stateArr[0]; + int outputs = stateArr[1]; + + switch( state ) + { + case STATE_UNLINKED: + currentToolTip.add( WailaText.P2PUnlinked.getLocal() ); + break; + case STATE_OUTPUT: + currentToolTip.add( WailaText.P2POutput.getLocal() ); + break; + case STATE_INPUT: + currentToolTip.add( getOutputText( outputs ) ); + break; + } + } + } + } + + return currentToolTip; + } + + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) + { + if( part instanceof PartP2PTunnel ) + { + PartP2PTunnel tunnel = (PartP2PTunnel) part; + + // The default state + int state = STATE_UNLINKED; + int outputCount = 0; + + if( !tunnel.isOutput() ) + { + outputCount = getOutputCount( tunnel ); + if( outputCount > 0 ) + { + // Only set it to INPUT if we know there are any outputs + state = STATE_INPUT; + } + } + else + { + PartP2PTunnel input = tunnel.getInput(); + if( input != null ) + { + state = STATE_OUTPUT; + } + } + + tag.setIntArray( TAG_P2P_STATE, new int[] { + state, + outputCount + } ); + } + + return tag; + } + + private static int getOutputCount( PartP2PTunnel tunnel ) + { + try + { + return Iterators.size( tunnel.getOutputs().iterator() ); + } + catch( GridAccessException e ) + { + // Well... unknown size it is! + return 0; + } + } + + private static String getOutputText( int outputs ) + { + if( outputs <= 1 ) + { + return WailaText.P2PInputOneOutput.getLocal(); + } + else + { + return String.format( WailaText.P2PInputManyOutputs.getLocal(), outputs ); + } + } + +} diff --git a/src/main/java/appeng/integration/modules/waila/part/PartStackWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/PartStackWailaDataProvider.java index 36945ba77..31ab7ddf6 100644 --- a/src/main/java/appeng/integration/modules/waila/part/PartStackWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/PartStackWailaDataProvider.java @@ -1,47 +1,47 @@ -///* -// * This file is part of Applied Energistics 2. -// * Copyright (c) 2013 - 2015, 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.item.ItemStack; -// -//import mcp.mobius.waila.api.IWailaConfigHandler; -// -//import appeng.api.parts.IPart; -//import appeng.api.parts.PartItemStack; -// -// -///** -// * Part ItemStack provider for WAILA -// * -// * @author TheJulianJES -// * @version rv2 -// * @since rv2 -// */ -//public class PartStackWailaDataProvider extends BasePartWailaDataProvider -//{ -// -// @Override -// public ItemStack getWailaStack( final IPart part, final IWailaConfigHandler config, ItemStack partStack ) -// { -// partStack = part.getItemStack( PartItemStack.PICK ); -// return partStack; -// } -// -//} +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2015, 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.item.ItemStack; + +import mcp.mobius.waila.api.IWailaConfigHandler; + +import appeng.api.parts.IPart; +import appeng.api.parts.PartItemStack; + + +/** + * Part ItemStack provider for WAILA + * + * @author TheJulianJES + * @version rv2 + * @since rv2 + */ +public class PartStackWailaDataProvider extends BasePartWailaDataProvider +{ + + @Override + public ItemStack getWailaStack( final IPart part, final IWailaConfigHandler config, ItemStack partStack ) + { + partStack = part.getItemStack( PartItemStack.PICK ); + return partStack; + } + +} diff --git a/src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java index 3afcac571..c7e3a8261 100644 --- a/src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/PowerStateWailaDataProvider.java @@ -1,91 +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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final 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( final boolean isActive, final 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; -// } -//} +/* + * 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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final 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( final boolean isActive, final 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 index 817d84995..829a9c557 100644 --- a/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/part/StorageMonitorWailaDataProvider.java @@ -1,81 +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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final 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 ) -// { -// final IAEItemStack ais = (IAEItemStack) displayed; -// currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() ); -// } -// else if( displayed instanceof IAEFluidStack ) -// { -// final 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; -// } -//} +/* + * 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( final IPart part, final List currentToolTip, final IWailaDataAccessor accessor, final 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 ) + { + final IAEItemStack ais = (IAEItemStack) displayed; + currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() ); + } + else if( displayed instanceof IAEFluidStack ) + { + final 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/tile/ChargerWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java index d84425295..88e273917 100644 --- a/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java @@ -1,78 +1,83 @@ -///* -// * 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( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final 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; -// } -//} +/* + * 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.client.Minecraft; +import net.minecraft.client.util.ITooltipFlag; +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; + +import javax.annotation.Nonnull; + + +/** + * 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( @Nonnull final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final 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.isEmpty() ) + { + final String currentInventory = chargingItem.getDisplayName(); + final EntityPlayer player = accessor.getPlayer(); + + currentToolTip.add( WailaText.Contains + ": " + currentInventory ); + ITooltipFlag.TooltipFlags tooltipFlag = Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL; + chargingItem.getItem().addInformation( chargingItem, player.world, currentToolTip, tooltipFlag ); + } + } + + 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 index 6745d239c..7159cfd3d 100644 --- a/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/tile/CraftingMonitorWailaDataProvider.java @@ -1,74 +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( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final 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; -// } -//} +/* + * 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( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final 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 index 18963f9dc..cff256ddf 100644 --- a/src/main/java/appeng/integration/modules/waila/tile/PowerStateWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/tile/PowerStateWailaDataProvider.java @@ -1,82 +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( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final 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 +/* + * 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( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final 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 index b51a9382c..7b8942eb8 100644 --- a/src/main/java/appeng/integration/modules/waila/tile/PowerStorageWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/tile/PowerStorageWailaDataProvider.java @@ -1,174 +1,174 @@ -///* -// * 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.util.math.BlockPos; -//import net.minecraft.world.World; -// -//import gnu.trove.map.TObjectLongMap; -//import gnu.trove.map.hash.TObjectLongHashMap; -//import mcp.mobius.waila.api.ITaggedList; -//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( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) -// { -// // Removes RF tooltip on WAILA 1.5.9+ -// ( (ITaggedList) currentToolTip ).removeEntries( "RFEnergyStorage" ); -// -// 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 ); -// -// if( internalCurrentPower >= 0 ) -// { -// final long internalMaxPower = (long) ( 100 * maxPower ); -// -// final String formatCurrentPower = Platform.formatPowerLong( internalCurrentPower, false ); -// final String formatMaxPower = Platform.formatPowerLong( internalMaxPower, false ); -// -// currentToolTip.add( WailaText.Contains.getLocal() + ": " + 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 pos pos of the power storage -// * -// * @return tag send to the client -// */ -// @Override -// public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) -// { -// 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( final NBTTagCompound tag, final 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 = -1; -// } -// -// return internalCurrentPower; -// } -//} +/* + * 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.util.math.BlockPos; +import net.minecraft.world.World; + +import gnu.trove.map.TObjectLongMap; +import gnu.trove.map.hash.TObjectLongHashMap; +import mcp.mobius.waila.api.ITaggedList; +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( final ItemStack itemStack, final List currentToolTip, final IWailaDataAccessor accessor, final IWailaConfigHandler config ) + { + // Removes RF tooltip on WAILA 1.5.9+ + ( (ITaggedList) currentToolTip ).removeEntries( "RFEnergyStorage" ); + + 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 ); + + if( internalCurrentPower >= 0 ) + { + final long internalMaxPower = (long) ( 100 * maxPower ); + + final String formatCurrentPower = Platform.formatPowerLong( internalCurrentPower, false ); + final String formatMaxPower = Platform.formatPowerLong( internalMaxPower, false ); + + currentToolTip.add( WailaText.Contains.getLocal() + ": " + 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 pos pos of the power storage + * + * @return tag send to the client + */ + @Override + public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos ) + { + 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( final NBTTagCompound tag, final 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 = -1; + } + + return internalCurrentPower; + } +}