diff --git a/build.gradle b/build.gradle index e3b370257..66926b415 100644 --- a/build.gradle +++ b/build.gradle @@ -60,261 +60,17 @@ sourceSets { api main { java { - include 'appeng/core/AppEng.java' - include 'appeng/core/crash/CrashInfo.java' - include 'appeng/core/CommonHelper.java' - include 'appeng/core/crash/**' - include 'appeng/core/AEConfig.java' - include 'appeng/core/features/AEFeature.java' - include 'appeng/core/settings/**' - include 'appeng/util/ConfigManager.java' - include 'appeng/core/settings/TickRates.java' - include 'appeng/util/IConfigManagerHost.java' - include 'appeng/services/export/ExportConfig.java' - include 'appeng/client/ActionKey.java' - include 'appeng/client/EffectType.java' - include 'appeng/core/AELog.java' - include 'appeng/core/Registration.java' - include 'appeng/core/features/ItemDefinition.java' - include 'appeng/util/inv/InvOperation.java' - include 'appeng/core/features/registries/PartModels.java' - include 'appeng/core/features/registries/PartModels.java' - include 'appeng/core/api/**' - include 'appeng/core/api/definitions/ApiItems.java' - include 'appeng/items/tools/quartz/**' - include 'appeng/items/AEBaseItem.java' - include 'appeng/util/helpers/ItemComparisonHelper.java' - include 'appeng/items/contents/QuartzKnifeObj.java' - include 'appeng/core/ApiDefinitions.java' - include 'appeng/core/Api.java' - include 'appeng/decorative/solid/BlockQuartzOre.java' - include 'appeng/bootstrap/**' - include 'appeng/block/AEBaseBlock.java' - include 'appeng/block/AEBaseBlockItem.java' - include 'appeng/block/AEBaseTileBlock.java' - include 'appeng/tile/**' - include 'appeng/parts/**' - include 'appeng/helpers/**' - include 'appeng/items/**' - include 'appeng/util/**' - include 'appeng/debug/**' - include 'appeng/core/localization/**' - include 'appeng/core/stats/**' - include 'appeng/client/render/crafting/ItemEncodedPatternRendering.java' + exclude 'appeng/client/render/model/UVLModelLoader.java' + exclude 'appeng/client/core/api/imc/**' + exclude 'appeng/core/IMCHandler.java' + exclude 'appeng/recipes/handlers/**' + exclude 'appeng/worldgen/**' + exclude 'appeng/services/export/**' + exclude 'appeng/spatial/StorageChunkProvider.java' + exclude 'appeng/spatial/StorageHelper.java' + exclude 'appeng/spatial/CachedPlane.java' + exclude 'appeng/spatial/StorageWorldProvider.java' exclude 'appeng/parts/p2p/PartP2PFluids.java' - exclude 'appeng/parts/p2p/PartP2PItems.java' - include 'appeng/tile/AEBaseTile.java' - include 'appeng/tile/AEBaseInvTile.java' - include 'appeng/util/Platform.java' - include 'appeng/util/SettingsFrom.java' - include 'appeng/core/features/IStackSrc.java' - include 'appeng/helpers/ICustomNameObject.java' - include 'appeng/core/CreativeTab.java' - include 'appeng/core/CreativeTabFacade.java' - include 'appeng/decorative/AEDecorativeBlock.java' - include 'appeng/decorative/solid/BlockQuartzPillar.java' - include 'appeng/helpers/MetaRotation.java' - include 'appeng/core/features/ActivityState.java' - include 'appeng/core/features/BlockStackSrc.java' - include 'appeng/core/features/ItemStackSrc.java' - include 'appeng/core/features/BlockDefinition.java' - include 'appeng/core/features/TileDefinition.java' - include 'appeng/core/features/ColoredItemDefinition.java' - include 'appeng/util/helpers/ItemHandlerUtil.java' - include 'appeng/util/inv/IAEAppEngInventory.java' - include 'appeng/decorative/solid/BlockChargedQuartzOre.java' - include 'appeng/client/render/effects/ChargedOreFX.java' - include 'appeng/bootstrap/components/BuiltInModelComponent.java' - include 'appeng/bootstrap/components/ModelOverrideComponent.java' - include 'appeng/client/render/model/GlassBakedModel.java' - include 'appeng/decorative/solid/BlockQuartzGlass.java' - include 'appeng/decorative/solid/GlassState.java' - include 'appeng/client/render/model/GlassModel.java' - include 'appeng/client/render/model/RenderHelper.java' - include 'appeng/client/render/model/GlassModelLoader.java' - include 'appeng/helpers/AEGlassMaterial.java' - include 'appeng/block/spatial/BlockMatrixFrame.java' - include 'appeng/util/LookDirection.java' - include 'appeng/decorative/solid/BlockQuartzLamp.java' - include 'appeng/client/render/effects/VibrantFX.java' - include 'appeng/client/render/effects/LightningFX.java' - include 'appeng/block/misc/BlockQuartzFixture.java' - - include 'appeng/core/sync/AppEngPacket.java' - include 'appeng/core/sync/network/INetworkInfo.java' -// include 'appeng/core/sync/network/NetworkHandler.java' - include 'appeng/core/sync/network/IPacketHandler.java' - include 'appeng/core/sync/network/TargetPoint.java' - - include 'appeng/core/stats/AeStats.java' - include 'appeng/me/GridAccessException.java' - - include 'appeng/util/item/AEItemStack.java' - include 'appeng/util/item/AEStack.java' - include 'appeng/util/item/AESharedItemStack.java' - include 'appeng/util/item/AEItemStackRegistry.java' - include 'appeng/services/compass/ICompassCallback.java' - include 'appeng/hooks/CompassResult.java' - include 'appeng/container/ContainerOpenContext.java' - include 'appeng/decorative/solid/BlockSkyStone.java' - - include 'appeng/block/storage/BlockSkyChest.java' - include 'appeng/tile/storage/TileSkyChest.java' - include 'appeng/block/storage/SkyChestRenderingCustomizer.java' - include 'appeng/client/render/tesr/SkyChestTESR.java' - include 'appeng/tile/inventory/AppEngInternalInventory.java' - include 'appeng/util/inv/filter/**' - - include 'appeng/client/render/StaticBlockColor.java' - - exclude 'appeng/block/paint/PaintBakedModel.java' - exclude 'appeng/block/paint/PaintModel.java' - exclude 'appeng/block/qnb/QnbFormedBakedModel.java' - exclude 'appeng/block/qnb/QnbFormedModel.java' - - include 'appeng/client/render/spatial/SpatialPylonRendering.java' - -// include 'appeng/client/ClientHelper.java' -// include 'appeng/server/ServerHelper.java' - include 'appeng/block/AEBaseBlock.java' - include 'appeng/helpers/ICustomCollision.java' - include 'appeng/client/ClientHelper.java' - include 'appeng/server/ServerHelper.java' - include 'appeng/core/CommonHelper.java' - include 'appeng/helpers/IMouseWheelItem.java' - include 'appeng/client/gui/AEBaseGui.java' - include 'appeng/client/gui/widgets/ITooltip.java' - include 'appeng/client/gui/widgets/GuiCustomSlot.java' - include 'appeng/client/gui/widgets/IScrollSource.java' - include 'appeng/client/gui/widgets/GuiScrollbar.java' - include 'appeng/client/me/**' - include 'appeng/client/gui/widgets/ISortSource.java' - include 'appeng/items/storage/ItemViewCell.java' - include 'appeng/util/ItemSorters.java' - include 'appeng/util/prioritylist/**' - include 'appeng/fluids/util/**' - include 'appeng/fluids/container/slots/IMEFluidSlot.java' - include 'appeng/fluids/items/FluidDummyItem.java' - include 'appeng/items/contents/**' - include 'appeng/container/interfaces/IInventorySlotAware.java' - include 'appeng/me/helpers/**' - include 'appeng/me/cluster/*' - include 'appeng/util/iterators/*' - include 'appeng/util/inv/**' - include 'appeng/util/InventoryAdaptor.java' - include 'appeng/tile/inventory/AppEngInternalAEInventory.java' - include 'appeng/core/worlddata/**' - include 'appeng/services/compass/**' - include 'appeng/services/CompassService*' - include 'appeng/parts/automation/StackUpgradeInventory*' - include 'appeng/parts/automation/UpgradeInventory*' - include 'appeng/me/GridStorage*' - include 'appeng/capabilities/*' - include 'appeng/container/slot/AppEngSlot*' - include 'appeng/container/AEBaseContainer*' - include 'appeng/helpers/InventoryAction.java' - include 'appeng/container/guisync/**' - include 'appeng/fluids/**' - exclude 'appeng/fluids/client/gui/**' - include 'appeng/core/features/**' - include 'appeng/entity/**' - include 'appeng/facade/**' - include 'appeng/hooks/**' - include 'appeng/block/**' - include 'appeng/client/render/renderable/**' - include 'appeng/client/render/tesr/**' - include 'appeng/client/render/ColorableTileBlockColor.java' - include 'appeng/client/render/cablebus/**' - include 'appeng/client/render/effects/EnergyFx.java' - include 'appeng/client/render/TesrRenderHelper.java' - include 'appeng/core/stats/IAdvancementTrigger.java' - include 'appeng/client/render/StaticItemColor.java' - include 'appeng/core/FacadeConfig.java' - include 'appeng/spatial/DefaultSpatialHandler.java' - exclude 'appeng/core/sync/packets/PacketSwitchGuis.java' - include 'appeng/core/sync/network/NetworkHandler.java' - include 'appeng/core/sync/packets/PacketProgressBar.java' - include 'appeng/container/slot/SlotDisabled.java' - include 'appeng/container/slot/SlotFake.java' - include 'appeng/container/slot/SlotInaccessible.java' - include 'appeng/container/slot/SlotPlayerHotBar.java' - include 'appeng/container/slot/SlotPlayerInv.java' - include 'appeng/core/sync/packets/PacketTargetItemStack.java' - include 'appeng/core/sync/packets/PacketSwapSlots.java' - include 'appeng/core/sync/packets/PacketInventoryAction.java' - include 'appeng/container/implementations/ContainerCraftAmount.java' - include 'appeng/container/implementations/ContainerCraftConfirm.java' - include 'appeng/helpers/WirelessTerminalGuiObject.java' - include 'appeng/core/sync/packets/PacketValueConfig.java' - include 'appeng/client/render/StackSizeRenderer.java' - include 'appeng/fluids/client/render/FluidStackSizeRenderer.java' - include 'appeng/core/localization/GuiText.java' - include 'appeng/util/ISlimReadableNumberConverter.java' - include 'appeng/util/IWideReadableNumberConverter.java' - include 'appeng/util/ReadableNumberConverter.java' - include 'appeng/container/slot/IOptionalSlot.java' - include 'appeng/client/gui/Size1Slot.java' - include 'appeng/container/slot/SlotOutput.java' - include 'appeng/container/slot/AppEngCraftingSlot.java' - include 'appeng/container/slot/SlotRestrictedInput.java' - include 'appeng/container/implementations/ContainerSkyChest.java' - include 'appeng/container/slot/SlotNormal.java' - include 'appeng/client/gui/implementations/GuiSkyChest.java' - include 'appeng/block/grindstone/**' - include 'appeng/tile/grindstone/**' - include 'appeng/container/implementations/ContainerGrinder.java' - include 'appeng/recipes/conditions/**' - include 'appeng/recipes/game/DisassembleRecipe.java' - include 'appeng/recipes/ingredients/**' - include 'appeng/forge/data/**' - include 'appeng/client/render/tesr/CrankTESR.java' - include 'appeng/client/render/FacingToRotation.java' - include 'appeng/client/gui/implementations/GuiGrinder.java' - include 'appeng/tile/misc/TileSkyCompass.java' - include 'appeng/block/misc/BlockSkyCompass.java' - include 'appeng/client/render/tesr/SkyCompassTESR.java' - include 'appeng/block/misc/SkyCompassRendering.java' - include 'appeng/client/render/model/SkyCompassModelLoader.java' - include 'appeng/client/render/model/SkyCompassModel.java' - include 'appeng/client/render/model/SkyCompassBakedModel.java' - include 'appeng/client/render/model/MatrixVertexTransformer.java' - include 'appeng/client/render/model/AutoRotatingModel.java' - include 'appeng/client/render/model/AutoRotatingBakedModel.java' - include 'appeng/client/render/model/AutoRotatingModelLoader.java' - include 'appeng/client/render/cablebus/QuadRotator.java' - include 'appeng/thirdparty/codechicken/lib/**' - include 'appeng/client/render/model/AutoRotatingCacheKey.java' - include 'appeng/tile/misc/TileInscriber.java' - include 'appeng/parts/automation/DefinitionUpgradeInventory.java' - include 'appeng/core/sync/packets/PacketAssemblerAnimation.java' - include 'appeng/tile/grid/**' - include 'appeng/tile/powersink/AEBasePoweredTile.java' - include 'appeng/tile/powersink/IExternalPowerSink.java' - include 'appeng/block/misc/BlockInscriber.java' - include 'appeng/tile/powersink/ForgeEnergyAdapter.java' - include 'appeng/block/misc/InscriberRendering.java' - include 'appeng/client/render/tesr/InscriberTESR.java' - include 'appeng/hooks/TickHandler.java' - include 'appeng/me/**' - include 'appeng/util/IWorldCallable.java' - include 'appeng/crafting/**' - include 'appeng/util/ReadOnlyCollection.java' - include 'appeng/me/NetworkEventBus.java' - include 'appeng/container/ContainerNull.java' - include 'appeng/tile/crafting/**' - include 'appeng/block/crafting/**' - include 'appeng/client/render/crafting/CraftingCubeState.java' - include 'appeng/items/misc/ItemEncodedPattern.java' - include 'appeng/client/render/crafting/CraftingCubeRendering.java' - include 'appeng/core/sync/packets/**' - include 'appeng/hooks/CompassResult.java' - include 'appeng/container/implementations/CraftingCPURecord.java' - include 'appeng/fluids/container/IFluidSyncContainer.java' - include 'appeng/helpers/IContainerCraftingPacket.java' - include 'appeng/parts/PartPlacement.java' - include 'appeng/container/implementations/ContainerPatternTerm.java' - include 'appeng/parts/reporting/**' - include 'appeng/container/**' } compileClasspath += sourceSets.api.output runtimeClasspath += sourceSets.api.output diff --git a/src/api/java/appeng/api/config/PowerUnits.java b/src/api/java/appeng/api/config/PowerUnits.java index 3111e7d9d..78dc456c0 100644 --- a/src/api/java/appeng/api/config/PowerUnits.java +++ b/src/api/java/appeng/api/config/PowerUnits.java @@ -24,6 +24,9 @@ package appeng.api.config; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; + public enum PowerUnits { AE( "gui.appliedenergistics2.units.appliedenergstics" ), // Native Units - AE Energy @@ -61,4 +64,8 @@ public enum PowerUnits return ( value * this.conversionRatio ) / target.conversionRatio; } + public ITextComponent textComponent() { + return new TranslationTextComponent(unlocalizedName); + } + } \ No newline at end of file diff --git a/src/api/java/appeng/api/features/IWirelessTermRegistry.java b/src/api/java/appeng/api/features/IWirelessTermRegistry.java index 45f341077..57beeae53 100644 --- a/src/api/java/appeng/api/features/IWirelessTermRegistry.java +++ b/src/api/java/appeng/api/features/IWirelessTermRegistry.java @@ -26,6 +26,7 @@ package appeng.api.features; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; import net.minecraft.world.IBlockReader; @@ -61,5 +62,5 @@ public interface IWirelessTermRegistry * opens the wireless terminal gui, the wireless terminal item, must be in * the active slot on the tool bar. */ - void openWirelessTerminalGui( ItemStack item, IBlockReader world, PlayerEntity player ); + void openWirelessTerminalGui( ItemStack item, IBlockReader world, PlayerEntity player, Hand hand ); } diff --git a/src/api/java/appeng/api/util/WorldCoord.java b/src/api/java/appeng/api/util/WorldCoord.java index 75d10853a..b0af1c171 100644 --- a/src/api/java/appeng/api/util/WorldCoord.java +++ b/src/api/java/appeng/api/util/WorldCoord.java @@ -100,6 +100,11 @@ public class WorldCoord return this; } + public BlockPos getBlockPos() + { + return new BlockPos(x, y, z); + } + /** * Will Return NULL if it's at some diagonal! */ diff --git a/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java b/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java index e0d721341..9e5322901 100644 --- a/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java +++ b/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java @@ -18,8 +18,12 @@ package appeng.block.crafting; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerCraftingCPU; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.state.BooleanProperty; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.state.StateContainer; @@ -83,7 +87,7 @@ public abstract class AbstractCraftingUnitBlock exte { if ( !w.isRemote() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing( side ), GuiBridge.GUI_CRAFTING_CPU ); + ContainerOpener.openContainer(ContainerCraftingCPU.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; diff --git a/src/main/java/appeng/block/crafting/BlockMolecularAssembler.java b/src/main/java/appeng/block/crafting/BlockMolecularAssembler.java index ef6fe45d2..524359bcf 100644 --- a/src/main/java/appeng/block/crafting/BlockMolecularAssembler.java +++ b/src/main/java/appeng/block/crafting/BlockMolecularAssembler.java @@ -20,6 +20,10 @@ package appeng.block.crafting; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerInscriber; +import appeng.container.implementations.ContainerMAC; import appeng.tile.crafting.TileMolecularAssembler; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -69,7 +73,7 @@ public class BlockMolecularAssembler extends AEBaseTileBlock if( tg != null && !p.isCrouching() ) { if (p instanceof ServerPlayerEntity) { - ContainerGrinder.open((ServerPlayerEntity) p, tg, getNameTextComponent()); + ContainerOpener.openContainer(ContainerGrinder.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/misc/BlockCellWorkbench.java b/src/main/java/appeng/block/misc/BlockCellWorkbench.java index 12ea19cc5..faaaa0308 100644 --- a/src/main/java/appeng/block/misc/BlockCellWorkbench.java +++ b/src/main/java/appeng/block/misc/BlockCellWorkbench.java @@ -21,6 +21,8 @@ package appeng.block.misc; import javax.annotation.Nullable; +import appeng.container.ContainerLocator; +import appeng.container.implementations.ContainerCellWorkbench; import net.minecraft.block.material.Material; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -30,7 +32,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.World; -import appeng.api.util.AEPartLocation; import appeng.block.AEBaseTileBlock; import appeng.tile.misc.TileCellWorkbench; @@ -58,7 +59,7 @@ public class BlockCellWorkbench extends AEBaseTileBlock { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit.getFace()), GuiBridge.GUI_CELL_WORKBENCH ); + ContainerCellWorkbench.open(p, ContainerLocator.forTileEntity(tg)); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/misc/BlockCondenser.java b/src/main/java/appeng/block/misc/BlockCondenser.java index 789d3cb62..6c934fe2c 100644 --- a/src/main/java/appeng/block/misc/BlockCondenser.java +++ b/src/main/java/appeng/block/misc/BlockCondenser.java @@ -21,6 +21,10 @@ package appeng.block.misc; import javax.annotation.Nullable; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerCondenser; +import appeng.container.implementations.ContainerDrive; import net.minecraft.block.material.Material; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -58,7 +62,7 @@ public class BlockCondenser extends AEBaseTileBlock final TileCondenser tc = this.getTileEntity( w, pos ); if( tc != null && !player.isCrouching() ) { - // FIXME Platform.openGUI( player, tc, AEPartLocation.fromFacing(hit), GuiBridge.GUI_CONDENSER ); + ContainerOpener.openContainer(ContainerCondenser.TYPE, player, ContainerLocator.forTileEntitySide(tc, hit.getFace())); return ActionResultType.SUCCESS; } } diff --git a/src/main/java/appeng/block/misc/BlockInscriber.java b/src/main/java/appeng/block/misc/BlockInscriber.java index 369366c48..df8106480 100644 --- a/src/main/java/appeng/block/misc/BlockInscriber.java +++ b/src/main/java/appeng/block/misc/BlockInscriber.java @@ -20,6 +20,11 @@ package appeng.block.misc; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerInscriber; +import appeng.container.implementations.ContainerInterface; +import appeng.fluids.container.ContainerFluidLevelEmitter; import appeng.tile.misc.TileInscriber; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; @@ -50,7 +55,7 @@ public class BlockInscriber extends AEBaseTileBlock { final TileInscriber tg = this.getTileEntity(w, pos); if (tg != null) { if (!tg.isRemote()) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit.getFace()), GuiBridge.GUI_INSCRIBER ); + ContainerOpener.openContainer(ContainerInscriber.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/misc/BlockInterface.java b/src/main/java/appeng/block/misc/BlockInterface.java index 5b516ff87..f621ca65f 100644 --- a/src/main/java/appeng/block/misc/BlockInterface.java +++ b/src/main/java/appeng/block/misc/BlockInterface.java @@ -21,6 +21,10 @@ package appeng.block.misc; import appeng.api.util.IOrientable; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerDrive; +import appeng.container.implementations.ContainerInterface; import appeng.tile.misc.TileInterface; import appeng.util.Platform; import net.minecraft.block.Block; @@ -83,7 +87,7 @@ public class BlockInterface extends AEBaseTileBlock { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_INTERFACE ); + ContainerOpener.openContainer(ContainerInterface.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/misc/BlockSecurityStation.java b/src/main/java/appeng/block/misc/BlockSecurityStation.java index e0a846344..3750d5124 100644 --- a/src/main/java/appeng/block/misc/BlockSecurityStation.java +++ b/src/main/java/appeng/block/misc/BlockSecurityStation.java @@ -21,6 +21,10 @@ package appeng.block.misc; import javax.annotation.Nullable; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerFormationPlane; +import appeng.container.implementations.ContainerSecurityStation; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -92,7 +96,7 @@ public class BlockSecurityStation extends AEBaseTileBlock return ActionResultType.SUCCESS; } - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_SECURITY ); + ContainerOpener.openContainer(ContainerSecurityStation.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); return ActionResultType.SUCCESS; } return ActionResultType.PASS; diff --git a/src/main/java/appeng/block/misc/BlockVibrationChamber.java b/src/main/java/appeng/block/misc/BlockVibrationChamber.java index 47295dae5..7af625cce 100644 --- a/src/main/java/appeng/block/misc/BlockVibrationChamber.java +++ b/src/main/java/appeng/block/misc/BlockVibrationChamber.java @@ -20,6 +20,10 @@ package appeng.block.misc; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerDrive; +import appeng.container.implementations.ContainerVibrationChamber; import appeng.core.AEConfig; import appeng.tile.AEBaseTile; import appeng.tile.misc.TileVibrationChamber; @@ -85,7 +89,7 @@ public final class BlockVibrationChamber extends AEBaseTileBlock { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, tg, AEPartLocation.fromFacing( side ), GuiBridge.GUI_WIRELESS ); + ContainerOpener.openContainer(ContainerWireless.TYPE, player, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/paint/PaintModel.java b/src/main/java/appeng/block/paint/PaintModel.java deleted file mode 100644 index b5b4c49af..000000000 --- a/src/main/java/appeng/block/paint/PaintModel.java +++ /dev/null @@ -1,45 +0,0 @@ - -package appeng.block.paint; - - -import java.util.Collection; -import java.util.Collections; -import java.util.function.Function; - -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.common.model.IModelState; -import net.minecraftforge.common.model.TRSRTransformation; - - -class PaintModel implements IModel -{ - - @Override - public Collection getDependencies() - { - return Collections.emptyList(); - } - - @Override - public Collection getTextures() - { - return PaintBakedModel.getRequiredTextures(); - } - - @Override - public IBakedModel bake( IModelState state, VertexFormat format, Function bakedTextureGetter ) - { - return new PaintBakedModel( format, bakedTextureGetter ); - } - - @Override - public IModelState getDefaultState() - { - return TRSRTransformation.identity(); - } - -} diff --git a/src/main/java/appeng/block/paint/PaintBakedModel.java b/src/main/java/appeng/block/paint/PaintSplotchesBakedModel.java similarity index 72% rename from src/main/java/appeng/block/paint/PaintBakedModel.java rename to src/main/java/appeng/block/paint/PaintSplotchesBakedModel.java index dbe9ae67a..255542304 100644 --- a/src/main/java/appeng/block/paint/PaintBakedModel.java +++ b/src/main/java/appeng/block/paint/PaintSplotchesBakedModel.java @@ -5,26 +5,31 @@ package appeng.block.paint; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Random; import java.util.function.Function; +import javax.annotation.Nonnull; import javax.annotation.Nullable; +import appeng.tile.misc.TilePaint; import com.google.common.collect.ImmutableList; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; -import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.model.ItemOverrideList; +import net.minecraft.client.renderer.model.Material; +import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.property.IExtendedBlockState; import appeng.client.render.cablebus.CubeBuilder; import appeng.core.AppEng; import appeng.helpers.Splotch; +import net.minecraftforge.client.model.data.IDynamicBakedModel; +import net.minecraftforge.client.model.data.IModelData; /** @@ -32,20 +37,17 @@ import appeng.helpers.Splotch; * a * matter cannon with paint balls. */ -class PaintBakedModel implements IBakedModel +class PaintSplotchesBakedModel implements IDynamicBakedModel { - private static final ResourceLocation TEXTURE_PAINT1 = new ResourceLocation( AppEng.MOD_ID, "blocks/paint1" ); - private static final ResourceLocation TEXTURE_PAINT2 = new ResourceLocation( AppEng.MOD_ID, "blocks/paint2" ); - private static final ResourceLocation TEXTURE_PAINT3 = new ResourceLocation( AppEng.MOD_ID, "blocks/paint3" ); - - private final VertexFormat vertexFormat; + private static final Material TEXTURE_PAINT1 = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(AppEng.MOD_ID, "blocks/paint1" )); + private static final Material TEXTURE_PAINT2 = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "blocks/paint2" )); + private static final Material TEXTURE_PAINT3 = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "blocks/paint3" )); private final TextureAtlasSprite[] textures; - PaintBakedModel( VertexFormat vertexFormat, Function bakedTextureGetter ) + PaintSplotchesBakedModel(Function bakedTextureGetter ) { - this.vertexFormat = vertexFormat; this.textures = new TextureAtlasSprite[] { bakedTextureGetter.apply( TEXTURE_PAINT1 ), bakedTextureGetter.apply( TEXTURE_PAINT2 ), @@ -53,35 +55,30 @@ class PaintBakedModel implements IBakedModel }; } + @Nonnull @Override - public List getQuads( @Nullable BlockState state, @Nullable Direction side, long rand ) - { + public List getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) { + if( side != null ) { return Collections.emptyList(); } - if( !( state instanceof IExtendedBlockState ) ) + PaintSplotches splotchesState = extraData.getData(TilePaint.SPLOTCHES); + + if( splotchesState == null ) { // This is the inventory model which should usually not be used other than in special cases List quads = new ArrayList<>( 1 ); - CubeBuilder builder = new CubeBuilder( this.vertexFormat, quads ); + CubeBuilder builder = new CubeBuilder( quads ); builder.setTexture( this.textures[0] ); builder.addCube( 0, 0, 0, 16, 16, 16 ); return quads; } - IExtendedBlockState extendedBlockState = (IExtendedBlockState) state; - PaintSplotches splotchesState = extendedBlockState.getValue( BlockPaint.SPLOTCHES ); - - if( splotchesState == null ) - { - return Collections.emptyList(); - } - List splotches = splotchesState.getSplotches(); - CubeBuilder builder = new CubeBuilder( this.vertexFormat ); + CubeBuilder builder = new CubeBuilder( ); float offsetConstant = 0.001f; for( final Splotch s : splotches ) @@ -179,19 +176,18 @@ class PaintBakedModel implements IBakedModel return this.textures[0]; } - @Override - public ItemCameraTransforms getItemCameraTransforms() - { - return ItemCameraTransforms.DEFAULT; - } - @Override public ItemOverrideList getOverrides() { return ItemOverrideList.EMPTY; } - static List getRequiredTextures() + @Override + public boolean func_230044_c_() { + return false; + } + + static List getRequiredTextures() { return ImmutableList.of( TEXTURE_PAINT1, TEXTURE_PAINT2, TEXTURE_PAINT3 ); diff --git a/src/main/java/appeng/block/paint/PaintSplotchesModel.java b/src/main/java/appeng/block/paint/PaintSplotchesModel.java new file mode 100644 index 000000000..7d5f1febe --- /dev/null +++ b/src/main/java/appeng/block/paint/PaintSplotchesModel.java @@ -0,0 +1,30 @@ + +package appeng.block.paint; + + +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.renderer.model.*; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; + +import java.util.Collection; +import java.util.Set; +import java.util.function.Function; + + +public class PaintSplotchesModel implements IModelGeometry +{ + + @Override + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { + return new PaintSplotchesBakedModel( spriteGetter ); + } + + @Override + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { + return PaintSplotchesBakedModel.getRequiredTextures(); + } + +} diff --git a/src/main/java/appeng/block/qnb/BlockQuantumLinkChamber.java b/src/main/java/appeng/block/qnb/BlockQuantumLinkChamber.java index 62a425721..4e1df61e4 100644 --- a/src/main/java/appeng/block/qnb/BlockQuantumLinkChamber.java +++ b/src/main/java/appeng/block/qnb/BlockQuantumLinkChamber.java @@ -25,6 +25,9 @@ import java.util.Random; import javax.annotation.Nullable; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerQNB; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; @@ -94,7 +97,7 @@ public class BlockQuantumLinkChamber extends BlockQuantumBase { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_QNB ); + ContainerOpener.openContainer(ContainerQNB.TYPE, p, ContainerLocator.forTileEntity(tg)); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java b/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java index 448fa984c..3056c0829 100644 --- a/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java +++ b/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java @@ -2,41 +2,37 @@ package appeng.block.qnb; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; - -import javax.annotation.Nullable; - +import appeng.client.render.cablebus.CubeBuilder; +import appeng.core.Api; +import appeng.core.AppEng; +import appeng.tile.qnb.TileQuantumBridge; import com.google.common.collect.ImmutableList; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; -import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.model.ItemOverrideList; +import net.minecraft.client.renderer.model.Material; +import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.client.model.data.IDynamicBakedModel; +import net.minecraftforge.client.model.data.IModelData; -import appeng.api.AEApi; -import appeng.client.render.cablebus.CubeBuilder; -import appeng.core.AppEng; +import javax.annotation.Nullable; +import java.util.*; +import java.util.function.Function; - -class QnbFormedBakedModel implements IBakedModel +class QnbFormedBakedModel implements IDynamicBakedModel { - private static final ResourceLocation TEXTURE_LINK = new ResourceLocation( AppEng.MOD_ID, "blocks/quantum_link" ); - private static final ResourceLocation TEXTURE_RING = new ResourceLocation( AppEng.MOD_ID, "blocks/quantum_ring" ); - private static final ResourceLocation TEXTURE_RING_LIGHT = new ResourceLocation( AppEng.MOD_ID, "blocks/quantum_ring_light" ); - private static final ResourceLocation TEXTURE_RING_LIGHT_CORNER = new ResourceLocation( AppEng.MOD_ID, "blocks/quantum_ring_light_corner" ); - private static final ResourceLocation TEXTURE_CABLE_GLASS = new ResourceLocation( AppEng.MOD_ID, "parts/cable/glass/transparent" ); - private static final ResourceLocation TEXTURE_COVERED_CABLE = new ResourceLocation( AppEng.MOD_ID, "parts/cable/covered/transparent" ); + private static final Material TEXTURE_LINK = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(AppEng.MOD_ID, "blocks/quantum_link" )); + private static final Material TEXTURE_RING = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "blocks/quantum_ring" )); + private static final Material TEXTURE_RING_LIGHT = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "blocks/quantum_ring_light" )); + private static final Material TEXTURE_RING_LIGHT_CORNER = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "blocks/quantum_ring_light_corner" )); + private static final Material TEXTURE_CABLE_GLASS = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "parts/cable/glass/transparent" )); + private static final Material TEXTURE_COVERED_CABLE = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "parts/cable/covered/transparent" )); private static final float DEFAULT_RENDER_MIN = 2.0f; private static final float DEFAULT_RENDER_MAX = 14.0f; @@ -47,8 +43,6 @@ class QnbFormedBakedModel implements IBakedModel private static final float CENTER_POWERED_RENDER_MIN = -0.01f; private static final float CENTER_POWERED_RENDER_MAX = 16.01f; - private final VertexFormat vertexFormat; - private final IBakedModel baseModel; private final Block linkBlock; @@ -60,9 +54,8 @@ class QnbFormedBakedModel implements IBakedModel private final TextureAtlasSprite lightTexture; private final TextureAtlasSprite lightCornerTexture; - public QnbFormedBakedModel( VertexFormat vertexFormat, IBakedModel baseModel, Function bakedTextureGetter ) + public QnbFormedBakedModel( IBakedModel baseModel, Function bakedTextureGetter ) { - this.vertexFormat = vertexFormat; this.baseModel = baseModel; this.linkTexture = bakedTextureGetter.apply( TEXTURE_LINK ); this.ringTexture = bakedTextureGetter.apply( TEXTURE_RING ); @@ -74,23 +67,25 @@ class QnbFormedBakedModel implements IBakedModel } @Override - public List getQuads( @Nullable BlockState state, @Nullable Direction side, long rand ) + public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData modelData) { - // Get the correct base model - if( !( state instanceof IExtendedBlockState ) ) + QnbFormedState formedState = modelData.getData(TileQuantumBridge.FORMED_STATE); + + if( formedState == null ) { return this.baseModel.getQuads( state, side, rand ); } - IExtendedBlockState extendedBlockState = (IExtendedBlockState) state; - QnbFormedState formedState = extendedBlockState.getValue( BlockQuantumBase.FORMED_STATE ); + if (side != null) { + return Collections.emptyList(); + } - return this.getQuads( formedState, state, side, rand ); + return this.getQuads( formedState, state ); } - private List getQuads( QnbFormedState formedState, BlockState state, Direction side, long rand ) + private List getQuads( QnbFormedState formedState, BlockState state ) { - CubeBuilder builder = new CubeBuilder( this.vertexFormat ); + CubeBuilder builder = new CubeBuilder( ); if( state.getBlock() == this.linkBlock ) { @@ -212,6 +207,11 @@ class QnbFormedBakedModel implements IBakedModel return true; } + @Override + public boolean func_230044_c_() { + return false; + } + @Override public boolean isBuiltInRenderer() { @@ -224,19 +224,13 @@ class QnbFormedBakedModel implements IBakedModel return this.baseModel.getParticleTexture(); } - @Override - public ItemCameraTransforms getItemCameraTransforms() - { - return this.baseModel.getItemCameraTransforms(); - } - @Override public ItemOverrideList getOverrides() { return this.baseModel.getOverrides(); } - public static List getRequiredTextures() + public static List getRequiredTextures() { return ImmutableList.of( TEXTURE_LINK, TEXTURE_RING, TEXTURE_CABLE_GLASS, TEXTURE_COVERED_CABLE, TEXTURE_RING_LIGHT, TEXTURE_RING_LIGHT_CORNER ); diff --git a/src/main/java/appeng/block/qnb/QnbFormedModel.java b/src/main/java/appeng/block/qnb/QnbFormedModel.java index e4884e650..ed359a6b2 100644 --- a/src/main/java/appeng/block/qnb/QnbFormedModel.java +++ b/src/main/java/appeng/block/qnb/QnbFormedModel.java @@ -2,63 +2,33 @@ package appeng.block.qnb; +import appeng.core.AppEng; +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.renderer.model.*; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; + import java.util.Collection; +import java.util.Set; import java.util.function.Function; -import com.google.common.collect.ImmutableList; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.client.model.ModelLoaderRegistry; -import net.minecraftforge.common.model.IModelState; -import net.minecraftforge.common.model.TRSRTransformation; - -import appeng.core.AppEng; - - -public class QnbFormedModel implements IModel +public class QnbFormedModel implements IModelGeometry { private static final ResourceLocation MODEL_RING = new ResourceLocation( AppEng.MOD_ID, "block/qnb/ring" ); @Override - public Collection getDependencies() - { - return ImmutableList.of( MODEL_RING ); + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { + IBakedModel ringModel = bakery.getBakedModel(MODEL_RING, modelTransform, spriteGetter); + return new QnbFormedBakedModel( ringModel, spriteGetter ); } @Override - public Collection getTextures() - { + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { return QnbFormedBakedModel.getRequiredTextures(); } - @Override - public IBakedModel bake( IModelState state, VertexFormat format, Function bakedTextureGetter ) - { - IBakedModel ringModel = this.getBaseModel( MODEL_RING, state, format, bakedTextureGetter ); - return new QnbFormedBakedModel( format, ringModel, bakedTextureGetter ); - } - - @Override - public IModelState getDefaultState() - { - return TRSRTransformation.identity(); - } - - private IBakedModel getBaseModel( ResourceLocation model, IModelState state, VertexFormat format, Function bakedTextureGetter ) - { - // Load the base model - try - { - return ModelLoaderRegistry.getModel( model ).bake( state, format, bakedTextureGetter ); - } - catch( Exception e ) - { - throw new RuntimeException( e ); - } - } } diff --git a/src/main/java/appeng/block/spatial/BlockSpatialIOPort.java b/src/main/java/appeng/block/spatial/BlockSpatialIOPort.java index 0030115cc..182366c19 100644 --- a/src/main/java/appeng/block/spatial/BlockSpatialIOPort.java +++ b/src/main/java/appeng/block/spatial/BlockSpatialIOPort.java @@ -21,6 +21,10 @@ package appeng.block.spatial; import javax.annotation.Nullable; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerSpatialIOPort; +import appeng.fluids.container.ContainerFluidLevelEmitter; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.BlockState; @@ -70,7 +74,7 @@ public class BlockSpatialIOPort extends AEBaseTileBlock { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_SPATIAL_IO_PORT ); + ContainerOpener.openContainer(ContainerSpatialIOPort.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/storage/BlockChest.java b/src/main/java/appeng/block/storage/BlockChest.java index 0f9ae4e58..0ce917f13 100644 --- a/src/main/java/appeng/block/storage/BlockChest.java +++ b/src/main/java/appeng/block/storage/BlockChest.java @@ -20,6 +20,10 @@ package appeng.block.storage; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerChest; +import appeng.container.implementations.ContainerQNB; import appeng.core.localization.PlayerMessages; import appeng.tile.storage.TileChest; import appeng.util.Platform; @@ -94,7 +98,7 @@ public class BlockChest extends AEBaseTileBlock if( hit.getFace() != tg.getUp() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_CHEST ); + ContainerOpener.openContainer(ContainerChest.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } else { diff --git a/src/main/java/appeng/block/storage/BlockDrive.java b/src/main/java/appeng/block/storage/BlockDrive.java index ea84a3c47..f66cb5c87 100644 --- a/src/main/java/appeng/block/storage/BlockDrive.java +++ b/src/main/java/appeng/block/storage/BlockDrive.java @@ -20,6 +20,10 @@ package appeng.block.storage; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerDrive; +import appeng.container.implementations.ContainerQuartzKnife; import appeng.tile.storage.TileDrive; import appeng.util.Platform; import net.minecraft.block.material.Material; @@ -55,7 +59,7 @@ public class BlockDrive extends AEBaseTileBlock { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_DRIVE ); + ContainerOpener.openContainer(ContainerDrive.TYPE, p, ContainerLocator.forTileEntity(tg)); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/storage/BlockIOPort.java b/src/main/java/appeng/block/storage/BlockIOPort.java index 82d11311a..fd1a9dee9 100644 --- a/src/main/java/appeng/block/storage/BlockIOPort.java +++ b/src/main/java/appeng/block/storage/BlockIOPort.java @@ -20,6 +20,10 @@ package appeng.block.storage; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerIOPort; +import appeng.fluids.container.ContainerFluidInterface; import appeng.tile.storage.TileIOPort; import appeng.util.Platform; import net.minecraft.block.Block; @@ -67,7 +71,7 @@ public class BlockIOPort extends AEBaseTileBlock { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_IOPORT ); + ContainerOpener.openContainer(ContainerIOPort.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/block/storage/BlockSkyChest.java b/src/main/java/appeng/block/storage/BlockSkyChest.java index e183734f1..1cf0e47bb 100644 --- a/src/main/java/appeng/block/storage/BlockSkyChest.java +++ b/src/main/java/appeng/block/storage/BlockSkyChest.java @@ -20,6 +20,8 @@ package appeng.block.storage; import appeng.block.AEBaseTileBlock; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; import appeng.container.implementations.ContainerSkyChest; import appeng.tile.storage.TileSkyChest; import appeng.util.Platform; @@ -83,7 +85,7 @@ public class BlockSkyChest extends AEBaseTileBlock return ActionResultType.PASS; } - ContainerSkyChest.open((ServerPlayerEntity) player, tile, getNameTextComponent()); + ContainerOpener.openContainer(ContainerSkyChest.TYPE, player, ContainerLocator.forTileEntity(tile)); } return ActionResultType.SUCCESS; diff --git a/src/main/java/appeng/client/ClientHelper.java b/src/main/java/appeng/client/ClientHelper.java index 0a58e6a2e..1ce6a351e 100644 --- a/src/main/java/appeng/client/ClientHelper.java +++ b/src/main/java/appeng/client/ClientHelper.java @@ -22,6 +22,11 @@ package appeng.client; import java.io.IOException; import java.util.*; +import appeng.client.render.effects.*; +import appeng.core.AEConfig; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketAssemblerAnimation; +import appeng.core.sync.packets.PacketValueConfig; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; @@ -49,6 +54,7 @@ import appeng.server.ServerHelper; import appeng.util.Platform; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.ForgeRegistries; public class ClientHelper extends ServerHelper @@ -115,34 +121,35 @@ public class ClientHelper extends ServerHelper } } + // FIXME: Instead of doing a custom packet and this dispatcher, we can use the vanilla particle system @Override public void spawnEffect( final EffectType effect, final World world, final double posX, final double posY, final double posZ, final Object o ) { - // FIXME if( AEConfig.instance().isEnableEffects() ) - // FIXME { - // FIXME switch( effect ) - // FIXME { - // FIXME case Assembler: - // FIXME this.spawnAssembler( world, posX, posY, posZ, o ); - // FIXME return; - // FIXME case Vibrant: - // FIXME this.spawnVibrant( world, posX, posY, posZ ); - // FIXME return; - // FIXME case Crafting: - // FIXME this.spawnCrafting( world, posX, posY, posZ ); - // FIXME return; - // FIXME case Energy: - // FIXME this.spawnEnergy( world, posX, posY, posZ ); - // FIXME return; - // FIXME case Lightning: - // FIXME this.spawnLightning( world, posX, posY, posZ ); - // FIXME return; - // FIXME case LightningArc: - // FIXME this.spawnLightningArc( world, posX, posY, posZ, (Vec3d) o ); - // FIXME return; - // FIXME default: - // FIXME } - // FIXME } + if( AEConfig.instance().isEnableEffects() ) + { + switch( effect ) + { + case Assembler: + this.spawnAssembler( world, posX, posY, posZ, o ); + return; + case Vibrant: + this.spawnVibrant( world, posX, posY, posZ ); + return; + case Crafting: + this.spawnCrafting( world, posX, posY, posZ ); + return; + case Energy: + this.spawnEnergy( world, posX, posY, posZ ); + return; + case Lightning: + this.spawnLightning( world, posX, posY, posZ ); + return; + case LightningArc: + this.spawnLightningArc( world, posX, posY, posZ, (Vec3d) o ); + return; + default: + } + } } @Override @@ -218,12 +225,13 @@ public class ClientHelper extends ServerHelper // FIXME } } + // FIXME: double check all of these particle spawns, also move any of these that are triggered as part of a packet to the vanilla way of spawning particles from the server directly private void spawnAssembler( final World world, final double posX, final double posY, final double posZ, final Object o ) { - // FIXME final PacketAssemblerAnimation paa = (PacketAssemblerAnimation) o; + final PacketAssemblerAnimation paa = (PacketAssemblerAnimation) o; - // FIXME final AssemblerFX fx = new AssemblerFX( world, posX, posY, posZ, 0.0D, 0.0D, 0.0D, paa.rate, paa.is ); - // FIXME Minecraft.getInstance().particles.addEffect( fx ); + final AssemblerFX fx = new AssemblerFX( world, posX, posY, posZ, 0.0D, 0.0D, 0.0D, paa.rate, paa.is.asItemStackRepresentation() ); + Minecraft.getInstance().particles.addEffect( fx ); } private void spawnVibrant( final World w, final double x, final double y, final double z ) @@ -234,8 +242,7 @@ public class ClientHelper extends ServerHelper final double d1 = ( Platform.getRandomFloat() - 0.5F ) * 0.26D; final double d2 = ( Platform.getRandomFloat() - 0.5F ) * 0.26D; - // FIXME final VibrantFX fx = new VibrantFX( w, x + d0, y + d1, z + d2, 0.0D, 0.0D, 0.0D ); - // FIXME Minecraft.getInstance().particles.addEffect( fx ); + Minecraft.getInstance().particles.addParticle(VibrantFX.TYPE, x + d0, y + d1, z + d2, 0.0D, 0.0D, 0.0D); } } @@ -245,13 +252,7 @@ public class ClientHelper extends ServerHelper final float y = (float) ( ( ( Platform.getRandomInt() % 100 ) * 0.01 ) - 0.5 ) * 0.7f; final float z = (float) ( ( ( Platform.getRandomInt() % 100 ) * 0.01 ) - 0.5 ) * 0.7f; - // FIXME final CraftingFx fx = new CraftingFx( w, posX + x, posY + y, posZ + z, Items.DIAMOND ); - - // FIXME fx.setMotionX( -x * 0.2f ); - // FIXME fx.setMotionY( -y * 0.2f ); - // FIXME fx.setMotionZ( -z * 0.2f ); - - // FIXME Minecraft.getInstance().particles.addEffect( fx ); + Minecraft.getInstance().particles.addParticle(CraftingFx.TYPE, posX + x, posY + y, posZ + z, -x * 0.2, -y * 0.2, -z * 0.2); } private void spawnEnergy( final World w, final double posX, final double posY, final double posZ ) @@ -260,25 +261,18 @@ public class ClientHelper extends ServerHelper final float y = (float) ( ( ( Platform.getRandomInt() % 100 ) * 0.01 ) - 0.5 ) * 0.7f; final float z = (float) ( ( ( Platform.getRandomInt() % 100 ) * 0.01 ) - 0.5 ) * 0.7f; - // FIXME final EnergyFx fx = new EnergyFx( w, posX + x, posY + y, posZ + z, Items.DIAMOND ); - - // FIXME fx.setMotionX( -x * 0.1f ); - // FIXME fx.setMotionY( -y * 0.1f ); - // FIXME fx.setMotionZ( -z * 0.1f ); - - // FIXME Minecraft.getInstance().particles.addEffect( fx ); + Minecraft.getInstance().particles.addParticle(EnergyFx.TYPE, posX + x, posY + y, posZ + z, -x * 0.1, -y * 0.1, -z * 0.1); } private void spawnLightning( final World world, final double posX, final double posY, final double posZ ) { - // FIXME final LightningFX fx = new LightningFX( world, posX, posY + 0.3f, posZ, 0.0f, 0.0f, 0.0f ); - // FIXME Minecraft.getInstance().particles.addEffect( fx ); + Minecraft.getInstance().particles.addParticle(LightningFX.TYPE, posX, posY + 0.3f, posZ, 0.0f, 0.0f, 0.0f); } private void spawnLightningArc( final World world, final double posX, final double posY, final double posZ, final Vec3d second ) { - // FIXME final LightningFX fx = new LightningArcFX( world, posX, posY, posZ, second.x, second.y, second.z, 0.0f, 0.0f, 0.0f ); - // FIXME Minecraft.getInstance().particles.addEffect( fx ); + final LightningFX fx = new LightningArcFX( world, posX, posY, posZ, second.x, second.y, second.z, 0.0f, 0.0f, 0.0f ); + Minecraft.getInstance().particles.addEffect( fx ); } private void wheelEvent( final InputEvent.MouseScrollEvent me ) @@ -297,26 +291,12 @@ public class ClientHelper extends ServerHelper if( mainHand || offHand ) { -// FIXME try -// FIXME { -// FIXME NetworkHandler.instance().sendToServer( new PacketValueConfig( "Item", me.getScrollDelta() > 0 ? "WheelUp" : "WheelDown" ) ); -// FIXME me.setCanceled( true ); -// FIXME } -// FIXME catch( final IOException e ) -// FIXME { -// FIXME AELog.debug( e ); -// FIXME } + NetworkHandler.instance().sendToServer( new PacketValueConfig( "Item", me.getScrollDelta() > 0 ? "WheelUp" : "WheelDown" ) ); + me.setCanceled( true ); } } } - @SubscribeEvent - public void onTextureStitch( final TextureStitchEvent.Pre event ) - { -// FIXME ParticleTextures.registerSprite( event ); -// FIXME InscriberTESR.registerTexture( event ); - } - @Override public boolean isActionKey( ActionKey key, InputMappings.Input pressedKey ) { diff --git a/src/main/java/appeng/client/gui/AEBaseGui.java b/src/main/java/appeng/client/gui/AEBaseGui.java index f6ff860ac..285219033 100644 --- a/src/main/java/appeng/client/gui/AEBaseGui.java +++ b/src/main/java/appeng/client/gui/AEBaseGui.java @@ -68,7 +68,6 @@ import net.minecraftforge.fml.client.gui.GuiUtils; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; -import java.io.IOException; import java.text.DecimalFormat; import java.text.ParseException; import java.util.*; @@ -266,7 +265,7 @@ public abstract class AEBaseGui extends ContainerScre final int ox = this.guiLeft; // (width - xSize) / 2; final int oy = this.guiTop; // (height - ySize) / 2; RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); - this.drawBG( ox, oy, x, y ); + this.drawBG( ox, oy, x, y, f ); final List slots = this.getInventorySlots(); for( final Slot slot : slots ) @@ -655,7 +654,7 @@ public abstract class AEBaseGui extends ContainerScre return null; } - public abstract void drawBG( int offsetX, int offsetY, int mouseX, int mouseY ); + public abstract void drawBG(int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks); @Override public boolean mouseScrolled(double x, double y, double wheelDelta) { diff --git a/src/main/java/appeng/client/gui/AEBaseMEGui.java b/src/main/java/appeng/client/gui/AEBaseMEGui.java index ef8058b68..59a25a776 100644 --- a/src/main/java/appeng/client/gui/AEBaseMEGui.java +++ b/src/main/java/appeng/client/gui/AEBaseMEGui.java @@ -45,7 +45,7 @@ public abstract class AEBaseMEGui extends AEBaseGui extends AEBaseGui currentToolTip = this.getItemToolTip( stack ); + final List currentToolTip = this.getTooltipFromItem( stack ); try { @@ -67,7 +67,7 @@ public abstract class AEBaseMEGui extends AEBaseGui bigNumber || ( myStack.getStackSize() > 1 && stack.isItemDamaged() ) ) + if( myStack.getStackSize() > bigNumber || ( myStack.getStackSize() > 1 && stack.isDamaged() ) ) { final String local = ButtonToolTips.ItemsStored.getLocal(); final String formattedAmount = NumberFormat.getNumberInstance( Locale.US ).format( myStack.getStackSize() ); @@ -84,8 +84,7 @@ public abstract class AEBaseMEGui extends AEBaseGui extends AEBaseGui. - */ - -package appeng.client.gui; - - -import net.minecraft.inventory.container.Container; - - -public class GuiNull extends AEBaseGui -{ - - public GuiNull( final Container container ) - { - super( container ); - } - - @Override - public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) - { - } - - @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) - { - - } -} diff --git a/src/main/java/appeng/client/gui/config/AEConfigGui.java b/src/main/java/appeng/client/gui/config/AEConfigGui.java deleted file mode 100644 index 9908f3d6b..000000000 --- a/src/main/java/appeng/client/gui/config/AEConfigGui.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.client.gui.config; - - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.client.gui.screen.Screen; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; - -import appeng.core.AEConfig; -import appeng.core.AppEng; - - -public class AEConfigGui extends GuiConfig -{ - - public AEConfigGui( final Screen parent ) - { - super( parent, getConfigElements(), AppEng.MOD_ID, false, false, GuiConfig.getAbridgedConfigPath( AEConfig.instance().getFilePath() ) ); - } - - private static List getConfigElements() - { - final List list = new ArrayList<>(); - - for( final String cat : AEConfig.instance().getCategoryNames() ) - { - if( cat.equals( "versionchecker" ) ) - { - continue; - } - - if( cat.equals( "settings" ) ) - { - continue; - } - - final ConfigCategory cc = AEConfig.instance().getCategory( cat ); - - if( cc.isChild() ) - { - continue; - } - - final ConfigElement ce = new ConfigElement( cc ); - list.add( ce ); - } - - return list; - } -} diff --git a/src/main/java/appeng/client/gui/config/AEConfigGuiFactory.java b/src/main/java/appeng/client/gui/config/AEConfigGuiFactory.java deleted file mode 100644 index e9a5345e3..000000000 --- a/src/main/java/appeng/client/gui/config/AEConfigGuiFactory.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.client.gui.config; - - -import java.util.Set; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screen.Screen; -import net.minecraftforge.fml.client.IModGuiFactory; - - -public class AEConfigGuiFactory implements IModGuiFactory -{ - - @Override - public void initialize( final Minecraft minecraftInstance ) - { - - } - - /** - * If this method returns false, the config button in the mod list will be disabled - * - * @return true if this object provides a config gui screen, false otherwise - */ - @Override - public boolean hasConfigGui() - { - return false; - } - - /** - * Return an initialized {@link Screen}. This screen will be displayed - * when the "config" button is pressed in the mod list. It will - * have a single argument constructor - the "parent" screen, the same as all - * Minecraft GUIs. The expected behaviour is that this screen will replace the - * "mod list" screen completely, and will return to the mod list screen through - * the parent link, once the appropriate action is taken from the config screen. - *

- * This config GUI is anticipated to provide configuration to the mod in a friendly - * visual way. It should not be abused to set internals such as IDs (they're gonna - * keep disappearing anyway), but rather, interesting behaviours. This config GUI - * is never run when a server game is running, and should be used to configure - * desired behaviours that affect server state. Costs, mod game modes, stuff like that - * can be changed here. - * - * @param parentScreen The screen to which must be returned when closing the - * returned screen. - * @return A class that will be instantiated on clicks on the config button - * or null if no GUI is desired. - */ - @Override - public Screen createConfigGui(Screen parentScreen ) - { - return new AEConfigGui( parentScreen ); - } - - @Override - public Set runtimeGuiCategories() - { - return null; - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/AESubGui.java b/src/main/java/appeng/client/gui/implementations/AESubGui.java new file mode 100644 index 000000000..1f6994bce --- /dev/null +++ b/src/main/java/appeng/client/gui/implementations/AESubGui.java @@ -0,0 +1,100 @@ +package appeng.client.gui.implementations; + +import appeng.api.definitions.IDefinitions; +import appeng.api.definitions.IParts; +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerCraftingTerm; +import appeng.container.implementations.ContainerMEMonitorable; +import appeng.container.implementations.ContainerPatternTerm; +import appeng.container.implementations.ContainerWirelessTerm; +import appeng.core.Api; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketSwitchGuis; +import appeng.helpers.IPriorityHost; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.parts.reporting.PartCraftingTerminal; +import appeng.parts.reporting.PartPatternTerminal; +import appeng.parts.reporting.PartTerminal; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nullable; +import java.util.function.Consumer; + +final class AESubGui { + + private final AEBaseGui gui; + private final ContainerType originalGui; + private final ItemStack originalGuiIcon; + + /** + * Based on the container we're opening for, try to determine what it's "primary" GUI would be + * so that we can go back to it. + */ + public AESubGui(AEBaseGui gui, Object containerTarget) { + this.gui = gui; + + final IDefinitions definitions = Api.INSTANCE.definitions(); + final IParts parts = definitions.parts(); + + if (containerTarget instanceof IPriorityHost) { + IPriorityHost priorityHost = (IPriorityHost) containerTarget; + this.originalGuiIcon = priorityHost.getItemStackRepresentation(); + this.originalGui = priorityHost.getContainerType(); + } + + else if( containerTarget instanceof WirelessTerminalGuiObject) + { + this.originalGuiIcon = definitions.items().wirelessTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); + this.originalGui = ContainerWirelessTerm.TYPE; + } + + else if( containerTarget instanceof PartTerminal) + { + this.originalGuiIcon = parts.terminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); + this.originalGui = ContainerMEMonitorable.TYPE; + } + + else if( containerTarget instanceof PartCraftingTerminal) + { + this.originalGuiIcon = parts.craftingTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); + this.originalGui = ContainerCraftingTerm.TYPE; + } + + else if( containerTarget instanceof PartPatternTerminal) + { + this.originalGuiIcon = parts.patternTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); + this.originalGui = ContainerPatternTerm.TYPE; + } + + else { + this.originalGuiIcon = null; + this.originalGui = null; + } + } + + public final GuiTabButton addBackButton(Consumer buttonAdder, int x, int y) { + return addBackButton(buttonAdder, x, y, null); + } + + public final GuiTabButton addBackButton(Consumer buttonAdder, int x, int y, @Nullable String label) { + if( this.originalGui != null && !originalGuiIcon.isEmpty() ) + { + if (label == null) { + label = originalGuiIcon.getDisplayName().getString(); + } + ItemRenderer itemRenderer = gui.getMinecraft().getItemRenderer(); + GuiTabButton button = new GuiTabButton( gui.getGuiLeft() + x, gui.getGuiTop() + y, originalGuiIcon, label, itemRenderer, btn -> goBack() ); + buttonAdder.accept(button); + return button; + } + return null; + } + + public final void goBack() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( this.originalGui ) ); + } + +} diff --git a/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java b/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java index f81044d39..4ca0bc101 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java @@ -21,12 +21,10 @@ package appeng.client.gui.implementations; import java.io.IOException; -import appeng.api.implementations.IUpgradeableHost; +import net.minecraft.client.gui.widget.button.Button; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; -import org.lwjgl.input.Mouse; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; @@ -43,7 +41,6 @@ import appeng.container.implementations.ContainerCellWorkbench; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; -import appeng.tile.misc.TileCellWorkbench; import appeng.util.Platform; @@ -62,11 +59,11 @@ public class GuiCellWorkbench extends GuiUpgradeable @Override protected void addButtons() { - this.clear = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE ); - this.partition = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH ); + this.clear = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE, this::actionPerformed ); + this.partition = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH, this::actionPerformed ); this.copyMode = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 48, 11 * 16 + 5, 12 * 16 + 5, GuiText.CopyMode.getLocal(), GuiText.CopyModeDesc - .getLocal() ); - this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + .getLocal(), this::actionPerformed ); + this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed ); this.addButton( this.fuzzyMode ); this.addButton( this.partition ); @@ -75,7 +72,7 @@ public class GuiCellWorkbench extends GuiUpgradeable } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.handleButtonVisibility(); @@ -86,7 +83,7 @@ public class GuiCellWorkbench extends GuiUpgradeable if( this.container.availableUpgrades() <= 8 ) { GuiUtils.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + this.container.availableUpgrades() * 18, 0 /* FIXME this.zlevel was used */ ); - GuiUtilsGuiUtils.drawTexturedModalRect( offsetX + 177, offsetY + ( 7 + ( this.container.availableUpgrades() ) * 18 ), 177, 151, 35, 7, 0 /* FIXME this.zlevel was used */ ); + GuiUtils.drawTexturedModalRect( offsetX + 177, offsetY + ( 7 + ( this.container.availableUpgrades() ) * 18 ), 177, 151, 35, 7, 0 /* FIXME this.zlevel was used */ ); } else if( this.container.availableUpgrades() <= 16 ) { @@ -170,38 +167,32 @@ public class GuiCellWorkbench extends GuiUpgradeable } @Override - protected void actionPerformed( final GuiButton btn ) + protected void actionPerformed( final Button btn ) { - try + if( btn == this.copyMode ) { - if( btn == this.copyMode ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "CopyMode" ) ); - } - else if( btn == this.partition ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Partition" ) ); - } - else if( btn == this.clear ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Clear" ) ); - } - else if( btn == this.fuzzyMode ) - { - final boolean backwards = Mouse.isButtonDown( 1 ); - - FuzzyMode fz = (FuzzyMode) this.fuzzyMode.getCurrentValue(); - fz = Platform.rotateEnum( fz, backwards, Settings.FUZZY_MODE.getPossibleValues() ); - - NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Fuzzy", fz.name() ) ); - } - else - { - super.actionPerformed( btn ); - } + NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "CopyMode" ) ); } - catch( final IOException ignored ) + else if( btn == this.partition ) { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Partition" ) ); + } + else if( btn == this.clear ) + { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Clear" ) ); + } + else if( btn == this.fuzzyMode ) + { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + + FuzzyMode fz = (FuzzyMode) this.fuzzyMode.getCurrentValue(); + fz = Platform.rotateEnum( fz, backwards, Settings.FUZZY_MODE.getPossibleValues() ); + + NetworkHandler.instance().sendToServer( new PacketValueConfig( "CellWorkbench.Fuzzy", fz.name() ) ); + } + else + { + super.actionPerformed( btn ); } } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiChest.java b/src/main/java/appeng/client/gui/implementations/GuiChest.java index e2d2a9f92..1407e8283 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiChest.java +++ b/src/main/java/appeng/client/gui/implementations/GuiChest.java @@ -19,9 +19,8 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; +import appeng.container.implementations.ContainerPriority; +import net.minecraft.client.gui.widget.button.Button; import net.minecraft.entity.player.PlayerInventory; import appeng.client.gui.AEBaseGui; @@ -31,7 +30,6 @@ import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.tile.storage.TileChest; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -46,14 +44,11 @@ public class GuiChest extends AEBaseGui this.ySize = 166; } - @Override - protected void actionPerformed( final GuiButton par1GuiButton ) throws IOException + protected void actionPerformed( final Button button ) { - super.actionPerformed( par1GuiButton ); - - if( par1GuiButton == this.priority ) + if( button == this.priority ) { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); } } @@ -62,7 +57,7 @@ public class GuiChest extends AEBaseGui { super.init(); - this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) ); + this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, this::actionPerformed ) ); } @Override @@ -73,7 +68,7 @@ public class GuiChest extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/chest.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiCondenser.java b/src/main/java/appeng/client/gui/implementations/GuiCondenser.java index 0720e7076..9110d0079 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCondenser.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCondenser.java @@ -19,13 +19,9 @@ package appeng.client.gui.implementations; -import java.io.IOException; - import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; -import org.lwjgl.input.Mouse; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.Settings; @@ -37,7 +33,6 @@ import appeng.container.implementations.ContainerCondenser; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketConfigButton; -import appeng.tile.misc.TileCondenser; public class GuiCondenser extends AEBaseGui @@ -51,19 +46,6 @@ public class GuiCondenser extends AEBaseGui this.ySize = 197; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( this.mode == btn ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( Settings.CONDENSER_OUTPUT, backwards ) ); - } - } - @Override public void init() { @@ -72,7 +54,10 @@ public class GuiCondenser extends AEBaseGui this.pb = new GuiProgressBar( this.container, "guis/condenser.png", 120 + this.guiLeft, 25 + this.guiTop, 178, 25, 6, 18, Direction.VERTICAL, GuiText.StoredEnergy .getLocal() ); - this.mode = new GuiImgButton( 128 + this.guiLeft, 52 + this.guiTop, Settings.CONDENSER_OUTPUT, this.container.getOutput() ); + this.mode = new GuiImgButton( 128 + this.guiLeft, 52 + this.guiTop, Settings.CONDENSER_OUTPUT, this.container.getOutput(), btn -> { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( Settings.CONDENSER_OUTPUT, backwards ) ); + } ); this.addButton( this.pb ); this.addButton( this.mode ); @@ -89,7 +74,7 @@ public class GuiCondenser extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/condenser.png" ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java b/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java index c3220f057..f59cad66a 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java @@ -19,56 +19,31 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import appeng.core.Api; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; - -import appeng.api.definitions.IDefinitions; -import appeng.api.definitions.IParts; -import appeng.api.storage.ITerminalHost; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiNumberBox; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.AEBaseContainer; import appeng.container.implementations.ContainerCraftAmount; import appeng.core.AEConfig; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketCraftRequest; -import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.helpers.Reflected; -import appeng.helpers.WirelessTerminalGuiObject; -import appeng.parts.reporting.PartCraftingTerminal; -import appeng.parts.reporting.PartPatternTerminal; -import appeng.parts.reporting.PartTerminal; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.util.InputMappings; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiCraftAmount extends AEBaseGui { + private final AESubGui subGui; + private GuiNumberBox amountToCraft; - private GuiTabButton originalGuiBtn; - private GuiButton next; - - private GuiButton plus1; - private GuiButton plus10; - private GuiButton plus100; - private GuiButton plus1000; - private GuiButton minus1; - private GuiButton minus10; - private GuiButton minus100; - private GuiButton minus1000; - - private GuiBridge originalGui; + private Button next; public GuiCraftAmount(ContainerCraftAmount container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); + this.subGui = new AESubGui(this, container.getTarget()); } @Override @@ -81,52 +56,19 @@ public class GuiCraftAmount extends AEBaseGui final int c = AEConfig.instance().craftItemsByStackAmounts( 2 ); final int d = AEConfig.instance().craftItemsByStackAmounts( 3 ); - this.addButton( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a ) ); - this.addButton( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b ) ); - this.addButton( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c ) ); - this.addButton( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d ) ); + this.addButton( new Button(this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a, btn -> addQty(a) ) ); + this.addButton( new Button(this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b, btn -> addQty(b) ) ); + this.addButton( new Button(this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c, btn -> addQty(c) ) ); + this.addButton( new Button(this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d, btn -> addQty(d) ) ); - this.addButton( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a ) ); - this.addButton( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b ) ); - this.addButton( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c ) ); - this.addButton( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d ) ); + this.addButton( new Button(this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a, btn -> addQty(-a) ) ); + this.addButton( new Button(this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b, btn -> addQty(-b) ) ); + this.addButton( new Button(this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c, btn -> addQty(-c) ) ); + this.addButton( new Button(this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d, btn -> addQty(-d) ) ); - this.addButton( this.next = new GuiButton( 0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal() ) ); + this.next = this.addButton(new Button(this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal(), this::confirm )); - ItemStack myIcon = null; - final Object target = this.container.getTarget(); - final IDefinitions definitions = Api.INSTANCE.definitions(); - final IParts parts = definitions.parts(); - - if( target instanceof WirelessTerminalGuiObject ) - { - myIcon = definitions.items().wirelessTerminal().maybeStack( 1 ).orElse( myIcon ); - - this.originalGui = GuiBridge.GUI_WIRELESS_TERM; - } - - if( target instanceof PartTerminal ) - { - myIcon = parts.terminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - this.originalGui = GuiBridge.GUI_ME; - } - - if( target instanceof PartCraftingTerminal ) - { - myIcon = parts.craftingTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - this.originalGui = GuiBridge.GUI_CRAFTING_TERMINAL; - } - - if( target instanceof PartPatternTerminal ) - { - myIcon = parts.patternTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - this.originalGui = GuiBridge.GUI_PATTERN_TERMINAL; - } - - if( this.originalGui != null && !myIcon.isEmpty() ) - { - this.addButton( this.originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), this.itemRender ) ); - } + subGui.addBackButton(this::addButton, 154, 0); this.amountToCraft = new GuiNumberBox( this.font, this.guiLeft + 62, this.guiTop + 57, 59, this.font.FONT_HEIGHT, Integer.class ); this.amountToCraft.setEnableBackgroundDrawing( false ); @@ -137,6 +79,10 @@ public class GuiCraftAmount extends AEBaseGui this.amountToCraft.setText( "1" ); } + private void confirm(Button button) { + NetworkHandler.instance().sendToServer( new PacketCraftRequest( Integer.parseInt( this.amountToCraft.getText() ), hasShiftDown() ) ); + } + @Override public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) { @@ -144,9 +90,9 @@ public class GuiCraftAmount extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { - this.next.displayString = hasShiftDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal(); + this.next.setMessage(hasShiftDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal()); this.bindTexture( "guis/craft_amt.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); @@ -154,27 +100,32 @@ public class GuiCraftAmount extends AEBaseGui try { Long.parseLong( this.amountToCraft.getText() ); - this.next.enabled = !this.amountToCraft.getText().isEmpty(); + this.next.active = !this.amountToCraft.getText().isEmpty(); } catch( final NumberFormatException e ) { - this.next.enabled = false; + this.next.active = false; } - this.amountToCraft.drawTextBox(); + this.amountToCraft.render(offsetX, offsetY, partialTicks); } @Override - protected void keyTyped( final char character, final int key ) throws IOException - { - if( !this.checkHotbarKeys( key ) ) + public boolean charTyped(char ch, int p_charTyped_2_) { + // Forward entered text to the craft amount text-field + return this.amountToCraft.charTyped(ch, p_charTyped_2_); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) { + if( !this.checkHotbarKeys( InputMappings.getInputByCode(keyCode, scanCode) ) ) { - if( key == 28 ) + if( keyCode == 28 ) { - this.actionPerformed( this.next ); + this.next.onPress(); } - if( ( key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ) ) && this.amountToCraft - .textboxKeyTyped( character, key ) ) + if( ( keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14 ) + && this.amountToCraft.keyPressed( keyCode, scanCode, p_keyPressed_3_ ) ) { try { @@ -207,45 +158,11 @@ public class GuiCraftAmount extends AEBaseGui { // :P } - } - else - { - super.keyTyped( character, key ); + return true; } } - } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - try - { - - if( btn == this.originalGuiBtn ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( this.originalGui ) ); - } - - if( btn == this.next ) - { - NetworkHandler.instance().sendToServer( new PacketCraftRequest( Integer.parseInt( this.amountToCraft.getText() ), hasShiftDown() ) ); - } - } - catch( final NumberFormatException e ) - { - // nope.. - this.amountToCraft.setText( "1" ); - } - - final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000; - final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000; - - if( isPlus || isMinus ) - { - this.addQty( this.getQty( btn ) ); - } + return super.keyPressed( keyCode, scanCode, p_keyPressed_3_ ); } private void addQty( final int i ) diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java index 3fdf4092d..104c3bac0 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java @@ -19,26 +19,6 @@ package appeng.client.gui.implementations; -import java.io.IOException; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import appeng.core.Api; -import com.google.common.base.Joiner; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.fml.client.gui.GuiUtils; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; - -import appeng.api.storage.ITerminalHost; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; @@ -46,21 +26,32 @@ import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiScrollbar; import appeng.container.implementations.ContainerCraftConfirm; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketSwitchGuis; import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.WirelessTerminalGuiObject; -import appeng.parts.reporting.PartCraftingTerminal; -import appeng.parts.reporting.PartPatternTerminal; -import appeng.parts.reporting.PartTerminal; import appeng.util.Platform; +import com.google.common.base.Joiner; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.util.InputMappings; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; + +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class GuiCraftConfirm extends AEBaseGui { + private final AESubGui subGui; + private final int rows = 5; private final IItemList storage = Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ).createList(); @@ -69,45 +60,24 @@ public class GuiCraftConfirm extends AEBaseGui private final List visual = new ArrayList<>(); - private GuiBridge OriginalGui; - private GuiButton cancel; - private GuiButton start; - private GuiButton selectCPU; + private Button cancel; + private Button start; + private Button selectCPU; private int tooltip = -1; public GuiCraftConfirm(ContainerCraftConfirm container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); + this.subGui = new AESubGui(this, container.getTarget()); this.xSize = 238; this.ySize = 206; final GuiScrollbar scrollbar = new GuiScrollbar(); this.setScrollBar( scrollbar ); - - Object te = container.getTarget(); - if( te instanceof WirelessTerminalGuiObject ) - { - this.OriginalGui = GuiBridge.GUI_WIRELESS_TERM; - } - - if( te instanceof PartTerminal ) - { - this.OriginalGui = GuiBridge.GUI_ME; - } - - if( te instanceof PartCraftingTerminal ) - { - this.OriginalGui = GuiBridge.GUI_CRAFTING_TERMINAL; - } - - if( te instanceof PartPatternTerminal ) - { - this.OriginalGui = GuiBridge.GUI_PATTERN_TERMINAL; - } } boolean isAutoStart() { - return ( (ContainerCraftConfirm) this.container ).isAutoStart(); + return this.container.isAutoStart(); } @Override @@ -115,30 +85,26 @@ public class GuiCraftConfirm extends AEBaseGui { super.init(); - this.start = new GuiButton( 0, this.guiLeft + 162, this.guiTop + this.ySize - 25, 50, 20, GuiText.Start.getLocal() ); - this.start.enabled = false; + this.start = new Button(this.guiLeft + 162, this.guiTop + this.ySize - 25, 50, 20, GuiText.Start.getLocal(), btn -> start() ); + this.start.active = false; this.addButton( this.start ); - this.selectCPU = new GuiButton( 0, this.guiLeft + ( 219 - 180 ) / 2, this.guiTop + this.ySize - 68, 180, 20, GuiText.CraftingCPU - .getLocal() + ": " + GuiText.Automatic ); - this.selectCPU.enabled = false; + this.selectCPU = new Button(this.guiLeft + ( 219 - 180 ) / 2, this.guiTop + this.ySize - 68, 180, 20, GuiText.CraftingCPU + .getLocal() + ": " + GuiText.Automatic, btn -> selectNextCpu() ); + this.selectCPU.active = false; this.addButton( this.selectCPU ); - if( this.OriginalGui != null ) - { - this.cancel = new GuiButton( 0, this.guiLeft + 6, this.guiTop + this.ySize - 25, 50, 20, GuiText.Cancel.getLocal() ); - } + subGui.addBackButton(this::addButton, 6, this.ySize - 25, GuiText.Cancel.getLocal()); this.addButton( this.cancel ); } - @Override public void render(final int mouseX, final int mouseY, final float btn ) { this.updateCPUButtonText(); - this.start.enabled = !( this.container.hasNoCPU() || this.isSimulation() ); - this.selectCPU.enabled = !this.isSimulation(); + this.start.active = !( this.container.hasNoCPU() || this.isSimulation() ); + this.selectCPU.active = !this.isSimulation(); final int gx = ( this.width - this.xSize ) / 2; final int gy = ( this.height - this.ySize ) / 2; @@ -195,12 +161,12 @@ public class GuiCraftConfirm extends AEBaseGui btnTextText = GuiText.NoCraftingCPUs.getLocal(); } - this.selectCPU.displayString = btnTextText; + this.selectCPU.setMessage(btnTextText); } private boolean isSimulation() { - return ( (ContainerCraftConfirm) this.container ).isSimulation(); + return this.container.isSimulation(); } @Override @@ -247,8 +213,8 @@ public class GuiCraftConfirm extends AEBaseGui final IAEItemStack refStack = this.visual.get( z );// repo.getReferenceItem( z ); if( refStack != null ) { - GlStateManager.pushMatrix(); - GlStateManager.scale( 0.5, 0.5, 0.5 ); + RenderSystem.pushMatrix(); + RenderSystem.scalef( 0.5f, 0.5f, 0.5f ); final IAEItemStack stored = this.storage.findPrecise( refStack ); final IAEItemStack pendingStack = this.pending.findPrecise( refStack ); @@ -347,7 +313,7 @@ public class GuiCraftConfirm extends AEBaseGui } } - GlStateManager.popMatrix(); + RenderSystem.popMatrix(); final int posX = x * ( 1 + sectionLength ) + xo + sectionLength - 19; final int posY = y * offY + yo; @@ -355,7 +321,7 @@ public class GuiCraftConfirm extends AEBaseGui if( this.tooltip == z - viewStart ) { - dspToolTip = Platform.getItemDisplayName( refStack ); + dspToolTip = Platform.getItemDisplayName( refStack ).getFormattedText(); if( lineList.size() > 0 ) { @@ -392,7 +358,7 @@ public class GuiCraftConfirm extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.setScrollBar(); this.bindTexture( "guis/craftingreport.png" ); @@ -533,52 +499,25 @@ public class GuiCraftConfirm extends AEBaseGui } @Override - protected void keyTyped( final char character, final int key ) throws IOException - { - if( !this.checkHotbarKeys( key ) ) + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) { + if( !this.checkHotbarKeys( InputMappings.getInputByCode(keyCode, scanCode) ) ) { - if( key == 28 ) + if( keyCode == 28 ) { - this.actionPerformed( this.start ); + this.start(); + return true; } - super.keyTyped( character, key ); } + return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.selectCPU ) - { - try - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "Terminal.Cpu", backwards ? "Prev" : "Next" ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } - } - - if( btn == this.cancel ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( this.OriginalGui ) ); - } - - if( btn == this.start ) - { - try - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "Terminal.Start", "Start" ) ); - } - catch( final Throwable e ) - { - AELog.debug( e ); - } - } + private void selectNextCpu() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketValueConfig( "Terminal.Cpu", backwards ? "Prev" : "Next" ) ); } + + private void start() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "Terminal.Start", "Start" ) ); + } + } diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java index 871752187..c38c1e2a2 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java @@ -19,24 +19,6 @@ package appeng.client.gui.implementations; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import appeng.core.Api; -import com.google.common.base.Joiner; - -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.fml.client.gui.GuiUtils; -import org.apache.commons.lang3.time.DurationFormatUtils; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; - import appeng.api.config.SortDir; import appeng.api.config.SortOrder; import appeng.api.config.ViewItems; @@ -50,11 +32,26 @@ import appeng.client.gui.widgets.ISortSource; import appeng.container.implementations.ContainerCraftingCPU; import appeng.core.AEConfig; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; import appeng.util.Platform; import appeng.util.ReadableNumberConverter; +import com.google.common.base.Joiner; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; +import org.apache.commons.lang3.time.DurationFormatUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.TimeUnit; public class GuiCraftingCPU extends AEBaseGui implements ISortSource @@ -89,7 +86,7 @@ public class GuiCraftingCPU extends AEBaseGui implements I private IItemList pending = Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ).createList(); private List visual = new ArrayList<>(); - private GuiButton cancel; + private Button cancel; private int tooltip = -1; public GuiCraftingCPU(ContainerCraftingCPU container, PlayerInventory playerInventory, ITextComponent title) { @@ -109,22 +106,8 @@ public class GuiCraftingCPU extends AEBaseGui implements I this.visual = new ArrayList<>(); } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - if( this.cancel == btn ) - { - try - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "TileCrafting.Cancel", "Cancel" ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } - } + private void cancel() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "TileCrafting.Cancel", "Cancel" ) ); } @Override @@ -132,8 +115,8 @@ public class GuiCraftingCPU extends AEBaseGui implements I { super.init(); this.setScrollBar(); - this.cancel = new GuiButton( 0, this.guiLeft + CANCEL_LEFT_OFFSET, this.guiTop + this.ySize - CANCEL_TOP_OFFSET, CANCEL_WIDTH, CANCEL_HEIGHT, GuiText.Cancel - .getLocal() ); + this.cancel = new Button(this.guiLeft + CANCEL_LEFT_OFFSET, this.guiTop + this.ySize - CANCEL_TOP_OFFSET, CANCEL_WIDTH, CANCEL_HEIGHT, GuiText.Cancel + .getLocal(), btn -> cancel() ); this.addButton( this.cancel ); } @@ -148,7 +131,7 @@ public class GuiCraftingCPU extends AEBaseGui implements I @Override public void render(final int mouseX, final int mouseY, final float btn ) { - this.cancel.enabled = !this.visual.isEmpty(); + this.cancel.active = !this.visual.isEmpty(); final int gx = ( this.width - this.xSize ) / 2; final int gy = ( this.height - this.ySize ) / 2; @@ -216,8 +199,8 @@ public class GuiCraftingCPU extends AEBaseGui implements I final IAEItemStack refStack = this.visual.get( z );// repo.getReferenceItem( z ); if( refStack != null ) { - GlStateManager.pushMatrix(); - GlStateManager.scale( 0.5, 0.5, 0.5 ); + RenderSystem.pushMatrix(); + RenderSystem.scalef( 0.5f, 0.5f, 0.5f ); final IAEItemStack stored = this.storage.findPrecise( refStack ); final IAEItemStack activeStack = this.active.findPrecise( refStack ); @@ -298,7 +281,7 @@ public class GuiCraftingCPU extends AEBaseGui implements I } } - GlStateManager.popMatrix(); + RenderSystem.popMatrix(); final int posX = x * ( 1 + SECTION_LENGTH ) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 19; final int posY = y * offY + ITEMSTACK_TOP_OFFSET; @@ -306,7 +289,7 @@ public class GuiCraftingCPU extends AEBaseGui implements I if( this.tooltip == z - viewStart ) { - dspToolTip = Platform.getItemDisplayName( refStack ); + dspToolTip = Platform.getItemDisplayName( refStack ).getFormattedText(); if( lineList.size() > 0 ) { @@ -336,7 +319,7 @@ public class GuiCraftingCPU extends AEBaseGui implements I } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/craftingcpu.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java index c9bca14b2..4a48e6d7e 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java @@ -23,102 +23,31 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import appeng.container.implementations.ContainerCraftingCPU; -import appeng.core.Api; -import net.minecraft.util.text.ITextComponent; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; - -import appeng.api.definitions.IDefinitions; -import appeng.api.definitions.IParts; -import appeng.api.storage.ITerminalHost; -import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerCraftingStatus; import appeng.core.AELog; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketSwitchGuis; import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.WirelessTerminalGuiObject; -import appeng.parts.reporting.PartCraftingTerminal; -import appeng.parts.reporting.PartPatternTerminal; -import appeng.parts.reporting.PartTerminal; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; + +import java.io.IOException; public class GuiCraftingStatus extends GuiCraftingCPU { - private GuiButton selectCPU; + private final ContainerCraftingStatus craftingStatus; - private GuiTabButton originalGuiBtn; - private GuiBridge originalGui; - private ItemStack myIcon = ItemStack.EMPTY; + private final AESubGui subGui; - public GuiCraftingStatus(ContainerCraftingCPU container, PlayerInventory playerInventory, ITextComponent title) { + private Button selectCPU; + + public GuiCraftingStatus(ContainerCraftingStatus container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); - - final Object target = this.container.getTarget(); - final IDefinitions definitions = Api.INSTANCE.definitions(); - final IParts parts = definitions.parts(); - - if( target instanceof WirelessTerminalGuiObject ) - { - this.myIcon = definitions.items().wirelessTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - - this.originalGui = GuiBridge.GUI_WIRELESS_TERM; - } - - if( target instanceof PartTerminal ) - { - this.myIcon = parts.terminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - - this.originalGui = GuiBridge.GUI_ME; - } - - if( target instanceof PartCraftingTerminal ) - { - this.myIcon = parts.craftingTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - - this.originalGui = GuiBridge.GUI_CRAFTING_TERMINAL; - } - - if( target instanceof PartPatternTerminal ) - { - this.myIcon = parts.patternTerminal().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - - this.originalGui = GuiBridge.GUI_PATTERN_TERMINAL; - } - } - - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.selectCPU ) - { - try - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "Terminal.Cpu", backwards ? "Prev" : "Next" ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } - } - - if( btn == this.originalGuiBtn ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( this.originalGui ) ); - } + this.craftingStatus = container; + this.subGui = new AESubGui(this, container.getTarget()); } @Override @@ -126,17 +55,14 @@ public class GuiCraftingStatus extends GuiCraftingCPU { super.init(); - this.selectCPU = new GuiButton( 0, this.guiLeft + 8, this.guiTop + this.ySize - 25, 150, 20, GuiText.CraftingCPU - .getLocal() + ": " + GuiText.NoCraftingCPUs ); - // selectCPU.enabled = false; + this.selectCPU = new Button(this.guiLeft + 8, this.guiTop + this.ySize - 25, 150, 20, GuiText.CraftingCPU + .getLocal() + ": " + GuiText.NoCraftingCPUs, btn -> selectNextCpu() ); this.addButton( this.selectCPU ); - if( !this.myIcon.isEmpty() ) - { - this.addButton( - this.originalGuiBtn = new GuiTabButton( this.guiLeft + 213, this.guiTop - 4, this.myIcon, this.myIcon.getDisplayName(), this.itemRender ) ); - this.originalGuiBtn.setHideEdge( 13 ); - } + subGui.addBackButton(btn -> { + addButton(btn); + btn.setHideEdge( 13 ); + }, 213, -4); } @Override @@ -150,25 +76,25 @@ public class GuiCraftingStatus extends GuiCraftingCPU { String btnTextText = GuiText.NoCraftingJobs.getLocal(); - if( this.container.selectedCpu >= 0 )// && status.selectedCpu < status.cpus.size() ) + if( this.craftingStatus.selectedCpu >= 0 )// && status.selectedCpu < status.cpus.size() ) { - if( this.container.myName.length() > 0 ) + if( this.craftingStatus.myName.length() > 0 ) { - final String name = this.container.myName.substring( 0, Math.min( 20, this.container.myName.length() ) ); + final String name = this.craftingStatus.myName.substring( 0, Math.min( 20, this.craftingStatus.myName.length() ) ); btnTextText = GuiText.CPUs.getLocal() + ": " + name; } else { - btnTextText = GuiText.CPUs.getLocal() + ": #" + this.container.selectedCpu; + btnTextText = GuiText.CPUs.getLocal() + ": #" + this.craftingStatus.selectedCpu; } } - if( this.container.noCPU ) + if( this.craftingStatus.noCPU ) { btnTextText = GuiText.NoCraftingJobs.getLocal(); } - this.selectCPU.displayString = btnTextText; + this.selectCPU.setMessage(btnTextText); } @Override @@ -176,4 +102,11 @@ public class GuiCraftingStatus extends GuiCraftingCPU { return in; // the cup name is on the button } + + // FIXME: Extract to separate class? Shared with GuiCraftConfirm + private void selectNextCpu() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketValueConfig( "Terminal.Cpu", backwards ? "Prev" : "Next" ) ); + } + } diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java index 3a6e528b7..f348f30f3 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java @@ -19,14 +19,10 @@ package appeng.client.gui.implementations; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; import appeng.api.config.ActionItems; import appeng.api.config.Settings; -import appeng.api.storage.ITerminalHost; import appeng.client.gui.widgets.GuiImgButton; import appeng.container.implementations.ContainerCraftingTerm; import appeng.container.slot.SlotCraftingMatrix; @@ -41,34 +37,25 @@ import net.minecraft.util.text.ITextComponent; public class GuiCraftingTerm extends GuiMEMonitorable { - private GuiImgButton clearBtn; - public GuiCraftingTerm(ContainerCraftingTerm container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); this.setReservedSpace( 73 ); } - @Override - protected void actionPerformed( final GuiButton btn ) - { - super.actionPerformed( btn ); - - if( this.clearBtn == btn ) + private void clear() { + Slot s = null; + for( final Object j : this.container.inventorySlots ) { - Slot s = null; - for( final Object j : this.container.inventorySlots ) + if( j instanceof SlotCraftingMatrix ) { - if( j instanceof SlotCraftingMatrix ) - { - s = (Slot) j; - } + s = (Slot) j; } + } - if( s != null ) - { - final PacketInventoryAction p = new PacketInventoryAction( InventoryAction.MOVE_REGION, s.slotNumber, 0 ); - NetworkHandler.instance().sendToServer( p ); - } + if( s != null ) + { + final PacketInventoryAction p = new PacketInventoryAction( InventoryAction.MOVE_REGION, s.slotNumber, 0 ); + NetworkHandler.instance().sendToServer( p ); } } @@ -76,8 +63,8 @@ public class GuiCraftingTerm extends GuiMEMonitorable public void init() { super.init(); - this.addButton( this.clearBtn = new GuiImgButton( this.guiLeft + 92, this.guiTop + this.ySize - 156, Settings.ACTIONS, ActionItems.STASH ) ); - this.clearBtn.setHalfSize( true ); + GuiImgButton clearBtn = this.addButton( new GuiImgButton( this.guiLeft + 92, this.guiTop + this.ySize - 156, Settings.ACTIONS, ActionItems.STASH, btn -> clear() )); + clearBtn.setHalfSize( true ); } @Override diff --git a/src/main/java/appeng/client/gui/implementations/GuiDrive.java b/src/main/java/appeng/client/gui/implementations/GuiDrive.java index 618ae59bc..37e00c6a4 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiDrive.java +++ b/src/main/java/appeng/client/gui/implementations/GuiDrive.java @@ -19,19 +19,14 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerDrive; +import appeng.container.implementations.ContainerPriority; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.tile.storage.TileDrive; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -39,30 +34,21 @@ import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiDrive extends AEBaseGui { - private GuiTabButton priority; - public GuiDrive(ContainerDrive container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); this.ySize = 199; } - @Override - protected void actionPerformed( final GuiButton par1GuiButton ) throws IOException - { - super.actionPerformed( par1GuiButton ); - - if( par1GuiButton == this.priority ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - } - @Override public void init() { super.init(); - this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) ); + this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) ); + } + + private void openPriorityGui() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); } @Override @@ -73,7 +59,7 @@ public class GuiDrive extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/drive.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiFormationPlane.java b/src/main/java/appeng/client/gui/implementations/GuiFormationPlane.java index 8c797365a..f5c34d459 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiFormationPlane.java +++ b/src/main/java/appeng/client/gui/implementations/GuiFormationPlane.java @@ -19,32 +19,24 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.util.text.ITextComponent; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - import appeng.api.config.FuzzyMode; import appeng.api.config.Settings; import appeng.api.config.YesNo; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerFormationPlane; +import appeng.container.implementations.ContainerPriority; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketConfigButton; import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.parts.automation.PartFormationPlane; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; public class GuiFormationPlane extends GuiUpgradeable { - private GuiTabButton priority; private GuiImgButton placeMode; public GuiFormationPlane(ContainerFormationPlane container, PlayerInventory playerInventory, ITextComponent title) { @@ -55,10 +47,10 @@ public class GuiFormationPlane extends GuiUpgradeable @Override protected void addButtons() { - this.placeMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.PLACE_BLOCK, YesNo.YES ); - this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + this.placeMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.PLACE_BLOCK, YesNo.YES, btn -> selectNextPlaceMode() ); + this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed ); - this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) ); + this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) ); this.addButton( this.placeMode ); this.addButton( this.fuzzyMode ); @@ -87,20 +79,13 @@ public class GuiFormationPlane extends GuiUpgradeable return "guis/storagebus.png"; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.priority ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - else if( btn == this.placeMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.placeMode.getSetting(), backwards ) ); - } + private void openPriorityGui() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); } + + private void selectNextPlaceMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.placeMode.getSetting(), backwards ) ); + } + } diff --git a/src/main/java/appeng/client/gui/implementations/GuiGrinder.java b/src/main/java/appeng/client/gui/implementations/GuiGrinder.java index ea8a9c2a8..432da01d5 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiGrinder.java +++ b/src/main/java/appeng/client/gui/implementations/GuiGrinder.java @@ -24,7 +24,6 @@ import net.minecraft.entity.player.PlayerInventory; import appeng.client.gui.AEBaseGui; import appeng.container.implementations.ContainerGrinder; import appeng.core.localization.GuiText; -import appeng.tile.grindstone.TileGrinder; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -45,7 +44,7 @@ public class GuiGrinder extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/grinder.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiIOPort.java b/src/main/java/appeng/client/gui/implementations/GuiIOPort.java index 2df2f7722..4c37650be 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiIOPort.java +++ b/src/main/java/appeng/client/gui/implementations/GuiIOPort.java @@ -19,16 +19,6 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import appeng.core.Api; -import net.minecraft.util.text.ITextComponent; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - -import appeng.api.AEApi; import appeng.api.config.FullnessMode; import appeng.api.config.OperationMode; import appeng.api.config.RedstoneMode; @@ -36,10 +26,12 @@ import appeng.api.config.Settings; import appeng.api.definitions.IDefinitions; import appeng.client.gui.widgets.GuiImgButton; import appeng.container.implementations.ContainerIOPort; +import appeng.core.Api; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketConfigButton; -import appeng.tile.storage.TileIOPort; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; public class GuiIOPort extends GuiUpgradeable @@ -56,9 +48,9 @@ public class GuiIOPort extends GuiUpgradeable @Override protected void addButtons() { - this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE ); - this.fullMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.FULLNESS_MODE, FullnessMode.EMPTY ); - this.operationMode = new GuiImgButton( this.guiLeft + 80, this.guiTop + 17, Settings.OPERATION_MODE, OperationMode.EMPTY ); + this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, this::actionPerformed); + this.fullMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.FULLNESS_MODE, FullnessMode.EMPTY, btn -> selectNextFullMode() ); + this.operationMode = new GuiImgButton( this.guiLeft + 80, this.guiTop + 17, Settings.OPERATION_MODE, OperationMode.EMPTY, btn -> selectNextOperationMode() ); this.addButton( this.operationMode ); this.addButton( this.redstoneMode ); @@ -88,9 +80,9 @@ public class GuiIOPort extends GuiUpgradeable } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { - super.drawBG( offsetX, offsetY, mouseX, mouseY ); + super.drawBG( offsetX, offsetY, mouseX, mouseY, partialTicks); final IDefinitions definitions = Api.INSTANCE.definitions(); @@ -105,21 +97,14 @@ public class GuiIOPort extends GuiUpgradeable return "guis/io_port.png"; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.fullMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.fullMode.getSetting(), backwards ) ); - } - - if( btn == this.operationMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.operationMode.getSetting(), backwards ) ); - } + private void selectNextFullMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.fullMode.getSetting(), backwards ) ); } + + private void selectNextOperationMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.operationMode.getSetting(), backwards ) ); + } + } diff --git a/src/main/java/appeng/client/gui/implementations/GuiInscriber.java b/src/main/java/appeng/client/gui/implementations/GuiInscriber.java index 53528fb0a..b5e418f68 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInscriber.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInscriber.java @@ -25,9 +25,7 @@ import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiProgressBar; import appeng.client.gui.widgets.GuiProgressBar.Direction; import appeng.container.implementations.ContainerInscriber; -import appeng.container.implementations.ContainerUpgradeable; import appeng.core.localization.GuiText; -import appeng.tile.misc.TileInscriber; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -67,7 +65,7 @@ public class GuiInscriber extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/inscriber.png" ); this.pb.x = 135 + this.guiLeft; diff --git a/src/main/java/appeng/client/gui/implementations/GuiInterface.java b/src/main/java/appeng/client/gui/implementations/GuiInterface.java index 342efae3b..77b15b934 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInterface.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInterface.java @@ -19,33 +19,25 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.util.text.ITextComponent; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - import appeng.api.config.Settings; import appeng.api.config.YesNo; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiTabButton; import appeng.client.gui.widgets.GuiToggleButton; import appeng.container.implementations.ContainerInterface; +import appeng.container.implementations.ContainerPriority; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketConfigButton; import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.helpers.IInterfaceHost; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; public class GuiInterface extends GuiUpgradeable { - private GuiTabButton priority; - private GuiImgButton BlockMode; + private GuiImgButton blockMode; private GuiToggleButton interfaceMode; public GuiInterface(ContainerInterface container, PlayerInventory playerInventory, ITextComponent title) { @@ -56,23 +48,22 @@ public class GuiInterface extends GuiUpgradeable @Override protected void addButtons() { - this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ); - this.addButton( this.priority ); + this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) ); - this.BlockMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.BLOCK, YesNo.NO ); - this.addButton( this.BlockMode ); + this.blockMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.BLOCK, YesNo.NO, btn -> selectNextBlockMode() ); + this.addButton( this.blockMode); this.interfaceMode = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 26, 84, 85, GuiText.InterfaceTerminal - .getLocal(), GuiText.InterfaceTerminalHint.getLocal() ); + .getLocal(), GuiText.InterfaceTerminalHint.getLocal(), btn -> selectNextInterfaceMode() ); this.addButton( this.interfaceMode ); } @Override public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) { - if( this.BlockMode != null ) + if( this.blockMode != null ) { - this.BlockMode.set( ( (ContainerInterface) this.cvb ).getBlockingMode() ); + this.blockMode.set( ( (ContainerInterface) this.cvb ).getBlockingMode() ); } if( this.interfaceMode != null ) @@ -95,26 +86,18 @@ public class GuiInterface extends GuiUpgradeable return "guis/interface.png"; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.priority ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - - if( btn == this.interfaceMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( Settings.INTERFACE_TERMINAL, backwards ) ); - } - - if( btn == this.BlockMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.BlockMode.getSetting(), backwards ) ); - } + private void openPriorityGui() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); } + + private void selectNextBlockMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.blockMode.getSetting(), backwards ) ); + } + + private void selectNextInterfaceMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( Settings.INTERFACE_TERMINAL, backwards ) ); + } + } diff --git a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java index d5105d8ef..e16845788 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java @@ -19,27 +19,6 @@ package appeng.client.gui.implementations; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; - -import com.google.common.collect.HashMultimap; - -import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; - import appeng.api.storage.channels.IItemStorageChannel; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiScrollbar; @@ -47,12 +26,21 @@ import appeng.client.gui.widgets.MEGuiTextField; import appeng.client.me.ClientDCInternalInv; import appeng.client.me.SlotDisconnected; import appeng.container.implementations.ContainerInterfaceTerminal; +import appeng.core.Api; import appeng.core.localization.GuiText; -import appeng.parts.reporting.PartInterfaceTerminal; import appeng.util.Platform; +import com.google.common.collect.HashMultimap; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; +import java.util.*; + public class GuiInterfaceTerminal extends AEBaseGui { @@ -147,21 +135,21 @@ public class GuiInterfaceTerminal extends AEBaseGui } @Override - protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) throws IOException + public boolean mouseClicked( final double xCoord, final double yCoord, final int btn ) { - this.searchField.mouseClicked( xCoord, yCoord, btn ); - - if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) ) - { - this.searchField.setText( "" ); - this.refreshList(); + if (this.searchField.mouseClicked( xCoord, yCoord, btn )) { + if (btn == 1 && this.searchField.isMouseOver(xCoord, yCoord)) { + this.searchField.setText(""); + this.refreshList(); + } + return true; } - super.mouseClicked( xCoord, yCoord, btn ); + return super.mouseClicked( xCoord, yCoord, btn ); } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/interfaceterminal.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); @@ -185,29 +173,22 @@ public class GuiInterfaceTerminal extends AEBaseGui if( this.searchField != null ) { - this.searchField.drawTextBox(); + this.searchField.render(mouseX, mouseY, partialTicks); } } @Override - protected void keyTyped( final char character, final int key ) throws IOException - { - if( !this.checkHotbarKeys( key ) ) + public boolean charTyped(char character, int key) { + if( character == ' ' && this.searchField.getText().isEmpty() ) { - if( character == ' ' && this.searchField.getText().isEmpty() ) - { - return; - } - - if( this.searchField.textboxKeyTyped( character, key ) ) - { - this.refreshList(); - } - else - { - super.keyTyped( character, key ); - } + return true; } + if( this.searchField.charTyped( character, key ) ) + { + this.refreshList(); + return true; + } + return false; } public void postUpdate( final CompoundNBT in ) @@ -341,16 +322,17 @@ public class GuiInterfaceTerminal extends AEBaseGui // Potential later use to filter by input // ListNBT inTag = encodedValue.getTagList( "in", 10 ); - final ListNBT outTag = encodedValue.getTagList( "out", 10 ); + final ListNBT outTag = encodedValue.getList( "out", 10 ); - for( int i = 0; i < outTag.tagCount(); i++ ) + for( int i = 0; i < outTag.size(); i++ ) { - final ItemStack parsedItemStack = new ItemStack( outTag.getCompoundTagAt( i ) ); + final ItemStack parsedItemStack = ItemStack.read( outTag.getCompound( i ) ); if( !parsedItemStack.isEmpty() ) { final String displayName = Platform .getItemDisplayName( Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ).createStack( parsedItemStack ) ) + .getString() .toLowerCase(); if( displayName.contains( searchTerm ) ) { diff --git a/src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java b/src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java index 40100de0d..2d38286b8 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java +++ b/src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java @@ -21,10 +21,10 @@ package appeng.client.gui.implementations; import java.io.IOException; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.util.InputMappings; import net.minecraft.util.text.ITextComponent; -import org.lwjgl.input.Mouse; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.FuzzyMode; @@ -42,7 +42,6 @@ import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketConfigButton; import appeng.core.sync.packets.PacketValueConfig; -import appeng.parts.automation.PartLevelEmitter; public class GuiLevelEmitter extends GuiUpgradeable @@ -50,14 +49,14 @@ public class GuiLevelEmitter extends GuiUpgradeable private GuiNumberBox level; - private GuiButton plus1; - private GuiButton plus10; - private GuiButton plus100; - private GuiButton plus1000; - private GuiButton minus1; - private GuiButton minus10; - private GuiButton minus100; - private GuiButton minus1000; + private Button plus1; + private Button plus10; + private Button plus100; + private Button plus1000; + private Button minus1; + private Button minus10; + private Button minus100; + private Button minus1000; private GuiImgButton levelMode; private GuiImgButton craftingMode; @@ -83,25 +82,25 @@ public class GuiLevelEmitter extends GuiUpgradeable @Override protected void addButtons() { - this.levelMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL ); - this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL ); - this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); - this.craftingMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO ); + this.levelMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL, btn -> selectNextLevelMode() ); + this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL, this::actionPerformed ); + this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed ); + this.craftingMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO, btn -> selectNextCraftingMode() ); final int a = AEConfig.instance().levelByStackAmounts( 0 ); final int b = AEConfig.instance().levelByStackAmounts( 1 ); final int c = AEConfig.instance().levelByStackAmounts( 2 ); final int d = AEConfig.instance().levelByStackAmounts( 3 ); - this.addButton( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a ) ); - this.addButton( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b ) ); - this.addButton( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c ) ); - this.addButton( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d ) ); + this.addButton( this.plus1 = new Button(this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a, btn -> addQty(a) ) ); + this.addButton( this.plus10 = new Button(this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b, btn -> addQty(b) ) ); + this.addButton( this.plus100 = new Button(this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c, btn -> addQty(c) ) ); + this.addButton( this.plus1000 = new Button(this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d, btn -> addQty(d) ) ); - this.addButton( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a ) ); - this.addButton( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b ) ); - this.addButton( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c ) ); - this.addButton( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d ) ); + this.addButton( this.minus1 = new Button(this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a, btn -> addQty(-a) ) ); + this.addButton( this.minus10 = new Button(this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b, btn -> addQty(-b) ) ); + this.addButton( this.minus100 = new Button(this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c, btn -> addQty(-c) ) ); + this.addButton( this.minus1000 = new Button(this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d, btn -> addQty(-d) ) ); this.addButton( this.levelMode ); this.addButton( this.redstoneMode ); @@ -116,22 +115,22 @@ public class GuiLevelEmitter extends GuiUpgradeable // configure enabled status... this.level.setEnabled( notCraftingMode ); - this.plus1.enabled = notCraftingMode; - this.plus10.enabled = notCraftingMode; - this.plus100.enabled = notCraftingMode; - this.plus1000.enabled = notCraftingMode; - this.minus1.enabled = notCraftingMode; - this.minus10.enabled = notCraftingMode; - this.minus100.enabled = notCraftingMode; - this.minus1000.enabled = notCraftingMode; - this.levelMode.enabled = notCraftingMode; - this.redstoneMode.enabled = notCraftingMode; + this.plus1.active = notCraftingMode; + this.plus10.active = notCraftingMode; + this.plus100.active = notCraftingMode; + this.plus1000.active = notCraftingMode; + this.minus1.active = notCraftingMode; + this.minus10.active = notCraftingMode; + this.minus100.active = notCraftingMode; + this.minus1000.active = notCraftingMode; + this.levelMode.active = notCraftingMode; + this.redstoneMode.active = notCraftingMode; super.drawFG( offsetX, offsetY, mouseX, mouseY ); if( this.craftingMode != null ) { - this.craftingMode.set( ( (ContainerLevelEmitter) this.cvb ).getCraftingMode() ); + this.craftingMode.set( this.cvb.getCraftingMode() ); } if( this.levelMode != null ) @@ -141,10 +140,10 @@ public class GuiLevelEmitter extends GuiUpgradeable } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { - super.drawBG( offsetX, offsetY, mouseX, mouseY ); - this.level.drawTextBox(); + super.drawBG( offsetX, offsetY, mouseX, mouseY, partialTicks); + this.level.render(mouseX, mouseY, partialTicks); } @Override @@ -166,30 +165,14 @@ public class GuiLevelEmitter extends GuiUpgradeable return GuiText.LevelEmitter; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); + private void selectNextCraftingMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.craftingMode.getSetting(), backwards ) ); + } - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.craftingMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.craftingMode.getSetting(), backwards ) ); - } - - if( btn == this.levelMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.levelMode.getSetting(), backwards ) ); - } - - final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000; - final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000; - - if( isPlus || isMinus ) - { - this.addQty( this.getQty( btn ) ); - } + private void selectNextLevelMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.levelMode.getSetting(), backwards ) ); } private void addQty( final long i ) @@ -231,51 +214,45 @@ public class GuiLevelEmitter extends GuiUpgradeable // nope.. this.level.setText( "0" ); } - catch( final IOException e ) - { - AELog.debug( e ); - } } @Override - protected void keyTyped( final char character, final int key ) throws IOException + public boolean charTyped(char character, int key) { + // Forward entered characters to the number-text-field + return level.charTyped(character, key); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) { - if( !this.checkHotbarKeys( key ) ) + if( !this.checkHotbarKeys( InputMappings.getInputByCode(keyCode, scanCode) ) ) { - if( ( key == 211 || key == 205 || key == 203 || key == 14 || Character.isDigit( character ) ) && this.level.textboxKeyTyped( character, key ) ) + if( keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14 ) { - try + String Out = this.level.getText(); + + boolean Fixed = false; + while( Out.startsWith( "0" ) && Out.length() > 1 ) { - String Out = this.level.getText(); - - boolean Fixed = false; - while( Out.startsWith( "0" ) && Out.length() > 1 ) - { - Out = Out.substring( 1 ); - Fixed = true; - } - - if( Fixed ) - { - this.level.setText( Out ); - } - - if( Out.isEmpty() ) - { - Out = "0"; - } - - NetworkHandler.instance().sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) ); + Out = Out.substring( 1 ); + Fixed = true; } - catch( final IOException e ) + + if( Fixed ) { - AELog.debug( e ); + this.level.setText( Out ); } - } - else - { - super.keyTyped( character, key ); + + if( Out.isEmpty() ) + { + Out = "0"; + } + + NetworkHandler.instance().sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) ); + return true; } } + + return super.keyPressed( keyCode, scanCode, p_keyPressed_3_ ); } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiMAC.java b/src/main/java/appeng/client/gui/implementations/GuiMAC.java index 91fe312d8..15a6cacdc 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMAC.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMAC.java @@ -28,7 +28,6 @@ import appeng.client.gui.widgets.GuiProgressBar; import appeng.client.gui.widgets.GuiProgressBar.Direction; import appeng.container.implementations.ContainerMAC; import appeng.core.localization.GuiText; -import appeng.tile.crafting.TileMolecularAssembler; import net.minecraft.util.text.ITextComponent; @@ -54,7 +53,7 @@ public class GuiMAC extends GuiUpgradeable @Override protected void addButtons() { - this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE ); + this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, this::actionPerformed ); this.addButton( this.redstoneMode ); } @@ -66,11 +65,11 @@ public class GuiMAC extends GuiUpgradeable } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.pb.x = 148 + this.guiLeft; this.pb.y = 48 + this.guiTop; - super.drawBG( offsetX, offsetY, mouseX, mouseY ); + super.drawBG( offsetX, offsetY, mouseX, mouseY, partialTicks); } @Override diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java index 5e5dc045a..93feb4988 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java @@ -22,14 +22,14 @@ package appeng.client.gui.implementations; import java.io.IOException; import java.util.List; +import appeng.container.implementations.ContainerCraftingStatus; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.util.InputMappings; +import net.minecraft.inventory.container.Slot; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import appeng.api.config.SearchBoxMode; @@ -38,7 +38,6 @@ import appeng.api.config.TerminalStyle; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.tiles.IMEChest; import appeng.api.implementations.tiles.IViewCellStorage; -import appeng.api.storage.ITerminalHost; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigurableObject; @@ -64,11 +63,11 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketSwitchGuis; import appeng.core.sync.packets.PacketValueConfig; import appeng.helpers.WirelessTerminalGuiObject; -import appeng.integration.Integrations; import appeng.parts.reporting.AbstractPartTerminal; import appeng.tile.misc.TileSecurityStation; import appeng.util.IConfigManagerHost; import appeng.util.Platform; +import org.lwjgl.glfw.GLFW; public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfigManagerHost @@ -164,17 +163,15 @@ public class GuiMEMonitorable extends AEBaseME this.getScrollBar().setRange( 0, ( this.repo.size() + this.perRow - 1 ) / this.perRow - this.rows, Math.max( 1, this.rows / 6 ) ); } - @Override - protected void actionPerformed( final GuiButton btn ) - { - if( btn == this.craftingStatusBtn ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_CRAFTING_STATUS ) ); - } + private void showCraftingStatus() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis(ContainerCraftingStatus.TYPE) ); + } + protected void actionPerformed( final Button btn ) + { if( btn instanceof GuiImgButton ) { - final boolean backwards = Mouse.isButtonDown( 1 ); + final boolean backwards = minecraft.mouseHelper.isRightDown(); final GuiImgButton iBtn = (GuiImgButton) btn; if( iBtn.getSetting() != Settings.ACTIONS ) @@ -192,14 +189,7 @@ public class GuiMEMonitorable extends AEBaseME } else { - try - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + NetworkHandler.instance().sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) ); } iBtn.set( next ); @@ -221,7 +211,7 @@ public class GuiMEMonitorable extends AEBaseME @Override public void init() { - Keyboard.enableRepeatEvents( true ); + minecraft.keyboardListener.enableRepeatEvents( true ); this.maxRows = this.getMaxRows(); this.perRow = AEConfig.instance() @@ -275,27 +265,25 @@ public class GuiMEMonitorable extends AEBaseME if( this.customSortOrder ) { - this.buttonList - .add( this.SortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ) ) ); + this.SortByBox = this.addButton( new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ), this::actionPerformed ) ); offset += 20; } if( this.viewCell || this instanceof GuiWirelessTerm ) { - this.buttonList - .add( this.ViewBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting( Settings.VIEW_MODE ) ) ); + this.ViewBox = this.addButton( new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting( Settings.VIEW_MODE ), this::actionPerformed ) ); offset += 20; } this.addButton( this.SortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc - .getSetting( Settings.SORT_DIRECTION ) ) ); + .getSetting( Settings.SORT_DIRECTION ), this::actionPerformed ) ); offset += 20; this.addButton( this.searchBoxSettings = new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance() .getConfigManager() .getSetting( - Settings.SEARCH_MODE ) ) ); + Settings.SEARCH_MODE ), this::actionPerformed ) ); offset += 20; @@ -303,7 +291,7 @@ public class GuiMEMonitorable extends AEBaseME { this.addButton( this.terminalStyleBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.TERMINAL_STYLE, AEConfig.instance() .getConfigManager() - .getSetting( Settings.TERMINAL_STYLE ) ) ); + .getSetting( Settings.TERMINAL_STYLE ), this::actionPerformed ) ); } this.searchField = new MEGuiTextField( this.font, this.guiLeft + Math.max( 80, this.offsetX ), this.guiTop + 4, 90, 12 ); @@ -315,8 +303,8 @@ public class GuiMEMonitorable extends AEBaseME if( this.viewCell || this instanceof GuiWirelessTerm ) { - this.addButton( this.craftingStatusBtn = new GuiTabButton( this.guiLeft + 170, this.guiTop - 4, 2 + 11 * 16, GuiText.CraftingStatus - .getLocal(), this.itemRender ) ); + this.craftingStatusBtn = this.addButton( new GuiTabButton( this.guiLeft + 170, this.guiTop - 4, 2 + 11 * 16, GuiText.CraftingStatus + .getLocal(), this.itemRenderer, btn -> showCraftingStatus() ) ); this.craftingStatusBtn.setHideEdge( 13 ); } @@ -326,11 +314,11 @@ public class GuiMEMonitorable extends AEBaseME final boolean isKeepFilter = SearchBoxMode.AUTOSEARCH_KEEP == searchModeSetting || SearchBoxMode.JEI_AUTOSEARCH_KEEP == searchModeSetting || SearchBoxMode.MANUAL_SEARCH_KEEP == searchModeSetting || SearchBoxMode.JEI_MANUAL_SEARCH_KEEP == searchModeSetting; final boolean isJEIEnabled = SearchBoxMode.JEI_AUTOSEARCH == searchModeSetting || SearchBoxMode.JEI_MANUAL_SEARCH == searchModeSetting; - this.searchField.setFocused( this.isAutoFocus ); + this.searchField.setFocused2( this.isAutoFocus ); if( isJEIEnabled ) { - memoryText = Integrations.jei().getSearchText(); + memoryText = null; // FIXME Integrations.jei().getSearchText(); } if( isKeepFilter && memoryText != null && !memoryText.isEmpty() ) @@ -382,31 +370,31 @@ public class GuiMEMonitorable extends AEBaseME } @Override - protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) throws IOException + public boolean mouseClicked( final double xCoord, final double yCoord, final int btn ) { - this.searchField.mouseClicked( xCoord, yCoord, btn ); - - if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) ) - { - this.searchField.setText( "" ); - this.repo.setSearchString( "" ); - this.repo.updateView(); - this.setScrollBar(); + if (this.searchField.mouseClicked( xCoord, yCoord, btn )) { + if (btn == 1 && this.searchField.isMouseOver(xCoord, yCoord)) { + this.searchField.setText(""); + this.repo.setSearchString(""); + this.repo.updateView(); + this.setScrollBar(); + } + return true; } - super.mouseClicked( xCoord, yCoord, btn ); + return super.mouseClicked( xCoord, yCoord, btn ); } @Override public void removed() { super.removed(); - Keyboard.enableRepeatEvents( false ); + minecraft.keyboardListener.enableRepeatEvents( false ); memoryText = this.searchField.getText(); } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( this.getBackground() ); @@ -447,7 +435,7 @@ public class GuiMEMonitorable extends AEBaseME if( this.searchField != null ) { - this.searchField.drawTextBox(); + this.searchField.render(mouseX, mouseY, partialTicks); } } @@ -469,59 +457,71 @@ public class GuiMEMonitorable extends AEBaseME protected void repositionSlot( final AppEngSlot s ) { - s.yPos = s.getY() + this.ySize - 78 - 5; + // FIXME .... it's final now, WHAT DO WE DO ARGH + // s.yPos = s.getY() + this.ySize - 78 - 5; } @Override - protected void keyTyped( final char character, final int key ) throws IOException + public boolean charTyped(char character, int p_charTyped_2_) { + if( character == ' ' && this.searchField.getText().isEmpty() ) + { + return true; + } + + final boolean mouseInGui = this.isMouseOver( this.currentMouseX, this.currentMouseY ); + if( this.isAutoFocus && !this.searchField.isFocused() && mouseInGui ) + { + this.searchField.setFocused2( true ); + } + + if (this.searchField.charTyped(character, p_charTyped_2_)) { + this.repo.setSearchString( this.searchField.getText() ); + this.repo.updateView(); + this.setScrollBar(); + return true; + } + + return false; + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) { - if( !this.checkHotbarKeys( key ) ) + InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode); + + if( !this.checkHotbarKeys(input) ) { - if( AppEng.proxy.isActionKey( ActionKey.TOGGLE_FOCUS, key ) ) + if( AppEng.proxy.isActionKey( ActionKey.TOGGLE_FOCUS, input ) ) { - this.searchField.setFocused( !this.searchField.isFocused() ); - return; + this.searchField.setFocused2( !this.searchField.isFocused() ); + return true; } - if( this.searchField.isFocused() && key == Keyboard.KEY_RETURN ) + if( this.searchField.isFocused() && keyCode == GLFW.GLFW_KEY_ENTER ) { - this.searchField.setFocused( false ); - return; + this.searchField.setFocused2( false ); + return true; } - if( character == ' ' && this.searchField.getText().isEmpty() ) - { - return; - } - - final boolean mouseInGui = this.isPointInRegion( 0, 0, this.xSize, this.ySize, this.currentMouseX, this.currentMouseY ); - - if( this.isAutoFocus && !this.searchField.isFocused() && mouseInGui ) - { - this.searchField.setFocused( true ); - } - - if( this.searchField.textboxKeyTyped( character, key ) ) + if( this.searchField.keyPressed( keyCode, scanCode, p_keyPressed_3_ ) ) { this.repo.setSearchString( this.searchField.getText() ); this.repo.updateView(); this.setScrollBar(); // tell forge the key event is handled and should not be sent out - this.keyHandled = mouseInGui; - } - else - { - super.keyTyped( character, key ); + return true; } } + + return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); } @Override - public void updateScreen() + public void tick() { this.repo.setPower( this.container.isPowered() ); - super.updateScreen(); + super.tick(); } @Override diff --git a/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java index 3e9c70ebc..23391a6b0 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java @@ -19,25 +19,10 @@ package appeng.client.gui.implementations; -import java.io.IOException; -import java.util.List; - -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.fml.client.gui.GuiUtils; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - import appeng.api.config.Settings; import appeng.api.config.SortDir; import appeng.api.config.SortOrder; import appeng.api.config.ViewItems; -import appeng.api.implementations.guiobjects.INetworkTool; import appeng.api.storage.data.IAEItemStack; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiImgButton; @@ -49,6 +34,14 @@ import appeng.container.implementations.ContainerNetworkStatus; import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.util.Platform; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; + +import java.util.List; public class GuiNetworkStatus extends AEBaseGui implements ISortSource @@ -70,29 +63,21 @@ public class GuiNetworkStatus extends AEBaseGui implemen this.repo.setRowSize( 5 ); } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.units ) - { - AEConfig.instance().nextPowerUnit( backwards ); - this.units.set( AEConfig.instance().selectedPowerUnit() ); - } - } - @Override public void init() { super.init(); - this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit() ); + this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit(), btn -> selectNextUnit() ); this.addButton( this.units ); } + private void selectNextUnit() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + AEConfig.instance().nextPowerUnit( backwards ); + this.units.set( AEConfig.instance().selectedPowerUnit() ); + } + @Override public void render(final int mouseX, final int mouseY, final float btn ) { @@ -160,8 +145,8 @@ public class GuiNetworkStatus extends AEBaseGui implemen final IAEItemStack refStack = this.repo.getReferenceItem( z ); if( refStack != null ) { - GlStateManager.pushMatrix(); - GlStateManager.scale( 0.5, 0.5, 0.5 ); + RenderSystem.pushMatrix(); + RenderSystem.scalef( 0.5f, 0.5f, 0.5f ); String str = Long.toString( refStack.getStackSize() ); if( refStack.getStackSize() >= 10000 ) @@ -173,13 +158,13 @@ public class GuiNetworkStatus extends AEBaseGui implemen this.font.drawString( str, (int) ( ( x * sectionLength + xo + sectionLength - 19 - ( w * 0.5 ) ) * 2 ), ( y * 18 + yo + 6 ) * 2, 4210752 ); - GlStateManager.popMatrix(); + RenderSystem.popMatrix(); final int posX = x * sectionLength + xo + sectionLength - 18; final int posY = y * 18 + yo; if( this.tooltip == z - viewStart ) { - toolTip = Platform.getItemDisplayName( refStack ); + toolTip = Platform.getItemDisplayName( refStack ).getFormattedText(); toolTip += ( '\n' + GuiText.Installed.getLocal() + ": " + ( refStack.getStackSize() ) ); if( refStack.getCountRequestable() > 0 ) @@ -210,7 +195,7 @@ public class GuiNetworkStatus extends AEBaseGui implemen } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/networkstatus.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); @@ -237,11 +222,11 @@ public class GuiNetworkStatus extends AEBaseGui implemen } @Override - protected void renderToolTip( final ItemStack stack, final int x, final int y ) + protected void renderTooltip( final ItemStack stack, final int x, final int y ) { final Slot s = this.getSlot( x, y ); - if( s instanceof SlotME && stack != null ) + if( s instanceof SlotME && !stack.isEmpty() ) { IAEItemStack myStack = null; @@ -256,8 +241,7 @@ public class GuiNetworkStatus extends AEBaseGui implemen if( myStack != null ) { - ITooltipFlag.TooltipFlags tooltipFlag = this.minecraft.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL; - List currentToolTip = stack.getTooltip( this.minecraft.player, tooltipFlag ); + List currentToolTip = getTooltipFromItem(stack); while( currentToolTip.size() > 1 ) { @@ -271,7 +255,7 @@ public class GuiNetworkStatus extends AEBaseGui implemen } } - super.renderToolTip( stack, x, y ); + super.renderTooltip( stack, x, y ); } @Override diff --git a/src/main/java/appeng/client/gui/implementations/GuiNetworkTool.java b/src/main/java/appeng/client/gui/implementations/GuiNetworkTool.java index 73362b6ce..c5ce20308 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiNetworkTool.java +++ b/src/main/java/appeng/client/gui/implementations/GuiNetworkTool.java @@ -19,19 +19,13 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - -import appeng.api.implementations.guiobjects.INetworkTool; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiToggleButton; import appeng.container.implementations.ContainerNetworkTool; -import appeng.core.AELog; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -46,35 +40,21 @@ public class GuiNetworkTool extends AEBaseGui this.ySize = 166; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - try - { - if( btn == this.tFacades ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "NetworkTool", "Toggle" ) ); - } - } - catch( final IOException e ) - { - AELog.debug( e ); - } - } - @Override public void init() { super.init(); this.tFacades = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 8, 23, 22, GuiText.TransparentFacades.getLocal(), GuiText.TransparentFacadesHint - .getLocal() ); + .getLocal(), btn -> toggleFacades() ); this.addButton( this.tFacades ); } + private void toggleFacades() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "NetworkTool", "Toggle" ) ); + } + @Override public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) { @@ -88,7 +68,7 @@ public class GuiNetworkTool extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/toolbox.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java b/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java index 85cfbf7ff..004022486 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java @@ -19,25 +19,19 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; - import appeng.api.config.ActionItems; import appeng.api.config.ItemSubstitution; import appeng.api.config.Settings; -import appeng.api.storage.ITerminalHost; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerPatternTerm; import appeng.container.slot.AppEngSlot; -import appeng.core.AELog; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; +import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; @@ -57,79 +51,55 @@ public class GuiPatternTerm extends GuiMEMonitorable private GuiTabButton tabProcessButton; private GuiImgButton substitutionsEnabledBtn; private GuiImgButton substitutionsDisabledBtn; - private GuiImgButton encodeBtn; - private GuiImgButton clearBtn; public GuiPatternTerm(ContainerPatternTerm container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); this.setReservedSpace( 81 ); } - @Override - protected void actionPerformed( final GuiButton btn ) - { - super.actionPerformed( btn ); - - try - { - - if( this.tabCraftButton == btn || this.tabProcessButton == btn ) - { - NetworkHandler.instance() - .sendToServer( - new PacketValueConfig( "PatternTerminal.CraftMode", this.tabProcessButton == btn ? CRAFTMODE_CRFTING : CRAFTMODE_PROCESSING ) ); - } - - if( this.encodeBtn == btn ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "PatternTerminal.Encode", "1" ) ); - } - - if( this.clearBtn == btn ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "PatternTerminal.Clear", "1" ) ); - } - - if( this.substitutionsEnabledBtn == btn || this.substitutionsDisabledBtn == btn ) - { - NetworkHandler.instance() - .sendToServer( - new PacketValueConfig( "PatternTerminal.Substitute", this.substitutionsEnabledBtn == btn ? SUBSITUTION_DISABLE : SUBSITUTION_ENABLE ) ); - } - } - catch( final IOException e ) - { - AELog.error( e ); - } - } - @Override public void init() { super.init(); this.tabCraftButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.CRAFTING_TABLE ), GuiText.CraftingPattern - .getLocal(), this.itemRender ); + .getLocal(), this.itemRenderer, btn -> toggleCraftMode(CRAFTMODE_PROCESSING) ); this.addButton( this.tabCraftButton ); this.tabProcessButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.FURNACE ), GuiText.ProcessingPattern - .getLocal(), this.itemRender ); + .getLocal(), this.itemRenderer, btn -> toggleCraftMode(CRAFTMODE_CRFTING) ); this.addButton( this.tabProcessButton ); - this.substitutionsEnabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.ENABLED ); + this.substitutionsEnabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.ENABLED, btn -> toggleSubstitutions(SUBSITUTION_DISABLE) ); this.substitutionsEnabledBtn.setHalfSize( true ); this.addButton( this.substitutionsEnabledBtn ); - this.substitutionsDisabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.DISABLED ); + this.substitutionsDisabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.DISABLED, btn -> toggleSubstitutions(SUBSITUTION_ENABLE) ); this.substitutionsDisabledBtn.setHalfSize( true ); this.addButton( this.substitutionsDisabledBtn ); - this.clearBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE ); - this.clearBtn.setHalfSize( true ); - this.addButton( this.clearBtn ); + GuiImgButton clearBtn = new GuiImgButton(this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE, btn -> clear()); + clearBtn.setHalfSize( true ); + this.addButton(clearBtn); - this.encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE ); - this.addButton( this.encodeBtn ); + GuiImgButton encodeBtn = new GuiImgButton(this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE, btn -> encode()); + this.addButton(encodeBtn); + } + + private void toggleCraftMode(String mode) { + NetworkHandler.instance().sendToServer(new PacketValueConfig( "PatternTerminal.CraftMode", mode ) ); + } + + private void toggleSubstitutions(String mode) { + NetworkHandler.instance().sendToServer(new PacketValueConfig( "PatternTerminal.Substitute", mode ) ); + } + + private void encode() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "PatternTerminal.Encode", "1" ) ); + } + + private void clear() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "PatternTerminal.Clear", "1" ) ); } @Override @@ -179,6 +149,6 @@ public class GuiPatternTerm extends GuiMEMonitorable { final int offsetPlayerSide = s.isPlayerSide() ? 5 : 3; - s.yPos = s.getY() + this.ySize - 78 - offsetPlayerSide; + // FIXME OH NOOOOO WE CANNOT, ITS FINAL s.yPos = s.getY() + this.ySize - 78 - offsetPlayerSide; } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiPriority.java b/src/main/java/appeng/client/gui/implementations/GuiPriority.java index ed3d08b7d..51d457130 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiPriority.java +++ b/src/main/java/appeng/client/gui/implementations/GuiPriority.java @@ -19,47 +19,33 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; - import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiNumberBox; -import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerPriority; import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketSwitchGuis; import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.IPriorityHost; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.util.InputMappings; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; +import java.io.IOException; + public class GuiPriority extends AEBaseGui { + private final AESubGui subGui; + private GuiNumberBox priority; - private GuiTabButton originalGuiBtn; - - private GuiButton plus1; - private GuiButton plus10; - private GuiButton plus100; - private GuiButton plus1000; - private GuiButton minus1; - private GuiButton minus10; - private GuiButton minus100; - private GuiButton minus1000; - - private GuiBridge OriginalGui; public GuiPriority(ContainerPriority container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); + this.subGui = new AESubGui(this, container.getPriorityHost()); } @Override @@ -72,23 +58,17 @@ public class GuiPriority extends AEBaseGui final int c = AEConfig.instance().priorityByStacksAmounts( 2 ); final int d = AEConfig.instance().priorityByStacksAmounts( 3 ); - this.addButton( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 32, 22, 20, "+" + a ) ); - this.addButton( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 32, 28, 20, "+" + b ) ); - this.addButton( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 32, 32, 20, "+" + c ) ); - this.addButton( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 32, 38, 20, "+" + d ) ); + this.addButton( new Button(this.guiLeft + 20, this.guiTop + 32, 22, 20, "+" + a, btn -> addQty(a) ) ); + this.addButton( new Button(this.guiLeft + 48, this.guiTop + 32, 28, 20, "+" + b, btn -> addQty(b) ) ); + this.addButton( new Button(this.guiLeft + 82, this.guiTop + 32, 32, 20, "+" + c, btn -> addQty(c) ) ); + this.addButton( new Button(this.guiLeft + 120, this.guiTop + 32, 38, 20, "+" + d, btn -> addQty(d) ) ); - this.addButton( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 69, 22, 20, "-" + a ) ); - this.addButton( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 69, 28, 20, "-" + b ) ); - this.addButton( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 69, 32, 20, "-" + c ) ); - this.addButton( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 69, 38, 20, "-" + d ) ); + this.addButton( new Button(this.guiLeft + 20, this.guiTop + 69, 22, 20, "-" + a, btn -> addQty(-a) ) ); + this.addButton( new Button(this.guiLeft + 48, this.guiTop + 69, 28, 20, "-" + b, btn -> addQty(-b) ) ); + this.addButton( new Button(this.guiLeft + 82, this.guiTop + 69, 32, 20, "-" + c, btn -> addQty(-c) ) ); + this.addButton( new Button(this.guiLeft + 120, this.guiTop + 69, 38, 20, "-" + d, btn -> addQty(-d) ) ); - final ItemStack myIcon = container.getPriorityHost().getItemStackRepresentation(); - this.OriginalGui = container.getPriorityHost().getGuiBridge(); - - if( this.OriginalGui != null && !myIcon.isEmpty() ) - { - this.addButton( this.originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), this.itemRender ) ); - } + this.subGui.addBackButton(this::addButton, 154, 0); this.priority = new GuiNumberBox( this.font, this.guiLeft + 62, this.guiTop + 57, 59, this.font.FONT_HEIGHT, Long.class ); this.priority.setEnableBackgroundDrawing( false ); @@ -106,31 +86,12 @@ public class GuiPriority extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/priority.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); - this.priority.drawTextBox(); - } - - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - if( btn == this.originalGuiBtn ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( this.OriginalGui ) ); - } - - final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000; - final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000; - - if( isPlus || isMinus ) - { - this.addQty( this.getQty( btn ) ); - } + this.priority.render(mouseX, mouseY, partialTicks); } private void addQty( final int i ) @@ -168,53 +129,69 @@ public class GuiPriority extends AEBaseGui // nope.. this.priority.setText( "0" ); } - catch( final IOException e ) - { - AELog.debug( e ); - } } @Override - protected void keyTyped( final char character, final int key ) throws IOException - { - if( !this.checkHotbarKeys( key ) ) - { - if( ( key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ) ) && this.priority - .textboxKeyTyped( character, key ) ) + public boolean charTyped(char character, int key) { + if (priority.charTyped(character, key)) { + String out = this.priority.getText(); + + boolean fixed = false; + while( out.startsWith( "0" ) && out.length() > 1 ) { - try - { - String out = this.priority.getText(); - - boolean fixed = false; - while( out.startsWith( "0" ) && out.length() > 1 ) - { - out = out.substring( 1 ); - fixed = true; - } - - if( fixed ) - { - this.priority.setText( out ); - } - - if( out.isEmpty() ) - { - out = "0"; - } - - NetworkHandler.instance().sendToServer( new PacketValueConfig( "PriorityHost.Priority", out ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + out = out.substring( 1 ); + fixed = true; } - else + + if( fixed ) { - super.keyTyped( character, key ); + this.priority.setText( out ); + } + + if( out.isEmpty() ) + { + out = "0"; + } + + NetworkHandler.instance().sendToServer( new PacketValueConfig( "PriorityHost.Priority", out ) ); + return true; + } + return false; + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) + { + if( !this.checkHotbarKeys( InputMappings.getInputByCode(keyCode, scanCode) ) ) + { + if( ( keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14 ) && this.priority + .keyPressed( keyCode, scanCode, p_keyPressed_3_ ) ) + { + String out = this.priority.getText(); + + boolean fixed = false; + while( out.startsWith( "0" ) && out.length() > 1 ) + { + out = out.substring( 1 ); + fixed = true; + } + + if( fixed ) + { + this.priority.setText( out ); + } + + if( out.isEmpty() ) + { + out = "0"; + } + + NetworkHandler.instance().sendToServer( new PacketValueConfig( "PriorityHost.Priority", out ) ); + return true; } } + + return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); } protected String getBackground() diff --git a/src/main/java/appeng/client/gui/implementations/GuiQNB.java b/src/main/java/appeng/client/gui/implementations/GuiQNB.java index 8b8576946..e82684597 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiQNB.java +++ b/src/main/java/appeng/client/gui/implementations/GuiQNB.java @@ -24,7 +24,6 @@ import net.minecraft.entity.player.PlayerInventory; import appeng.client.gui.AEBaseGui; import appeng.container.implementations.ContainerQNB; import appeng.core.localization.GuiText; -import appeng.tile.qnb.TileQuantumBridge; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -45,7 +44,7 @@ public class GuiQNB extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/chest.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java b/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java index 83714a81d..0555736d6 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java +++ b/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java @@ -30,7 +30,6 @@ import appeng.core.AELog; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; -import appeng.items.contents.QuartzKnifeObj; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -50,7 +49,7 @@ public class GuiQuartzKnife extends AEBaseGui { super.init(); - this.name = new TextFieldWidget( 0, this.font, this.guiLeft + 24, this.guiTop + 32, 79, this.font.FONT_HEIGHT ); + this.name = new TextFieldWidget( this.font, this.guiLeft + 24, this.guiTop + 32, 79, this.font.FONT_HEIGHT, "" ); this.name.setEnableBackgroundDrawing( false ); this.name.setMaxStringLength( 32 ); this.name.setTextColor( 0xFFFFFF ); @@ -66,32 +65,37 @@ public class GuiQuartzKnife extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/quartzknife.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); - this.name.drawTextBox(); + this.name.render(mouseX, mouseY, partialTicks); } @Override - protected void keyTyped( final char character, final int key ) throws IOException + public boolean charTyped(char character, int key) { + if( this.name.charTyped( character, key ) ) + { + final String Out = this.name.getText(); + container.setName( Out ); + NetworkHandler.instance().sendToServer( new PacketValueConfig( "QuartzKnife.Name", Out ) ); + return true; + } + + return super.charTyped(character, key); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) { - if( this.name.textboxKeyTyped( character, key ) ) + if( this.name.keyPressed( keyCode, scanCode, p_keyPressed_3_ ) ) { - try - { - final String Out = this.name.getText(); - container.setName( Out ); - NetworkHandler.instance().sendToServer( new PacketValueConfig( "QuartzKnife.Name", Out ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } - } - else - { - super.keyTyped( character, key ); + final String Out = this.name.getText(); + container.setName( Out ); + NetworkHandler.instance().sendToServer( new PacketValueConfig( "QuartzKnife.Name", Out ) ); + return true; } + + return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiSecurityStation.java b/src/main/java/appeng/client/gui/implementations/GuiSecurityStation.java index 32035d942..b88bf7938 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiSecurityStation.java +++ b/src/main/java/appeng/client/gui/implementations/GuiSecurityStation.java @@ -21,6 +21,7 @@ package appeng.client.gui.implementations; import java.io.IOException; +import net.minecraft.client.gui.widget.button.Button; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.SecurityPermissions; @@ -54,45 +55,8 @@ public class GuiSecurityStation extends GuiMEMonitorable toggleOption(SecurityPermissions.INJECT) ) ); - this.addButton( this.extract = new GuiToggleButton( this.guiLeft + 56 + 18, top, 11 * 16 + 1, 12 * 16 + 1, SecurityPermissions.EXTRACT - .getTranslationKey(), SecurityPermissions.EXTRACT.getUnlocalizedTip() ) ); + this.extract = this.addButton( new GuiToggleButton( this.guiLeft + 56 + 18, top, 11 * 16 + 1, 12 * 16 + 1, SecurityPermissions.EXTRACT + .getTranslatedName(), SecurityPermissions.EXTRACT.getTranslatedTip(), btn -> toggleOption(SecurityPermissions.EXTRACT ) ) ); - this.addButton( this.craft = new GuiToggleButton( this.guiLeft + 56 + 18 * 2, top, 11 * 16 + 2, 12 * 16 + 2, SecurityPermissions.CRAFT - .getTranslationKey(), SecurityPermissions.CRAFT.getUnlocalizedTip() ) ); + this.craft = this.addButton( new GuiToggleButton( this.guiLeft + 56 + 18 * 2, top, 11 * 16 + 2, 12 * 16 + 2, SecurityPermissions.CRAFT + .getTranslatedName(), SecurityPermissions.CRAFT.getTranslatedTip(), btn -> toggleOption(SecurityPermissions.CRAFT ) ) ); - this.addButton( this.build = new GuiToggleButton( this.guiLeft + 56 + 18 * 3, top, 11 * 16 + 3, 12 * 16 + 3, SecurityPermissions.BUILD - .getTranslationKey(), SecurityPermissions.BUILD.getUnlocalizedTip() ) ); + this.build = this.addButton( new GuiToggleButton( this.guiLeft + 56 + 18 * 3, top, 11 * 16 + 3, 12 * 16 + 3, SecurityPermissions.BUILD + .getTranslatedName(), SecurityPermissions.BUILD.getTranslatedTip(), btn -> toggleOption(SecurityPermissions.BUILD ) ) ); - this.addButton( this.security = new GuiToggleButton( this.guiLeft + 56 + 18 * 4, top, 11 * 16 + 4, 12 * 16 + 4, SecurityPermissions.SECURITY - .getTranslationKey(), SecurityPermissions.SECURITY.getUnlocalizedTip() ) ); + this.security = this.addButton( new GuiToggleButton( this.guiLeft + 56 + 18 * 4, top, 11 * 16 + 4, 12 * 16 + 4, SecurityPermissions.SECURITY + .getTranslatedName(), SecurityPermissions.SECURITY.getTranslatedTip(), btn -> toggleOption(SecurityPermissions.SECURITY ) ) ); } @Override diff --git a/src/main/java/appeng/client/gui/implementations/GuiSkyChest.java b/src/main/java/appeng/client/gui/implementations/GuiSkyChest.java index 1a7563c04..64e8090ff 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiSkyChest.java +++ b/src/main/java/appeng/client/gui/implementations/GuiSkyChest.java @@ -49,7 +49,7 @@ public class GuiSkyChest extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { bindTexture(TEXTURE); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiSpatialIOPort.java b/src/main/java/appeng/client/gui/implementations/GuiSpatialIOPort.java index 7c5e984b3..bf9553d64 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiSpatialIOPort.java +++ b/src/main/java/appeng/client/gui/implementations/GuiSpatialIOPort.java @@ -19,23 +19,16 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.fml.client.gui.GuiUtils; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - import appeng.api.config.Settings; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiImgButton; import appeng.container.implementations.ContainerSpatialIOPort; import appeng.core.AEConfig; import appeng.core.localization.GuiText; -import appeng.tile.spatial.TileSpatialIOPort; import appeng.util.Platform; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiSpatialIOPort extends AEBaseGui @@ -48,29 +41,21 @@ public class GuiSpatialIOPort extends AEBaseGui this.ySize = 199; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.units ) - { - AEConfig.instance().nextPowerUnit( backwards ); - this.units.set( AEConfig.instance().selectedPowerUnit() ); - } - } - @Override public void init() { super.init(); - this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit() ); + this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit(), btn -> selectNextUnit() ); this.addButton( this.units ); } + private void selectNextUnit() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + AEConfig.instance().nextPowerUnit( backwards ); + this.units.set( AEConfig.instance().selectedPowerUnit() ); + } + @Override public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) { @@ -97,7 +82,7 @@ public class GuiSpatialIOPort extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/spatialio.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/implementations/GuiStorageBus.java b/src/main/java/appeng/client/gui/implementations/GuiStorageBus.java index 8d6afa7b3..ebe2251de 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiStorageBus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiStorageBus.java @@ -19,30 +19,18 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.util.text.ITextComponent; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.ActionItems; -import appeng.api.config.FuzzyMode; -import appeng.api.config.Settings; -import appeng.api.config.StorageFilter; +import appeng.api.config.*; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerPriority; import appeng.container.implementations.ContainerStorageBus; -import appeng.core.AELog; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketConfigButton; import appeng.core.sync.packets.PacketSwitchGuis; import appeng.core.sync.packets.PacketValueConfig; -import appeng.parts.misc.PartStorageBus; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; public class GuiStorageBus extends GuiUpgradeable @@ -50,9 +38,6 @@ public class GuiStorageBus extends GuiUpgradeable private GuiImgButton rwMode; private GuiImgButton storageFilter; - private GuiTabButton priority; - private GuiImgButton partition; - private GuiImgButton clear; public GuiStorageBus(ContainerStorageBus container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); @@ -62,19 +47,17 @@ public class GuiStorageBus extends GuiUpgradeable @Override protected void addButtons() { - this.clear = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE ); - this.partition = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH ); - this.rwMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE ); - this.storageFilter = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY ); - this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + addButton( new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE, btn -> clear() ) ); + addButton( new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH, btn -> partition() ) ); + this.rwMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE, btn -> toggleReadWriteMode() ); + this.storageFilter = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY, btn -> toggleStorageFilterMode() ); + this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed ); - this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) ); + this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) ); this.addButton( this.storageFilter ); this.addButton( this.fuzzyMode ); this.addButton( this.rwMode ); - this.addButton( this.partition ); - this.addButton( this.clear ); } @Override @@ -105,39 +88,26 @@ public class GuiStorageBus extends GuiUpgradeable return "guis/storagebus.png"; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - try - { - if( btn == this.partition ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) ); - } - else if( btn == this.clear ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) ); - } - else if( btn == this.priority ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - else if( btn == this.rwMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.rwMode.getSetting(), backwards ) ); - } - else if( btn == this.storageFilter ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.storageFilter.getSetting(), backwards ) ); - } - } - catch( final IOException e ) - { - AELog.debug( e ); - } + private void partition() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) ); } + + private void clear() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) ); + } + + private void openPriorityGui() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); + } + + private void toggleReadWriteMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.rwMode.getSetting(), backwards ) ); + } + + private void toggleStorageFilterMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.storageFilter.getSetting(), backwards ) ); + } + } diff --git a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java index 99000c102..cc277acde 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java @@ -19,8 +19,7 @@ package appeng.client.gui.implementations; -import java.io.IOException; - +import net.minecraft.client.gui.widget.button.Button; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.FuzzyMode; @@ -64,7 +63,7 @@ public class GuiUpgradeable extends AEBaseGui protected boolean hasToolbox() { - return ( (ContainerUpgradeable) this.container ).hasToolbox(); + return ( this.container ).hasToolbox(); } @Override @@ -76,10 +75,10 @@ public class GuiUpgradeable extends AEBaseGui protected void addButtons() { - this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE ); - this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); - this.craftMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_ONLY, YesNo.NO ); - this.schedulingMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT ); + this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, this::actionPerformed ); + this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed ); + this.craftMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_ONLY, YesNo.NO, this::actionPerformed ); + this.schedulingMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT, this::actionPerformed ); this.addButton( this.craftMode ); this.addButton( this.redstoneMode ); @@ -115,7 +114,7 @@ public class GuiUpgradeable extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.handleButtonVisibility(); @@ -166,12 +165,11 @@ public class GuiUpgradeable extends AEBaseGui return this.bc instanceof PartImportBus ? GuiText.ImportBus : GuiText.ExportBus; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException + // FIXME: replace with individual methods + protected void actionPerformed( final Button btn ) { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); + // Detect right-clicks + final boolean backwards = minecraft.mouseHelper.isRightDown(); if( btn == this.redstoneMode ) { diff --git a/src/main/java/appeng/client/gui/implementations/GuiVibrationChamber.java b/src/main/java/appeng/client/gui/implementations/GuiVibrationChamber.java index a11335547..89a937d56 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiVibrationChamber.java +++ b/src/main/java/appeng/client/gui/implementations/GuiVibrationChamber.java @@ -71,7 +71,7 @@ public class GuiVibrationChamber extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/vibchamber.png" ); this.pb.x = 99 + this.guiLeft; diff --git a/src/main/java/appeng/client/gui/implementations/GuiWireless.java b/src/main/java/appeng/client/gui/implementations/GuiWireless.java index 6583ddce7..5c9656cfe 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWireless.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWireless.java @@ -19,23 +19,16 @@ package appeng.client.gui.implementations; -import java.io.IOException; - -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.fml.client.gui.GuiUtils; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - import appeng.api.config.Settings; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiImgButton; import appeng.container.implementations.ContainerWireless; import appeng.core.AEConfig; import appeng.core.localization.GuiText; -import appeng.tile.networking.TileWireless; import appeng.util.Platform; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiWireless extends AEBaseGui @@ -48,29 +41,21 @@ public class GuiWireless extends AEBaseGui this.ySize = 166; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean backwards = Mouse.isButtonDown( 1 ); - - if( btn == this.units ) - { - AEConfig.instance().nextPowerUnit( backwards ); - this.units.set( AEConfig.instance().selectedPowerUnit() ); - } - } - @Override public void init() { super.init(); - this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit() ); + this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance().selectedPowerUnit(), btn -> toggleUnits() ); this.addButton( this.units ); } + private void toggleUnits() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + AEConfig.instance().nextPowerUnit( backwards ); + this.units.set( AEConfig.instance().selectedPowerUnit() ); + } + @Override public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) { @@ -90,7 +75,7 @@ public class GuiWireless extends AEBaseGui } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { this.bindTexture( "guis/wireless.png" ); GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME this.zlevel was used */ ); diff --git a/src/main/java/appeng/client/gui/widgets/GuiImgButton.java b/src/main/java/appeng/client/gui/widgets/GuiImgButton.java index 08de6d0bb..dc38d651f 100644 --- a/src/main/java/appeng/client/gui/widgets/GuiImgButton.java +++ b/src/main/java/appeng/client/gui/widgets/GuiImgButton.java @@ -19,59 +19,39 @@ package appeng.client.gui.widgets; +import appeng.api.config.*; +import appeng.core.localization.ButtonToolTips; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; + import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.ResourceLocation; -import net.minecraft.client.resources.I18n; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.ActionItems; -import appeng.api.config.CondenserOutput; -import appeng.api.config.FullnessMode; -import appeng.api.config.FuzzyMode; -import appeng.api.config.ItemSubstitution; -import appeng.api.config.LevelType; -import appeng.api.config.OperationMode; -import appeng.api.config.PowerUnits; -import appeng.api.config.RedstoneMode; -import appeng.api.config.RelativeDirection; -import appeng.api.config.SchedulingMode; -import appeng.api.config.SearchBoxMode; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.StorageFilter; -import appeng.api.config.TerminalStyle; -import appeng.api.config.ViewItems; -import appeng.api.config.YesNo; -import appeng.core.localization.ButtonToolTips; - public class GuiImgButton extends Button implements ITooltip { private static final Pattern COMPILE = Pattern.compile( "%s" ); private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL ); + public static final ResourceLocation TEXTURE_STATES = new ResourceLocation("appliedenergistics2", "textures/guis/states.png"); private static Map appearances; private final Enum buttonSetting; private boolean halfSize = false; private String fillVar; private Enum currentValue; - public GuiImgButton( final int x, final int y, final Enum idx, final Enum val ) + public GuiImgButton( final int x, final int y, final Enum idx, final Enum val, IPressable onPress ) { - super( 0, 0, 16, "" ); + super( x, y, 16, 16, "", onPress ); this.buttonSetting = idx; this.currentValue = val; - this.x = x; - this.y = y; - this.width = 16; - this.height = 16; if( appearances == null ) { @@ -84,9 +64,9 @@ public class GuiImgButton extends Button implements ITooltip this.registerApp( 16 * 9, Settings.ACCESS, AccessRestriction.WRITE, ButtonToolTips.IOMode, ButtonToolTips.Write ); this.registerApp( 16 * 9 + 2, Settings.ACCESS, AccessRestriction.READ_WRITE, ButtonToolTips.IOMode, ButtonToolTips.ReadWrite ); - this.registerApp( 16 * 10, Settings.POWER_UNITS, PowerUnits.AE, ButtonToolTips.PowerUnits, PowerUnits.AE.unlocalizedName ); - this.registerApp( 16 * 10 + 1, Settings.POWER_UNITS, PowerUnits.EU, ButtonToolTips.PowerUnits, PowerUnits.EU.unlocalizedName ); - this.registerApp( 16 * 10 + 4, Settings.POWER_UNITS, PowerUnits.RF, ButtonToolTips.PowerUnits, PowerUnits.RF.unlocalizedName ); + this.registerApp( 16 * 10, Settings.POWER_UNITS, PowerUnits.AE, ButtonToolTips.PowerUnits, PowerUnits.AE.textComponent() ); + this.registerApp( 16 * 10 + 1, Settings.POWER_UNITS, PowerUnits.EU, ButtonToolTips.PowerUnits, PowerUnits.EU.textComponent() ); + this.registerApp( 16 * 10 + 4, Settings.POWER_UNITS, PowerUnits.RF, ButtonToolTips.PowerUnits, PowerUnits.RF.textComponent() ); this.registerApp( 3, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE, ButtonToolTips.RedstoneMode, ButtonToolTips.AlwaysActive ); this.registerApp( 0, Settings.REDSTONE_CONTROLLED, RedstoneMode.LOW_SIGNAL, ButtonToolTips.RedstoneMode, ButtonToolTips.ActiveWithoutSignal ); @@ -177,38 +157,48 @@ public class GuiImgButton extends Button implements ITooltip } } - private void registerApp( final int iconIndex, final Settings setting, final Enum val, final ButtonToolTips title, final Object hint ) + private void registerApp( final int iconIndex, final Settings setting, final Enum val, final ButtonToolTips title, final ITextComponent hint ) { final ButtonAppearance a = new ButtonAppearance(); - a.displayName = title.getUnlocalized(); - a.displayValue = (String) ( hint instanceof String ? hint : ( (ButtonToolTips) hint ).getUnlocalized() ); + a.displayName = title.getTranslationKey(); + a.displayValue = hint; a.index = iconIndex; appearances.put( new EnumPair( setting, val ), a ); } + private void registerApp( final int iconIndex, final Settings setting, final Enum val, final ButtonToolTips title, final ButtonToolTips hint ) + { + registerApp(iconIndex, setting, val, title, hint.getTranslationKey()); + } + public void setVisibility( final boolean vis ) { this.visible = vis; - this.enabled = vis; + this.active = vis; } @Override - public void drawButton( final Minecraft par1Minecraft, final int par2, final int par3, float partial ) - { + public void renderButton(final int mouseX, final int mouseY, float partial) { + + Minecraft minecraft = Minecraft.getInstance(); + if( this.visible ) { final int iconIndex = this.getIconIndex(); + TextureManager textureManager = minecraft.getTextureManager(); + textureManager.bindTexture(TEXTURE_STATES); + RenderSystem.disableDepthTest(); if( this.halfSize ) { this.width = 8; this.height = 8; - GlStateManager.pushMatrix(); - GlStateManager.translate( this.x, this.y, 0.0F ); - GlStateManager.scale( 0.5f, 0.5f, 0.5f ); + RenderSystem.pushMatrix(); + RenderSystem.translatef( this.x, this.y, 0.0F ); + RenderSystem.scalef( 0.5f, 0.5f, 0.5f ); - if( this.enabled ) + if( this.active ) { RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); } @@ -217,21 +207,16 @@ public class GuiImgButton extends Button implements ITooltip RenderSystem.color4f( 0.5f, 0.5f, 0.5f, 1.0f ); } - par1Minecraft.renderEngine.bindTexture( new ResourceLocation( "appliedenergistics2", "textures/guis/states.png" ) ); - this.hovered = par2 >= this.x && par3 >= this.y && par2 < this.x + this.width && par3 < this.y + this.height; - - final int uv_y = (int) Math.floor( iconIndex / 16 ); + final int uv_y = (int) Math.floor( iconIndex / 16.0f ); final int uv_x = iconIndex - uv_y * 16; - this.drawTexturedModalRect( 0, 0, 256 - 16, 256 - 16, 16, 16 ); - this.drawTexturedModalRect( 0, 0, uv_x * 16, uv_y * 16, 16, 16 ); - this.mouseDragged( par1Minecraft, par2, par3 ); - - GlStateManager.popMatrix(); + GuiUtils.drawTexturedModalRect( 0, 0, 256 - 16, 256 - 16, 16, 16, 0 ); + GuiUtils.drawTexturedModalRect( 0, 0, uv_x * 16, uv_y * 16, 16, 16, 0 ); + RenderSystem.popMatrix(); } else { - if( this.enabled ) + if( this.active ) { RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); } @@ -240,16 +225,13 @@ public class GuiImgButton extends Button implements ITooltip RenderSystem.color4f( 0.5f, 0.5f, 0.5f, 1.0f ); } - par1Minecraft.renderEngine.bindTexture( new ResourceLocation( "appliedenergistics2", "textures/guis/states.png" ) ); - this.hovered = par2 >= this.x && par3 >= this.y && par2 < this.x + this.width && par3 < this.y + this.height; - final int uv_y = (int) Math.floor( iconIndex / 16 ); final int uv_x = iconIndex - uv_y * 16; - this.drawTexturedModalRect( this.x, this.y, 256 - 16, 256 - 16, 16, 16 ); - this.drawTexturedModalRect( this.x, this.y, uv_x * 16, uv_y * 16, 16, 16 ); - this.mouseDragged( par1Minecraft, par2, par3 ); + GuiUtils.drawTexturedModalRect( this.x, this.y, 256 - 16, 256 - 16, 16, 16, 0 ); + GuiUtils.drawTexturedModalRect( this.x, this.y, uv_x * 16, uv_y * 16, 16, 16, 0 ); } + RenderSystem.enableDepthTest(); } RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); } @@ -281,8 +263,8 @@ public class GuiImgButton extends Button implements ITooltip @Override public String getMessage() { - String displayName = null; - String displayValue = null; + ITextComponent displayName = null; + ITextComponent displayValue = null; if( this.buttonSetting != null && this.currentValue != null ) { @@ -298,17 +280,8 @@ public class GuiImgButton extends Button implements ITooltip if( displayName != null ) { - String name = I18n.format( displayName ); - String value = I18n.format( displayValue ); - - if( name == null || name.isEmpty() ) - { - name = displayName; - } - if( value == null || value.isEmpty() ) - { - value = displayValue; - } + String name = displayName.getString(); + String value = displayValue.getString(); if( this.fillVar != null ) { @@ -428,7 +401,7 @@ public class GuiImgButton extends Button implements ITooltip private static class ButtonAppearance { public int index; - public String displayName; - public String displayValue; + public ITextComponent displayName; + public ITextComponent displayValue; } } diff --git a/src/main/java/appeng/client/gui/widgets/GuiNumberBox.java b/src/main/java/appeng/client/gui/widgets/GuiNumberBox.java index 38d014ed2..f9126bd44 100644 --- a/src/main/java/appeng/client/gui/widgets/GuiNumberBox.java +++ b/src/main/java/appeng/client/gui/widgets/GuiNumberBox.java @@ -22,7 +22,7 @@ package appeng.client.gui.widgets; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.widget.TextFieldWidget; - +// FIXME: Fix this piece of crap (i.e. onChange listener) public class GuiNumberBox extends TextFieldWidget { @@ -30,7 +30,7 @@ public class GuiNumberBox extends TextFieldWidget public GuiNumberBox( final FontRenderer fontRenderer, final int x, final int y, final int width, final int height, final Class type ) { - super( 0, fontRenderer, x, y, width, height ); + super( fontRenderer, x, y, width, height, "0" ); this.type = type; } diff --git a/src/main/java/appeng/client/gui/widgets/GuiProgressBar.java b/src/main/java/appeng/client/gui/widgets/GuiProgressBar.java index 0bfa159ef..331daaa1b 100644 --- a/src/main/java/appeng/client/gui/widgets/GuiProgressBar.java +++ b/src/main/java/appeng/client/gui/widgets/GuiProgressBar.java @@ -20,14 +20,16 @@ package appeng.client.gui.widgets; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.util.ResourceLocation; import appeng.container.interfaces.IProgressProvider; import appeng.core.localization.GuiText; +import net.minecraftforge.fml.client.gui.GuiUtils; -public class GuiProgressBar extends Button implements ITooltip +public class GuiProgressBar extends Widget implements ITooltip { private final IProgressProvider source; @@ -45,13 +47,9 @@ public class GuiProgressBar extends Button implements ITooltip public GuiProgressBar( final IProgressProvider source, final String texture, final int posX, final int posY, final int u, final int y, final int width, final int height, final Direction dir, final String title ) { - super( posX, posY, width, "" ); + super( posX, posY, width, height, "" ); this.source = source; - this.x = posX; - this.y = posY; this.texture = new ResourceLocation( "appliedenergistics2", "textures/" + texture ); - this.width = width; - this.height = height; this.fill_u = u; this.fill_v = y; this.layout = dir; @@ -59,26 +57,24 @@ public class GuiProgressBar extends Button implements ITooltip } @Override - public void drawButton( final Minecraft par1Minecraft, final int par2, final int par3, final float partial ) + public void renderButton( final int par2, final int par3, final float partial ) { if( this.visible ) { - par1Minecraft.getTextureManager().bindTexture( this.texture ); + Minecraft.getInstance().getTextureManager().bindTexture( this.texture ); final int max = this.source.getMaxProgress(); final int current = this.source.getCurrentProgress(); if( this.layout == Direction.VERTICAL ) { final int diff = this.height - ( max > 0 ? ( this.height * current ) / max : 0 ); - this.drawTexturedModalRect( this.x, this.y + diff, this.fill_u, this.fill_v + diff, this.width, this.height - diff ); + GuiUtils.drawTexturedModalRect( this.x, this.y + diff, this.fill_u, this.fill_v + diff, this.width, this.height - diff, 0 ); } else { final int diff = this.width - ( max > 0 ? ( this.width * current ) / max : 0 ); - this.drawTexturedModalRect( this.x, this.y, this.fill_u + diff, this.fill_v, this.width - diff, this.height ); + GuiUtils.drawTexturedModalRect( this.x, this.y, this.fill_u + diff, this.fill_v, this.width - diff, this.height, 0 ); } - - this.mouseDragged( par1Minecraft, par2, par3 ); } } diff --git a/src/main/java/appeng/client/gui/widgets/GuiTabButton.java b/src/main/java/appeng/client/gui/widgets/GuiTabButton.java index deb7a62e2..018210e5f 100644 --- a/src/main/java/appeng/client/gui/widgets/GuiTabButton.java +++ b/src/main/java/appeng/client/gui/widgets/GuiTabButton.java @@ -19,34 +19,31 @@ package appeng.client.gui.widgets; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.RenderItem; import net.minecraft.item.ItemStack; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiTabButton extends Button implements ITooltip { + public static final ResourceLocation TEXTURE_STATES = new ResourceLocation("appliedenergistics2", "textures/guis/states.png"); private final ItemRenderer itemRenderer; - private final String message; private int hideEdge = 0; private int myIcon = -1; private ItemStack myItem; - public GuiTabButton( final int x, final int y, final int ico, final String message, final ItemRenderer ir ) + public GuiTabButton( final int x, final int y, final int ico, final String message, final ItemRenderer ir, IPressable onPress ) { - super( 0, 0, 16, "" ); + super( x, y, 22, 22, message, onPress ); - this.x = x; - this.y = y; - this.width = 22; - this.height = 22; this.myIcon = ico; - this.message = message; this.itemRenderer = ir; } @@ -59,65 +56,51 @@ public class GuiTabButton extends Button implements ITooltip * @param message mouse over message * @param ir renderer */ - public GuiTabButton( final int x, final int y, final ItemStack ico, final String message, final ItemRenderer ir ) + public GuiTabButton( final int x, final int y, final ItemStack ico, final String message, final ItemRenderer ir, IPressable onPress ) { - super( 0, 0, 16, "" ); - this.x = x; - this.y = y; - this.width = 22; - this.height = 22; + super( x, y, 22, 22, message, onPress ); this.myItem = ico; - this.message = message; this.itemRenderer = ir; } @Override - public void drawButton( final Minecraft minecraft, final int x, final int y, float partial ) + public void renderButton( final int x, final int y, float partial ) { + final Minecraft minecraft = Minecraft.getInstance(); + if( this.visible ) { RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); - minecraft.renderEngine.bindTexture( new ResourceLocation( "appliedenergistics2", "textures/guis/states.png" ) ); - this.hovered = x >= this.x && y >= this.y && x < this.x + this.width && y < this.y + this.height; + minecraft.textureManager.bindTexture(TEXTURE_STATES); int uv_x = ( this.hideEdge > 0 ? 11 : 13 ); final int offsetX = this.hideEdge > 0 ? 1 : 0; - this.drawTexturedModalRect( this.x, this.y, uv_x * 16, 0, 25, 22 ); + GuiUtils.drawTexturedModalRect( this.x, this.y, uv_x * 16, 0, 25, 22, 0 ); if( this.myIcon >= 0 ) { final int uv_y = (int) Math.floor( this.myIcon / 16 ); uv_x = this.myIcon - uv_y * 16; - this.drawTexturedModalRect( offsetX + this.x + 3, this.y + 3, uv_x * 16, uv_y * 16, 16, 16 ); + GuiUtils.drawTexturedModalRect( offsetX + this.x + 3, this.y + 3, uv_x * 16, uv_y * 16, 16, 16, 0 ); } - this.mouseDragged( minecraft, x, y ); - if( this.myItem != null ) { - this.zLevel = 100.0F; this.itemRenderer.zLevel = 100.0F; RenderSystem.enableDepthTest(); - RenderHelper.enableGUIStandardItemLighting(); +// FIXME RenderHelper.enableGUIStandardItemLighting(); this.itemRenderer.renderItemAndEffectIntoGUI( this.myItem, offsetX + this.x + 3, this.y + 3 ); RenderSystem.disableDepthTest(); this.itemRenderer.zLevel = 0.0F; - this.zLevel = 0.0F; } } } - @Override - public String getMessage() - { - return this.message; - } - @Override public int xPos() { diff --git a/src/main/java/appeng/client/gui/widgets/GuiToggleButton.java b/src/main/java/appeng/client/gui/widgets/GuiToggleButton.java index a5495aab4..c72a58d39 100644 --- a/src/main/java/appeng/client/gui/widgets/GuiToggleButton.java +++ b/src/main/java/appeng/client/gui/widgets/GuiToggleButton.java @@ -21,15 +21,17 @@ package appeng.client.gui.widgets; import java.util.regex.Pattern; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.ResourceLocation; import net.minecraft.client.resources.I18n; +import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiToggleButton extends Button implements ITooltip { + public static final ResourceLocation TEXTURE_STATES = new ResourceLocation("appliedenergistics2", "textures/guis/states.png"); private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL ); private final int iconIdxOn; private final int iconIdxOff; @@ -39,17 +41,13 @@ public class GuiToggleButton extends Button implements ITooltip private boolean isActive; - public GuiToggleButton( final int x, final int y, final int on, final int off, final String displayName, final String displayHint ) + public GuiToggleButton( final int x, final int y, final int on, final int off, final String displayName, final String displayHint, IPressable onPress ) { - super( 0, 0, 16, "" ); + super( x, y, 16, 16, "", onPress ); this.iconIdxOn = on; this.iconIdxOff = off; this.displayName = displayName; this.displayHint = displayHint; - this.x = x; - this.y = y; - this.width = 16; - this.height = 16; } public void setState( final boolean isOn ) @@ -58,22 +56,20 @@ public class GuiToggleButton extends Button implements ITooltip } @Override - public void drawButton( final Minecraft par1Minecraft, final int par2, final int par3, final float partial ) + public void renderButton( final int mouseX, final int mouseY, final float partial ) { if( this.visible ) { final int iconIndex = this.getIconIndex(); RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); - par1Minecraft.renderEngine.bindTexture( new ResourceLocation( "appliedenergistics2", "textures/guis/states.png" ) ); - this.hovered = par2 >= this.x && par3 >= this.y && par2 < this.x + this.width && par3 < this.y + this.height; + Minecraft.getInstance().textureManager.bindTexture( TEXTURE_STATES ); final int uv_y = (int) Math.floor( iconIndex / 16 ); final int uv_x = iconIndex - uv_y * 16; - this.drawTexturedModalRect( this.x, this.y, 256 - 16, 256 - 16, 16, 16 ); - this.drawTexturedModalRect( this.x, this.y, uv_x * 16, uv_y * 16, 16, 16 ); - this.mouseDragged( par1Minecraft, par2, par3 ); + GuiUtils.drawTexturedModalRect( this.x, this.y, 256 - 16, 256 - 16, 16, 16, 0 ); + GuiUtils.drawTexturedModalRect( this.x, this.y, uv_x * 16, uv_y * 16, 16, 16, 0 ); } } diff --git a/src/main/java/appeng/client/gui/widgets/MEGuiTextField.java b/src/main/java/appeng/client/gui/widgets/MEGuiTextField.java index 9e322c558..b6eaa34d7 100644 --- a/src/main/java/appeng/client/gui/widgets/MEGuiTextField.java +++ b/src/main/java/appeng/client/gui/widgets/MEGuiTextField.java @@ -19,10 +19,11 @@ package appeng.client.gui.widgets; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; @@ -39,10 +40,6 @@ public class MEGuiTextField extends TextFieldWidget { private static final int PADDING = 2; - private final int _xPos; - private final int _yPos; - private final int _width; - private final int _height; private final int _fontPad; private int selectionColor = 0xFF00FF00; @@ -58,21 +55,19 @@ public class MEGuiTextField extends TextFieldWidget */ public MEGuiTextField( final FontRenderer fontRenderer, final int xPos, final int yPos, final int width, final int height ) { - super( 0, fontRenderer, xPos + PADDING, yPos + PADDING, width - 2 * PADDING - fontRenderer.getCharWidth( '_' ), height - 2 * PADDING ); + super( fontRenderer, xPos + PADDING, yPos + PADDING, width - 2 * PADDING - (int) fontRenderer.getCharWidth( '_' ), height - 2 * PADDING, "" ); - this._fontPad = fontRenderer.getCharWidth( '_' ); - this._xPos = xPos; - this._yPos = yPos; - this._width = width; - this._height = height; + this._fontPad = (int) fontRenderer.getCharWidth( '_' ); } @Override - public boolean mouseClicked( final int xPos, final int yPos, final int button ) + public boolean mouseClicked( final double xPos, final double yPos, final int button ) { - super.mouseClicked( xPos, yPos, button ); + if (!super.mouseClicked( xPos, yPos, button )) { + return false; + } - final boolean requiresFocus = this.isMouseIn( xPos, yPos ); + final boolean requiresFocus = this.isMouseOver( xPos, yPos ); if( !this.isFocused() ) { this.setFocused2( requiresFocus ); @@ -81,22 +76,6 @@ public class MEGuiTextField extends TextFieldWidget return true; } - /** - * Checks if the mouse is within the element - * - * @param xCoord current x coord of the mouse - * @param yCoord current y coord of the mouse - * - * @return true if mouse position is within the text field area - */ - public boolean isMouseIn( final int xCoord, final int yCoord ) - { - final boolean withinXRange = this._xPos <= xCoord && xCoord < this._xPos + this._width; - final boolean withinYRange = this._yPos <= yCoord && yCoord < this._yPos + this._height; - - return withinXRange && withinYRange; - } - public void selectAll() { this.setCursorPosition( 0 ); @@ -109,7 +88,7 @@ public class MEGuiTextField extends TextFieldWidget } @Override - public void drawTextBox() + public void renderButton(int mouseX, int mouseY, float partial) { if( this.getVisible() ) { @@ -123,7 +102,7 @@ public class MEGuiTextField extends TextFieldWidget fill( this.x - PADDING + 1, this.y - PADDING + 1, this.x + this.width + this._fontPad + PADDING - 1, this.y + this.height + PADDING - 1, 0xFFA8A8A8 ); } - super.drawTextBox(); + super.renderButton(mouseX, mouseY, partial); } } @@ -173,16 +152,16 @@ public class MEGuiTextField extends TextFieldWidget float alpha = ( this.selectionColor >> 24 & 255 ) / 255.0F; RenderSystem.color4f( red, green, blue, alpha ); - GlStateManager.disableTexture2D(); - GlStateManager.enableColorLogic(); - GlStateManager.colorLogicOp( GlStateManager.LogicOp.OR_REVERSE ); + RenderSystem.disableTexture(); + RenderSystem.enableColorLogicOp(); + RenderSystem.logicOp( GlStateManager.LogicOp.OR_REVERSE ); bufferbuilder.begin( 7, DefaultVertexFormats.POSITION ); bufferbuilder.pos( startX, endY, 0.0D ).endVertex(); bufferbuilder.pos( endX, endY, 0.0D ).endVertex(); bufferbuilder.pos( endX, startY, 0.0D ).endVertex(); bufferbuilder.pos( startX, startY, 0.0D ).endVertex(); tessellator.draw(); - GlStateManager.disableColorLogic(); + RenderSystem.disableColorLogicOp(); RenderSystem.enableTexture(); } diff --git a/src/main/java/appeng/client/render/DelegateBakedModel.java b/src/main/java/appeng/client/render/DelegateBakedModel.java index bfafcb2dc..f4a4dc803 100644 --- a/src/main/java/appeng/client/render/DelegateBakedModel.java +++ b/src/main/java/appeng/client/render/DelegateBakedModel.java @@ -21,22 +21,46 @@ package appeng.client.render; import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.model.ItemOverrideList; +import net.minecraft.util.Direction; import org.apache.commons.lang3.tuple.Pair; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import javax.annotation.Nullable; +import java.util.List; +import java.util.Random; + public abstract class DelegateBakedModel implements IBakedModel { - private IBakedModel baseModel; + private final IBakedModel baseModel; protected DelegateBakedModel( IBakedModel base ) { this.baseModel = base; } + @Override + @Deprecated + public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { + return baseModel.getQuads(state, side, rand); + } + + @Override + public boolean func_230044_c_() { + return baseModel.func_230044_c_(); + } + + @Override + public ItemOverrideList getOverrides() { + return baseModel.getOverrides(); + } + @Override public IBakedModel handlePerspective( ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat ) { @@ -62,6 +86,19 @@ public abstract class DelegateBakedModel implements IBakedModel return this.baseModel.isAmbientOcclusion(); } + @Override + public boolean isGui3d() + { + return this.baseModel.isGui3d(); + } + + @Override + public boolean isBuiltInRenderer() + { + return this.baseModel.isBuiltInRenderer(); + } + + public IBakedModel getBaseModel() { return this.baseModel; diff --git a/src/main/java/appeng/client/render/DummyFluidDispatcherBakedModel.java b/src/main/java/appeng/client/render/DummyFluidDispatcherBakedModel.java index 70bef8da1..2440cde46 100644 --- a/src/main/java/appeng/client/render/DummyFluidDispatcherBakedModel.java +++ b/src/main/java/appeng/client/render/DummyFluidDispatcherBakedModel.java @@ -32,6 +32,8 @@ import net.minecraft.client.renderer.TransformationMatrix; import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ItemOverrideList; +import net.minecraft.client.renderer.model.Material; +import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.entity.LivingEntity; import net.minecraft.fluid.Fluids; @@ -53,9 +55,9 @@ import appeng.fluids.items.FluidDummyItem; */ public class DummyFluidDispatcherBakedModel extends DelegateBakedModel { - private final Function bakedTextureGetter; + private final Function bakedTextureGetter; - public DummyFluidDispatcherBakedModel( IBakedModel baseModel, Function bakedTextureGetter ) + public DummyFluidDispatcherBakedModel( IBakedModel baseModel, Function bakedTextureGetter ) { super( baseModel ); this.bakedTextureGetter = bakedTextureGetter; @@ -108,7 +110,9 @@ public class DummyFluidDispatcherBakedModel extends DelegateBakedModel } FluidAttributes attributes = fluidStack.getFluid().getAttributes(); - TextureAtlasSprite sprite = DummyFluidDispatcherBakedModel.this.bakedTextureGetter.apply( attributes.getStillTexture( fluidStack ) ); + ResourceLocation stillTexture = attributes.getStillTexture(fluidStack); + Material stillMaterial = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, stillTexture); + TextureAtlasSprite sprite = DummyFluidDispatcherBakedModel.this.bakedTextureGetter.apply(stillMaterial); if( sprite == null ) { return new DummyFluidBakedModel( ImmutableList.of() ); diff --git a/src/main/java/appeng/client/render/DummyFluidItemModel.java b/src/main/java/appeng/client/render/DummyFluidItemModel.java index 6dd4bdd7d..e3869f82c 100644 --- a/src/main/java/appeng/client/render/DummyFluidItemModel.java +++ b/src/main/java/appeng/client/render/DummyFluidItemModel.java @@ -19,71 +19,39 @@ package appeng.client.render; +import appeng.core.AppEng; +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.renderer.model.*; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; + import java.util.Collection; import java.util.Collections; +import java.util.Set; import java.util.function.Function; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.client.model.ModelLoaderRegistry; -import net.minecraftforge.common.model.IModelState; - -import appeng.core.AppEng; - /** * The model class for facades. Since facades wrap existing models, they don't declare any dependencies here other * than the cable anchor. */ -public class DummyFluidItemModel implements IModel +public class DummyFluidItemModel implements IModelGeometry { // We use this to get the default item transforms and make our lives easier private static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "item/dummy_fluid_item_base" ); - private IModel baseModel = null; + @Override + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { + IBakedModel bakedBaseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter); - private IModel getBaseModel() - { - if( this.baseModel == null ) - { - try - { - this.baseModel = ModelLoaderRegistry.getModel( MODEL_BASE ); - } - catch( Exception e ) - { - throw new RuntimeException( e ); - } - } - return this.baseModel; + return new DummyFluidDispatcherBakedModel( bakedBaseModel, spriteGetter ); } @Override - public Collection getDependencies() - { + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { return Collections.emptyList(); } - @Override - public Collection getTextures() - { - return Collections.emptyList(); - } - - @Override - public IBakedModel bake( IModelState state, VertexFormat format, Function bakedTextureGetter ) - { - IBakedModel bakedBaseModel = this.getBaseModel().bake( state, format, bakedTextureGetter ); - - return new DummyFluidDispatcherBakedModel( bakedBaseModel, bakedTextureGetter ); - } - - @Override - public IModelState getDefaultState() - { - return this.getBaseModel().getDefaultState(); - } } diff --git a/src/main/java/appeng/client/render/SimpleModelLoader.java b/src/main/java/appeng/client/render/SimpleModelLoader.java new file mode 100644 index 000000000..8e873946d --- /dev/null +++ b/src/main/java/appeng/client/render/SimpleModelLoader.java @@ -0,0 +1,32 @@ +package appeng.client.render; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonObject; +import net.minecraft.resources.IResourceManager; +import net.minecraftforge.client.model.IModelLoader; +import net.minecraftforge.client.model.geometry.IModelGeometry; + +import java.util.function.Supplier; + +/** + * A quaint model loader that does not accept any additional parameters in JSON. + */ +public class SimpleModelLoader> implements IModelLoader { + + private final Supplier factory; + + public SimpleModelLoader(Supplier factory) { + this.factory = factory; + } + + @Override + public void onResourceManagerReload(IResourceManager resourceManager) { + + } + + @Override + public T read(JsonDeserializationContext deserializationContext, JsonObject modelContents) { + return factory.get(); + } + +} diff --git a/src/main/java/appeng/client/render/crafting/CraftingCubeBakedModel.java b/src/main/java/appeng/client/render/crafting/CraftingCubeBakedModel.java index 96285efea..f9888579e 100644 --- a/src/main/java/appeng/client/render/crafting/CraftingCubeBakedModel.java +++ b/src/main/java/appeng/client/render/crafting/CraftingCubeBakedModel.java @@ -19,25 +19,20 @@ package appeng.client.render.crafting; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.List; - -import javax.annotation.Nullable; - +import appeng.client.render.cablebus.CubeBuilder; +import appeng.tile.crafting.TileCraftingTile; +import appeng.util.Platform; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; -import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.model.ItemOverrideList; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.Direction; -import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.client.model.data.IDynamicBakedModel; +import net.minecraftforge.client.model.data.IModelData; -import appeng.block.crafting.AbstractCraftingUnitBlock; -import appeng.client.render.cablebus.CubeBuilder; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.*; /** @@ -45,38 +40,34 @@ import appeng.client.render.cablebus.CubeBuilder; * Primarily this base class handles adding the "ring" that frames the multi-block structure and delegates * rendering of the "inner" part of each block to the subclasses of this class. */ -abstract class CraftingCubeBakedModel implements IBakedModel +abstract class CraftingCubeBakedModel implements IDynamicBakedModel { - private final VertexFormat format; - private final TextureAtlasSprite ringCorner; private final TextureAtlasSprite ringHor; private final TextureAtlasSprite ringVer; - CraftingCubeBakedModel( VertexFormat format, TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer ) + CraftingCubeBakedModel( TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer ) { - this.format = format; this.ringCorner = ringCorner; this.ringHor = ringHor; this.ringVer = ringVer; } + @Nonnull @Override - public List getQuads( @Nullable BlockState state, @Nullable Direction side, long rand ) - { - + public List getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) { if( side == null ) { return Collections.emptyList(); // No generic quads for this model } - EnumSet connections = getConnections( state ); + EnumSet connections = getConnections( extraData ); List quads = new ArrayList<>(); - CubeBuilder builder = new CubeBuilder( this.format, quads ); + CubeBuilder builder = new CubeBuilder( quads ); builder.setDrawFaces( EnumSet.of( side ) ); @@ -114,7 +105,7 @@ abstract class CraftingCubeBakedModel implements IBakedModel break; } - this.addInnerCube( side, state, builder, x1, y1, z1, x2, y2, z2 ); + this.addInnerCube( side, state, extraData, builder, x1, y1, z1, x2, y2, z2 ); return quads; } @@ -194,7 +185,7 @@ abstract class CraftingCubeBakedModel implements IBakedModel // drawn in those directions. Since a corner is drawn if the three touching faces dont have adjacent // crafting cube blocks, we'd have to check for a, side, and the perpendicular direction. But in this // block, we've already checked for side (due to face culling) and a (see above). - Direction perpendicular = a.rotateAround( side.getAxis() ); + Direction perpendicular = Platform.rotateAround( a, side ); for( Direction cornerCandidate : EnumSet.of( perpendicular, perpendicular.getOpposite() ) ) { if( !connections.contains( cornerCandidate ) ) @@ -256,15 +247,9 @@ abstract class CraftingCubeBakedModel implements IBakedModel // Retrieve the cube connection state from the block state // If none is present, just assume there are no adjacent crafting cube blocks - private static EnumSet getConnections( @Nullable BlockState state ) + private static EnumSet getConnections( IModelData modelData ) { - if( !( state instanceof IExtendedBlockState ) ) - { - return EnumSet.noneOf( Direction.class ); - } - - IExtendedBlockState extState = (IExtendedBlockState) state; - CraftingCubeState cubeState = extState.getValue( AbstractCraftingUnitBlock.STATE ); + CraftingCubeState cubeState = modelData.getData( TileCraftingTile.STATE ); if( cubeState == null ) { return EnumSet.noneOf( Direction.class ); @@ -273,7 +258,7 @@ abstract class CraftingCubeBakedModel implements IBakedModel return cubeState.getConnections(); } - protected abstract void addInnerCube( Direction facing, BlockState state, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2 ); + protected abstract void addInnerCube(Direction facing, BlockState state, IModelData modelData, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2); @Override public boolean isAmbientOcclusion() @@ -300,14 +285,13 @@ abstract class CraftingCubeBakedModel implements IBakedModel } @Override - public ItemCameraTransforms getItemCameraTransforms() - { - return ItemCameraTransforms.DEFAULT; + public boolean func_230044_c_() { + return false; } @Override - public ItemOverrideList getOverrides() - { + public ItemOverrideList getOverrides() { return ItemOverrideList.EMPTY; } + } diff --git a/src/main/java/appeng/client/render/crafting/CraftingCubeModel.java b/src/main/java/appeng/client/render/crafting/CraftingCubeModel.java index 6e0a8fb08..6d3d935af 100644 --- a/src/main/java/appeng/client/render/crafting/CraftingCubeModel.java +++ b/src/main/java/appeng/client/render/crafting/CraftingCubeModel.java @@ -19,44 +19,42 @@ package appeng.client.render.crafting; -import java.util.Collection; -import java.util.Collections; -import java.util.function.Function; - -import com.google.common.collect.ImmutableList; - -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.common.model.IModelState; -import net.minecraftforge.common.model.TRSRTransformation; - import appeng.block.crafting.AbstractCraftingUnitBlock; import appeng.core.AppEng; +import com.google.common.collect.ImmutableList; +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.renderer.model.*; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; + +import java.util.Collection; +import java.util.Set; +import java.util.function.Function; /** * The built-in model for the connected texture crafting cube. */ -class CraftingCubeModel implements IModel +class CraftingCubeModel implements IModelGeometry { - private final static ResourceLocation RING_CORNER = texture( "ring_corner" ); - private final static ResourceLocation RING_SIDE_HOR = texture( "ring_side_hor" ); - private final static ResourceLocation RING_SIDE_VER = texture( "ring_side_ver" ); - private final static ResourceLocation UNIT_BASE = texture( "unit_base" ); - private final static ResourceLocation LIGHT_BASE = texture( "light_base" ); - private final static ResourceLocation ACCELERATOR_LIGHT = texture( "accelerator_light" ); - private final static ResourceLocation STORAGE_1K_LIGHT = texture( "storage_1k_light" ); - private final static ResourceLocation STORAGE_4K_LIGHT = texture( "storage_4k_light" ); - private final static ResourceLocation STORAGE_16K_LIGHT = texture( "storage_16k_light" ); - private final static ResourceLocation STORAGE_64K_LIGHT = texture( "storage_64k_light" ); - private final static ResourceLocation MONITOR_BASE = texture( "monitor_base" ); - private final static ResourceLocation MONITOR_LIGHT_DARK = texture( "monitor_light_dark" ); - private final static ResourceLocation MONITOR_LIGHT_MEDIUM = texture( "monitor_light_medium" ); - private final static ResourceLocation MONITOR_LIGHT_BRIGHT = texture( "monitor_light_bright" ); + private final static Material RING_CORNER = texture( "ring_corner" ); + private final static Material RING_SIDE_HOR = texture( "ring_side_hor" ); + private final static Material RING_SIDE_VER = texture( "ring_side_ver" ); + private final static Material UNIT_BASE = texture( "unit_base" ); + private final static Material LIGHT_BASE = texture( "light_base" ); + private final static Material ACCELERATOR_LIGHT = texture( "accelerator_light" ); + private final static Material STORAGE_1K_LIGHT = texture( "storage_1k_light" ); + private final static Material STORAGE_4K_LIGHT = texture( "storage_4k_light" ); + private final static Material STORAGE_16K_LIGHT = texture( "storage_16k_light" ); + private final static Material STORAGE_64K_LIGHT = texture( "storage_64k_light" ); + private final static Material MONITOR_BASE = texture( "monitor_base" ); + private final static Material MONITOR_LIGHT_DARK = texture( "monitor_light_dark" ); + private final static Material MONITOR_LIGHT_MEDIUM = texture( "monitor_light_medium" ); + private final static Material MONITOR_LIGHT_BRIGHT = texture( "monitor_light_bright" ); private final AbstractCraftingUnitBlock.CraftingUnitType type; @@ -66,47 +64,39 @@ class CraftingCubeModel implements IModel } @Override - public Collection getDependencies() - { - return Collections.emptyList(); - } - - @Override - public Collection getTextures() - { + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { return ImmutableList.of( RING_CORNER, RING_SIDE_HOR, RING_SIDE_VER, UNIT_BASE, LIGHT_BASE, ACCELERATOR_LIGHT, STORAGE_1K_LIGHT, STORAGE_4K_LIGHT, STORAGE_16K_LIGHT, STORAGE_64K_LIGHT, MONITOR_BASE, MONITOR_LIGHT_DARK, MONITOR_LIGHT_MEDIUM, MONITOR_LIGHT_BRIGHT ); } @Override - public IBakedModel bake( IModelState state, VertexFormat format, Function bakedTextureGetter ) - { + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { // Retrieve our textures and pass them on to the baked model - TextureAtlasSprite ringCorner = bakedTextureGetter.apply( RING_CORNER ); - TextureAtlasSprite ringSideHor = bakedTextureGetter.apply( RING_SIDE_HOR ); - TextureAtlasSprite ringSideVer = bakedTextureGetter.apply( RING_SIDE_VER ); + TextureAtlasSprite ringCorner = spriteGetter.apply( RING_CORNER ); + TextureAtlasSprite ringSideHor = spriteGetter.apply( RING_SIDE_HOR ); + TextureAtlasSprite ringSideVer = spriteGetter.apply( RING_SIDE_VER ); switch( this.type ) { case UNIT: - return new UnitBakedModel( format, ringCorner, ringSideHor, ringSideVer, bakedTextureGetter.apply( UNIT_BASE ) ); + return new UnitBakedModel( ringCorner, ringSideHor, ringSideVer, spriteGetter.apply( UNIT_BASE ) ); case ACCELERATOR: case STORAGE_1K: case STORAGE_4K: case STORAGE_16K: case STORAGE_64K: - return new LightBakedModel( format, ringCorner, ringSideHor, ringSideVer, bakedTextureGetter - .apply( LIGHT_BASE ), getLightTexture( bakedTextureGetter, this.type ) ); + return new LightBakedModel( ringCorner, ringSideHor, ringSideVer, spriteGetter + .apply( LIGHT_BASE ), getLightTexture( spriteGetter, this.type ) ); case MONITOR: - return new MonitorBakedModel( format, ringCorner, ringSideHor, ringSideVer, bakedTextureGetter.apply( UNIT_BASE ), bakedTextureGetter - .apply( MONITOR_BASE ), bakedTextureGetter.apply( - MONITOR_LIGHT_DARK ), bakedTextureGetter.apply( MONITOR_LIGHT_MEDIUM ), bakedTextureGetter.apply( MONITOR_LIGHT_BRIGHT ) ); + return new MonitorBakedModel( ringCorner, ringSideHor, ringSideVer, spriteGetter.apply( UNIT_BASE ), spriteGetter + .apply( MONITOR_BASE ), spriteGetter.apply( + MONITOR_LIGHT_DARK ), spriteGetter.apply( MONITOR_LIGHT_MEDIUM ), spriteGetter.apply( MONITOR_LIGHT_BRIGHT ) ); default: throw new IllegalArgumentException( "Unsupported crafting unit type: " + this.type ); } } - private static TextureAtlasSprite getLightTexture( Function textureGetter, AbstractCraftingUnitBlock.CraftingUnitType type ) + private static TextureAtlasSprite getLightTexture( Function textureGetter, AbstractCraftingUnitBlock.CraftingUnitType type ) { switch( type ) { @@ -125,14 +115,8 @@ class CraftingCubeModel implements IModel } } - @Override - public IModelState getDefaultState() + private static Material texture( String name ) { - return TRSRTransformation.identity(); - } - - private static ResourceLocation texture( String name ) - { - return new ResourceLocation( AppEng.MOD_ID, "blocks/crafting/" + name ); + return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(AppEng.MOD_ID, "blocks/crafting/" + name)); } } diff --git a/src/main/java/appeng/client/render/crafting/CraftingCubeModelLoader.java b/src/main/java/appeng/client/render/crafting/CraftingCubeModelLoader.java new file mode 100644 index 000000000..f9bd1d85f --- /dev/null +++ b/src/main/java/appeng/client/render/crafting/CraftingCubeModelLoader.java @@ -0,0 +1,61 @@ +/* + * 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.client.render.crafting; + + +import appeng.block.crafting.AbstractCraftingUnitBlock; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import net.minecraft.resources.IResourceManager; +import net.minecraftforge.client.model.IModelLoader; + + +/** + * Loader that allows access to the built-in crafting cube model from block-model JSONs. + */ +public class CraftingCubeModelLoader implements IModelLoader +{ + + public static final CraftingCubeModelLoader INSTANCE = new CraftingCubeModelLoader(); + + @Override + public void onResourceManagerReload(IResourceManager resourceManager) { + } + + @Override + public CraftingCubeModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) { + AbstractCraftingUnitBlock.CraftingUnitType unitType = null; + + JsonElement typeEl = modelContents.get("type"); + if (typeEl != null) { + String typeName = deserializationContext.deserialize(typeEl, String.class); + if (typeName != null) { + unitType = AbstractCraftingUnitBlock.CraftingUnitType.valueOf(typeName.toUpperCase()); + } + } + if (unitType == null) { + throw new JsonParseException("type property is missing"); + } + + return new CraftingCubeModel(unitType); + } + +} diff --git a/src/main/java/appeng/client/render/crafting/EncodedPatternRenderer.java b/src/main/java/appeng/client/render/crafting/EncodedPatternRenderer.java new file mode 100644 index 000000000..ee46b5a26 --- /dev/null +++ b/src/main/java/appeng/client/render/crafting/EncodedPatternRenderer.java @@ -0,0 +1,25 @@ + +package appeng.client.render.crafting; + + +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + + +/** + * This special model handles switching between rendering the crafting output of an encoded pattern (when shift is being + * held), and showing the encoded pattern itself. Matters are further complicated by only wanting to show the crafting output when + * the pattern is being rendered in the GUI, and not anywhere else. + */ +@OnlyIn(Dist.CLIENT) +public class EncodedPatternRenderer extends ItemStackTileEntityRenderer { + + @Override + public void render(ItemStack is, MatrixStack ms, IRenderTypeBuffer buffers, int combinedLight, int combinedOverlay) { + } + +} diff --git a/src/main/java/appeng/client/render/crafting/ItemEncodedPatternBakedModel.java b/src/main/java/appeng/client/render/crafting/ItemEncodedPatternBakedModel.java deleted file mode 100644 index 98c56d20a..000000000 --- a/src/main/java/appeng/client/render/crafting/ItemEncodedPatternBakedModel.java +++ /dev/null @@ -1,242 +0,0 @@ - -package appeng.client.render.crafting; - - -import java.util.List; - -import javax.annotation.Nullable; -import javax.vecmath.Matrix4f; - -import com.google.common.collect.ImmutableMap; - -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.input.Keyboard; - -import net.minecraft.block.BlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; -import net.minecraft.client.renderer.block.model.ItemOverrideList; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Direction; -import net.minecraft.world.World; -import net.minecraftforge.client.model.PerspectiveMapWrapper; -import net.minecraftforge.common.model.TRSRTransformation; - -import appeng.items.misc.ItemEncodedPattern; - - -/** - * This special model handles switching between rendering the crafting output of an encoded pattern (when shift is being - * held), and - * showing the encoded pattern itself. Matters are further complicated by only wanting to show the crafting output when - * the pattern is being - * rendered in the GUI, and not anywhere else. - */ -class ItemEncodedPatternBakedModel implements IBakedModel -{ - private final IBakedModel baseModel; - - private final ImmutableMap transforms; - - private final CustomOverrideList overrides; - - ItemEncodedPatternBakedModel( IBakedModel baseModel, ImmutableMap transforms ) - { - this.baseModel = baseModel; - this.transforms = transforms; - this.overrides = new CustomOverrideList(); - } - - @Override - public List getQuads( @Nullable BlockState state, @Nullable Direction side, long rand ) - { - return this.baseModel.getQuads( state, side, rand ); - } - - @Override - public boolean isAmbientOcclusion() - { - return this.baseModel.isAmbientOcclusion(); - } - - @Override - public boolean isGui3d() - { - return this.baseModel.isGui3d(); - } - - @Override - public boolean isBuiltInRenderer() - { - return this.baseModel.isBuiltInRenderer(); - } - - @Override - public TextureAtlasSprite getParticleTexture() - { - return this.baseModel.getParticleTexture(); - } - - @Override - @Deprecated - public ItemCameraTransforms getItemCameraTransforms() - { - return this.baseModel.getItemCameraTransforms(); - } - - @Override - public ItemOverrideList getOverrides() - { - return this.overrides; - } - - @Override - public Pair handlePerspective( ItemCameraTransforms.TransformType cameraTransformType ) - { - if( this.baseModel instanceof IBakedModel ) - { - return this.baseModel.handlePerspective( cameraTransformType ); - } - - return PerspectiveMapWrapper.handlePerspective( this, this.transforms, cameraTransformType ); - } - - /** - * Since the ItemOverrideList handling comes before handling the perspective awareness (which is the first place - * where we - * know how we are being rendered) we need to remember the model of the crafting output, and make the decision on - * which to render later on. - * Sadly, Forge is pretty inconsistent when it will call the handlePerspective method, so some methods are called - * even on this interim-model. - * Usually those methods only matter for rendering on the ground and other cases, where we wouldn't render the - * crafting output model anyway, - * so in those cases we delegate to the model of the encoded pattern. - */ - private class ShiftHoldingModelWrapper implements IBakedModel - { - - private final IBakedModel outputModel; - - private ShiftHoldingModelWrapper( IBakedModel outputModel ) - { - this.outputModel = outputModel; - } - - @Override - public Pair handlePerspective( ItemCameraTransforms.TransformType cameraTransformType ) - { - final IBakedModel selectedModel; - - // No need to re-check for shift being held since this model is only handed out in that case - if( cameraTransformType == ItemCameraTransforms.TransformType.GUI ) - { - selectedModel = this.outputModel; - } - else - { - selectedModel = ItemEncodedPatternBakedModel.this.baseModel; - } - - // Now retroactively handle the isGui3d call, for which we always return false below - if( selectedModel.isGui3d() != ItemEncodedPatternBakedModel.this.baseModel.isGui3d() ) - { - RenderSystem.enableLighting(); - } - - if( selectedModel instanceof IBakedModel ) - { - return selectedModel.handlePerspective( cameraTransformType ); - } - - return PerspectiveMapWrapper.handlePerspective( this, ItemEncodedPatternBakedModel.this.transforms, cameraTransformType ); - } - - @Override - public List getQuads( @Nullable BlockState state, @Nullable Direction side, long rand ) - { - // This may be called for items on the ground, in which case we will always fall back to the pattern - return ItemEncodedPatternBakedModel.this.baseModel.getQuads( state, side, rand ); - } - - @Override - public boolean isAmbientOcclusion() - { - return ItemEncodedPatternBakedModel.this.baseModel.isAmbientOcclusion(); - } - - @Override - public boolean isGui3d() - { - // NOTE: Sadly, Forge will let Minecraft call this method before handling the perspective awareness - return ItemEncodedPatternBakedModel.this.baseModel.isGui3d(); - } - - @Override - public boolean isBuiltInRenderer() - { - // This may be called for items on the ground, in which case we will always fall back to the pattern - return ItemEncodedPatternBakedModel.this.baseModel.isBuiltInRenderer(); - } - - @Override - public TextureAtlasSprite getParticleTexture() - { - // This may be called for items on the ground, in which case we will always fall back to the pattern - return ItemEncodedPatternBakedModel.this.baseModel.getParticleTexture(); - } - - @Override - public ItemCameraTransforms getItemCameraTransforms() - { - // This may be called for items on the ground, in which case we will always fall back to the pattern - return ItemEncodedPatternBakedModel.this.baseModel.getItemCameraTransforms(); - } - - @Override - public ItemOverrideList getOverrides() - { - // This may be called for items on the ground, in which case we will always fall back to the pattern - return ItemEncodedPatternBakedModel.this.baseModel.getOverrides(); - } - } - - /** - * Item Override Lists are the only point during item rendering where we can access the item stack that is being - * rendered. - * So this is the point where we actually check if shift is being held, and if so, determine the crafting output - * model. - */ - private class CustomOverrideList extends ItemOverrideList - { - - CustomOverrideList() - { - super( ItemEncodedPatternBakedModel.this.baseModel.getOverrides().getOverrides() ); - } - - @Override - public IBakedModel handleItemState( IBakedModel originalModel, ItemStack stack, World world, LivingEntity entity ) - { - boolean shiftHeld = Keyboard.isKeyDown( GLFW.GLFW_KEY_LSHIFT ) || Keyboard.isKeyDown( GLFW.GLFW_KEY_RSHIFT ); - if( shiftHeld ) - { - ItemEncodedPattern iep = (ItemEncodedPattern) stack.getItem(); - ItemStack output = iep.getOutput( stack ); - if( !output.isEmpty() ) - { - IBakedModel realModel = Minecraft.getInstance().getRenderItem().getItemModelMesher().getItemModel( output ); - // Give the item model a chance to handle the overrides as well - realModel = realModel.getOverrides().handleItemState( realModel, output, world, entity ); - return new ShiftHoldingModelWrapper( realModel ); - } - } - - return ItemEncodedPatternBakedModel.this.baseModel.getOverrides().handleItemState( originalModel, stack, world, entity ); - } - } -} diff --git a/src/main/java/appeng/client/render/crafting/ItemEncodedPatternModel.java b/src/main/java/appeng/client/render/crafting/ItemEncodedPatternModel.java deleted file mode 100644 index 88ce1a1a7..000000000 --- a/src/main/java/appeng/client/render/crafting/ItemEncodedPatternModel.java +++ /dev/null @@ -1,68 +0,0 @@ - -package appeng.client.render.crafting; - - -import java.util.Collection; -import java.util.Collections; -import java.util.function.Function; - -import com.google.common.collect.ImmutableMap; - -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.client.model.ModelLoaderRegistry; -import net.minecraftforge.client.model.PerspectiveMapWrapper; -import net.minecraftforge.common.model.IModelState; -import net.minecraftforge.common.model.TRSRTransformation; - -import appeng.core.AppEng; - - -/** - * Simple model for the encoded pattern built-in baked model. - */ -class ItemEncodedPatternModel implements IModel -{ - - private static final ResourceLocation BASE_MODEL = new ResourceLocation( AppEng.MOD_ID, "item/encoded_pattern" ); - - @Override - public Collection getDependencies() - { - return Collections.singletonList( BASE_MODEL ); - } - - @Override - public Collection getTextures() - { - return Collections.emptyList(); - } - - @Override - public IBakedModel bake( IModelState state, VertexFormat format, Function bakedTextureGetter ) - { - IBakedModel baseModel; - try - { - baseModel = ModelLoaderRegistry.getModel( BASE_MODEL ).bake( state, format, bakedTextureGetter ); - } - catch( Exception e ) - { - throw new RuntimeException( e ); - } - - ImmutableMap transforms = PerspectiveMapWrapper.getTransforms( state ); - - return new ItemEncodedPatternBakedModel( baseModel, transforms ); - } - - @Override - public IModelState getDefaultState() - { - return TRSRTransformation.identity(); - } -} diff --git a/src/main/java/appeng/client/render/crafting/LightBakedModel.java b/src/main/java/appeng/client/render/crafting/LightBakedModel.java index 326e0a61f..344073012 100644 --- a/src/main/java/appeng/client/render/crafting/LightBakedModel.java +++ b/src/main/java/appeng/client/render/crafting/LightBakedModel.java @@ -26,6 +26,7 @@ import net.minecraft.util.Direction; import appeng.block.crafting.AbstractCraftingUnitBlock; import appeng.client.render.cablebus.CubeBuilder; +import net.minecraftforge.client.model.data.IModelData; /** @@ -39,15 +40,15 @@ class LightBakedModel extends CraftingCubeBakedModel private final TextureAtlasSprite lightTexture; - LightBakedModel( VertexFormat format, TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer, TextureAtlasSprite baseTexture, TextureAtlasSprite lightTexture ) + LightBakedModel( TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer, TextureAtlasSprite baseTexture, TextureAtlasSprite lightTexture ) { - super( format, ringCorner, ringHor, ringVer ); + super( ringCorner, ringHor, ringVer ); this.baseTexture = baseTexture; this.lightTexture = lightTexture; } @Override - protected void addInnerCube( Direction facing, BlockState state, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2 ) + protected void addInnerCube(Direction facing, BlockState state, IModelData modelData, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2) { builder.setTexture( this.baseTexture ); builder.addCube( x1, y1, z1, x2, y2, z2 ); diff --git a/src/main/java/appeng/client/render/crafting/MonitorBakedModel.java b/src/main/java/appeng/client/render/crafting/MonitorBakedModel.java index 92507d1f2..78d1c46ad 100644 --- a/src/main/java/appeng/client/render/crafting/MonitorBakedModel.java +++ b/src/main/java/appeng/client/render/crafting/MonitorBakedModel.java @@ -19,15 +19,14 @@ package appeng.client.render.crafting; -import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.Direction; -import net.minecraftforge.common.property.IExtendedBlockState; - import appeng.api.util.AEColor; import appeng.block.crafting.BlockCraftingMonitor; import appeng.client.render.cablebus.CubeBuilder; +import appeng.tile.crafting.TileCraftingMonitorTile; +import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.Direction; +import net.minecraftforge.client.model.data.IModelData; /** @@ -50,9 +49,9 @@ class MonitorBakedModel extends CraftingCubeBakedModel private final TextureAtlasSprite lightBrightTexture; - MonitorBakedModel( VertexFormat format, TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer, TextureAtlasSprite chassisTexture, TextureAtlasSprite baseTexture, TextureAtlasSprite lightDarkTexture, TextureAtlasSprite lightMediumTexture, TextureAtlasSprite lightBrightTexture ) + MonitorBakedModel( TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer, TextureAtlasSprite chassisTexture, TextureAtlasSprite baseTexture, TextureAtlasSprite lightDarkTexture, TextureAtlasSprite lightMediumTexture, TextureAtlasSprite lightBrightTexture ) { - super( format, ringCorner, ringHor, ringVer ); + super( ringCorner, ringHor, ringVer ); this.chassisTexture = chassisTexture; this.baseTexture = baseTexture; this.lightDarkTexture = lightDarkTexture; @@ -61,9 +60,9 @@ class MonitorBakedModel extends CraftingCubeBakedModel } @Override - protected void addInnerCube( Direction side, BlockState state, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2 ) + protected void addInnerCube(Direction side, BlockState state, IModelData modelData, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2) { - Direction forward = getForward( state ); + Direction forward = getForward( modelData ); // For sides other than the front, use the chassis texture if( side != forward ) @@ -77,7 +76,7 @@ class MonitorBakedModel extends CraftingCubeBakedModel builder.addCube( x1, y1, z1, x2, y2, z2 ); // Now add the three layered light textures - AEColor color = getColor( state ); + AEColor color = getColor( modelData ); boolean powered = state.get( BlockCraftingMonitor.POWERED ); builder.setRenderFullBright( powered ); @@ -96,31 +95,20 @@ class MonitorBakedModel extends CraftingCubeBakedModel } - private static AEColor getColor( BlockState state ) - { - if( state instanceof IExtendedBlockState ) - { - IExtendedBlockState extState = (IExtendedBlockState) state; - AEColor color = extState.getValue( BlockCraftingMonitor.COLOR ); - if( color != null ) - { - return color; - } + private static AEColor getColor(IModelData modelData) { + + AEColor color = modelData.getData(TileCraftingMonitorTile.COLOR); + if (color != null) { + return color; } return AEColor.TRANSPARENT; } - private static Direction getForward( BlockState state ) - { - if( state instanceof IExtendedBlockState ) - { - IExtendedBlockState extState = (IExtendedBlockState) state; - Direction forward = extState.getValue( BlockCraftingMonitor.FORWARD ); - if( forward != null ) - { - return forward; - } + private static Direction getForward(IModelData modelData) { + Direction forward = modelData.getData(BlockCraftingMonitor.FORWARD); + if (forward != null) { + return forward; } return Direction.NORTH; diff --git a/src/main/java/appeng/client/render/crafting/UnitBakedModel.java b/src/main/java/appeng/client/render/crafting/UnitBakedModel.java index 2cc751e80..7c2f51e9b 100644 --- a/src/main/java/appeng/client/render/crafting/UnitBakedModel.java +++ b/src/main/java/appeng/client/render/crafting/UnitBakedModel.java @@ -21,10 +21,10 @@ package appeng.client.render.crafting; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.Direction; import appeng.client.render.cablebus.CubeBuilder; +import net.minecraftforge.client.model.data.IModelData; /** @@ -35,14 +35,14 @@ class UnitBakedModel extends CraftingCubeBakedModel private final TextureAtlasSprite unitTexture; - UnitBakedModel( VertexFormat format, TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer, TextureAtlasSprite unitTexture ) + UnitBakedModel( TextureAtlasSprite ringCorner, TextureAtlasSprite ringHor, TextureAtlasSprite ringVer, TextureAtlasSprite unitTexture ) { - super( format, ringCorner, ringHor, ringVer ); + super( ringCorner, ringHor, ringVer ); this.unitTexture = unitTexture; } @Override - protected void addInnerCube( Direction facing, BlockState state, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2 ) + protected void addInnerCube(Direction facing, BlockState state, IModelData modelData, CubeBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2) { builder.setTexture( this.unitTexture ); builder.addCube( x1, y1, z1, x2, y2, z2 ); diff --git a/src/main/java/appeng/client/render/effects/AssemblerFX.java b/src/main/java/appeng/client/render/effects/AssemblerFX.java index 9d31305d7..22d5d864a 100644 --- a/src/main/java/appeng/client/render/effects/AssemblerFX.java +++ b/src/main/java/appeng/client/render/effects/AssemblerFX.java @@ -20,12 +20,24 @@ package appeng.client.render.effects; import com.mojang.blaze3d.vertex.IVertexBuilder; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.client.particle.IAnimatedSprite; +import net.minecraft.client.particle.IParticleFactory; import net.minecraft.client.particle.IParticleRenderType; import net.minecraft.client.particle.Particle; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.command.arguments.ItemInput; +import net.minecraft.command.arguments.ItemParser; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; +import net.minecraft.particles.BasicParticleType; +import net.minecraft.particles.IParticleData; +import net.minecraft.particles.ItemParticleData; +import net.minecraft.particles.ParticleType; +import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import appeng.api.storage.data.IAEItemStack; @@ -33,23 +45,32 @@ import appeng.client.EffectType; import appeng.core.AppEng; import appeng.entity.EntityFloatingItem; import appeng.entity.ICanDie; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +import java.util.Locale; public class AssemblerFX extends Particle implements ICanDie { + public static final ParticleType TYPE = new ParticleType<>(false, new AssemblerParticleData.Deserializer()); + + static { + TYPE.setRegistryName(AppEng.MOD_ID, "assembler_fx"); + } + private final EntityFloatingItem fi; private final float speed; private float time = 0; - public AssemblerFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b, final float speed, final IAEItemStack is ) + public AssemblerFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b, final float speed, final ItemStack displayItem ) { super( w, x, y, z, r, g, b ); this.motionX = 0; this.motionY = 0; this.motionZ = 0; this.speed = speed; - final ItemStack displayItem = is.asItemStackRepresentation(); this.fi = new EntityFloatingItem( this, w, x, y, z, displayItem ); w.addEntity( this.fi ); this.maxAge = (int) Math.ceil( Math.max( 1, 100.0f / speed ) ) + 2; @@ -99,7 +120,6 @@ public class AssemblerFX extends Particle implements ICanDie @Override public IParticleRenderType getRenderType() { - // TODO: FIXME return IParticleRenderType.NO_RENDER; } @@ -117,4 +137,102 @@ public class AssemblerFX extends Particle implements ICanDie } } } + + public static class AssemblerParticleData implements IParticleData { + + private final float r; + private final float g; + private final float b; + private final float speed; + private final ItemStack itemStack; + + public AssemblerParticleData(float r, float g, float b, float speed, ItemStack itemStack) { + this.r = r; + this.g = g; + this.b = b; + this.speed = speed; + this.itemStack = itemStack; + } + + @Override + public ParticleType getType() { + return TYPE; + } + + @Override + public void write(PacketBuffer buffer) { + buffer.writeFloat(r); + buffer.writeFloat(g); + buffer.writeFloat(b); + buffer.writeFloat(speed); + buffer.writeItemStack(itemStack); + } + + public static class Deserializer implements IDeserializer { + + @Override + public AssemblerParticleData deserialize(ParticleType particleTypeIn, StringReader reader) throws CommandSyntaxException { + reader.expect(' '); + float r = reader.readFloat(); + reader.expect(' '); + float g = reader.readFloat(); + reader.expect(' '); + float b = reader.readFloat(); + reader.expect(' '); + float speed = reader.readFloat(); + reader.expect(' '); + ItemParser itemparser = (new ItemParser(reader, false)).parse(); + ItemStack itemstack = (new ItemInput(itemparser.getItem(), itemparser.getNbt())).createStack(1, false); + return new AssemblerParticleData(r, g, b, speed, itemstack); + } + + @Override + public AssemblerParticleData read(ParticleType particleTypeIn, PacketBuffer buffer) { + float r = buffer.readFloat(); + float g = buffer.readFloat(); + float b = buffer.readFloat(); + float speed = buffer.readFloat(); + ItemStack itemStack = buffer.readItemStack(); + return new AssemblerParticleData(r, g, b, speed, itemStack); + } + + } + + @Override + public String getParameters() { + return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f ", Registry.PARTICLE_TYPE.getKey(this.getType()), this.r, this.g, this.b, this.speed) + + (new ItemInput(this.itemStack.getItem(), this.itemStack.getTag())).serialize(); + } + + public float getR() { + return r; + } + + public float getG() { + return g; + } + + public float getB() { + return b; + } + + public float getSpeed() { + return speed; + } + + public ItemStack getItemStack() { + return itemStack; + } + } + + @OnlyIn(Dist.CLIENT) + public static class Factory implements IParticleFactory { + public Factory(IAnimatedSprite spriteSet) { + } + + public Particle makeParticle(AssemblerParticleData data, World world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { + return new AssemblerFX(world, x, y, z, data.r, data.g, data.b, data.speed, data.itemStack); + } + } + } diff --git a/src/main/java/appeng/client/render/effects/CraftingFx.java b/src/main/java/appeng/client/render/effects/CraftingFx.java index d2cea4912..227ad3a73 100644 --- a/src/main/java/appeng/client/render/effects/CraftingFx.java +++ b/src/main/java/appeng/client/render/effects/CraftingFx.java @@ -19,130 +19,120 @@ package appeng.client.render.effects; -import net.minecraft.client.particle.BreakingParticle; -import net.minecraft.client.particle.IParticleRenderType; +import appeng.core.AppEng; +import com.mojang.blaze3d.vertex.IVertexBuilder; +import net.minecraft.client.particle.*; +import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.entity.Entity; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.particles.BasicParticleType; +import net.minecraft.particles.ItemParticleData; +import net.minecraft.particles.ParticleType; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import appeng.api.util.AEPartLocation; -import appeng.client.render.textures.ParticleTextures; @OnlyIn( Dist.CLIENT ) public class CraftingFx extends BreakingParticle { - private final TextureAtlasSprite particleTextureIndex; + public static final BasicParticleType TYPE = new BasicParticleType(false); + + static { + TYPE.setRegistryName(AppEng.MOD_ID, "crafting_fx"); + } private final int startBlkX; private final int startBlkY; private final int startBlkZ; - public CraftingFx( final World par1World, final double par2, final double par4, final double par6, final Item par8Item ) + public CraftingFx( final World par1World, final double x, final double y, final double z, final IAnimatedSprite sprite ) { - super( par1World, par2, par4, par6, par8Item ); + super( par1World, x, y, z, new ItemStack(Items.DIAMOND) ); this.particleGravity = 0; this.particleBlue = 1; this.particleGreen = 0.9f; this.particleRed = 1; this.particleAlpha = 1.3f; this.particleScale = 1.5f; - this.particleTextureIndex = ParticleTextures.BlockEnergyParticle; + this.selectSpriteRandomly(sprite); this.maxAge /= 1.2; - this.startBlkX = MathHelper.floor( this.getPosX() ); - this.startBlkY = MathHelper.floor( this.getPosY() ); - this.startBlkZ = MathHelper.floor( this.getPosZ() ); + this.startBlkX = MathHelper.floor( this.posX ); + this.startBlkY = MathHelper.floor( this.posY ); + this.startBlkZ = MathHelper.floor( this.posZ ); } @Override - public int getFXLayer() - { - return 1; - } + public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) { - @Override - public IParticleRenderType getRenderType() { - // TODO: FIXME - return IParticleRenderType.NO_RENDER; - } - - @Override - public void renderParticle( final BufferBuilder par1Tessellator, final Entity p_180434_2_, final float partialTick, final float x, final float y, final float z, final float rx, final float rz ) - { - if( partialTick < 0 || partialTick > 1 ) + if( partialTicks < 0 || partialTicks > 1 ) { return; } - final float f6 = this.particleTextureIndex.getMinU(); - final float f7 = this.particleTextureIndex.getMaxU(); - final float f8 = this.particleTextureIndex.getMinV(); - final float f9 = this.particleTextureIndex.getMaxV(); - final float scale = 0.1F * this.particleScale; - - float offX = (float) ( this.prevPosX + ( this.getPosX() - this.prevPosX ) * partialTick ); - float offY = (float) ( this.prevPosY + ( this.getPosY() - this.prevPosY ) * partialTick ); - float offZ = (float) ( this.prevPosZ + ( this.getPosZ() - this.prevPosZ ) * partialTick ); + float offX = (float)(MathHelper.lerp(partialTicks, this.prevPosX, this.posX)); + float offY = (float)(MathHelper.lerp(partialTicks, this.prevPosY, this.posY)); + float offZ = (float)(MathHelper.lerp(partialTicks, this.prevPosZ, this.posZ)); final int blkX = MathHelper.floor( offX ); final int blkY = MathHelper.floor( offY ); final int blkZ = MathHelper.floor( offZ ); + // I believe this particle is same as breaking particle, but should not exit the original block it was + // spawned in (which is encased in glass) if( blkX == this.startBlkX && blkY == this.startBlkY && blkZ == this.startBlkZ ) { - offX -= interpPosX; - offY -= interpPosY; - offZ -= interpPosZ; + Vec3d vec3d = renderInfo.getProjectedView(); + offX -= vec3d.x; + offY -= vec3d.y; + offZ -= vec3d.z; - int i = this.getBrightnessForRender( partialTick ); - int j = i >> 16 & 65535; - int k = i & 65535; + Vector3f[] avector3f = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)}; + float scale = this.getScale(partialTicks); - // AELog.info( "" + partialTick ); - final float f14 = 1.0F; - par1Tessellator.pos( offX - x * scale - rx * scale, offY - y * scale, offZ - z * scale - rz * scale ) - .tex( f7, f9 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); - par1Tessellator.pos( offX - x * scale + rx * scale, offY + y * scale, offZ - z * scale + rz * scale ) - .tex( f7, f8 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); - par1Tessellator.pos( offX + x * scale + rx * scale, offY + y * scale, offZ + z * scale + rz * scale ) - .tex( f6, f8 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); - par1Tessellator.pos( offX + x * scale - rx * scale, offY - y * scale, offZ + z * scale - rz * scale ) - .tex( f6, f9 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); + for(int i = 0; i < 4; ++i) { + Vector3f vector3f = avector3f[i]; + vector3f.transform(renderInfo.getRotation()); + vector3f.mul(scale); + vector3f.add(offX, offY, offZ); + } + + float minU = this.getMinU(); + float maxU = this.getMaxU(); + float minV = this.getMinV(); + float maxV = this.getMaxV(); + int j = this.getBrightnessForRender(partialTicks); + buffer.pos(avector3f[0].getX(), avector3f[0].getY(), avector3f[0].getZ()).tex(maxU, maxV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); + buffer.pos(avector3f[1].getX(), avector3f[1].getY(), avector3f[1].getZ()).tex(maxU, minV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); + buffer.pos(avector3f[2].getX(), avector3f[2].getY(), avector3f[2].getZ()).tex(minU, minV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); + buffer.pos(avector3f[3].getX(), avector3f[3].getY(), avector3f[3].getZ()).tex(minU, maxV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex(); } } public void fromItem( final AEPartLocation d ) { - this.getPosX() += 0.2 * d.xOffset; - this.getPosY() += 0.2 * d.yOffset; - this.getPosZ() += 0.2 * d.zOffset; + this.posX += 0.2 * d.xOffset; + this.posY += 0.2 * d.yOffset; + this.posZ += 0.2 * d.zOffset; this.particleScale *= 0.8f; } @Override public void tick() { - this.prevPosX = this.getPosX(); - this.prevPosY = this.getPosY(); - this.prevPosZ = this.getPosZ(); + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; if( this.age++ >= this.maxAge ) { @@ -172,4 +162,18 @@ public class CraftingFx extends BreakingParticle { this.motionZ = motionZ; } + + @OnlyIn(Dist.CLIENT) + public static class Factory implements IParticleFactory { + private final IAnimatedSprite spriteSet; + + public Factory(IAnimatedSprite p_i50477_1_) { + this.spriteSet = p_i50477_1_; + } + + public Particle makeParticle(BasicParticleType data, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { + return new CraftingFx(worldIn, x, y, z, spriteSet); + } + } + } diff --git a/src/main/java/appeng/client/render/effects/EnergyFx.java b/src/main/java/appeng/client/render/effects/EnergyFx.java index 414e4b812..5247f76f1 100644 --- a/src/main/java/appeng/client/render/effects/EnergyFx.java +++ b/src/main/java/appeng/client/render/effects/EnergyFx.java @@ -19,13 +19,15 @@ package appeng.client.render.effects; -import net.minecraft.client.particle.BreakingParticle; -import net.minecraft.client.particle.IParticleRenderType; +import appeng.core.AppEng; +import net.minecraft.client.particle.*; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.particles.BasicParticleType; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; @@ -38,22 +40,26 @@ import appeng.api.util.AEPartLocation; public class EnergyFx extends BreakingParticle { - // FIXME private final TextureAtlasSprite particleTextureIndex; + public static final BasicParticleType TYPE = new BasicParticleType(false); + + static { + TYPE.setRegistryName(AppEng.MOD_ID, "energy_fx"); + } private final int startBlkX; private final int startBlkY; private final int startBlkZ; - public EnergyFx( final World par1World, final double par2, final double par4, final double par6, final ItemStack par8Item ) + public EnergyFx( final World par1World, final double par2, final double par4, final double par6, final IAnimatedSprite sprite ) { - super( par1World, par2, par4, par6, par8Item ); + super( par1World, par2, par4, par6, new ItemStack(Items.DIAMOND) ); this.particleGravity = 0; this.particleBlue = 1; this.particleGreen = 1; this.particleRed = 1; this.particleAlpha = 1.4f; this.particleScale = 3.5f; - // FIXME this.particleTextureIndex = ParticleTextures.BlockEnergyParticle; + this.selectSpriteRandomly(sprite); this.startBlkX = MathHelper.floor( this.posX ); this.startBlkY = MathHelper.floor( this.posY ); @@ -163,4 +169,22 @@ public class EnergyFx extends BreakingParticle { this.motionZ = motionZ; } + + @OnlyIn(Dist.CLIENT) + public static class Factory implements IParticleFactory { + private final IAnimatedSprite spriteSet; + + public Factory(IAnimatedSprite spriteSet) { + this.spriteSet = spriteSet; + } + + public Particle makeParticle(BasicParticleType typeIn, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { + EnergyFx result = new EnergyFx(worldIn, x, y, z, spriteSet); + result.setMotionX((float) xSpeed); + result.setMotionY((float) ySpeed); + result.setMotionZ((float) zSpeed); + return result; + } + } + } diff --git a/src/main/java/appeng/client/render/effects/LightningArcFX.java b/src/main/java/appeng/client/render/effects/LightningArcFX.java index f88b44ca0..603746974 100644 --- a/src/main/java/appeng/client/render/effects/LightningArcFX.java +++ b/src/main/java/appeng/client/render/effects/LightningArcFX.java @@ -21,11 +21,23 @@ package appeng.client.render.effects; import java.util.Random; +import appeng.core.AppEng; +import net.minecraft.client.particle.*; +import net.minecraft.particles.BasicParticleType; +import net.minecraft.particles.ParticleType; import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public class LightningArcFX extends LightningFX { + public static final ParticleType TYPE = new ParticleType<>(false, LightningArcParticleData.DESERIALIZER); + + static { + TYPE.setRegistryName(AppEng.MOD_ID, "lightning_arc_fx"); + } + private static final Random RANDOM_GENERATOR = new Random(); private final double rx; @@ -61,4 +73,20 @@ public class LightningArcFX extends LightningFX localSteps[s][2] = ( lastDirectionZ + ( RANDOM_GENERATOR.nextDouble() - 0.5 ) * len * 1.2 ) / 2.0; } } + + @OnlyIn(Dist.CLIENT) + public static class Factory implements IParticleFactory { + private final IAnimatedSprite spriteSet; + + public Factory(IAnimatedSprite spriteSet) { + this.spriteSet = spriteSet; + } + + public Particle makeParticle(LightningArcParticleData data, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { + SpriteTexturedParticle lightningFX = new LightningArcFX(worldIn, x, y, z, data.target.x, data.target.y, data.target.z, 0, 0, 0); + lightningFX.selectSpriteRandomly(this.spriteSet); + return lightningFX; + } + } + } diff --git a/src/main/java/appeng/client/render/effects/LightningArcParticleData.java b/src/main/java/appeng/client/render/effects/LightningArcParticleData.java new file mode 100644 index 000000000..9e08597fa --- /dev/null +++ b/src/main/java/appeng/client/render/effects/LightningArcParticleData.java @@ -0,0 +1,61 @@ +package appeng.client.render.effects; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.sun.javafx.geom.Vec3f; +import net.minecraft.network.PacketBuffer; +import net.minecraft.particles.IParticleData; +import net.minecraft.particles.ParticleType; + +import java.util.Locale; + +/** + * Contains the target point of the lightning arc (the source point is infered from the particle starting position). + */ +public class LightningArcParticleData implements IParticleData { + + public final Vec3f target; + + public LightningArcParticleData(Vec3f target) { + this.target = target; + } + + public static final IDeserializer DESERIALIZER = new IDeserializer() { + @Override + public LightningArcParticleData deserialize(ParticleType particleTypeIn, StringReader reader) throws CommandSyntaxException { + reader.expect(' '); + float x = reader.readFloat(); + reader.expect(' '); + float y = reader.readFloat(); + reader.expect(' '); + float z = reader.readFloat(); + return new LightningArcParticleData(new Vec3f(x, y, z)); + } + + @Override + public LightningArcParticleData read(ParticleType particleTypeIn, PacketBuffer buffer) { + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + return new LightningArcParticleData(new Vec3f(x, y, z)); + } + }; + + @Override + public ParticleType getType() { + return LightningArcFX.TYPE; + } + + @Override + public void write(PacketBuffer buffer) { + buffer.writeFloat(target.x); + buffer.writeFloat(target.y); + buffer.writeFloat(target.z); + } + + @Override + public String getParameters() { + return String.format(Locale.ROOT, "%.2f %.2f %.2f", target.x, target.y, target.z); + } + +} diff --git a/src/main/java/appeng/client/render/effects/LightningFX.java b/src/main/java/appeng/client/render/effects/LightningFX.java index 64cdd3bc9..e9226159d 100644 --- a/src/main/java/appeng/client/render/effects/LightningFX.java +++ b/src/main/java/appeng/client/render/effects/LightningFX.java @@ -62,7 +62,7 @@ public class LightningFX extends SpriteTexturedParticle this.regen(); } - private LightningFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b, final int maxAge ) + protected LightningFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b, final int maxAge ) { super( w, x, y, z, r, g, b ); this.precomputedSteps = new double[LightningFX.STEPS][3]; diff --git a/src/main/java/appeng/client/render/effects/MatterCannonFX.java b/src/main/java/appeng/client/render/effects/MatterCannonFX.java index 2638c66d7..92005da3e 100644 --- a/src/main/java/appeng/client/render/effects/MatterCannonFX.java +++ b/src/main/java/appeng/client/render/effects/MatterCannonFX.java @@ -19,26 +19,37 @@ package appeng.client.render.effects; +import appeng.core.AppEng; +import com.mojang.blaze3d.vertex.IVertexBuilder; import net.minecraft.client.particle.BreakingParticle; +import net.minecraft.client.particle.IAnimatedSprite; +import net.minecraft.client.particle.IParticleFactory; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.entity.Entity; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.particles.BasicParticleType; import net.minecraft.world.World; import appeng.api.util.AEPartLocation; -import appeng.client.render.textures.ParticleTextures; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public class MatterCannonFX extends BreakingParticle { - private final TextureAtlasSprite particleTextureIndex; + public static final BasicParticleType TYPE = new BasicParticleType(false); - public MatterCannonFX( final World par1World, final double par2, final double par4, final double par6, final ItemStack par8Item ) + static { + TYPE.setRegistryName(AppEng.MOD_ID, "matter_cannon_fx"); + } + + public MatterCannonFX( final World par1World, final double x, final double y, final double z, IAnimatedSprite sprite ) { - super( par1World, par2, par4, par6, par8Item ); + super( par1World, x, y, z, new ItemStack(Items.DIAMOND) ); this.particleGravity = 0; this.particleBlue = 1; this.particleGreen = 1; @@ -48,7 +59,7 @@ public class MatterCannonFX extends BreakingParticle this.motionX = 0.0f; this.motionY = 0.0f; this.motionZ = 0.0f; - this.particleTextureIndex = ParticleTextures.BlockMatterCannonParticle; + this.selectSpriteRandomly(sprite); } public void fromItem( final AEPartLocation d ) @@ -78,49 +89,17 @@ public class MatterCannonFX extends BreakingParticle this.particleAlpha *= 0.59f; } - @Override - public int getFXLayer() - { - return 1; + @OnlyIn(Dist.CLIENT) + public static class Factory implements IParticleFactory { + private final IAnimatedSprite spriteSet; + + public Factory(IAnimatedSprite spriteSet) { + this.spriteSet = spriteSet; + } + + public Particle makeParticle(BasicParticleType data, World world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { + return new MatterCannonFX(world, x, y, z, spriteSet); + } } - @Override - public void renderParticle( final BufferBuilder par1Tessellator, final Entity p_180434_2_, final float par2, final float par3, final float par4, final float par5, final float par6, final float par7 ) - { - final float f6 = this.particleTextureIndex.getMinU(); - final float f7 = this.particleTextureIndex.getMaxU(); - final float f8 = this.particleTextureIndex.getMinV(); - final float f9 = this.particleTextureIndex.getMaxV(); - final float f10 = 0.05F * this.particleScale; - - final float f11 = (float) ( this.prevPosX + ( this.posX - this.prevPosX ) * par2 - interpPosX ); - final float f12 = (float) ( this.prevPosY + ( this.posY - this.prevPosY ) * par2 - interpPosY ); - final float f13 = (float) ( this.prevPosZ + ( this.posZ - this.prevPosZ ) * par2 - interpPosZ ); - final float f14 = 1.0F; - - int i = this.getBrightnessForRender( par2 ); - int j = i >> 16 & 65535; - int k = i & 65535; - - par1Tessellator.pos( f11 - par3 * f10 - par6 * f10, f12 - par4 * f10, f13 - par5 * f10 - par7 * f10 ) - .tex( f7, f9 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); - par1Tessellator.pos( f11 - par3 * f10 + par6 * f10, f12 + par4 * f10, f13 - par5 * f10 + par7 * f10 ) - .tex( f7, f8 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); - par1Tessellator.pos( f11 + par3 * f10 + par6 * f10, f12 + par4 * f10, f13 + par5 * f10 + par7 * f10 ) - .tex( f6, f8 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); - par1Tessellator.pos( f11 + par3 * f10 - par6 * f10, f12 - par4 * f10, f13 + par5 * f10 - par7 * f10 ) - .tex( f6, f9 ) - .color( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ) - .lightmap( j, k ) - .endVertex(); - } } diff --git a/src/main/java/appeng/client/render/model/BiometricCardModel.java b/src/main/java/appeng/client/render/model/BiometricCardModel.java index c5bc9b9d6..a4bd61af3 100644 --- a/src/main/java/appeng/client/render/model/BiometricCardModel.java +++ b/src/main/java/appeng/client/render/model/BiometricCardModel.java @@ -9,48 +9,41 @@ import javax.annotation.Nullable; import com.mojang.datafixers.util.Pair; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.IModelTransform; -import net.minecraft.client.renderer.model.IUnbakedModel; -import net.minecraft.client.renderer.model.Material; -import net.minecraft.client.renderer.model.ModelBakery; +import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.ResourceLocation; import appeng.core.AppEng; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; /** * Model wrapper for the biometric card item model, which combines a base card layer with a "visual hash" of the player * name */ -public class BiometricCardModel implements IUnbakedModel +public class BiometricCardModel implements IModelGeometry { private static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "item/biometric_card" ); private static final Material TEXTURE = new Material( AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "items/biometric_card_hash" ) ); @Override - public Collection getDependencies() - { - return Collections.singletonList( MODEL_BASE ); - } - - @Override - public Collection getTextures( Function modelGetter, Set> missingTextureErrors ) + public Collection getTextures( IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors ) { return Collections.singleton( TEXTURE ); } @Nullable @Override - public IBakedModel bakeModel( ModelBakery modelBakeryIn, Function spriteGetterIn, IModelTransform transformIn, ResourceLocation locationIn ) + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform transformIn, ItemOverrideList overrides, ResourceLocation locationIn ) { - TextureAtlasSprite texture = spriteGetterIn.apply( TEXTURE ); + TextureAtlasSprite texture = spriteGetter.apply( TEXTURE ); - IBakedModel baseModel = modelBakeryIn.getBakedModel( MODEL_BASE, transformIn, spriteGetterIn ); + IBakedModel baseModel = bakery.getBakedModel( MODEL_BASE, transformIn, spriteGetter ); return new BiometricCardBakedModel( baseModel, texture ); } + } diff --git a/src/main/java/appeng/client/render/model/BuiltInModelLoader.java b/src/main/java/appeng/client/render/model/BuiltInModelLoader.java deleted file mode 100644 index f27e0cc2c..000000000 --- a/src/main/java/appeng/client/render/model/BuiltInModelLoader.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.client.render.model; - - -import java.util.Map; - -import com.google.common.collect.ImmutableMap; - -import net.minecraft.client.renderer.model.IUnbakedModel; -import net.minecraft.resources.IResourceManager; -import net.minecraft.resources.IResourceManagerReloadListener; -import net.minecraft.util.ResourceLocation; - -import appeng.core.AppEng; -import net.minecraftforge.client.model.IModelLoader; - - -/** - * Manages built-in models. - */ -public class BuiltInModelLoader implements IModelLoader -{ - - private final Map builtInModels; - - public BuiltInModelLoader( Map builtInModels ) - { - this.builtInModels = ImmutableMap.copyOf( builtInModels ); - } - - @Override - public boolean accepts( ResourceLocation modelLocation ) - { - if( !modelLocation.getNamespace().equals( AppEng.MOD_ID ) ) - { - return false; - } - - return this.builtInModels.containsKey( modelLocation.getResourcePath() ); - } - - @Override - public IModel loadModel( ResourceLocation modelLocation ) throws Exception - { - return this.builtInModels.get( modelLocation.getResourcePath() ); - } - - @Override - public void onResourceManagerReload( IResourceManager resourceManager ) - { - for( IModel model : this.builtInModels.values() ) - { - if( model instanceof IResourceManagerReloadListener ) - { - ( (IResourceManagerReloadListener) model ).onResourceManagerReload( resourceManager ); - } - } - } -} diff --git a/src/main/java/appeng/client/render/model/ColorApplicatorModel.java b/src/main/java/appeng/client/render/model/ColorApplicatorModel.java index fbf9b31ab..4f37e50ed 100644 --- a/src/main/java/appeng/client/render/model/ColorApplicatorModel.java +++ b/src/main/java/appeng/client/render/model/ColorApplicatorModel.java @@ -10,24 +10,22 @@ import javax.annotation.Nullable; import com.mojang.datafixers.util.Pair; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.IModelTransform; -import net.minecraft.client.renderer.model.IUnbakedModel; -import net.minecraft.client.renderer.model.Material; -import net.minecraft.client.renderer.model.ModelBakery; +import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.IModelConfiguration; import net.minecraftforge.client.model.ModelLoaderRegistry; import appeng.core.AppEng; +import net.minecraftforge.client.model.geometry.IModelGeometry; /** * A color applicator uses the base model, and extends it with additional layers that are colored according to the * selected color of the applicator. */ -public class ColorApplicatorModel implements IUnbakedModel +public class ColorApplicatorModel implements IModelGeometry { private static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "item/color_applicator_colored" ); @@ -37,27 +35,18 @@ public class ColorApplicatorModel implements IUnbakedModel private static final Material TEXTURE_BRIGHT = new Material( AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "items/color_applicator_tip_bright" ) ); @Override - public Collection getDependencies() - { - return Collections.singletonList( MODEL_BASE ); - } - - @Override - public Collection getTextures( Function modelGetter, Set> missingTextureErrors ) - { + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { return Arrays.asList( TEXTURE_DARK, TEXTURE_MEDIUM, TEXTURE_DARK ); } - @Nullable @Override - public IBakedModel bakeModel( ModelBakery modelBakeryIn, Function spriteGetterIn, IModelTransform transformIn, ResourceLocation locationIn ) - { - IBakedModel baseModel = modelBakeryIn.getBakedModel( MODEL_BASE, transformIn, spriteGetterIn ); + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { + IBakedModel baseModel = bakery.getBakedModel( MODEL_BASE, modelTransform, spriteGetter ); - TextureAtlasSprite texDark = spriteGetterIn.apply( TEXTURE_DARK ); - TextureAtlasSprite texMedium = spriteGetterIn.apply( TEXTURE_MEDIUM ); - TextureAtlasSprite texBright = spriteGetterIn.apply( TEXTURE_BRIGHT ); + TextureAtlasSprite texDark = spriteGetter.apply( TEXTURE_DARK ); + TextureAtlasSprite texMedium = spriteGetter.apply( TEXTURE_MEDIUM ); + TextureAtlasSprite texBright = spriteGetter.apply( TEXTURE_BRIGHT ); - return new ColorApplicatorBakedModel( baseModel, transformIn, texDark, texMedium, texBright ); + return new ColorApplicatorBakedModel( baseModel, modelTransform, texDark, texMedium, texBright ); } } diff --git a/src/main/java/appeng/client/render/model/DriveBakedModel.java b/src/main/java/appeng/client/render/model/DriveBakedModel.java index bf1eb6474..e23a0ce78 100644 --- a/src/main/java/appeng/client/render/model/DriveBakedModel.java +++ b/src/main/java/appeng/client/render/model/DriveBakedModel.java @@ -19,53 +19,48 @@ package appeng.client.render.model; +import appeng.block.storage.DriveSlotState; +import appeng.block.storage.DriveSlotsState; +import appeng.client.render.DelegateBakedModel; +import appeng.tile.storage.TileDrive; +import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.util.Direction; +import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Map; - -import javax.annotation.Nullable; - -import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.ItemCameraTransforms; -import net.minecraft.client.renderer.model.ItemOverrideList; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.Direction; -import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; -import net.minecraftforge.common.property.IExtendedBlockState; - -import appeng.block.storage.BlockDrive; -import appeng.block.storage.DriveSlotState; -import appeng.block.storage.DriveSlotsState; +import java.util.Random; -public class DriveBakedModel implements IBakedModel +public class DriveBakedModel extends DelegateBakedModel { private final IBakedModel bakedBase; private final Map bakedCells; public DriveBakedModel( IBakedModel bakedBase, Map bakedCells ) { + super(bakedBase); this.bakedBase = bakedBase; this.bakedCells = bakedCells; } + @Nonnull @Override - public List getQuads( @Nullable BlockState state, @Nullable Direction side, long rand ) - { + public List getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) { - List result = new ArrayList<>(); + List result = new ArrayList<>(this.bakedBase.getQuads(state, side, rand, extraData)); - result.addAll( this.bakedBase.getQuads( state, side, rand ) ); + DriveSlotsState slotsState = extraData.getData( TileDrive.SLOTS_STATE ); - if( side == null && state instanceof IExtendedBlockState ) + if( side == null && slotsState != null ) { - IExtendedBlockState extState = (IExtendedBlockState) state; - DriveSlotsState slotsState = extState.getValue( BlockDrive.SLOTS_STATE ); - for( int row = 0; row < 5; row++ ) { for( int col = 0; col < 2; col++ ) @@ -82,12 +77,12 @@ public class DriveBakedModel implements IBakedModel float xOffset = -col * 7 / 16.0f; float yOffset = -row * 3 / 16.0f; - transform.setTranslation( new Vector3f( xOffset, yOffset, 0 ) ); + transform.setTranslation( xOffset, yOffset, 0 ); MatrixVertexTransformer transformer = new MatrixVertexTransformer( transform ); - for( BakedQuad bakedQuad : bakedCell.getQuads( state, null, rand ) ) + for( BakedQuad bakedQuad : bakedCell.getQuads( state, null, rand, extraData ) ) { - UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder( bakedQuad.getFormat() ); + BakedQuadBuilder builder = new BakedQuadBuilder(); transformer.setParent( builder ); transformer.setVertexFormat( builder.getVertexFormat() ); bakedQuad.pipe( transformer ); @@ -100,39 +95,4 @@ public class DriveBakedModel implements IBakedModel return result; } - @Override - public boolean isAmbientOcclusion() - { - return this.bakedBase.isAmbientOcclusion(); - } - - @Override - public boolean isGui3d() - { - return this.bakedBase.isGui3d(); - } - - @Override - public boolean isBuiltInRenderer() - { - return this.bakedBase.isGui3d(); - } - - @Override - public TextureAtlasSprite getParticleTexture() - { - return this.bakedBase.getParticleTexture(); - } - - @Override - public ItemCameraTransforms getItemCameraTransforms() - { - return this.bakedBase.getItemCameraTransforms(); - } - - @Override - public ItemOverrideList getOverrides() - { - return this.bakedBase.getOverrides(); - } } diff --git a/src/main/java/appeng/client/render/model/DriveModel.java b/src/main/java/appeng/client/render/model/DriveModel.java index b9a253505..d228cce5a 100644 --- a/src/main/java/appeng/client/render/model/DriveModel.java +++ b/src/main/java/appeng/client/render/model/DriveModel.java @@ -19,28 +19,19 @@ package appeng.client.render.model; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumMap; -import java.util.Map; +import appeng.block.storage.DriveSlotState; +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.renderer.model.*; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; + +import java.util.*; import java.util.function.Function; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.client.model.ModelLoaderRegistry; -import net.minecraftforge.common.model.IModelState; -import net.minecraftforge.common.model.TRSRTransformation; - -import appeng.block.storage.DriveSlotState; - - -public class DriveModel implements IModel +public class DriveModel implements IModelGeometry { private static final ResourceLocation MODEL_BASE = new ResourceLocation( "appliedenergistics2:block/drive_base" ); @@ -53,45 +44,23 @@ public class DriveModel implements IModel DriveSlotState.FULL, new ResourceLocation( "appliedenergistics2:block/drive_cell_full" ) ); @Override - public Collection getDependencies() - { - return ImmutableList.builder().add( MODEL_BASE ).addAll( MODELS_CELLS.values() ).build(); - } - - @Override - public Collection getTextures() - { - return Collections.emptyList(); - } - - @Override - public IBakedModel bake( IModelState state, VertexFormat format, Function bakedTextureGetter ) - { + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { EnumMap cellModels = new EnumMap<>( DriveSlotState.class ); // Load the base model and the model for each cell state. - IModel baseModel; - try + for( DriveSlotState slotState : MODELS_CELLS.keySet() ) { - baseModel = ModelLoaderRegistry.getModel( MODEL_BASE ); - for( DriveSlotState slotState : MODELS_CELLS.keySet() ) - { - IModel model = ModelLoaderRegistry.getModel( MODELS_CELLS.get( slotState ) ); - cellModels.put( slotState, model.bake( state, format, bakedTextureGetter ) ); - } - } - catch( Exception e ) - { - throw new RuntimeException( e ); + IBakedModel cellModel = bakery.getBakedModel( MODELS_CELLS.get( slotState ), modelTransform, spriteGetter ); + cellModels.put( slotState, cellModel ); } - IBakedModel bakedBase = baseModel.bake( state, format, bakedTextureGetter ); - return new DriveBakedModel( bakedBase, cellModels ); + IBakedModel baseModel = bakery.getBakedModel( MODEL_BASE, modelTransform, spriteGetter ); + return new DriveBakedModel( baseModel, cellModels ); } @Override - public IModelState getDefaultState() - { - return TRSRTransformation.identity(); + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { + return Collections.emptyList(); } + } diff --git a/src/main/java/appeng/client/render/model/GlassModelLoader.java b/src/main/java/appeng/client/render/model/GlassModelLoader.java deleted file mode 100644 index 765733ad8..000000000 --- a/src/main/java/appeng/client/render/model/GlassModelLoader.java +++ /dev/null @@ -1,21 +0,0 @@ -package appeng.client.render.model; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import net.minecraft.resources.IResourceManager; -import net.minecraftforge.client.model.IModelLoader; - -public class GlassModelLoader implements IModelLoader { - - public static final GlassModelLoader INSTANCE = new GlassModelLoader(); - - @Override - public void onResourceManagerReload(IResourceManager resourceManager) { - } - - @Override - public GlassModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) { - return new GlassModel(); - } - -} diff --git a/src/main/java/appeng/client/render/model/MemoryCardModel.java b/src/main/java/appeng/client/render/model/MemoryCardModel.java index d3cbfbacb..e96626dc0 100644 --- a/src/main/java/appeng/client/render/model/MemoryCardModel.java +++ b/src/main/java/appeng/client/render/model/MemoryCardModel.java @@ -9,47 +9,40 @@ import javax.annotation.Nullable; import com.mojang.datafixers.util.Pair; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.IModelTransform; -import net.minecraft.client.renderer.model.IUnbakedModel; -import net.minecraft.client.renderer.model.Material; -import net.minecraft.client.renderer.model.ModelBakery; +import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.ResourceLocation; import appeng.core.AppEng; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; /** * Model wrapper for the memory card item model, which combines a base card layer with a "visual hash" of the part/tile. */ -public class MemoryCardModel implements IUnbakedModel +public class MemoryCardModel implements IModelGeometry { private static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "item/memory_card" ); private static final Material TEXTURE = new Material( AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "items/memory_card_hash" ) ); @Override - public Collection getDependencies() - { - return Collections.singletonList( MODEL_BASE ); - } - - @Override - public Collection getTextures( Function modelGetter, Set> missingTextureErrors ) + public Collection getTextures( IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors ) { return Collections.singleton( TEXTURE ); } @Nullable @Override - public IBakedModel bakeModel( ModelBakery modelBakeryIn, Function spriteGetterIn, IModelTransform transformIn, ResourceLocation locationIn ) + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { - TextureAtlasSprite texture = spriteGetterIn.apply( TEXTURE ); + TextureAtlasSprite texture = spriteGetter.apply( TEXTURE ); - IBakedModel baseModel = modelBakeryIn.getBakedModel( MODEL_BASE, transformIn, spriteGetterIn ); + IBakedModel baseModel = bakery.getBakedModel( MODEL_BASE, modelTransform, spriteGetter ); return new MemoryCardBakedModel( baseModel, texture ); } + } diff --git a/src/main/java/appeng/client/render/model/SkyCompassModelLoader.java b/src/main/java/appeng/client/render/model/SkyCompassModelLoader.java deleted file mode 100644 index 502573f47..000000000 --- a/src/main/java/appeng/client/render/model/SkyCompassModelLoader.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.client.render.model; - - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import net.minecraft.resources.IResourceManager; -import net.minecraftforge.client.model.IModelLoader; - - -/** - * Allows the built-in sky compass model the be loaded from JSON. - */ -public class SkyCompassModelLoader implements IModelLoader { - - public static final SkyCompassModelLoader INSTANCE = new SkyCompassModelLoader(); - - @Override - public void onResourceManagerReload(IResourceManager resourceManager) { - } - - @Override - public SkyCompassModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) { - return new SkyCompassModel(); - } - -} diff --git a/src/main/java/appeng/client/render/spatial/SpatialPylonBakedModel.java b/src/main/java/appeng/client/render/spatial/SpatialPylonBakedModel.java index f63a2725f..df165ba39 100644 --- a/src/main/java/appeng/client/render/spatial/SpatialPylonBakedModel.java +++ b/src/main/java/appeng/client/render/spatial/SpatialPylonBakedModel.java @@ -19,50 +19,43 @@ package appeng.client.render.spatial; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - -import com.google.common.collect.ImmutableMap; - -import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; -import net.minecraft.client.renderer.block.model.ItemOverrideList; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.Direction; -import net.minecraftforge.common.property.IExtendedBlockState; - -import appeng.block.spatial.BlockSpatialPylon; import appeng.client.render.cablebus.CubeBuilder; import appeng.tile.spatial.TileSpatialPylon; +import com.google.common.collect.ImmutableMap; +import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.model.ItemOverrideList; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.Direction; +import net.minecraftforge.client.model.data.IDynamicBakedModel; +import net.minecraftforge.client.model.data.IModelData; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; +import java.util.Map; +import java.util.Random; /** * The baked model that will be used for rendering the spatial pylon. */ -class SpatialPylonBakedModel implements IBakedModel +class SpatialPylonBakedModel implements IDynamicBakedModel { private final Map textures; - private final VertexFormat format; - - SpatialPylonBakedModel( VertexFormat format, Map textures ) + SpatialPylonBakedModel( Map textures ) { this.textures = ImmutableMap.copyOf( textures ); - this.format = format; } + @Nonnull @Override - public List getQuads( @Nullable BlockState state, @Nullable Direction side, long rand ) - { - int flags = this.getFlags( state ); + public List getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) { + int flags = this.getFlags( extraData ); - CubeBuilder builder = new CubeBuilder( this.format ); + CubeBuilder builder = new CubeBuilder(); if( flags != 0 ) { @@ -162,16 +155,10 @@ class SpatialPylonBakedModel implements IBakedModel return builder.getOutput(); } - private int getFlags( BlockState state ) + private int getFlags( IModelData modelData ) { - if( !( state instanceof IExtendedBlockState ) ) - { - return 0; - } - - IExtendedBlockState extState = (IExtendedBlockState) state; - - return extState.getValue( BlockSpatialPylon.STATE ); + Integer flags = modelData.getData(TileSpatialPylon.STATE); + return flags != null ? flags : 0; } private static SpatialPylonTextureType getTextureTypeFromSideOutside( int flags, Direction ori, Direction dir ) @@ -222,6 +209,11 @@ class SpatialPylonBakedModel implements IBakedModel return SpatialPylonTextureType.BASE; } + @Override + public boolean func_230044_c_() { + return false; + } + @Override public boolean isAmbientOcclusion() { @@ -246,12 +238,6 @@ class SpatialPylonBakedModel implements IBakedModel return this.textures.get( SpatialPylonTextureType.DIM ); } - @Override - public ItemCameraTransforms getItemCameraTransforms() - { - return ItemCameraTransforms.DEFAULT; - } - @Override public ItemOverrideList getOverrides() { diff --git a/src/main/java/appeng/client/render/spatial/SpatialPylonModel.java b/src/main/java/appeng/client/render/spatial/SpatialPylonModel.java index b60432c13..41a203544 100644 --- a/src/main/java/appeng/client/render/spatial/SpatialPylonModel.java +++ b/src/main/java/appeng/client/render/spatial/SpatialPylonModel.java @@ -19,62 +19,45 @@ package appeng.client.render.spatial; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumMap; -import java.util.Map; +import appeng.core.AppEng; +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.renderer.model.*; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.IModelConfiguration; +import net.minecraftforge.client.model.geometry.IModelGeometry; + +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.common.model.IModelState; -import net.minecraftforge.common.model.TRSRTransformation; -import appeng.core.AppEng; - - -class SpatialPylonModel implements IModel +public class SpatialPylonModel implements IModelGeometry { @Override - public Collection getDependencies() - { - return Collections.emptyList(); - } - - @Override - public Collection getTextures() - { - return Arrays.stream( SpatialPylonTextureType.values() ).map( SpatialPylonModel::getTexturePath ).collect( Collectors.toList() ); - } - - @Override - public IBakedModel bake( IModelState state, VertexFormat format, Function bakedTextureGetter ) - { + public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function spriteGetter, IModelTransform modelTransform, ItemOverrideList overrides, ResourceLocation modelLocation) { Map textures = new EnumMap<>( SpatialPylonTextureType.class ); for( SpatialPylonTextureType type : SpatialPylonTextureType.values() ) { - ResourceLocation loc = getTexturePath( type ); - textures.put( type, bakedTextureGetter.apply( loc ) ); + textures.put( type, spriteGetter.apply(getTexturePath( type )) ); } - return new SpatialPylonBakedModel( format, textures ); + return new SpatialPylonBakedModel( textures ); } @Override - public IModelState getDefaultState() - { - return TRSRTransformation.identity(); + public Collection getTextures(IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors) { + return Arrays.stream( SpatialPylonTextureType.values() ) + .map( SpatialPylonModel::getTexturePath ) + .collect( Collectors.toList() ); } - private static ResourceLocation getTexturePath( SpatialPylonTextureType type ) + private static Material getTexturePath( SpatialPylonTextureType type ) { - return new ResourceLocation( AppEng.MOD_ID, "blocks/spatial_pylon/" + type.name().toLowerCase() ); + return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation( AppEng.MOD_ID, "blocks/spatial_pylon/" + type.name().toLowerCase() ) ); } + } diff --git a/src/main/java/appeng/client/render/textures/ParticleTextures.java b/src/main/java/appeng/client/render/textures/ParticleTextures.java deleted file mode 100644 index 255a31dc4..000000000 --- a/src/main/java/appeng/client/render/textures/ParticleTextures.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.client.render.textures; - - -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.TextureStitchEvent; - - -public class ParticleTextures -{ - public static TextureAtlasSprite BlockEnergyParticle; - public static TextureAtlasSprite BlockMatterCannonParticle; - - public static void registerSprite( TextureStitchEvent.Pre event ) - { - BlockEnergyParticle = event.getMap().registerSprite( new ResourceLocation( "appliedenergistics2:particles/energy" ) ); - BlockMatterCannonParticle = event.getMap().registerSprite( new ResourceLocation( "appliedenergistics2:particles/matter_cannon" ) ); - } -} diff --git a/src/main/java/appeng/container/AEBaseContainer.java b/src/main/java/appeng/container/AEBaseContainer.java index 21e163b63..7ef45b1cf 100644 --- a/src/main/java/appeng/container/AEBaseContainer.java +++ b/src/main/java/appeng/container/AEBaseContainer.java @@ -33,10 +33,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.IContainerListener; -import net.minecraft.inventory.container.Slot; +import net.minecraft.inventory.container.*; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.items.IItemHandler; @@ -89,7 +86,7 @@ public abstract class AEBaseContainer extends Container private final HashMap syncData = new HashMap<>(); private boolean isContainerValid = true; private String customName; - private ContainerOpenContext openContext; + private ContainerLocator locator; private IMEInventoryHandler cellInv; private IEnergySource powerSrc; private boolean sentCustomName; @@ -1060,6 +1057,7 @@ public abstract class AEBaseContainer extends Container private void sendCustomName() { + // FIXME: Trash this, this is handled by NamedContainerProvider now if( !this.sentCustomName ) { this.sentCustomName = true; @@ -1096,16 +1094,9 @@ public abstract class AEBaseContainer extends Container if( this.getCustomName() != null ) { - try - { - NetworkHandler.instance() - .sendTo( new PacketValueConfig( "CustomName", this.getCustomName() ), - (ServerPlayerEntity) this.getPlayerInventory().player ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + NetworkHandler.instance() + .sendTo( new PacketValueConfig( "CustomName", this.getCustomName() ), + (ServerPlayerEntity) this.getPlayerInventory().player ); } } } @@ -1242,14 +1233,14 @@ public abstract class AEBaseContainer extends Container this.isContainerValid = isContainerValid; } - public ContainerOpenContext getOpenContext() + public ContainerLocator getLocator() { - return this.openContext; + return this.locator; } - public void setOpenContext( final ContainerOpenContext openContext ) + public void setLocator(final ContainerLocator locator) { - this.openContext = openContext; + this.locator = locator; } public IEnergySource getPowerSource() @@ -1261,4 +1252,5 @@ public abstract class AEBaseContainer extends Container { this.powerSrc = powerSrc; } + } diff --git a/src/main/java/appeng/container/ContainerLocator.java b/src/main/java/appeng/container/ContainerLocator.java new file mode 100644 index 000000000..21407268d --- /dev/null +++ b/src/main/java/appeng/container/ContainerLocator.java @@ -0,0 +1,187 @@ +/* + * 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.container; + + +import appeng.api.parts.IPartHost; +import appeng.api.util.AEPartLocation; +import appeng.api.util.DimensionalCoord; +import appeng.parts.AEBasePart; +import appeng.parts.misc.PartInterface; +import com.google.common.base.Preconditions; +import io.netty.handler.codec.DecoderException; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.PacketBuffer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import org.apache.commons.lang3.NotImplementedException; + +/** + * Describes how a container the player has opened was originally + * located. This can be one of three ways: + * + *

    + *
  • A tile entity at a given block position.
  • + *
  • A part (i.e. cable bus part) at the side of a given block position.
  • + *
  • An item held by the player.
  • + *
+ */ +public final class ContainerLocator { + + private enum Type { + ITEM, + BLOCK, + PART + } + + private final Type type; + private final int itemIndex; + private final int dimensionId; + private final BlockPos blockPos; + private final AEPartLocation side; + + private ContainerLocator(Type type, int itemIndex, int dimensionId, BlockPos blockPos, AEPartLocation side) { + this.type = type; + this.itemIndex = itemIndex; + this.dimensionId = dimensionId; + this.blockPos = blockPos; + this.side = side; + } + + public static ContainerLocator forTileEntity(TileEntity te) { + if (te.getWorld() == null) { + throw new IllegalArgumentException("Cannot open a tile entity that is not in a world"); + } + int dimensionId = te.getWorld().getDimension().getType().getId(); + return new ContainerLocator(Type.BLOCK, -1, dimensionId, te.getPos(), null); + } + + public static ContainerLocator forTileEntitySide(TileEntity te, Direction side) { + if (te.getWorld() == null) { + throw new IllegalArgumentException("Cannot open a tile entity that is not in a world"); + } + int dimensionId = te.getWorld().getDimension().getType().getId(); + return new ContainerLocator(Type.PART, -1, dimensionId, te.getPos(), AEPartLocation.fromFacing(side)); + } + + public static ContainerLocator forHand(Hand hand) { + // FIXME can we get an inventory location for the hand? + throw new IllegalStateException(); + } + + public static ContainerLocator forPart(AEBasePart part) { + IPartHost host = part.getHost(); + DimensionalCoord pos = host.getLocation(); + return new ContainerLocator( + Type.PART, + -1, + pos.getWorld().getDimension().getType().getId(), + pos.getBlockPos(), + part.getSide() + ); + } + + public boolean hasItemIndex() { + return type == Type.ITEM; + } + + public int getItemIndex() { + Preconditions.checkState(type == Type.ITEM); + return itemIndex; + } + + public int getDimensionId() { + return dimensionId; + } + + public boolean hasBlockPos() { + return type == Type.BLOCK || type == Type.PART; + } + + public BlockPos getBlockPos() { + Preconditions.checkState(type == Type.BLOCK || type == Type.PART); + return blockPos; + } + + public boolean hasSide() { + return type == Type.PART; + } + + public AEPartLocation getSide() { + Preconditions.checkState(type == Type.PART); + return side; + } + + public void write(PacketBuffer buf) { + switch (type) { + case ITEM: + buf.writeByte(0); + buf.writeInt(itemIndex); + break; + case BLOCK: + buf.writeByte(1); + buf.writeInt(dimensionId); + buf.writeBlockPos(blockPos); + break; + case PART: + buf.writeByte(2); + buf.writeInt(dimensionId); + buf.writeBlockPos(blockPos); + buf.writeByte(side.ordinal()); + break; + default: + throw new IllegalStateException("Unsupported ContainerLocator type: " + type); + } + } + + public static ContainerLocator read(PacketBuffer buf) { + byte type = buf.readByte(); + switch (type) { + case 0: + return new ContainerLocator( + Type.ITEM, + buf.readInt(), + -1, + null, + null + ); + case 1: + return new ContainerLocator( + Type.BLOCK, + -1, + buf.readInt(), + buf.readBlockPos(), + null + ); + case 2: + return new ContainerLocator( + Type.PART, + -1, + buf.readInt(), + buf.readBlockPos(), + AEPartLocation.values()[buf.readByte()] + ); + default: + throw new DecoderException("ContainerLocator type out of range: " + type); + } + } + +} diff --git a/src/main/java/appeng/container/ContainerOpenContext.java b/src/main/java/appeng/container/ContainerOpenContext.java deleted file mode 100644 index 6f7ed7248..000000000 --- a/src/main/java/appeng/container/ContainerOpenContext.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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.container; - - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import appeng.api.parts.IPart; -import appeng.api.util.AEPartLocation; - - -public class ContainerOpenContext -{ - - private final boolean isItem; - private World w; - private int x; - private int y; - private int z; - private AEPartLocation side; - - public ContainerOpenContext( final Object myItem ) - { - final boolean isWorld = myItem instanceof IPart || myItem instanceof TileEntity; - this.isItem = !isWorld; - } - - public TileEntity getTile() - { - if( this.isItem ) - { - return null; - } - return this.w.getTileEntity( new BlockPos( this.x, this.y, this.z ) ); - } - - public AEPartLocation getSide() - { - return this.side; - } - - public void setSide( final AEPartLocation side ) - { - this.side = side; - } - - private int getZ() - { - return this.z; - } - - public void setZ( final int z ) - { - this.z = z; - } - - private int getY() - { - return this.y; - } - - public void setY( final int y ) - { - this.y = y; - } - - private int getX() - { - return this.x; - } - - public void setX( final int x ) - { - this.x = x; - } - - private World getWorld() - { - return this.w; - } - - public void setWorld( final World w ) - { - this.w = w; - } -} diff --git a/src/main/java/appeng/container/ContainerOpener.java b/src/main/java/appeng/container/ContainerOpener.java new file mode 100644 index 000000000..98904c36d --- /dev/null +++ b/src/main/java/appeng/container/ContainerOpener.java @@ -0,0 +1,43 @@ +package appeng.container; + +import appeng.core.AELog; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.ContainerType; + +import java.util.HashMap; +import java.util.Map; + +/** + * Allows opening containers generically. + */ +public final class ContainerOpener { + + private ContainerOpener() { + } + + private static final Map, Opener> registry = new HashMap<>(); + + public static void addOpener(ContainerType type, Opener opener) { + registry.put(type, opener); + } + + public static boolean openContainer(ContainerType type, PlayerEntity player, ContainerLocator locator) { + Opener opener = registry.get(type); + if (opener == null) { + AELog.warn("Trying to open container for unknown container type {}", type); + return false; + } + + return opener.open(player, locator); + } + + @FunctionalInterface + public interface Opener { + + boolean open(PlayerEntity player, ContainerLocator locator); + + } + +} diff --git a/src/main/java/appeng/container/helper/PartContainerHelper.java b/src/main/java/appeng/container/helper/PartContainerHelper.java new file mode 100644 index 000000000..a58f87eaa --- /dev/null +++ b/src/main/java/appeng/container/helper/PartContainerHelper.java @@ -0,0 +1,110 @@ +package appeng.container.helper; + +import appeng.api.config.SecurityPermissions; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartHost; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerLocator; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.inventory.container.SimpleNamedContainerProvider; +import net.minecraft.network.PacketBuffer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.network.NetworkHooks; + +/** + * Helper for containers that can be opened for {@link appeng.api.parts.IPart parts} that are attached + * to a {@link appeng.api.parts.IPartHost part host}. + * + * @param + * @param

The type of part this container is for. + */ +public final class PartContainerHelper { + + private final Class

partClass; + + private final ContainerFactory factory; + + private final SecurityPermissions requiredPermission; + + public PartContainerHelper(ContainerFactory factory, Class

partClass) { + this(factory, partClass, null); + } + + public PartContainerHelper(ContainerFactory factory, Class

partClass, SecurityPermissions requiredPermission) { + this.partClass = partClass; + this.factory = factory; + this.requiredPermission = requiredPermission; + } + + /** + * Opens a container that is based around a single tile entity. + * The tile entity's position is encoded in the packet buffer. + */ + public C fromNetwork(int windowId, PlayerInventory inv, PacketBuffer packetBuf) { + BlockPos pos = packetBuf.readBlockPos(); + TileEntity te = inv.player.world.getTileEntity(pos); + if (partClass.isInstance(te)) { + return factory.create(windowId, inv, partClass.cast(te)); + } + return null; + } + + public boolean open(PlayerEntity player, ContainerLocator locator) { + if (!(player instanceof ServerPlayerEntity)) { + // Cannot open containers on the client or for non-players + // FIXME logging? + return false; + } + + if (!locator.hasBlockPos() || !locator.hasSide()) { + return false; // No block was clicked or the side is unknown + // FIXME: If no side is provided, should be try with INTERNAL??? + } + + TileEntity tileEntity = player.world.getTileEntity(locator.getBlockPos()); + if (!(tileEntity instanceof IPartHost)) { + // FIXME logging? + return false; // Wrong tile entity at block position + } + IPartHost partHost = (IPartHost) tileEntity; + IPart part = partHost.getPart(locator.getSide()); + if (!(partClass.isInstance(part))) { + // FIXME logging? + return false; + } + P actualPart = partClass.cast(tileEntity); + + // Use block name at position + // FIXME: this is not right, we'd need to check the part's item stack, or custom naming interface impl + ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent(); + + // FIXME: Check permissions... + if (requiredPermission != null) { + throw new IllegalStateException(); // NOT YET IMPLEMENTED + } + + INamedContainerProvider container = new SimpleNamedContainerProvider( + (wnd, p, pl) -> { + C c = factory.create(wnd, p, actualPart); + // Set the original locator on the opened server-side container for it to more + // easily remember how to re-open after being closed. + c.setLocator(locator); + return c; + }, title + ); + NetworkHooks.openGui((ServerPlayerEntity) player, container, locator.getBlockPos()); + + return true; + } + + @FunctionalInterface + public interface ContainerFactory { + C create(int windowId, PlayerInventory playerInv, T part); + } + +} diff --git a/src/main/java/appeng/container/helper/PartOrTileContainerHelper.java b/src/main/java/appeng/container/helper/PartOrTileContainerHelper.java new file mode 100644 index 000000000..db749450c --- /dev/null +++ b/src/main/java/appeng/container/helper/PartOrTileContainerHelper.java @@ -0,0 +1,119 @@ +package appeng.container.helper; + +import appeng.api.config.SecurityPermissions; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartHost; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerLocator; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.inventory.container.SimpleNamedContainerProvider; +import net.minecraft.network.PacketBuffer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.network.NetworkHooks; + +/** + * Helper for containers that can be opened for a part or tile given that either + * implements a given interface. + * + * @param + */ +// FIXME: This is also used in contexts where access is via an item that implements I or exposes I via IGuiItemObject +public final class PartOrTileContainerHelper { + + private final Class interfaceClass; + + private final ContainerFactory factory; + + private final SecurityPermissions requiredPermission; + + public PartOrTileContainerHelper(ContainerFactory factory, Class interfaceClass) { + this(factory, interfaceClass, null); + } + + public PartOrTileContainerHelper(ContainerFactory factory, Class interfaceClass, SecurityPermissions requiredPermission) { + this.interfaceClass = interfaceClass; + this.factory = factory; + this.requiredPermission = requiredPermission; + } + + /** + * Opens a container that is based around a single tile entity. + * The tile entity's position is encoded in the packet buffer. + */ + public C fromNetwork(int windowId, PlayerInventory inv, PacketBuffer packetBuf) { + I host = getHostFromLocator(inv.player, ContainerLocator.read(packetBuf)); + if (host != null) { + return factory.create(windowId, inv, host); + } + return null; + } + + public boolean open(PlayerEntity player, ContainerLocator locator) { + if (!(player instanceof ServerPlayerEntity)) { + // Cannot open containers on the client or for non-players + // FIXME logging? + return false; + } + + I accessInterface = getHostFromLocator(player, locator); + + // Use block name at position + // FIXME: this is not right, we'd need to check the part's item stack, or custom naming interface impl + // FIXME: Should move this up, because at this point, it's hard to know where the terminal host came from (part or tile) + ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent(); + + // FIXME: Check permissions... + if (requiredPermission != null) { + throw new IllegalStateException(); // NOT YET IMPLEMENTED + } + + INamedContainerProvider container = new SimpleNamedContainerProvider( + (wnd, p, pl) -> { + C c = factory.create(wnd, p, accessInterface); + // Set the original locator on the opened server-side container for it to more + // easily remember how to re-open after being closed. + c.setLocator(locator); + return c; + }, title + ); + NetworkHooks.openGui((ServerPlayerEntity) player, container, locator.getBlockPos()); + + return true; + } + + private I getHostFromLocator(PlayerEntity player, ContainerLocator locator) { + if (!locator.hasBlockPos() || !locator.hasSide()) { + return null; // No block was clicked or the side is unknown + // FIXME: If no side is provided, should be try with INTERNAL??? + } + + TileEntity tileEntity = player.world.getTileEntity(locator.getBlockPos()); + // The tile entity itself can host a terminal (i.e. Chest!) + if (interfaceClass.isInstance(tileEntity)) { + return interfaceClass.cast(tileEntity); + } else if (tileEntity instanceof IPartHost) { + // But it could also be a part attached to the tile entity + IPartHost partHost = (IPartHost) tileEntity; + IPart part = partHost.getPart(locator.getSide()); + if (interfaceClass.isInstance(part)) { + return interfaceClass.cast(part); + } else { + // FIXME: Logging? + return null; + } + } else { + // FIXME: Logging? Dont know how to obtain the terminal host + return null; + } + } + + @FunctionalInterface + public interface ContainerFactory { + C create(int windowId, PlayerInventory playerInv, I accessObj); + } + +} diff --git a/src/main/java/appeng/container/helper/TileContainerHelper.java b/src/main/java/appeng/container/helper/TileContainerHelper.java new file mode 100644 index 000000000..1095672c1 --- /dev/null +++ b/src/main/java/appeng/container/helper/TileContainerHelper.java @@ -0,0 +1,91 @@ +package appeng.container.helper; + +import appeng.api.config.SecurityPermissions; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerLocator; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.inventory.container.SimpleNamedContainerProvider; +import net.minecraft.network.PacketBuffer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.network.NetworkHooks; + +public final class TileContainerHelper { + + private final Class tileEntityClass; + + private final ContainerFactory factory; + + private final SecurityPermissions requiredPermission; + + public TileContainerHelper(ContainerFactory factory, Class tileEntityClass) { + this(factory, tileEntityClass, null); + } + + public TileContainerHelper(ContainerFactory factory, Class tileEntityClass, SecurityPermissions requiredPermission) { + this.tileEntityClass = tileEntityClass; + this.factory = factory; + this.requiredPermission = requiredPermission; + } + + /** + * Opens a container that is based around a single tile entity. + * The tile entity's position is encoded in the packet buffer. + */ + public C fromNetwork(int windowId, PlayerInventory inv, PacketBuffer packetBuf) { + BlockPos pos = packetBuf.readBlockPos(); + TileEntity te = inv.player.world.getTileEntity(pos); + if (tileEntityClass.isInstance(te)) { + return factory.create(windowId, inv, tileEntityClass.cast(te)); + } + return null; + } + + public boolean open(PlayerEntity player, ContainerLocator locator) { + if (!(player instanceof ServerPlayerEntity)) { + // Cannot open containers on the client or for non-players + return false; + } + + if (!locator.hasBlockPos()) { + return false; // No block was clicked + } + + TileEntity tileEntity = player.world.getTileEntity(locator.getBlockPos()); + if (!tileEntityClass.isInstance(tileEntity)) { + return false; // Wrong tile entity at block position + } + T te = tileEntityClass.cast(tileEntity); + + // Use block name at position + ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent(); + + // FIXME: Check permissions... + if (requiredPermission != null) { + throw new IllegalStateException(); // NOT YET IMPLEMENTED + } + + INamedContainerProvider container = new SimpleNamedContainerProvider( + (wnd, p, pl) -> { + C c = factory.create(wnd, p, te); + // Set the original locator on the opened server-side container for it to more + // easily remember how to re-open after being closed. + c.setLocator(locator); + return c; + }, title + ); + NetworkHooks.openGui((ServerPlayerEntity) player, container, locator.getBlockPos()); + + return true; + } + + @FunctionalInterface + public interface ContainerFactory { + C create(int windowId, PlayerInventory playerInv, T tileEntity); + } + +} diff --git a/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java b/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java index 231f32a61..4c1e504eb 100644 --- a/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java +++ b/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java @@ -21,13 +21,15 @@ package appeng.container.implementations; import java.util.Iterator; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; import appeng.core.Api; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.IContainerListener; -import net.minecraft.inventory.container.Slot; +import net.minecraft.inventory.container.*; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.wrapper.EmptyHandler; @@ -54,18 +56,32 @@ import appeng.util.iterators.NullIterator; public class ContainerCellWorkbench extends ContainerUpgradeable { + + public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerCellWorkbench::new, TileCellWorkbench.class); + private final TileCellWorkbench workBench; @GuiSync( 2 ) public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE; private ItemStack prevStack = ItemStack.EMPTY; private int lastUpgrades = 0; - public ContainerCellWorkbench(ContainerType containerType, int id, final PlayerInventory ip, final TileCellWorkbench te ) + public ContainerCellWorkbench(int id, final PlayerInventory ip, final TileCellWorkbench te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); this.workBench = te; } + public static ContainerCellWorkbench fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + public void setFuzzy( final FuzzyMode valueOf ) { final ICellWorkbenchItem cwi = this.workBench.getCell(); diff --git a/src/main/java/appeng/container/implementations/ContainerChest.java b/src/main/java/appeng/container/implementations/ContainerChest.java index 47f7ad272..dbaca8e05 100644 --- a/src/main/java/appeng/container/implementations/ContainerChest.java +++ b/src/main/java/appeng/container/implementations/ContainerChest.java @@ -19,27 +19,43 @@ package appeng.container.implementations; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.container.AEBaseContainer; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.storage.TileChest; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerChest extends AEBaseContainer { - private final TileChest chest; + public static ContainerType TYPE; - public ContainerChest( ContainerType containerType, int id, final PlayerInventory ip, final TileChest chest ) + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerChest::new, TileChest.class, SecurityPermissions.BUILD); + + public ContainerChest( int id, final PlayerInventory ip, final TileChest chest ) { - super( containerType, id, ip, chest, null ); - this.chest = chest; + super( TYPE, id, ip, chest, null ); - this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, this.chest.getInternalInventory(), 1, 80, 37, this + this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, chest.getInternalInventory(), 1, 80, 37, this .getPlayerInventory() ) ); this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); } + + public static ContainerChest fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + } diff --git a/src/main/java/appeng/container/implementations/ContainerCondenser.java b/src/main/java/appeng/container/implementations/ContainerCondenser.java index d39809bbd..f3e92cdc1 100644 --- a/src/main/java/appeng/container/implementations/ContainerCondenser.java +++ b/src/main/java/appeng/container/implementations/ContainerCondenser.java @@ -19,24 +19,32 @@ package appeng.container.implementations; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.ContainerType; -import net.minecraftforge.items.IItemHandler; - import appeng.api.config.CondenserOutput; import appeng.api.config.Settings; import appeng.container.AEBaseContainer; +import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; +import appeng.container.helper.TileContainerHelper; import appeng.container.interfaces.IProgressProvider; import appeng.container.slot.SlotOutput; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.misc.TileCondenser; import appeng.util.Platform; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.items.IItemHandler; public class ContainerCondenser extends AEBaseContainer implements IProgressProvider { + public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerCondenser::new, TileCondenser.class); + private final TileCondenser condenser; @GuiSync( 0 ) public long requiredEnergy = 0; @@ -45,9 +53,9 @@ public class ContainerCondenser extends AEBaseContainer implements IProgressProv @GuiSync( 2 ) public CondenserOutput output = CondenserOutput.TRASH; - public ContainerCondenser(ContainerType containerType, int id, final PlayerInventory ip, final TileCondenser condenser ) + public ContainerCondenser(int id, final PlayerInventory ip, final TileCondenser condenser ) { - super( containerType, id, ip, condenser, null ); + super( TYPE, id, ip, condenser, null ); this.condenser = condenser; IItemHandler inv = condenser.getInternalInventory(); @@ -60,6 +68,14 @@ public class ContainerCondenser extends AEBaseContainer implements IProgressProv this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 ); } + public static ContainerCondenser fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + @Override public void detectAndSendChanges() { diff --git a/src/main/java/appeng/container/implementations/ContainerCraftAmount.java b/src/main/java/appeng/container/implementations/ContainerCraftAmount.java index 71b1160cf..f99a8d7c3 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftAmount.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftAmount.java @@ -21,9 +21,13 @@ package appeng.container.implementations; import javax.annotation.Nonnull; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.Slot; +import net.minecraft.network.PacketBuffer; import net.minecraft.world.World; import appeng.api.config.SecurityPermissions; @@ -41,16 +45,29 @@ import appeng.tile.inventory.AppEngInternalInventory; public class ContainerCraftAmount extends AEBaseContainer { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerCraftAmount::new, ITerminalHost.class, SecurityPermissions.CRAFT); + private final Slot craftingItem; private IAEItemStack itemToCreate; - public ContainerCraftAmount(ContainerType containerType, int id, PlayerInventory ip, final ITerminalHost te) { - super(containerType, id, ip, te); + public ContainerCraftAmount(int id, PlayerInventory ip, final ITerminalHost te) { + super(TYPE, id, ip, te); this.craftingItem = new SlotInaccessible( new AppEngInternalInventory( null, 1 ), 0, 34, 53 ); this.addSlot( this.getCraftingItem() ); } + public static ContainerCraftAmount fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + @Override public void detectAndSendChanges() { diff --git a/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java b/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java index cdeda2e4c..8afb6c4bf 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java @@ -35,12 +35,20 @@ import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.container.AEBaseContainer; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; import appeng.container.guisync.GuiSync; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.container.helper.TileContainerHelper; import appeng.core.AELog; import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketMEInventoryUpdate; +import appeng.helpers.WirelessTerminalGuiObject; import appeng.me.helpers.PlayerSource; +import appeng.parts.reporting.PartCraftingTerminal; +import appeng.parts.reporting.PartPatternTerminal; +import appeng.parts.reporting.PartTerminal; import appeng.util.Platform; import com.google.common.collect.ImmutableSet; import net.minecraft.entity.player.PlayerEntity; @@ -48,6 +56,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.IContainerListener; +import net.minecraft.network.PacketBuffer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; @@ -62,6 +71,19 @@ import java.util.concurrent.Future; public class ContainerCraftConfirm extends AEBaseContainer { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerCraftConfirm::new, ITerminalHost.class, SecurityPermissions.CRAFT); + + public static ContainerCraftConfirm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final ArrayList cpus = new ArrayList<>(); private Future job; private ICraftingJob result; @@ -82,8 +104,8 @@ public class ContainerCraftConfirm extends AEBaseContainer @GuiSync( 7 ) public String myName = ""; - public ContainerCraftConfirm(ContainerType containerType, int id, PlayerInventory ip, ITerminalHost te) { - super(containerType, id, ip, te); + public ContainerCraftConfirm(int id, PlayerInventory ip, ITerminalHost te) { + super(TYPE, id, ip, te); } public void cycleCpu( final boolean next ) @@ -314,28 +336,28 @@ public class ContainerCraftConfirm extends AEBaseContainer public void startJob() { - /* FIXME GuiBridge */ Object originalGui = null; + ContainerType originalGui = null; final IActionHost ah = this.getActionHost(); - // FIXME if( ah instanceof WirelessTerminalGuiObject ) - // FIXME { - // FIXME originalGui = GuiBridge.GUI_WIRELESS_TERM; - // FIXME } -// FIXME - // FIXME if( ah instanceof PartTerminal ) - // FIXME { - // FIXME originalGui = GuiBridge.GUI_ME; - // FIXME } -// FIXME - // FIXME if( ah instanceof PartCraftingTerminal ) - // FIXME { - // FIXME originalGui = GuiBridge.GUI_CRAFTING_TERMINAL; - // FIXME } -// FIXME - // FIXME if( ah instanceof PartPatternTerminal ) - // FIXME { - // FIXME originalGui = GuiBridge.GUI_PATTERN_TERMINAL; - // FIXME } + if( ah instanceof WirelessTerminalGuiObject) + { + originalGui = ContainerWirelessTerm.TYPE; + } + + if( ah instanceof PartTerminal) + { + originalGui = ContainerMEMonitorable.TYPE; + } + + if( ah instanceof PartCraftingTerminal) + { + originalGui = ContainerCraftingTerm.TYPE; + } + + if( ah instanceof PartPatternTerminal) + { + originalGui = ContainerPatternTerm.TYPE; + } if( this.result != null && !this.isSimulation() ) { @@ -343,10 +365,9 @@ public class ContainerCraftConfirm extends AEBaseContainer final ICraftingLink g = cc.submitJob( this.result, null, this.getSelectedCpu() == -1 ? null : this.cpus.get( this.getSelectedCpu() ).getCpu(), true, this.getActionSrc() ); this.setAutoStart( false ); - if( g != null && originalGui != null && this.getOpenContext() != null ) + if( g != null && originalGui != null && this.getLocator() != null ) { - final TileEntity te = this.getOpenContext().getTile(); - // FIXME Platform.openGUI( this.getPlayerInventory().player, te, this.getOpenContext().getSide(), originalGui ); + ContainerOpener.openContainer(originalGui, getPlayerInventory().player, getLocator()); } } } diff --git a/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java b/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java index c06958672..36e632e80 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java @@ -21,6 +21,9 @@ package appeng.container.implementations; import java.io.IOException; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; import appeng.core.Api; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -49,12 +52,18 @@ import appeng.tile.crafting.TileCraftingTile; import appeng.util.Platform; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.IContainerListener; +import net.minecraft.network.PacketBuffer; import net.minecraft.util.text.ITextComponent; public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver, ICustomNameObject { + public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerCraftingCPU::new, TileCraftingTile.class, SecurityPermissions.CRAFT); + private final IItemList list = Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ).createList(); private IGrid network; private CraftingCPUCluster monitor = null; @@ -63,6 +72,11 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH @GuiSync( 0 ) public long eta = -1; + private ContainerCraftingCPU(int id, final PlayerInventory ip, final TileCraftingTile te ) + { + this( TYPE, id, ip, te ); + } + public ContainerCraftingCPU(ContainerType containerType, int id, final PlayerInventory ip, final Object te ) { super( containerType, id, ip, te ); @@ -84,6 +98,14 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH } } + public static ContainerCraftingCPU fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + protected void setCPU( final ICraftingCPU c ) { if( c == this.getMonitor() ) @@ -100,14 +122,7 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH { if( g instanceof PlayerEntity ) { - try - { - NetworkHandler.instance().sendTo( new PacketValueConfig( "CraftingStatus", "Clear" ), (ServerPlayerEntity) g ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + NetworkHandler.instance().sendTo( new PacketValueConfig( "CraftingStatus", "Clear" ), (ServerPlayerEntity) g ); } } diff --git a/src/main/java/appeng/container/implementations/ContainerCraftingStatus.java b/src/main/java/appeng/container/implementations/ContainerCraftingStatus.java index dcdf631ee..3e8e970dd 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftingStatus.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftingStatus.java @@ -23,8 +23,13 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.container.helper.TileContainerHelper; import com.google.common.collect.ImmutableSet; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.api.networking.crafting.ICraftingCPU; @@ -33,11 +38,25 @@ import appeng.api.storage.ITerminalHost; import appeng.container.guisync.GuiSync; import appeng.util.Platform; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerCraftingStatus extends ContainerCraftingCPU { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerCraftingStatus::new, ITerminalHost.class, SecurityPermissions.CRAFT); + + public static ContainerCraftingStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final List cpus = new ArrayList<>(); @GuiSync( 5 ) public int selectedCpu = -1; @@ -46,9 +65,9 @@ public class ContainerCraftingStatus extends ContainerCraftingCPU @GuiSync( 7 ) public String myName = ""; - public ContainerCraftingStatus(ContainerType containerType, int id, final PlayerInventory ip, final ITerminalHost te ) + public ContainerCraftingStatus(int id, final PlayerInventory ip, final ITerminalHost te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); } @Override diff --git a/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java b/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java index 202e0771b..b5935388e 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java @@ -19,6 +19,11 @@ package appeng.container.implementations; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.CraftingInventory; @@ -26,6 +31,7 @@ import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipeType; +import net.minecraft.network.PacketBuffer; import net.minecraft.world.World; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.wrapper.PlayerInvWrapper; @@ -45,15 +51,28 @@ import appeng.util.inv.WrapperInvItemHandler; public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerCraftingTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT); + + public static ContainerCraftingTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartCraftingTerminal ct; private final AppEngInternalInventory output = new AppEngInternalInventory( this, 1 ); private final SlotCraftingMatrix[] craftingSlots = new SlotCraftingMatrix[9]; private final SlotCraftingTerm outputSlot; private IRecipe currentRecipe; - public ContainerCraftingTerm(ContainerType containerType, int id, final PlayerInventory ip, final ITerminalHost monitorable ) + public ContainerCraftingTerm(int id, final PlayerInventory ip, final ITerminalHost monitorable ) { - super( containerType, id, ip, monitorable, false ); + super( TYPE, id, ip, monitorable, false ); this.ct = (PartCraftingTerminal) monitorable; final IItemHandler crafting = this.ct.getInventoryByName( "crafting" ); diff --git a/src/main/java/appeng/container/implementations/ContainerDrive.java b/src/main/java/appeng/container/implementations/ContainerDrive.java index 3359cde63..2e8731643 100644 --- a/src/main/java/appeng/container/implementations/ContainerDrive.java +++ b/src/main/java/appeng/container/implementations/ContainerDrive.java @@ -19,20 +19,37 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.container.AEBaseContainer; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.storage.TileDrive; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerDrive extends AEBaseContainer { - public ContainerDrive(ContainerType containerType, int id, final PlayerInventory ip, final TileDrive drive ) +public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerDrive::new, TileDrive.class); + + public static ContainerDrive fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + + public ContainerDrive(int id, final PlayerInventory ip, final TileDrive drive ) { - super( containerType, id, ip, drive, null ); + super( TYPE, id, ip, drive, null ); for( int y = 0; y < 5; y++ ) { @@ -45,4 +62,5 @@ public class ContainerDrive extends AEBaseContainer this.bindPlayerInventory( ip, 0, 199 - /* height of player inventory */82 ); } + } diff --git a/src/main/java/appeng/container/implementations/ContainerFormationPlane.java b/src/main/java/appeng/container/implementations/ContainerFormationPlane.java index 516f5e3b3..9f522375d 100644 --- a/src/main/java/appeng/container/implementations/ContainerFormationPlane.java +++ b/src/main/java/appeng/container/implementations/ContainerFormationPlane.java @@ -19,8 +19,12 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import appeng.api.config.FuzzyMode; @@ -39,12 +43,25 @@ import appeng.util.Platform; public class ContainerFormationPlane extends ContainerUpgradeable { + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerFormationPlane::new, PartFormationPlane.class, SecurityPermissions.BUILD); + + public static ContainerFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + @GuiSync( 6 ) public YesNo placeMode; - public ContainerFormationPlane(ContainerType containerType, int id, final PlayerInventory ip, final PartFormationPlane te ) + public ContainerFormationPlane(int id, final PlayerInventory ip, final PartFormationPlane te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); } @Override diff --git a/src/main/java/appeng/container/implementations/ContainerGrinder.java b/src/main/java/appeng/container/implementations/ContainerGrinder.java index 8df072546..85083ae0d 100644 --- a/src/main/java/appeng/container/implementations/ContainerGrinder.java +++ b/src/main/java/appeng/container/implementations/ContainerGrinder.java @@ -19,16 +19,12 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.inventory.container.SimpleNamedContainerProvider; import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.IItemHandler; import appeng.container.AEBaseContainer; @@ -42,6 +38,17 @@ public class ContainerGrinder extends AEBaseContainer public static ContainerType TYPE; + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerGrinder::new, TileGrinder.class); + + public static ContainerGrinder fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + public ContainerGrinder(int id, final PlayerInventory ip, final TileGrinder grinder ) { super( TYPE, id, ip, grinder, null ); @@ -61,21 +68,4 @@ public class ContainerGrinder extends AEBaseContainer this.bindPlayerInventory( ip, 0, 176 - /* height of player inventory */82 ); } - public static ContainerGrinder fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { - BlockPos pos = buf.readBlockPos(); - TileEntity te = inv.player.world.getTileEntity(pos); - if (te instanceof TileGrinder) { - return new ContainerGrinder(windowId, inv, (TileGrinder) te); - } - return null; - } - - public static void open(ServerPlayerEntity player, TileGrinder tile, ITextComponent title) { - BlockPos pos = tile.getPos(); - INamedContainerProvider container = new SimpleNamedContainerProvider( - (wnd, p, pl) -> new ContainerGrinder(wnd, p, tile), title - ); - NetworkHooks.openGui(player, container, pos); - } - } diff --git a/src/main/java/appeng/container/implementations/ContainerIOPort.java b/src/main/java/appeng/container/implementations/ContainerIOPort.java index db1539a5f..a94bed938 100644 --- a/src/main/java/appeng/container/implementations/ContainerIOPort.java +++ b/src/main/java/appeng/container/implementations/ContainerIOPort.java @@ -19,8 +19,12 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import appeng.api.config.FullnessMode; @@ -38,14 +42,27 @@ import appeng.util.Platform; public class ContainerIOPort extends ContainerUpgradeable { +public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerIOPort::new, TileIOPort.class, SecurityPermissions.BUILD); + + public static ContainerIOPort fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + @GuiSync( 2 ) public FullnessMode fMode = FullnessMode.EMPTY; @GuiSync( 3 ) public OperationMode opMode = OperationMode.EMPTY; - public ContainerIOPort(ContainerType containerType, int id, final PlayerInventory ip, final TileIOPort te ) + public ContainerIOPort(int id, final PlayerInventory ip, final TileIOPort te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); } @Override diff --git a/src/main/java/appeng/container/implementations/ContainerInscriber.java b/src/main/java/appeng/container/implementations/ContainerInscriber.java index c89b25389..0c5869a6d 100644 --- a/src/main/java/appeng/container/implementations/ContainerInscriber.java +++ b/src/main/java/appeng/container/implementations/ContainerInscriber.java @@ -19,22 +19,25 @@ package appeng.container.implementations; +import appeng.api.definitions.IItemDefinition; +import appeng.api.features.IInscriberRecipe; +import appeng.container.ContainerLocator; +import appeng.container.guisync.GuiSync; +import appeng.container.helper.TileContainerHelper; +import appeng.container.interfaces.IProgressProvider; +import appeng.container.slot.SlotOutput; +import appeng.container.slot.SlotRestrictedInput; import appeng.core.Api; +import appeng.tile.misc.TileInscriber; +import appeng.util.Platform; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; -import appeng.api.definitions.IItemDefinition; -import appeng.api.features.IInscriberRecipe; -import appeng.container.guisync.GuiSync; -import appeng.container.interfaces.IProgressProvider; -import appeng.container.slot.SlotOutput; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.misc.TileInscriber; -import appeng.util.Platform; - /** * @author AlgorithmX2 @@ -45,6 +48,19 @@ import appeng.util.Platform; public class ContainerInscriber extends ContainerUpgradeable implements IProgressProvider { + public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerInscriber::new, TileInscriber.class); + + public static ContainerInscriber fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final TileInscriber ti; private final Slot top; @@ -57,9 +73,9 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres @GuiSync( 3 ) public int processingTime = -1; - public ContainerInscriber(ContainerType containerType, int id, final PlayerInventory ip, final TileInscriber te ) + public ContainerInscriber(int id, final PlayerInventory ip, final TileInscriber te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); this.ti = te; IItemHandler inv = te.getInternalInventory(); diff --git a/src/main/java/appeng/container/implementations/ContainerInterface.java b/src/main/java/appeng/container/implementations/ContainerInterface.java index 6f09fd214..ed0f90298 100644 --- a/src/main/java/appeng/container/implementations/ContainerInterface.java +++ b/src/main/java/appeng/container/implementations/ContainerInterface.java @@ -19,6 +19,9 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.SecurityPermissions; @@ -32,11 +35,25 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.helpers.DualityInterface; import appeng.helpers.IInterfaceHost; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerInterface extends ContainerUpgradeable { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerInterface::new, IInterfaceHost.class, SecurityPermissions.BUILD); + + public static ContainerInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final DualityInterface myDuality; @GuiSync( 3 ) @@ -45,9 +62,9 @@ public class ContainerInterface extends ContainerUpgradeable @GuiSync( 4 ) public YesNo iTermMode = YesNo.YES; - public ContainerInterface(ContainerType containerType, int id, final PlayerInventory ip, final IInterfaceHost te ) + public ContainerInterface(int id, final PlayerInventory ip, final IInterfaceHost te ) { - super( containerType, id, ip, te.getInterfaceDuality().getHost() ); + super( TYPE, id, ip, te.getInterfaceDuality().getHost() ); this.myDuality = te.getInterfaceDuality(); diff --git a/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java index 0fe792435..375b69f8b 100644 --- a/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java @@ -24,11 +24,17 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import appeng.api.config.Settings; @@ -60,6 +66,19 @@ import appeng.util.inv.filter.IAEItemFilter; public final class ContainerInterfaceTerminal extends AEBaseContainer { + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerInterfaceTerminal::new, PartInterfaceTerminal.class, SecurityPermissions.BUILD); + + public static ContainerInterfaceTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + /** * this stuff is all server side.. */ @@ -70,9 +89,9 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer private IGrid grid; private CompoundNBT data = new CompoundNBT(); - public ContainerInterfaceTerminal(ContainerType containerType, int id, final PlayerInventory ip, final PartInterfaceTerminal anchor ) + public ContainerInterfaceTerminal(int id, final PlayerInventory ip, final PartInterfaceTerminal anchor ) { - super( containerType, id, ip, anchor ); + super( TYPE, id, ip, anchor ); if( Platform.isServer() ) { diff --git a/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java b/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java index 6dd70f1a8..b4fe118f7 100644 --- a/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java +++ b/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java @@ -19,10 +19,14 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import appeng.container.helper.TileContainerHelper; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.items.IItemHandler; @@ -43,6 +47,19 @@ import appeng.util.Platform; public class ContainerLevelEmitter extends ContainerUpgradeable { + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerLevelEmitter::new, PartLevelEmitter.class, SecurityPermissions.BUILD); + + public static ContainerLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartLevelEmitter lvlEmitter; @OnlyIn( Dist.CLIENT ) @@ -54,9 +71,9 @@ public class ContainerLevelEmitter extends ContainerUpgradeable @GuiSync( 4 ) public YesNo cmType; - public ContainerLevelEmitter( ContainerType containerType, int id, final PlayerInventory ip, final PartLevelEmitter te ) + public ContainerLevelEmitter( int id, final PlayerInventory ip, final PartLevelEmitter te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); this.lvlEmitter = te; } diff --git a/src/main/java/appeng/container/implementations/ContainerMAC.java b/src/main/java/appeng/container/implementations/ContainerMAC.java index 0dfb12087..1930a7ccf 100644 --- a/src/main/java/appeng/container/implementations/ContainerMAC.java +++ b/src/main/java/appeng/container/implementations/ContainerMAC.java @@ -19,17 +19,13 @@ package appeng.container.implementations; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import net.minecraftforge.items.IItemHandler; - import appeng.api.config.RedstoneMode; import appeng.api.config.SecurityPermissions; import appeng.api.config.Settings; import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; +import appeng.container.helper.TileContainerHelper; import appeng.container.interfaces.IProgressProvider; import appeng.container.slot.SlotMACPattern; import appeng.container.slot.SlotOutput; @@ -37,19 +33,39 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.items.misc.ItemEncodedPattern; import appeng.tile.crafting.TileMolecularAssembler; import appeng.util.Platform; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; +import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; public class ContainerMAC extends ContainerUpgradeable implements IProgressProvider { + public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerMAC::new, TileMolecularAssembler.class); + + public static ContainerMAC fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private static final int MAX_CRAFT_PROGRESS = 100; private final TileMolecularAssembler tma; @GuiSync( 4 ) public int craftProgress = 0; - public ContainerMAC(ContainerType containerType, int id, final PlayerInventory ip, final TileMolecularAssembler te ) + public ContainerMAC(int id, final PlayerInventory ip, final TileMolecularAssembler te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); this.tma = te; } diff --git a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java index f60f4e096..3abc07023 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java +++ b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java @@ -24,6 +24,8 @@ import java.nio.BufferOverflowException; import javax.annotation.Nonnull; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; import appeng.core.Api; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -31,6 +33,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.IContainerListener; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraft.tileentity.TileEntity; import appeng.api.config.Actionable; @@ -77,6 +80,19 @@ import appeng.util.Platform; public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerMEMonitorable::new, ITerminalHost.class); + + public static ContainerMEMonitorable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5]; private final IMEMonitor monitor; private final IItemList items = Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ).createList(); @@ -90,10 +106,9 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa private IConfigManager serverCM; private IGridNode networkNode; - - public ContainerMEMonitorable( ContainerType containerType, int id, final PlayerInventory ip, final ITerminalHost monitorable ) + public ContainerMEMonitorable( int id, final PlayerInventory ip, final ITerminalHost monitorable ) { - this( containerType, id, ip, monitorable, true ); + this( TYPE, id, ip, monitorable, true ); } public ContainerMEMonitorable(ContainerType containerType, int id, PlayerInventory ip, final ITerminalHost monitorable, final boolean bindInventory ) { @@ -211,14 +226,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa { if( crafter instanceof ServerPlayerEntity ) { - try - { - NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (ServerPlayerEntity) crafter ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (ServerPlayerEntity) crafter ); } } } diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index b490285eb..5535f2f4d 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -19,6 +19,9 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; @@ -27,20 +30,39 @@ import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.container.interfaces.IInventorySlotAware; +import net.minecraft.network.PacketBuffer; public class ContainerMEPortableCell extends ContainerMEMonitorable { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerMEPortableCell::new, IPortableCell.class); + + public static ContainerMEPortableCell fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private double powerMultiplier = 0.5; private final IPortableCell civ; private int ticks = 0; private final int slot; - public ContainerMEPortableCell(ContainerType containerType, int id, final PlayerInventory ip, final IPortableCell monitorable ) + public ContainerMEPortableCell(int id, final PlayerInventory ip, final IPortableCell monitorable ) { - super( containerType, id, ip, monitorable, false ); + this(TYPE, id, ip, monitorable); + } + + protected ContainerMEPortableCell(ContainerType type, int id, final PlayerInventory ip, final IPortableCell monitorable ) + { + super( type, id, ip, monitorable, false ); if( monitorable instanceof IInventorySlotAware ) { final int slotIndex = ( (IInventorySlotAware) monitorable ).getInventorySlot(); diff --git a/src/main/java/appeng/container/implementations/ContainerNetworkStatus.java b/src/main/java/appeng/container/implementations/ContainerNetworkStatus.java index 23a901c0a..1c36e87e8 100644 --- a/src/main/java/appeng/container/implementations/ContainerNetworkStatus.java +++ b/src/main/java/appeng/container/implementations/ContainerNetworkStatus.java @@ -21,7 +21,9 @@ package appeng.container.implementations; import java.io.IOException; -import appeng.api.parts.IPart; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.container.helper.TileContainerHelper; import appeng.core.Api; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -29,7 +31,6 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.implementations.guiobjects.INetworkTool; import appeng.api.networking.IGrid; import appeng.api.networking.IGridBlock; @@ -46,12 +47,25 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketMEInventoryUpdate; import appeng.util.Platform; import appeng.util.item.AEItemStack; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.network.PacketBuffer; public class ContainerNetworkStatus extends AEBaseContainer { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerNetworkStatus::new, INetworkTool.class); + + public static ContainerNetworkStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + @GuiSync( 0 ) public long avgAddition; @GuiSync( 1 ) @@ -63,8 +77,8 @@ public class ContainerNetworkStatus extends AEBaseContainer private IGrid network; private int delay = 40; - public ContainerNetworkStatus(ContainerType containerType, int id, PlayerInventory ip, final INetworkTool te) { - super(containerType, id, ip, null, null); + public ContainerNetworkStatus(int id, PlayerInventory ip, final INetworkTool te) { + super(TYPE, id, ip, null, null); final IGridHost host = te.getGridHost(); if( host != null ) diff --git a/src/main/java/appeng/container/implementations/ContainerNetworkTool.java b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java index 7a365949f..155af1320 100644 --- a/src/main/java/appeng/container/implementations/ContainerNetworkTool.java +++ b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java @@ -19,28 +19,45 @@ package appeng.container.implementations; +import appeng.api.implementations.guiobjects.INetworkTool; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerLocator; +import appeng.container.guisync.GuiSync; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.container.helper.TileContainerHelper; +import appeng.container.slot.SlotRestrictedInput; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; - -import appeng.api.implementations.guiobjects.INetworkTool; -import appeng.container.AEBaseContainer; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotRestrictedInput; +import net.minecraft.network.PacketBuffer; public class ContainerNetworkTool extends AEBaseContainer { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerNetworkTool::new, INetworkTool.class); + + public static ContainerNetworkTool fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final INetworkTool toolInv; @GuiSync( 1 ) public boolean facadeMode; - public ContainerNetworkTool(ContainerType containerType, int id, final PlayerInventory ip, final INetworkTool te ) + public ContainerNetworkTool(int id, final PlayerInventory ip, final INetworkTool te ) { - super( containerType, id, ip, null, null ); + super( TYPE, id, ip, null, null ); this.toolInv = te; this.lockPlayerInventorySlot( ip.currentItem ); diff --git a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java index 81145fb6d..f9c196836 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java @@ -20,14 +20,18 @@ package appeng.container.implementations; import appeng.api.config.Actionable; +import appeng.api.config.SecurityPermissions; import appeng.api.definitions.IDefinitions; import appeng.api.storage.IMEMonitor; import appeng.api.storage.ITerminalHost; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.container.ContainerLocator; import appeng.container.ContainerNull; import appeng.container.guisync.GuiSync; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.container.helper.TileContainerHelper; import appeng.container.slot.*; import appeng.core.Api; import appeng.core.sync.packets.PacketPatternSlot; @@ -58,6 +62,7 @@ import net.minecraft.item.crafting.IRecipeType; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListNBT; +import net.minecraft.network.PacketBuffer; import net.minecraft.world.World; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.wrapper.PlayerInvWrapper; @@ -70,6 +75,19 @@ import java.util.Optional; public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerPatternTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT); + + public static ContainerPatternTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartPatternTerminal patternTerminal; private final AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 ); private final IItemHandler crafting; @@ -85,9 +103,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA @GuiSync( 96 ) public boolean substitute = false; - public ContainerPatternTerm(ContainerType type, int id, final PlayerInventory ip, final ITerminalHost monitorable ) + public ContainerPatternTerm(int id, final PlayerInventory ip, final ITerminalHost monitorable ) { - super( type, id, ip, monitorable, false ); + super( TYPE, id, ip, monitorable, false ); this.patternTerminal = (PartPatternTerminal) monitorable; final IItemHandler patternInv = this.getPatternTerminal().getInventoryByName( "pattern" ); diff --git a/src/main/java/appeng/container/implementations/ContainerPriority.java b/src/main/java/appeng/container/implementations/ContainerPriority.java index 06b86b61a..f792a677f 100644 --- a/src/main/java/appeng/container/implementations/ContainerPriority.java +++ b/src/main/java/appeng/container/implementations/ContainerPriority.java @@ -19,10 +19,13 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -38,6 +41,19 @@ import appeng.util.Platform; public class ContainerPriority extends AEBaseContainer { +public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerPriority::new, IPriorityHost.class, SecurityPermissions.BUILD); + + public static ContainerPriority fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final IPriorityHost priHost; @OnlyIn( Dist.CLIENT ) @@ -45,9 +61,9 @@ public class ContainerPriority extends AEBaseContainer @GuiSync( 2 ) public long PriorityValue = -1; - public ContainerPriority(ContainerType containerType, int id, final PlayerInventory ip, final IPriorityHost te ) + public ContainerPriority(int id, final PlayerInventory ip, final IPriorityHost te ) { - super( containerType, id, ip, (TileEntity) ( te instanceof TileEntity ? te : null ), (IPart) ( te instanceof IPart ? te : null ) ); + super( TYPE, id, ip, (TileEntity) ( te instanceof TileEntity ? te : null ), (IPart) ( te instanceof IPart ? te : null ) ); this.priHost = te; } diff --git a/src/main/java/appeng/container/implementations/ContainerQNB.java b/src/main/java/appeng/container/implementations/ContainerQNB.java index fab97e429..0c333c16a 100644 --- a/src/main/java/appeng/container/implementations/ContainerQNB.java +++ b/src/main/java/appeng/container/implementations/ContainerQNB.java @@ -19,24 +19,43 @@ package appeng.container.implementations; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.container.AEBaseContainer; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.qnb.TileQuantumBridge; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerQNB extends AEBaseContainer { - public ContainerQNB(ContainerType containerType, int id, final PlayerInventory ip, final TileQuantumBridge quantumBridge ) +public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerQNB::new, TileQuantumBridge.class, SecurityPermissions.BUILD); + + public static ContainerQNB fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + + public ContainerQNB(int id, final PlayerInventory ip, final TileQuantumBridge quantumBridge ) { - super( containerType, id, ip, quantumBridge, null ); + super( TYPE, id, ip, quantumBridge, null ); this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge .getInternalInventory(), 0, 80, 37, this.getPlayerInventory() ) ).setStackLimit( 1 ) ); this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); } + } diff --git a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java index 1b1d3e202..6e2e3ca72 100644 --- a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java +++ b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java @@ -21,12 +21,15 @@ package appeng.container.implementations; import javax.annotation.Nonnull; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; import appeng.core.Api; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; import net.minecraftforge.items.IItemHandler; @@ -42,14 +45,27 @@ import appeng.util.Platform; public class ContainerQuartzKnife extends AEBaseContainer { +public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerQuartzKnife::new, QuartzKnifeObj.class); + + public static ContainerQuartzKnife fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final QuartzKnifeObj toolInv; private final IItemHandler inSlot = new AppEngInternalInventory( null, 1, 1 ); private String myName = ""; - public ContainerQuartzKnife(ContainerType containerType, int id, final PlayerInventory ip, final QuartzKnifeObj te ) + public ContainerQuartzKnife(int id, final PlayerInventory ip, final QuartzKnifeObj te ) { - super( containerType, id, ip, null, null ); + super( TYPE, id, ip, null, null ); this.toolInv = te; this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip ) ); diff --git a/src/main/java/appeng/container/implementations/ContainerSecurityStation.java b/src/main/java/appeng/container/implementations/ContainerSecurityStation.java index 389b4fdb1..9f84634ee 100644 --- a/src/main/java/appeng/container/implementations/ContainerSecurityStation.java +++ b/src/main/java/appeng/container/implementations/ContainerSecurityStation.java @@ -19,12 +19,16 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.container.helper.TileContainerHelper; import appeng.core.Api; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.IContainerListener; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import appeng.api.config.SecurityPermissions; @@ -44,6 +48,11 @@ import appeng.util.inv.InvOperation; public class ContainerSecurityStation extends ContainerMEMonitorable implements IAEAppEngInventory { +public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerSecurityStation::new, ITerminalHost.class, SecurityPermissions.SECURITY); + private final SlotRestrictedInput configSlot; private final AppEngInternalInventory wirelessEncoder = new AppEngInternalInventory( this, 2 ); @@ -55,9 +64,9 @@ public class ContainerSecurityStation extends ContainerMEMonitorable implements @GuiSync( 0 ) public int permissionMode = 0; - public ContainerSecurityStation(ContainerType containerType, int id, final PlayerInventory ip, final ITerminalHost monitorable ) + public ContainerSecurityStation(int id, final PlayerInventory ip, final ITerminalHost monitorable ) { - super( containerType, id, ip, monitorable, false ); + super( TYPE, id, ip, monitorable, false ); this.securityBox = (TileSecurityStation) monitorable; @@ -71,6 +80,14 @@ public class ContainerSecurityStation extends ContainerMEMonitorable implements this.bindPlayerInventory( ip, 0, 0 ); } + public static ContainerSecurityStation fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + public void toggleSetting( final String value, final PlayerEntity player ) { try diff --git a/src/main/java/appeng/container/implementations/ContainerSkyChest.java b/src/main/java/appeng/container/implementations/ContainerSkyChest.java index 7bf228a53..92f6335a2 100644 --- a/src/main/java/appeng/container/implementations/ContainerSkyChest.java +++ b/src/main/java/appeng/container/implementations/ContainerSkyChest.java @@ -19,28 +19,26 @@ package appeng.container.implementations; -import appeng.core.AppEng; -import net.minecraft.client.Minecraft; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.container.AEBaseContainer; import appeng.container.slot.SlotNormal; import appeng.tile.storage.TileSkyChest; -import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.inventory.container.SimpleNamedContainerProvider; import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.fml.network.NetworkHooks; public class ContainerSkyChest extends AEBaseContainer { - public static ContainerType TYPE; + +public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerSkyChest::new, TileSkyChest.class); + private final TileSkyChest chest; @@ -63,20 +61,11 @@ public class ContainerSkyChest extends AEBaseContainer } public static ContainerSkyChest fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { - BlockPos pos = buf.readBlockPos(); - TileEntity te = inv.player.world.getTileEntity(pos); - if (te instanceof TileSkyChest) { - return new ContainerSkyChest(windowId, inv, (TileSkyChest) te); - } - return null; + return helper.fromNetwork(windowId, inv, buf); } - public static void open(ServerPlayerEntity player, TileSkyChest tile, ITextComponent title) { - BlockPos pos = tile.getPos(); - INamedContainerProvider container = new SimpleNamedContainerProvider( - (wnd, p, pl) -> new ContainerSkyChest(wnd, p, tile), title - ); - NetworkHooks.openGui(player, container, pos); + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); } @Override diff --git a/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java b/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java index 4c76931b6..37a8469b1 100644 --- a/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java +++ b/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java @@ -19,6 +19,9 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.SecurityPermissions; @@ -34,11 +37,17 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.tile.spatial.TileSpatialIOPort; import appeng.util.Platform; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerSpatialIOPort extends AEBaseContainer { +public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerSpatialIOPort::new, TileSpatialIOPort.class, SecurityPermissions.BUILD); + @GuiSync( 0 ) public long currentPower; @GuiSync( 1 ) @@ -57,9 +66,9 @@ public class ContainerSpatialIOPort extends AEBaseContainer @GuiSync( 33 ) public int zSize; - public ContainerSpatialIOPort(ContainerType containerType, int id, final PlayerInventory ip, final TileSpatialIOPort spatialIOPort ) + public ContainerSpatialIOPort(int id, final PlayerInventory ip, final TileSpatialIOPort spatialIOPort ) { - super( containerType, id, ip, spatialIOPort, null ); + super( TYPE, id, ip, spatialIOPort, null ); if( Platform.isServer() ) { @@ -74,6 +83,14 @@ public class ContainerSpatialIOPort extends AEBaseContainer this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 ); } + public static ContainerSpatialIOPort fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + @Override public void detectAndSendChanges() { diff --git a/src/main/java/appeng/container/implementations/ContainerStorageBus.java b/src/main/java/appeng/container/implementations/ContainerStorageBus.java index e08d25595..388aa1f0c 100644 --- a/src/main/java/appeng/container/implementations/ContainerStorageBus.java +++ b/src/main/java/appeng/container/implementations/ContainerStorageBus.java @@ -21,10 +21,15 @@ package appeng.container.implementations; import java.util.Iterator; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import appeng.container.helper.TileContainerHelper; import appeng.core.Api; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import appeng.api.config.AccessRestriction; @@ -50,6 +55,19 @@ import appeng.util.iterators.NullIterator; public class ContainerStorageBus extends ContainerUpgradeable { + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerStorageBus::new, PartStorageBus.class, SecurityPermissions.BUILD); + + public static ContainerStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartStorageBus storageBus; @GuiSync( 3 ) @@ -58,9 +76,9 @@ public class ContainerStorageBus extends ContainerUpgradeable @GuiSync( 4 ) public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY; - public ContainerStorageBus(ContainerType containerType, int id, final PlayerInventory ip, final PartStorageBus te ) + public ContainerStorageBus(int id, final PlayerInventory ip, final PartStorageBus te ) { - super( containerType, id, ip, te ); + super( TYPE, id, ip, te ); this.storageBus = te; } diff --git a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java index 0894f8ea2..68db4099f 100644 --- a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java +++ b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java @@ -19,12 +19,21 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import appeng.container.helper.PartOrTileContainerHelper; +import appeng.parts.misc.PartStorageBus; +import appeng.tile.misc.TileCellWorkbench; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; import net.minecraft.world.World; import net.minecraftforge.items.IItemHandler; @@ -55,6 +64,19 @@ import appeng.util.Platform; public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSlotHost { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerUpgradeable::new, IUpgradeableHost.class, SecurityPermissions.BUILD); + + public static ContainerUpgradeable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final IUpgradeableHost upgradeable; @GuiSync( 0 ) public RedstoneMode rsMode = RedstoneMode.IGNORE; @@ -67,6 +89,11 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl private int tbSlot; private NetworkToolViewer tbInventory; + public ContainerUpgradeable(int id, final PlayerInventory ip, final IUpgradeableHost te ) + { + this(TYPE, id, ip, te); + } + public ContainerUpgradeable(ContainerType containerType, int id, final PlayerInventory ip, final IUpgradeableHost te ) { super( containerType, id, ip, (TileEntity) ( te instanceof TileEntity ? te : null ), (IPart) ( te instanceof IPart ? te : null ) ); diff --git a/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java b/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java index e07a948e3..0e1f6c822 100644 --- a/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java +++ b/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java @@ -19,6 +19,9 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.container.AEBaseContainer; @@ -28,19 +31,34 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.tile.misc.TileVibrationChamber; import appeng.util.Platform; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerVibrationChamber extends AEBaseContainer implements IProgressProvider { + +public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerVibrationChamber::new, TileVibrationChamber.class); + + public static ContainerVibrationChamber fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final TileVibrationChamber vibrationChamber; @GuiSync( 0 ) public int burnSpeed = 0; @GuiSync( 1 ) public int remainingBurnTime = 0; - public ContainerVibrationChamber(ContainerType containerType, int id, final PlayerInventory ip, final TileVibrationChamber vibrationChamber ) + public ContainerVibrationChamber(int id, final PlayerInventory ip, final TileVibrationChamber vibrationChamber ) { - super( containerType, id, ip, vibrationChamber, null ); + super( TYPE, id, ip, vibrationChamber, null ); this.vibrationChamber = vibrationChamber; this.addSlot( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber.getInternalInventory(), 0, 80, 37, this diff --git a/src/main/java/appeng/container/implementations/ContainerWireless.java b/src/main/java/appeng/container/implementations/ContainerWireless.java index 2f33b4039..b8654efb8 100644 --- a/src/main/java/appeng/container/implementations/ContainerWireless.java +++ b/src/main/java/appeng/container/implementations/ContainerWireless.java @@ -19,6 +19,10 @@ package appeng.container.implementations; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.TileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.container.AEBaseContainer; @@ -27,24 +31,36 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.tile.networking.TileWireless; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerWireless extends AEBaseContainer { - private final TileWireless wirelessTerminal; + public static ContainerType TYPE; + + private static final TileContainerHelper helper + = new TileContainerHelper<>(ContainerWireless::new, TileWireless.class, SecurityPermissions.BUILD); + + public static ContainerWireless fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final SlotRestrictedInput boosterSlot; @GuiSync( 1 ) public long range = 0; @GuiSync( 2 ) public long drain = 0; - public ContainerWireless(ContainerType containerType, int id, final PlayerInventory ip, final TileWireless te ) + public ContainerWireless(int id, final PlayerInventory ip, final TileWireless te ) { - super( containerType, id, ip, te, null ); - this.wirelessTerminal = te; + super( TYPE, id, ip, te, null ); - this.addSlot( this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, this.wirelessTerminal + this.addSlot( this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, te .getInternalInventory(), 0, 80, 47, this.getPlayerInventory() ) ); this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java index 800837e59..11154ccf5 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java @@ -19,6 +19,10 @@ package appeng.container.implementations; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import appeng.container.helper.PartOrTileContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.core.AEConfig; @@ -26,16 +30,30 @@ import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; import appeng.util.Platform; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; public class ContainerWirelessTerm extends ContainerMEPortableCell { + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerWirelessTerm::new, WirelessTerminalGuiObject.class); + + public static ContainerWirelessTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final WirelessTerminalGuiObject wirelessTerminalGUIObject; - public ContainerWirelessTerm(ContainerType containerType, int id, final PlayerInventory ip, final WirelessTerminalGuiObject gui ) + public ContainerWirelessTerm(int id, final PlayerInventory ip, final WirelessTerminalGuiObject gui ) { - super( containerType, id, ip, gui ); + super( TYPE, id, ip, gui ); this.wirelessTerminalGUIObject = gui; } diff --git a/src/main/java/appeng/container/implementations/CraftingCPURecord.java b/src/main/java/appeng/container/implementations/CraftingCPURecord.java index 0f9b78bf9..a2f319d6a 100644 --- a/src/main/java/appeng/container/implementations/CraftingCPURecord.java +++ b/src/main/java/appeng/container/implementations/CraftingCPURecord.java @@ -22,12 +22,12 @@ package appeng.container.implementations; import javax.annotation.Nonnull; import appeng.api.networking.crafting.ICraftingCPU; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.util.text.ITextComponent; public class CraftingCPURecord implements Comparable { - private final ITextComponent myName; private final ICraftingCPU cpu; private final long size; diff --git a/src/main/java/appeng/core/AppEng.java b/src/main/java/appeng/core/AppEng.java index c081795e5..539789619 100644 --- a/src/main/java/appeng/core/AppEng.java +++ b/src/main/java/appeng/core/AppEng.java @@ -20,25 +20,27 @@ package appeng.core; import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; +import java.util.function.Supplier; +import appeng.block.paint.PaintSplotchesModel; +import appeng.block.qnb.QnbFormedModel; import appeng.bootstrap.components.IClientSetupComponent; import appeng.bootstrap.components.IInitComponent; import appeng.client.ClientHelper; -import appeng.client.render.model.AutoRotatingModel; -import appeng.client.render.model.AutoRotatingModelLoader; -import appeng.client.render.model.GlassModelLoader; -import appeng.client.render.model.SkyCompassModelLoader; +import appeng.client.render.DummyFluidItemModel; +import appeng.client.render.SimpleModelLoader; +import appeng.client.render.crafting.CraftingCubeModelLoader; +import appeng.client.render.model.*; +import appeng.client.render.spatial.SpatialPylonModel; import appeng.core.stats.AdvancementTriggers; import appeng.core.worlddata.WorldData; import appeng.hooks.TickHandler; import appeng.parts.PartPlacement; +import appeng.server.AECommand; import appeng.server.ServerHelper; -import com.google.gson.Gson; +import appeng.services.VersionChecker; +import appeng.services.version.VersionCheckerConfig; import net.minecraft.block.Block; -import net.minecraft.client.renderer.model.BlockModelDefinition; -import net.minecraft.client.renderer.model.ModelBakery; import net.minecraft.entity.EntityType; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.Item; @@ -49,6 +51,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.client.model.geometry.IModelGeometry; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.CrashReportExtender; @@ -56,15 +59,13 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.config.ModConfig; import appeng.core.crash.ModCrashEnhancement; -import appeng.services.export.ExportConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent; import net.minecraftforge.fml.event.server.FMLServerStartedEvent; +import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.event.server.FMLServerStoppedEvent; import net.minecraftforge.fml.event.server.FMLServerStoppingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -91,12 +92,12 @@ public final class AppEng //FIXME private final Registration registration; - private File configDirectory; + private VersionCheckerConfig versionCheckerConfig = VersionCheckerConfig.create(); /** * determined in pre-init but used in init */ - private ExportConfig exportConfig; + // FIXME private ExportConfig exportConfig; public AppEng() { @@ -128,6 +129,7 @@ public final class AppEng modEventBus.addGenericListener(IRecipeSerializer.class, registration::registerRecipeSerializers); modEventBus.addListener(registration::registerParticleFactories); modEventBus.addListener(registration::registerTextures); + modEventBus.addListener(registration::registerCommands); modEventBus.addListener(this::commonSetup); @@ -150,17 +152,40 @@ public final class AppEng definitions.getRegistry().getBootstrapComponents( IInitComponent.class ).forEachRemaining(IInitComponent::initialize); Registration.setupInternalRegistries(); + + if( versionCheckerConfig.isVersionCheckingEnabled() ) + { + final VersionChecker versionChecker = new VersionChecker( versionCheckerConfig ); + final Thread versionCheckerThread = new Thread( versionChecker ); + + this.startService( "AE2 VersionChecker", versionCheckerThread ); + } + } @OnlyIn(Dist.CLIENT) private void clientSetup(FMLClientSetupEvent event) { final ApiDefinitions definitions = Api.INSTANCE.definitions(); definitions.getRegistry().getBootstrapComponents( IClientSetupComponent.class ).forEachRemaining(IClientSetupComponent::setup); - ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, "glass"), GlassModelLoader.INSTANCE); - ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, "sky_compass"), SkyCompassModelLoader.INSTANCE); + + addBuiltInModel("glass", GlassModel::new); + addBuiltInModel("sky_compass", SkyCompassModel::new); + addBuiltInModel("dummy_fluid_item", DummyFluidItemModel::new); + addBuiltInModel("memory_card", MemoryCardModel::new); + addBuiltInModel("biometric_card", BiometricCardModel::new); + addBuiltInModel("drive", DriveModel::new); + addBuiltInModel("color_applicator", ColorApplicatorModel::new); + addBuiltInModel("spatial_pylon", SpatialPylonModel::new); + addBuiltInModel("paint_splotches", PaintSplotchesModel::new); + addBuiltInModel("quantum_bridge_formed", QnbFormedModel::new); + ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, "crafting_cube"), CraftingCubeModelLoader.INSTANCE); ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, "auto_rotating"), AutoRotatingModelLoader.INSTANCE); } + private static > void addBuiltInModel(String id, Supplier modelFactory) { + ModelLoaderRegistry.registerLoader(new ResourceLocation(AppEng.MOD_ID, id), new SimpleModelLoader(modelFactory)); + } + @Nonnull public static AppEng instance() { @@ -205,7 +230,6 @@ public final class AppEng // AEConfig.init( configFile ); // FacadeConfig.init( facadeFile ); // -// final VersionCheckerConfig versionCheckerConfig = new VersionCheckerConfig( versionFile ); // this.exportConfig = new ForgeExportConfig( recipeConfiguration ); // // AELog.info( "Pre Initialization ( started )" ); @@ -225,14 +249,6 @@ public final class AppEng // // IntegrationRegistry.INSTANCE.preInit(); // -// if( versionCheckerConfig.isVersionCheckingEnabled() ) -// { -// final VersionChecker versionChecker = new VersionChecker( versionCheckerConfig ); -// final Thread versionCheckerThread = new Thread( versionChecker ); -// -// this.startService( "AE2 VersionChecker", versionCheckerThread ); -// } -// // AELog.info( "Pre Initialization ( ended after " + watch.elapsed( TimeUnit.MILLISECONDS ) + "ms )" ); // // // Instantiate all Plugins @@ -240,16 +256,16 @@ public final class AppEng // Api.INSTANCE ); // new PluginLoader().loadPlugins( injectables, event.getAsmData() ); // } -// -// private void startService( final String serviceName, final Thread thread ) -// { -// thread.setName( serviceName ); -// thread.setPriority( Thread.MIN_PRIORITY ); -// -// AELog.info( "Starting " + serviceName ); -// thread.start(); -// } -// + + private void startService( final String serviceName, final Thread thread ) + { + thread.setName( serviceName ); + thread.setPriority( Thread.MIN_PRIORITY ); + + AELog.info( "Starting " + serviceName ); + thread.start(); + } + // @EventHandler // private void init( final FMLCommonSetupEvent event ) // { @@ -322,9 +338,4 @@ public final class AppEng TickHandler.INSTANCE.shutdown(); } -// @EventHandler -// private void serverStarting( final FMLServerStartingEvent evt ) -// { -// evt.registerServerCommand( new AECommand( evt.getServer() ) ); -// } } diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index bd1ee20b6..db3b0b29d 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -32,36 +32,35 @@ import appeng.bootstrap.IModelRegistry; import appeng.bootstrap.components.*; import appeng.client.gui.implementations.GuiGrinder; import appeng.client.gui.implementations.GuiSkyChest; -import appeng.client.render.effects.ChargedOreFX; -import appeng.client.render.effects.LightningFX; -import appeng.client.render.effects.VibrantFX; -import appeng.client.render.model.GlassModelLoader; -import appeng.client.render.model.SkyCompassBakedModel; +import appeng.client.render.effects.*; import appeng.client.render.model.SkyCompassModel; import appeng.client.render.tesr.SkyChestTESR; -import appeng.container.implementations.ContainerGrinder; -import appeng.container.implementations.ContainerSkyChest; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerOpener; +import appeng.container.implementations.*; import appeng.core.features.registries.cell.BasicCellHandler; import appeng.core.features.registries.cell.BasicItemCellGuiHandler; import appeng.core.features.registries.cell.CreativeCellHandler; import appeng.core.stats.AeStats; import appeng.core.stats.PartItemPredicate; +import appeng.fluids.container.*; import appeng.fluids.registries.BasicFluidCellGuiHandler; import appeng.me.cache.*; import appeng.recipes.conditions.FeaturesEnabled; import appeng.recipes.game.DisassembleRecipe; import appeng.recipes.ingredients.PartIngredientSerializer; +import appeng.server.AECommand; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScreenManager; import net.minecraft.client.renderer.ItemModelMesher; import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.entity.EntityType; +import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.Item; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.particles.ParticleType; -import net.minecraft.stats.Stats; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -70,17 +69,14 @@ import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.ParticleFactoryRegisterEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.extensions.IForgeContainerType; import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.eventbus.api.GenericEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.loading.FMLEnvironment; -import net.minecraftforge.registries.ForgeRegistryEntry; +import net.minecraftforge.fml.network.IContainerFactory; import net.minecraftforge.registries.IForgeRegistry; -import net.minecraftforge.registries.ObjectHolder; final class Registration @@ -258,11 +254,241 @@ final class Registration public void registerContainerTypes( RegistryEvent.Register> event ) { final IForgeRegistry> registry = event.getRegistry(); - ContainerSkyChest.TYPE = IForgeContainerType.create(ContainerSkyChest::fromNetwork); - registry.register(ContainerSkyChest.TYPE.setRegistryName(AppEng.MOD_ID, "sky_chest")); + ContainerCellWorkbench.TYPE = registerContainer( + registry, + "cellworkbench", + ContainerCellWorkbench::fromNetwork, + ContainerCellWorkbench::open + ); + ContainerChest.TYPE = registerContainer( + registry, + "chest", + ContainerChest::fromNetwork, + ContainerChest::open + ); + ContainerCondenser.TYPE = registerContainer( + registry, + "condenser", + ContainerCondenser::fromNetwork, + ContainerCondenser::open + ); + ContainerCraftAmount.TYPE = registerContainer( + registry, + "craftamount", + ContainerCraftAmount::fromNetwork, + ContainerCraftAmount::open + ); + ContainerCraftConfirm.TYPE = registerContainer( + registry, + "craftconfirm", + ContainerCraftConfirm::fromNetwork, + ContainerCraftConfirm::open + ); + ContainerCraftingCPU.TYPE = registerContainer( + registry, + "craftingcpu", + ContainerCraftingCPU::fromNetwork, + ContainerCraftingCPU::open + ); + ContainerCraftingStatus.TYPE = registerContainer( + registry, + "craftingstatus", + ContainerCraftingStatus::fromNetwork, + ContainerCraftingStatus::open + ); + ContainerCraftingTerm.TYPE = registerContainer( + registry, + "craftingterm", + ContainerCraftingTerm::fromNetwork, + ContainerCraftingTerm::open + ); + ContainerDrive.TYPE = registerContainer( + registry, + "drive", + ContainerDrive::fromNetwork, + ContainerDrive::open + ); + ContainerFormationPlane.TYPE = registerContainer( + registry, + "formationplane", + ContainerFormationPlane::fromNetwork, + ContainerFormationPlane::open + ); + ContainerGrinder.TYPE = registerContainer( + registry, + "grinder", + ContainerGrinder::fromNetwork, + ContainerGrinder::open + ); + ContainerInscriber.TYPE = registerContainer( + registry, + "inscriber", + ContainerInscriber::fromNetwork, + ContainerInscriber::open + ); + ContainerInterface.TYPE = registerContainer( + registry, + "interface", + ContainerInterface::fromNetwork, + ContainerInterface::open + ); + ContainerInterfaceTerminal.TYPE = registerContainer( + registry, + "interfaceterminal", + ContainerInterfaceTerminal::fromNetwork, + ContainerInterfaceTerminal::open + ); + ContainerIOPort.TYPE = registerContainer( + registry, + "ioport", + ContainerIOPort::fromNetwork, + ContainerIOPort::open + ); + ContainerLevelEmitter.TYPE = registerContainer( + registry, + "levelemitter", + ContainerLevelEmitter::fromNetwork, + ContainerLevelEmitter::open + ); + ContainerMAC.TYPE = registerContainer( + registry, + "mac", + ContainerMAC::fromNetwork, + ContainerMAC::open + ); + ContainerMEMonitorable.TYPE = registerContainer( + registry, + "memonitorable", + ContainerMEMonitorable::fromNetwork, + ContainerMEMonitorable::open + ); + ContainerMEPortableCell.TYPE = registerContainer( + registry, + "meportablecell", + ContainerMEPortableCell::fromNetwork, + ContainerMEPortableCell::open + ); + ContainerNetworkStatus.TYPE = registerContainer( + registry, + "networkstatus", + ContainerNetworkStatus::fromNetwork, + ContainerNetworkStatus::open + ); + ContainerNetworkTool.TYPE = registerContainer( + registry, + "networktool", + ContainerNetworkTool::fromNetwork, + ContainerNetworkTool::open + ); + ContainerPatternTerm.TYPE = registerContainer( + registry, + "patternterm", + ContainerPatternTerm::fromNetwork, + ContainerPatternTerm::open + ); + ContainerPriority.TYPE = registerContainer( + registry, + "priority", + ContainerPriority::fromNetwork, + ContainerPriority::open + ); + ContainerQNB.TYPE = registerContainer( + registry, + "qnb", + ContainerQNB::fromNetwork, + ContainerQNB::open + ); + ContainerQuartzKnife.TYPE = registerContainer( + registry, + "quartzknife", + ContainerQuartzKnife::fromNetwork, + ContainerQuartzKnife::open + ); + ContainerSecurityStation.TYPE = registerContainer( + registry, + "securitystation", + ContainerSecurityStation::fromNetwork, + ContainerSecurityStation::open + ); + ContainerSkyChest.TYPE = registerContainer( + registry, + "skychest", + ContainerSkyChest::fromNetwork, + ContainerSkyChest::open + ); + ContainerSpatialIOPort.TYPE = registerContainer( + registry, + "spatialioport", + ContainerSpatialIOPort::fromNetwork, + ContainerSpatialIOPort::open + ); + ContainerStorageBus.TYPE = registerContainer( + registry, + "storagebus", + ContainerStorageBus::fromNetwork, + ContainerStorageBus::open + ); + ContainerUpgradeable.TYPE = registerContainer( + registry, + "upgradeable", + ContainerUpgradeable::fromNetwork, + ContainerUpgradeable::open + ); + ContainerVibrationChamber.TYPE = registerContainer( + registry, + "vibrationchamber", + ContainerVibrationChamber::fromNetwork, + ContainerVibrationChamber::open + ); + ContainerWireless.TYPE = registerContainer( + registry, + "wireless", + ContainerWireless::fromNetwork, + ContainerWireless::open + ); + ContainerWirelessTerm.TYPE = registerContainer( + registry, + "wirelessterm", + ContainerWirelessTerm::fromNetwork, + ContainerWirelessTerm::open + ); - ContainerGrinder.TYPE = IForgeContainerType.create(ContainerGrinder::fromNetwork); - registry.register(ContainerGrinder.TYPE.setRegistryName(AppEng.MOD_ID, "grinder")); + ContainerFluidFormationPlane.TYPE = registerContainer( + registry, + "fluid_formation_plane", + ContainerFluidFormationPlane::fromNetwork, + ContainerFluidFormationPlane::open + ); + ContainerFluidIO.TYPE = registerContainer( + registry, + "fluid_io", + ContainerFluidIO::fromNetwork, + ContainerFluidIO::open + ); + ContainerFluidInterface.TYPE = registerContainer( + registry, + "fluid_interface", + ContainerFluidInterface::fromNetwork, + ContainerFluidInterface::open + ); + ContainerFluidLevelEmitter.TYPE = registerContainer( + registry, + "fluid_level_emitter", + ContainerFluidLevelEmitter::fromNetwork, + ContainerFluidLevelEmitter::open + ); + ContainerFluidStorageBus.TYPE = registerContainer( + registry, + "fluid_storage_bus", + ContainerFluidStorageBus::fromNetwork, + ContainerFluidStorageBus::open + ); + ContainerFluidTerminal.TYPE = registerContainer( + registry, + "fluid_terminal", + ContainerFluidTerminal::fromNetwork, + ContainerFluidTerminal::open + ); DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { ScreenManager.registerFactory(ContainerSkyChest.TYPE, GuiSkyChest::new); @@ -270,6 +496,17 @@ final class Registration }); } + private ContainerType registerContainer(IForgeRegistry> registry, + String id, + IContainerFactory factory, + ContainerOpener.Opener opener) { + ContainerType type = IForgeContainerType.create(factory); + type.setRegistryName(AppEng.MOD_ID, id); + registry.register(type); + ContainerOpener.addOpener(type, opener); + return type; + } + public void registerRecipeSerializers( RegistryEvent.Register> event ) { IForgeRegistry> r = event.getRegistry(); @@ -306,9 +543,14 @@ final class Registration } public void registerParticleFactories(ParticleFactoryRegisterEvent event) { + Minecraft.getInstance().particles.registerFactory(AssemblerFX.TYPE, AssemblerFX.Factory::new); Minecraft.getInstance().particles.registerFactory(ChargedOreFX.TYPE, ChargedOreFX.Factory::new); - Minecraft.getInstance().particles.registerFactory(VibrantFX.TYPE, VibrantFX.Factory::new); + Minecraft.getInstance().particles.registerFactory(CraftingFx.TYPE, CraftingFx.Factory::new); + Minecraft.getInstance().particles.registerFactory(EnergyFx.TYPE, EnergyFx.Factory::new); + Minecraft.getInstance().particles.registerFactory(LightningArcFX.TYPE, LightningArcFX.Factory::new); Minecraft.getInstance().particles.registerFactory(LightningFX.TYPE, LightningFX.Factory::new); + Minecraft.getInstance().particles.registerFactory(MatterCannonFX.TYPE, MatterCannonFX.Factory::new); + Minecraft.getInstance().particles.registerFactory(VibrantFX.TYPE, VibrantFX.Factory::new); } // @@ -563,4 +805,9 @@ final class Registration SkyChestTESR.registerTextures(event); } + public void registerCommands( final FMLServerStartingEvent evt ) + { + new AECommand().register(evt.getCommandDispatcher()); + } + } diff --git a/src/main/java/appeng/core/api/definitions/ApiItems.java b/src/main/java/appeng/core/api/definitions/ApiItems.java index 2c36f5ca9..66d999c22 100644 --- a/src/main/java/appeng/core/api/definitions/ApiItems.java +++ b/src/main/java/appeng/core/api/definitions/ApiItems.java @@ -24,9 +24,8 @@ import appeng.api.definitions.IItems; import appeng.api.util.AEColoredItemDefinition; import appeng.bootstrap.FeatureFactory; import appeng.api.features.AEFeature; -import appeng.bootstrap.components.IEntityRegistrationComponent; +import appeng.client.render.crafting.EncodedPatternRenderer; import appeng.client.render.crafting.ItemEncodedPatternRendering; -import appeng.core.Api; import appeng.core.CreativeTabFacade; import appeng.debug.ToolDebugCard; import appeng.debug.ToolEraser; @@ -50,11 +49,9 @@ import appeng.items.tools.*; import appeng.items.tools.powered.*; import appeng.items.tools.quartz.*; import net.minecraft.entity.EntityClassification; -import net.minecraft.entity.EntityType; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraftforge.common.ToolType; -import org.lwjgl.system.APIUtil; import java.util.function.Consumer; @@ -293,7 +290,8 @@ public final class ApiItems implements IItems // rv1 this.encodedPattern = registry.item( "encoded_pattern", ItemEncodedPattern::new ) - .props(props -> props.maxStackSize(1)) + .props(props -> props.maxStackSize(1) + .setISTER(() -> EncodedPatternRenderer::new)) .features( AEFeature.PATTERNS ) .rendering( new ItemEncodedPatternRendering() ) .build(); diff --git a/src/main/java/appeng/core/features/registries/WirelessRegistry.java b/src/main/java/appeng/core/features/registries/WirelessRegistry.java index 8e7b0344c..33acb839d 100644 --- a/src/main/java/appeng/core/features/registries/WirelessRegistry.java +++ b/src/main/java/appeng/core/features/registries/WirelessRegistry.java @@ -22,8 +22,13 @@ package appeng.core.features.registries; import java.util.ArrayList; import java.util.List; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerMEPortableCell; +import appeng.container.implementations.ContainerWirelessTerm; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; import net.minecraft.world.IBlockReader; import appeng.api.AEApi; @@ -81,7 +86,7 @@ public final class WirelessRegistry implements IWirelessTermRegistry } @Override - public void openWirelessTerminalGui( ItemStack item, IBlockReader world, PlayerEntity player ) + public void openWirelessTerminalGui( ItemStack item, IBlockReader world, PlayerEntity player, Hand hand ) { if( Platform.isClient() ) { @@ -112,7 +117,7 @@ public final class WirelessRegistry implements IWirelessTermRegistry if( handler.hasPower( player, 0.5, item ) ) { - // FIXME Platform.openGUI( player, null, null, GuiBridge.GUI_WIRELESS_TERM ); + ContainerOpener.openContainer(ContainerWirelessTerm.TYPE, player, ContainerLocator.forHand(hand)); } else { diff --git a/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java b/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java index 1541dead9..25dcd39e6 100644 --- a/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java +++ b/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java @@ -2,6 +2,9 @@ package appeng.core.features.registries.cell; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerWireless; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -31,6 +34,6 @@ public class BasicItemCellGuiHandler implements ICellGuiHandler @Override public void openChestGui( final PlayerEntity player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan ) { - // FIXME Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_ME ); + ContainerOpener.openContainer(ContainerWireless.TYPE, player, ContainerLocator.forTileEntitySide((TileEntity) chest, chest.getUp())); } } diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index 46183a340..8a3998889 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -28,7 +28,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; import appeng.api.exceptions.AppEngException; import appeng.api.features.IWirelessTermHandler; @@ -47,10 +46,9 @@ import appeng.api.storage.ITerminalHost; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.client.gui.AEBaseGui; -import appeng.client.gui.GuiNull; import appeng.container.AEBaseContainer; import appeng.container.ContainerNull; -import appeng.container.ContainerOpenContext; +import appeng.container.ContainerLocator; import appeng.container.implementations.ContainerCellWorkbench; import appeng.container.implementations.ContainerChest; import appeng.container.implementations.ContainerCondenser; @@ -245,7 +243,7 @@ public enum GuiBridge { throw new IllegalStateException( "Unable to find gui class" ); } - this.guiClass = ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClass ); + this.guiClass = null; // FIXME ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClass ); if( this.guiClass == null ) { throw new IllegalStateException( "Cannot Load class: " + guiClass ); @@ -262,7 +260,6 @@ public enum GuiBridge this.getGui(); } - @Override public Object getServerGuiElement( final int ordinal, final PlayerEntity player, final World w, final int x, final int y, final int z ) { final AEPartLocation side = AEPartLocation.fromOrdinal( ordinal & 0x07 ); @@ -341,13 +338,13 @@ public enum GuiBridge { if( newContainer instanceof AEBaseContainer ) { - final AEBaseContainer bc = (AEBaseContainer) newContainer; - bc.setOpenContext( new ContainerOpenContext( myItem ) ); - bc.getOpenContext().setWorld( w ); - bc.getOpenContext().setX( x ); - bc.getOpenContext().setY( y ); - bc.getOpenContext().setZ( z ); - bc.getOpenContext().setSide( side ); + // FIXME final AEBaseContainer bc = (AEBaseContainer) newContainer; + // FIXME bc.setLocator( new ContainerLocator( myItem ) ); + // FIXME bc.getLocator().setWorld( w ); + // FIXME bc.getLocator().setX( x ); + // FIXME bc.getLocator().setY( y ); + // FIXME bc.getLocator().setZ( z ); + // FIXME bc.getLocator().setSide( side ); } return newContainer; @@ -405,7 +402,6 @@ public enum GuiBridge return inventory.getClass().getName(); } - @Override public Object getClientGuiElement( final int ordinal, final PlayerEntity player, final World w, final int x, final int y, final int z ) { final AEPartLocation side = AEPartLocation.fromOrdinal( ordinal & 0x07 ); @@ -448,7 +444,7 @@ public enum GuiBridge } } } - return new GuiNull( new ContainerNull() ); + return null; // FIXME } public Object ConstructGui( final PlayerInventory inventory, final AEPartLocation side, final Object tE ) diff --git a/src/main/java/appeng/core/sync/packets/PacketClick.java b/src/main/java/appeng/core/sync/packets/PacketClick.java index 4808118c7..a39a785c0 100644 --- a/src/main/java/appeng/core/sync/packets/PacketClick.java +++ b/src/main/java/appeng/core/sync/packets/PacketClick.java @@ -20,6 +20,8 @@ package appeng.core.sync.packets; import appeng.block.networking.BlockCableBus; +import appeng.items.tools.ToolNetworkTool; +import appeng.items.tools.powered.ToolColorApplicator; import io.netty.buffer.Unpooled; import net.minecraft.block.Block; @@ -126,25 +128,25 @@ public class PacketClick extends AppEngPacket { if( !is.isEmpty() ) { - // FIXME if( is.getItem() instanceof ToolNetworkTool ) - // FIXME { - // FIXME final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem(); - // FIXME tnt.serverSideToolLogic( is, player, this.hand, player.world, pos, this.side, this.hitX, this.hitY, - // FIXME this.hitZ ); - // FIXME } + if( is.getItem() instanceof ToolNetworkTool) + { + final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem(); + tnt.serverSideToolLogic( is, player, this.hand, player.world, pos, this.side, this.hitX, this.hitY, + this.hitZ ); + } - /* FIXME else */ if( maybeMemoryCard.isSameAs( is ) ) + if( maybeMemoryCard.isSameAs( is ) ) { final IMemoryCard mem = (IMemoryCard) is.getItem(); mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED ); is.setTag( null ); } - // FIXME else if( maybeColorApplicator.isSameAs( is ) ) - // FIXME { - // FIXME final ToolColorApplicator mem = (ToolColorApplicator) is.getItem(); - // FIXME mem.cycleColors( is, mem.getColor( is ), 1 ); - // FIXME } + else if( maybeColorApplicator.isSameAs( is ) ) + { + final ToolColorApplicator mem = (ToolColorApplicator) is.getItem(); + mem.cycleColors( is, mem.getColor( is ), 1 ); + } } } } diff --git a/src/main/java/appeng/core/sync/packets/PacketCraftRequest.java b/src/main/java/appeng/core/sync/packets/PacketCraftRequest.java index de20fc74e..206bf0a65 100644 --- a/src/main/java/appeng/core/sync/packets/PacketCraftRequest.java +++ b/src/main/java/appeng/core/sync/packets/PacketCraftRequest.java @@ -21,6 +21,8 @@ package appeng.core.sync.packets; import java.util.concurrent.Future; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerInscriber; import io.netty.buffer.Unpooled; import net.minecraft.entity.player.PlayerEntity; @@ -32,7 +34,7 @@ import appeng.api.networking.IGridNode; import appeng.api.networking.crafting.ICraftingGrid; import appeng.api.networking.crafting.ICraftingJob; import appeng.api.networking.security.IActionHost; -import appeng.container.ContainerOpenContext; +import appeng.container.ContainerLocator; import appeng.container.implementations.ContainerCraftAmount; import appeng.container.implementations.ContainerCraftConfirm; import appeng.core.AELog; @@ -96,11 +98,10 @@ public class PacketCraftRequest extends AppEngPacket final ICraftingGrid cg = g.getCache( ICraftingGrid.class ); futureJob = cg.beginCraftingJob( cca.getWorld(), cca.getGrid(), cca.getActionSrc(), cca.getItemToCraft(), null ); - final ContainerOpenContext context = cca.getOpenContext(); - if( context != null ) + final ContainerLocator locator = cca.getLocator(); + if( locator != null ) { - final TileEntity te = context.getTile(); - // FIXME Platform.openGUI( player, te, cca.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_CONFIRM ); + ContainerOpener.openContainer(ContainerCraftConfirm.TYPE, player, locator); if( player.openContainer instanceof ContainerCraftConfirm ) { diff --git a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java index 1e646d423..59b1a1746 100644 --- a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java @@ -21,6 +21,8 @@ package appeng.core.sync.packets; import java.io.IOException; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerInscriber; import io.netty.buffer.Unpooled; import net.minecraft.entity.player.PlayerEntity; @@ -31,7 +33,7 @@ import net.minecraft.tileentity.TileEntity; import appeng.api.storage.data.IAEItemStack; import appeng.container.AEBaseContainer; -import appeng.container.ContainerOpenContext; +import appeng.container.ContainerLocator; import appeng.container.implementations.ContainerCraftAmount; import appeng.core.AppEng; import appeng.core.sync.AppEngPacket; @@ -127,11 +129,10 @@ public class PacketInventoryAction extends AppEngPacket final AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer; if( this.action == InventoryAction.AUTO_CRAFT ) { - final ContainerOpenContext context = baseContainer.getOpenContext(); - if( context != null ) + final ContainerLocator locator = baseContainer.getLocator(); + if( locator != null ) { - final TileEntity te = context.getTile(); - // FIXME Platform.openGUI( sender, te, baseContainer.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_AMOUNT ); + ContainerOpener.openContainer(ContainerCraftAmount.TYPE, player, locator); if( sender.openContainer instanceof ContainerCraftAmount ) { diff --git a/src/main/java/appeng/core/sync/packets/PacketSwitchGuis.java b/src/main/java/appeng/core/sync/packets/PacketSwitchGuis.java index af2527315..97189a7a1 100644 --- a/src/main/java/appeng/core/sync/packets/PacketSwitchGuis.java +++ b/src/main/java/appeng/core/sync/packets/PacketSwitchGuis.java @@ -19,40 +19,43 @@ package appeng.core.sync.packets; +import appeng.container.ContainerOpener; import io.netty.buffer.Unpooled; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.network.PacketBuffer; import net.minecraft.tileentity.TileEntity; import appeng.container.AEBaseContainer; -import appeng.container.ContainerOpenContext; +import appeng.container.ContainerLocator; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.util.Platform; +import net.minecraftforge.registries.ForgeRegistries; public class PacketSwitchGuis extends AppEngPacket { - private final GuiBridge newGui; + private final ContainerType newGui; public PacketSwitchGuis( final PacketBuffer stream ) { - this.newGui = GuiBridge.values()[stream.readInt()]; + this.newGui = ForgeRegistries.CONTAINERS.getValue(stream.readResourceLocation()); } // api - public PacketSwitchGuis( final GuiBridge newGui ) + public PacketSwitchGuis( final ContainerType newGui ) { this.newGui = newGui; final PacketBuffer data = new PacketBuffer( Unpooled.buffer() ); data.writeInt( this.getPacketID() ); - data.writeInt( newGui.ordinal() ); + data.writeResourceLocation(newGui.getRegistryName()); this.configureWrite( data ); } @@ -64,11 +67,10 @@ public class PacketSwitchGuis extends AppEngPacket if( c instanceof AEBaseContainer ) { final AEBaseContainer bc = (AEBaseContainer) c; - final ContainerOpenContext context = bc.getOpenContext(); - if( context != null ) + final ContainerLocator locator = bc.getLocator(); + if( locator != null ) { - final TileEntity te = context.getTile(); - Platform.openGUI( player, te, context.getSide(), this.newGui ); + ContainerOpener.openContainer(newGui, player, locator); } } } diff --git a/src/main/java/appeng/core/sync/packets/PacketTransitionEffect.java b/src/main/java/appeng/core/sync/packets/PacketTransitionEffect.java index 64f51c9ac..2d730268b 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTransitionEffect.java +++ b/src/main/java/appeng/core/sync/packets/PacketTransitionEffect.java @@ -25,6 +25,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.SoundType; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SimpleSound; +import net.minecraft.client.particle.Particle; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -92,21 +93,19 @@ public class PacketTransitionEffect extends AppEngPacket { if( AppEng.proxy.shouldAddParticles( Platform.getRandom() ) ) { - final EnergyFx fx = new EnergyFx( world, this.x + ( this.mode ? ( Platform - .getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ), this.y + ( this.mode ? ( Platform - .getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ), this.z + ( this.mode ? ( Platform - .getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ), new ItemStack(Items.DIAMOND, 1) ); + double x = this.x + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ); + double y = this.y + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ); + double z = this.z + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ); + double speedX = -0.1f * this.d.xOffset; + double speedY = -0.1f * this.d.yOffset; + double speedZ = -0.1f * this.d.zOffset; + EnergyFx fx = (EnergyFx) Minecraft.getInstance().particles.addParticle(EnergyFx.TYPE, x, y, z, speedX, speedY, speedZ); + // FIXME: *sigh* custom particle data for this one thing :| if( !this.mode ) { - fx.fromItem( this.d ); + fx.fromItem( this.d ); } - - fx.setMotionX( -0.1f * this.d.xOffset ); - fx.setMotionY( -0.1f * this.d.yOffset ); - fx.setMotionZ( -0.1f * this.d.zOffset ); - - Minecraft.getInstance().particles.addEffect( fx ); } } diff --git a/src/main/java/appeng/core/sync/packets/PacketValueConfig.java b/src/main/java/appeng/core/sync/packets/PacketValueConfig.java index d14508129..a274dc278 100644 --- a/src/main/java/appeng/core/sync/packets/PacketValueConfig.java +++ b/src/main/java/appeng/core/sync/packets/PacketValueConfig.java @@ -19,12 +19,36 @@ package appeng.core.sync.packets; +import appeng.api.config.FuzzyMode; +import appeng.api.config.Settings; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.client.gui.implementations.GuiCraftingCPU; +import appeng.container.AEBaseContainer; +import appeng.container.implementations.ContainerCellWorkbench; +import appeng.container.implementations.ContainerCraftConfirm; +import appeng.container.implementations.ContainerCraftingCPU; +import appeng.container.implementations.ContainerCraftingStatus; +import appeng.container.implementations.ContainerLevelEmitter; +import appeng.container.implementations.ContainerNetworkTool; +import appeng.container.implementations.ContainerPatternTerm; +import appeng.container.implementations.ContainerPriority; +import appeng.container.implementations.ContainerQuartzKnife; +import appeng.container.implementations.ContainerSecurityStation; +import appeng.container.implementations.ContainerStorageBus; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; +import appeng.fluids.container.ContainerFluidLevelEmitter; +import appeng.fluids.container.ContainerFluidStorageBus; +import appeng.helpers.IMouseWheelItem; import io.netty.buffer.Unpooled; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screen.Screen; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.container.Container; +import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; +import net.minecraft.util.Hand; import java.io.IOException; @@ -43,7 +67,7 @@ public class PacketValueConfig extends AppEngPacket } // api - public PacketValueConfig( final String name, final String value ) throws IOException + public PacketValueConfig( final String name, final String value ) { this.Name = name; this.Value = value; @@ -63,172 +87,172 @@ public class PacketValueConfig extends AppEngPacket { final Container c = player.openContainer; -// FIXME if( this.Name.equals( "Item" ) && ( ( !player.getHeldItem( Hand.MAIN_HAND ).isEmpty() && player.getHeldItem( Hand.MAIN_HAND ).getItem() instanceof IMouseWheelItem ) || ( !player.getHeldItem( Hand.OFF_HAND ).isEmpty() && player.getHeldItem( Hand.OFF_HAND ).getItem() instanceof IMouseWheelItem ) ) ) -// FIXME { -// FIXME final Hand hand; -// FIXME if( !player.getHeldItem( Hand.MAIN_HAND ).isEmpty() && player.getHeldItem( Hand.MAIN_HAND ).getItem() instanceof IMouseWheelItem ) -// FIXME { -// FIXME hand = Hand.MAIN_HAND; -// FIXME } -// FIXME else if( !player.getHeldItem( Hand.OFF_HAND ).isEmpty() && player.getHeldItem( Hand.OFF_HAND ).getItem() instanceof IMouseWheelItem ) -// FIXME { -// FIXME hand = Hand.OFF_HAND; -// FIXME } -// FIXME else -// FIXME { -// FIXME return; -// FIXME } -// FIXME -// FIXME final ItemStack is = player.getHeldItem( hand ); -// FIXME final IMouseWheelItem si = (IMouseWheelItem) is.getItem(); -// FIXME si.onWheel( is, this.Value.equals( "WheelUp" ) ); -// FIXME } -// FIXME else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus ) -// FIXME { -// FIXME final ContainerCraftingStatus qk = (ContainerCraftingStatus) c; -// FIXME qk.cycleCpu( this.Value.equals( "Next" ) ); -// FIXME } -// FIXME else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm ) -// FIXME { -// FIXME final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; -// FIXME qk.cycleCpu( this.Value.equals( "Next" ) ); -// FIXME } -// FIXME else if( this.Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm ) -// FIXME { -// FIXME final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; -// FIXME qk.startJob(); -// FIXME } -// FIXME else if( this.Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU ) -// FIXME { -// FIXME final ContainerCraftingCPU qk = (ContainerCraftingCPU) c; -// FIXME qk.cancelCrafting(); -// FIXME } -// FIXME else if( this.Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife ) -// FIXME { -// FIXME final ContainerQuartzKnife qk = (ContainerQuartzKnife) c; -// FIXME qk.setName( this.Value ); -// FIXME } -// FIXME else if( this.Name.equals( "TileSecurityStation.ToggleOption" ) && c instanceof ContainerSecurityStation ) -// FIXME { -// FIXME final ContainerSecurityStation sc = (ContainerSecurityStation) c; -// FIXME sc.toggleSetting( this.Value, player ); -// FIXME } -// FIXME else if( this.Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority ) -// FIXME { -// FIXME final ContainerPriority pc = (ContainerPriority) c; -// FIXME pc.setPriority( Integer.parseInt( this.Value ), player ); -// FIXME } -// FIXME else if( this.Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter ) -// FIXME { -// FIXME final ContainerLevelEmitter lvc = (ContainerLevelEmitter) c; -// FIXME lvc.setLevel( Long.parseLong( this.Value ), player ); -// FIXME } -// FIXME else if( this.Name.equals( "FluidLevelEmitter.Value" ) && c instanceof ContainerFluidLevelEmitter ) -// FIXME { -// FIXME final ContainerFluidLevelEmitter lvc = (ContainerFluidLevelEmitter) c; -// FIXME lvc.setLevel( Long.parseLong( this.Value ), player ); -// FIXME } -// FIXME else if( this.Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm ) -// FIXME { -// FIXME final ContainerPatternTerm cpt = (ContainerPatternTerm) c; -// FIXME if( this.Name.equals( "PatternTerminal.CraftMode" ) ) -// FIXME { -// FIXME cpt.getPatternTerminal().setCraftingRecipe( this.Value.equals( "1" ) ); -// FIXME } -// FIXME else if( this.Name.equals( "PatternTerminal.Encode" ) ) -// FIXME { -// FIXME cpt.encode(); -// FIXME } -// FIXME else if( this.Name.equals( "PatternTerminal.Clear" ) ) -// FIXME { -// FIXME cpt.clear(); -// FIXME } -// FIXME else if( this.Name.equals( "PatternTerminal.Substitute" ) ) -// FIXME { -// FIXME cpt.getPatternTerminal().setSubstitution( this.Value.equals( "1" ) ); -// FIXME } -// FIXME } -// FIXME else if( this.Name.startsWith( "StorageBus." ) ) -// FIXME { -// FIXME if( this.Name.equals( "StorageBus.Action" ) ) -// FIXME { -// FIXME if( this.Value.equals( "Partition" ) ) -// FIXME { -// FIXME if( c instanceof ContainerStorageBus ) -// FIXME { -// FIXME ( (ContainerStorageBus) c ).partition(); -// FIXME } -// FIXME else if( c instanceof ContainerFluidStorageBus ) -// FIXME { -// FIXME ( (ContainerFluidStorageBus) c ).partition(); -// FIXME } -// FIXME } -// FIXME else if( this.Value.equals( "Clear" ) ) -// FIXME { -// FIXME if( c instanceof ContainerStorageBus ) -// FIXME { -// FIXME ( (ContainerStorageBus) c ).clear(); -// FIXME } -// FIXME else if( c instanceof ContainerFluidStorageBus ) -// FIXME { -// FIXME ( (ContainerFluidStorageBus) c ).clear(); -// FIXME } -// FIXME } -// FIXME } -// FIXME } -// FIXME else if( this.Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench ) -// FIXME { -// FIXME final ContainerCellWorkbench ccw = (ContainerCellWorkbench) c; -// FIXME if( this.Name.equals( "CellWorkbench.Action" ) ) -// FIXME { -// FIXME if( this.Value.equals( "CopyMode" ) ) -// FIXME { -// FIXME ccw.nextWorkBenchCopyMode(); -// FIXME } -// FIXME else if( this.Value.equals( "Partition" ) ) -// FIXME { -// FIXME ccw.partition(); -// FIXME } -// FIXME else if( this.Value.equals( "Clear" ) ) -// FIXME { -// FIXME ccw.clear(); -// FIXME } -// FIXME } -// FIXME else if( this.Name.equals( "CellWorkbench.Fuzzy" ) ) -// FIXME { -// FIXME ccw.setFuzzy( FuzzyMode.valueOf( this.Value ) ); -// FIXME } -// FIXME } -// FIXME else if( c instanceof ContainerNetworkTool ) -// FIXME { -// FIXME if( this.Name.equals( "NetworkTool" ) && this.Value.equals( "Toggle" ) ) -// FIXME { -// FIXME ( (ContainerNetworkTool) c ).toggleFacadeMode(); -// FIXME } -// FIXME } -// FIXME else if( c instanceof IConfigurableObject ) -// FIXME { -// FIXME final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager(); -// FIXME -// FIXME for( final Settings e : cm.getSettings() ) -// FIXME { -// FIXME if( e.name().equals( this.Name ) ) -// FIXME { -// FIXME final Enum def = cm.getSetting( e ); -// FIXME -// FIXME try -// FIXME { -// FIXME cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) ); -// FIXME } -// FIXME catch( final IllegalArgumentException err ) -// FIXME { -// FIXME // :P -// FIXME } -// FIXME -// FIXME break; -// FIXME } -// FIXME } -// FIXME } + if( this.Name.equals( "Item" ) && ( ( !player.getHeldItem( Hand.MAIN_HAND ).isEmpty() && player.getHeldItem( Hand.MAIN_HAND ).getItem() instanceof IMouseWheelItem) || ( !player.getHeldItem( Hand.OFF_HAND ).isEmpty() && player.getHeldItem( Hand.OFF_HAND ).getItem() instanceof IMouseWheelItem ) ) ) + { + final Hand hand; + if( !player.getHeldItem( Hand.MAIN_HAND ).isEmpty() && player.getHeldItem( Hand.MAIN_HAND ).getItem() instanceof IMouseWheelItem ) + { + hand = Hand.MAIN_HAND; + } + else if( !player.getHeldItem( Hand.OFF_HAND ).isEmpty() && player.getHeldItem( Hand.OFF_HAND ).getItem() instanceof IMouseWheelItem ) + { + hand = Hand.OFF_HAND; + } + else + { + return; + } + + final ItemStack is = player.getHeldItem( hand ); + final IMouseWheelItem si = (IMouseWheelItem) is.getItem(); + si.onWheel( is, this.Value.equals( "WheelUp" ) ); + } + else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus) + { + final ContainerCraftingStatus qk = (ContainerCraftingStatus) c; + qk.cycleCpu( this.Value.equals( "Next" ) ); + } + else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm ) + { + final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; + qk.cycleCpu( this.Value.equals( "Next" ) ); + } + else if( this.Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm ) + { + final ContainerCraftConfirm qk = (ContainerCraftConfirm) c; + qk.startJob(); + } + else if( this.Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU ) + { + final ContainerCraftingCPU qk = (ContainerCraftingCPU) c; + qk.cancelCrafting(); + } + else if( this.Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife ) + { + final ContainerQuartzKnife qk = (ContainerQuartzKnife) c; + qk.setName( this.Value ); + } + else if( this.Name.equals( "TileSecurityStation.ToggleOption" ) && c instanceof ContainerSecurityStation ) + { + final ContainerSecurityStation sc = (ContainerSecurityStation) c; + sc.toggleSetting( this.Value, player ); + } + else if( this.Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority ) + { + final ContainerPriority pc = (ContainerPriority) c; + pc.setPriority( Integer.parseInt( this.Value ), player ); + } + else if( this.Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter ) + { + final ContainerLevelEmitter lvc = (ContainerLevelEmitter) c; + lvc.setLevel( Long.parseLong( this.Value ), player ); + } + else if( this.Name.equals( "FluidLevelEmitter.Value" ) && c instanceof ContainerFluidLevelEmitter) + { + final ContainerFluidLevelEmitter lvc = (ContainerFluidLevelEmitter) c; + lvc.setLevel( Long.parseLong( this.Value ), player ); + } + else if( this.Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm ) + { + final ContainerPatternTerm cpt = (ContainerPatternTerm) c; + if( this.Name.equals( "PatternTerminal.CraftMode" ) ) + { + cpt.getPatternTerminal().setCraftingRecipe( this.Value.equals( "1" ) ); + } + else if( this.Name.equals( "PatternTerminal.Encode" ) ) + { + cpt.encode(); + } + else if( this.Name.equals( "PatternTerminal.Clear" ) ) + { + cpt.clear(); + } + else if( this.Name.equals( "PatternTerminal.Substitute" ) ) + { + cpt.getPatternTerminal().setSubstitution( this.Value.equals( "1" ) ); + } + } + else if( this.Name.startsWith( "StorageBus." ) ) + { + if( this.Name.equals( "StorageBus.Action" ) ) + { + if( this.Value.equals( "Partition" ) ) + { + if( c instanceof ContainerStorageBus ) + { + ( (ContainerStorageBus) c ).partition(); + } + else if( c instanceof ContainerFluidStorageBus) + { + ( (ContainerFluidStorageBus) c ).partition(); + } + } + else if( this.Value.equals( "Clear" ) ) + { + if( c instanceof ContainerStorageBus ) + { + ( (ContainerStorageBus) c ).clear(); + } + else if( c instanceof ContainerFluidStorageBus ) + { + ( (ContainerFluidStorageBus) c ).clear(); + } + } + } + } + else if( this.Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench ) + { + final ContainerCellWorkbench ccw = (ContainerCellWorkbench) c; + if( this.Name.equals( "CellWorkbench.Action" ) ) + { + if( this.Value.equals( "CopyMode" ) ) + { + ccw.nextWorkBenchCopyMode(); + } + else if( this.Value.equals( "Partition" ) ) + { + ccw.partition(); + } + else if( this.Value.equals( "Clear" ) ) + { + ccw.clear(); + } + } + else if( this.Name.equals( "CellWorkbench.Fuzzy" ) ) + { + ccw.setFuzzy( FuzzyMode.valueOf( this.Value ) ); + } + } + else if( c instanceof ContainerNetworkTool ) + { + if( this.Name.equals( "NetworkTool" ) && this.Value.equals( "Toggle" ) ) + { + ( (ContainerNetworkTool) c ).toggleFacadeMode(); + } + } + else if( c instanceof IConfigurableObject) + { + final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager(); + + for( final Settings e : cm.getSettings() ) + { + if( e.name().equals( this.Name ) ) + { + final Enum def = cm.getSetting( e ); + + try + { + cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) ); + } + catch( final IllegalArgumentException err ) + { + // :P + } + + break; + } + } + } } @Override @@ -236,44 +260,44 @@ public class PacketValueConfig extends AppEngPacket { final Container c = player.openContainer; -// FIXME if( this.Name.equals( "CustomName" ) && c instanceof AEBaseContainer ) -// FIXME { -// FIXME ( (AEBaseContainer) c ).setCustomName( this.Value ); -// FIXME } -// FIXME else if( this.Name.startsWith( "SyncDat." ) ) -// FIXME { -// FIXME ( (AEBaseContainer) c ).stringSync( Integer.parseInt( this.Name.substring( 8 ) ), this.Value ); -// FIXME } -// FIXME else if( this.Name.equals( "CraftingStatus" ) && this.Value.equals( "Clear" ) ) -// FIXME { -// FIXME final Screen gs = Minecraft.getInstance().currentScreen; -// FIXME if( gs instanceof GuiCraftingCPU ) -// FIXME { -// FIXME ( (GuiCraftingCPU) gs ).clearItems(); -// FIXME } -// FIXME } -// FIXME else if( c instanceof IConfigurableObject ) -// FIXME { -// FIXME final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager(); -// FIXME -// FIXME for( final Settings e : cm.getSettings() ) -// FIXME { -// FIXME if( e.name().equals( this.Name ) ) -// FIXME { -// FIXME final Enum def = cm.getSetting( e ); -// FIXME -// FIXME try -// FIXME { -// FIXME cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) ); -// FIXME } -// FIXME catch( final IllegalArgumentException err ) -// FIXME { -// FIXME // :P -// FIXME } -// FIXME -// FIXME break; -// FIXME } -// FIXME } -// FIXME } + if( this.Name.equals( "CustomName" ) && c instanceof AEBaseContainer) + { + ( (AEBaseContainer) c ).setCustomName( this.Value ); + } + else if( this.Name.startsWith( "SyncDat." ) ) + { + ( (AEBaseContainer) c ).stringSync( Integer.parseInt( this.Name.substring( 8 ) ), this.Value ); + } + else if( this.Name.equals( "CraftingStatus" ) && this.Value.equals( "Clear" ) ) + { + final Screen gs = Minecraft.getInstance().currentScreen; + if( gs instanceof GuiCraftingCPU) + { + ( (GuiCraftingCPU) gs ).clearItems(); + } + } + else if( c instanceof IConfigurableObject ) + { + final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager(); + + for( final Settings e : cm.getSettings() ) + { + if( e.name().equals( this.Name ) ) + { + final Enum def = cm.getSetting( e ); + + try + { + cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) ); + } + catch( final IllegalArgumentException err ) + { + // :P + } + + break; + } + } + } } } diff --git a/src/main/java/appeng/fluids/block/BlockFluidInterface.java b/src/main/java/appeng/fluids/block/BlockFluidInterface.java index cbc9b0eb8..aa7fb9bfe 100644 --- a/src/main/java/appeng/fluids/block/BlockFluidInterface.java +++ b/src/main/java/appeng/fluids/block/BlockFluidInterface.java @@ -21,6 +21,9 @@ package appeng.fluids.block; import javax.annotation.Nullable; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.fluids.container.ContainerFluidInterface; import net.minecraft.block.material.Material; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -57,7 +60,7 @@ public class BlockFluidInterface extends AEBaseTileBlock { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, tg, AEPartLocation.fromFacing(hit), GuiBridge.GUI_FLUID_INTERFACE ); + ContainerOpener.openContainer(ContainerFluidInterface.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace())); } return ActionResultType.SUCCESS; } diff --git a/src/main/java/appeng/fluids/client/gui/GuiFluidFormationPlane.java b/src/main/java/appeng/fluids/client/gui/GuiFluidFormationPlane.java index 088c4d7f4..0eac89646 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiFluidFormationPlane.java +++ b/src/main/java/appeng/fluids/client/gui/GuiFluidFormationPlane.java @@ -2,34 +2,26 @@ package appeng.fluids.client.gui; -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - import appeng.client.gui.implementations.GuiUpgradeable; import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerPriority; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketSwitchGuis; import appeng.fluids.client.gui.widgets.GuiFluidSlot; import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot; import appeng.fluids.container.ContainerFluidFormationPlane; -import appeng.fluids.parts.PartFluidFormationPlane; import appeng.fluids.util.IAEFluidTank; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; -public class GuiFluidFormationPlane extends GuiUpgradeable +public class GuiFluidFormationPlane extends GuiUpgradeable { - private final PartFluidFormationPlane plane; - private GuiTabButton priority; - - public GuiFluidFormationPlane( PlayerInventory PlayerInventory, PartFluidFormationPlane te ) + public GuiFluidFormationPlane(ContainerFluidFormationPlane container, PlayerInventory playerInventory, ITextComponent title) { - super( new ContainerFluidFormationPlane( PlayerInventory, te ) ); + super(container, playerInventory, title); this.ySize = 251; - this.plane = te; } @Override @@ -40,8 +32,7 @@ public class GuiFluidFormationPlane extends GuiUpgradeable final int xo = 8; final int yo = 23 + 6; - final IAEFluidTank config = this.plane.getConfig(); - final ContainerFluidFormationPlane container = (ContainerFluidFormationPlane) this.container; + final IAEFluidTank config = container.getFluidConfigInventory(); for( int y = 0; y < 7; y++ ) { @@ -63,7 +54,11 @@ public class GuiFluidFormationPlane extends GuiUpgradeable @Override protected void addButtons() { - this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer ) ); + this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) ); + } + + private void openPriorityGui() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); } @Override @@ -72,16 +67,6 @@ public class GuiFluidFormationPlane extends GuiUpgradeable return "guis/storagebus.png"; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - if( btn == this.priority ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - } - @Override protected GuiText getName() { diff --git a/src/main/java/appeng/fluids/client/gui/GuiFluidIO.java b/src/main/java/appeng/fluids/client/gui/GuiFluidIO.java index 67fc1df80..5d9ce36d6 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiFluidIO.java +++ b/src/main/java/appeng/fluids/client/gui/GuiFluidIO.java @@ -19,16 +19,15 @@ package appeng.fluids.client.gui; -import net.minecraft.entity.player.PlayerInventory; - import appeng.client.gui.implementations.GuiUpgradeable; import appeng.core.localization.GuiText; import appeng.fluids.client.gui.widgets.GuiFluidSlot; import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot; import appeng.fluids.container.ContainerFluidIO; import appeng.fluids.parts.PartFluidImportBus; -import appeng.fluids.parts.PartSharedFluidBus; import appeng.fluids.util.IAEFluidTank; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; /** @@ -36,14 +35,12 @@ import appeng.fluids.util.IAEFluidTank; * @version rv5 - 1/05/2018 * @since rv5 1/05/2018 */ -public class GuiFluidIO extends GuiUpgradeable +public class GuiFluidIO extends GuiUpgradeable { - private final PartSharedFluidBus bus; - public GuiFluidIO( PlayerInventory PlayerInventory, PartSharedFluidBus te ) + public GuiFluidIO(ContainerFluidIO container, PlayerInventory playerInventory, ITextComponent title) { - super( new ContainerFluidIO( PlayerInventory, te ) ); - this.bus = te; + super(container, playerInventory, title); } @Override @@ -51,8 +48,7 @@ public class GuiFluidIO extends GuiUpgradeable { super.init(); - final ContainerFluidIO container = (ContainerFluidIO) this.container; - final IAEFluidTank inv = this.bus.getConfig(); + final IAEFluidTank inv = this.container.getFluidConfigInventory(); final int y = 40; final int x = 80; diff --git a/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java b/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java index 1e06726e2..3dc212ee2 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java +++ b/src/main/java/appeng/fluids/client/gui/GuiFluidInterface.java @@ -19,37 +19,27 @@ package appeng.fluids.client.gui; -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; - import appeng.client.gui.implementations.GuiUpgradeable; import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerPriority; import appeng.core.localization.GuiText; - import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketSwitchGuis; import appeng.fluids.client.gui.widgets.GuiFluidSlot; import appeng.fluids.client.gui.widgets.GuiFluidTank; import appeng.fluids.container.ContainerFluidInterface; import appeng.fluids.helper.DualityFluidInterface; -import appeng.fluids.helper.IFluidInterfaceHost; import appeng.fluids.util.IAEFluidTank; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.fml.client.gui.GuiUtils; - -public class GuiFluidInterface extends GuiUpgradeable +public class GuiFluidInterface extends GuiUpgradeable { - public final static int ID_BUTTON_TANK = 222; - - private final IFluidInterfaceHost host; - private GuiTabButton priority; - - public GuiFluidInterface( final PlayerInventory ip, final IFluidInterfaceHost te ) + public GuiFluidInterface(ContainerFluidInterface container, PlayerInventory playerInventory, ITextComponent title) { - super( new ContainerFluidInterface( ip, te ) ); + super(container, playerInventory, title); this.ySize = 231; - this.host = te; } @Override @@ -57,19 +47,18 @@ public class GuiFluidInterface extends GuiUpgradeable { super.init(); - final IAEFluidTank configFluids = this.host.getDualityFluidInterface().getConfig(); - final IAEFluidTank fluidTank = this.host.getDualityFluidInterface().getTanks(); + final IAEFluidTank configFluids = this.container.getFluidConfigInventory(); + final IAEFluidTank fluidTank = this.container.getTanks(); for( int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i ) { - final GuiFluidTank guiTank = new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, this.getGuiLeft() + 35 + 18 * i, this + final GuiFluidTank guiTank = new GuiFluidTank( fluidTank, i, this.getGuiLeft() + 35 + 18 * i, this .getGuiTop() + 53, 16, 68 ); this.addButton( guiTank ); this.guiSlots.add( new GuiFluidSlot( configFluids, i, i, 35 + 18 * i, 35 ) ); } - this.priority = new GuiTabButton( this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer ); - this.addButton( this.priority ); + this.addButton( new GuiTabButton( this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) ); } @Override @@ -87,21 +76,14 @@ public class GuiFluidInterface extends GuiUpgradeable } @Override - public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY ) + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks) { this.bindTexture( "guis/interfacefluid.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize ); + GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME ZINDEX */ ); } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - if( btn == this.priority ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } + private void openPriorityGui() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); } @Override diff --git a/src/main/java/appeng/fluids/client/gui/GuiFluidLevelEmitter.java b/src/main/java/appeng/fluids/client/gui/GuiFluidLevelEmitter.java index 61e0ab42d..4a452af81 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiFluidLevelEmitter.java +++ b/src/main/java/appeng/fluids/client/gui/GuiFluidLevelEmitter.java @@ -2,9 +2,9 @@ package appeng.fluids.client.gui; -import java.io.IOException; -import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.util.InputMappings; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.RedstoneMode; @@ -13,33 +13,20 @@ import appeng.client.gui.implementations.GuiUpgradeable; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiNumberBox; import appeng.core.AEConfig; -import appeng.core.AELog; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; import appeng.fluids.client.gui.widgets.GuiFluidSlot; import appeng.fluids.container.ContainerFluidLevelEmitter; -import appeng.fluids.parts.PartFluidLevelEmitter; +import net.minecraft.util.text.ITextComponent; -public class GuiFluidLevelEmitter extends GuiUpgradeable +public class GuiFluidLevelEmitter extends GuiUpgradeable { - private final PartFluidLevelEmitter levelEmitter; private GuiNumberBox level; - private GuiButton plus1; - private GuiButton plus10; - private GuiButton plus100; - private GuiButton plus1000; - private GuiButton minus1; - private GuiButton minus10; - private GuiButton minus100; - private GuiButton minus1000; - - public GuiFluidLevelEmitter( final PlayerInventory PlayerInventory, final PartFluidLevelEmitter te ) - { - super( new ContainerFluidLevelEmitter( PlayerInventory, te ) ); - this.levelEmitter = te; + public GuiFluidLevelEmitter(ContainerFluidLevelEmitter container, PlayerInventory playerInventory, ITextComponent title) { + super(container, playerInventory, title); } @Override @@ -53,41 +40,41 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable this.level.setTextColor( 0xFFFFFF ); this.level.setVisible( true ); this.level.changeFocus( true ); - ( (ContainerFluidLevelEmitter) this.inventorySlots ).setTextField( this.level ); + container.setTextField( this.level ); final int y = 40; final int x = 80 + 44; - this.guiSlots.add( new GuiFluidSlot( this.levelEmitter.getConfig(), 0, 0, x, y ) ); + this.guiSlots.add( new GuiFluidSlot( this.container.getFluidConfigInventory(), 0, 0, x, y ) ); } @Override protected void addButtons() { - this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL ); + this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL, this::actionPerformed ); final int a = AEConfig.instance().levelByMillyBuckets( 0 ); final int b = AEConfig.instance().levelByMillyBuckets( 1 ); final int c = AEConfig.instance().levelByMillyBuckets( 2 ); final int d = AEConfig.instance().levelByMillyBuckets( 3 ); - this.addButton( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a ) ); - this.addButton( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b ) ); - this.addButton( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c ) ); - this.addButton( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d ) ); + this.addButton( new Button(this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a, btn -> addQty(a) ) ); + this.addButton( new Button(this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b, btn -> addQty(b) ) ); + this.addButton( new Button(this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c, btn -> addQty(c) ) ); + this.addButton( new Button(this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d, btn -> addQty(d) ) ); - this.addButton( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a ) ); - this.addButton( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b ) ); - this.addButton( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c ) ); - this.addButton( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d ) ); + this.addButton( new Button(this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a, btn -> addQty(-a) ) ); + this.addButton( new Button(this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b, btn -> addQty(-b) ) ); + this.addButton( new Button(this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c, btn -> addQty(-c) ) ); + this.addButton( new Button(this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d, btn -> addQty(-d) ) ); this.addButton( this.redstoneMode ); } @Override - public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { - super.drawBG( offsetX, offsetY, mouseX, mouseY ); - this.level.drawTextBox(); + super.drawBG( offsetX, offsetY, mouseX, mouseY, partialTicks); + this.level.render(mouseX, mouseY, partialTicks); } @Override @@ -113,20 +100,6 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable { } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); - - final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000; - final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000; - - if( isPlus || isMinus ) - { - this.addQty( this.getQty( btn ) ); - } - } - private void addQty( final long i ) { try @@ -166,51 +139,66 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable // nope.. this.level.setText( "0" ); } - catch( final IOException e ) - { - AELog.debug( e ); - } } @Override - protected void keyTyped( final char character, final int key ) throws IOException - { - if( !this.checkHotbarKeys( key ) ) - { - if( ( key == 211 || key == 205 || key == 203 || key == 14 || Character.isDigit( character ) ) && this.level.textboxKeyTyped( character, key ) ) + public boolean charTyped(char character, int keyCode) { + if (level.charTyped(character, keyCode)) { + String Out = this.level.getText(); + + boolean Fixed = false; + while( Out.startsWith( "0" ) && Out.length() > 1 ) { - try - { - String Out = this.level.getText(); - - boolean Fixed = false; - while( Out.startsWith( "0" ) && Out.length() > 1 ) - { - Out = Out.substring( 1 ); - Fixed = true; - } - - if( Fixed ) - { - this.level.setText( Out ); - } - - if( Out.isEmpty() ) - { - Out = "0"; - } - - NetworkHandler.instance().sendToServer( new PacketValueConfig( "FluidLevelEmitter.Value", Out ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + Out = Out.substring( 1 ); + Fixed = true; } - else + + if( Fixed ) { - super.keyTyped( character, key ); + this.level.setText( Out ); + } + + if( Out.isEmpty() ) + { + Out = "0"; + } + + NetworkHandler.instance().sendToServer( new PacketValueConfig( "FluidLevelEmitter.Value", Out ) ); + return true; + } + return super.charTyped(character, keyCode); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) + { + if( !this.checkHotbarKeys( InputMappings.getInputByCode(keyCode, scanCode) ) ) + { + if( ( keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14 ) && this.level.keyPressed( keyCode, scanCode, p_keyPressed_3_ ) ) + { + String Out = this.level.getText(); + + boolean Fixed = false; + while( Out.startsWith( "0" ) && Out.length() > 1 ) + { + Out = Out.substring( 1 ); + Fixed = true; + } + + if( Fixed ) + { + this.level.setText( Out ); + } + + if( Out.isEmpty() ) + { + Out = "0"; + } + + NetworkHandler.instance().sendToServer( new PacketValueConfig( "FluidLevelEmitter.Value", Out ) ); + return true; } } + return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); } } diff --git a/src/main/java/appeng/fluids/client/gui/GuiFluidStorageBus.java b/src/main/java/appeng/fluids/client/gui/GuiFluidStorageBus.java index b0c04aef7..3413c89c4 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiFluidStorageBus.java +++ b/src/main/java/appeng/fluids/client/gui/GuiFluidStorageBus.java @@ -21,9 +21,7 @@ package appeng.fluids.client.gui; import java.io.IOException; -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; +import appeng.container.implementations.ContainerPriority; import net.minecraft.entity.player.PlayerInventory; import appeng.api.config.AccessRestriction; @@ -46,6 +44,7 @@ import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot; import appeng.fluids.container.ContainerFluidStorageBus; import appeng.fluids.parts.PartFluidStorageBus; import appeng.fluids.util.IAEFluidTank; +import net.minecraft.util.text.ITextComponent; /** @@ -53,20 +52,14 @@ import appeng.fluids.util.IAEFluidTank; * @version rv6 - 22/05/2018 * @since rv6 22/05/2018 */ -public class GuiFluidStorageBus extends GuiUpgradeable +public class GuiFluidStorageBus extends GuiUpgradeable { private GuiImgButton rwMode; private GuiImgButton storageFilter; - private GuiTabButton priority; - private GuiImgButton partition; - private GuiImgButton clear; - private final PartFluidStorageBus bus; - public GuiFluidStorageBus( PlayerInventory PlayerInventory, PartFluidStorageBus te ) - { - super( new ContainerFluidStorageBus( PlayerInventory, te ) ); + public GuiFluidStorageBus(ContainerFluidStorageBus container, PlayerInventory playerInventory, ITextComponent title) { + super(container, playerInventory, title); this.ySize = 251; - this.bus = te; } @Override @@ -77,8 +70,7 @@ public class GuiFluidStorageBus extends GuiUpgradeable final int xo = 8; final int yo = 23 + 6; - final IAEFluidTank config = this.bus.getConfig(); - final ContainerFluidStorageBus container = (ContainerFluidStorageBus) this.inventorySlots; + final IAEFluidTank config = this.container.getFluidConfigInventory(); for( int y = 0; y < 7; y++ ) { @@ -100,19 +92,17 @@ public class GuiFluidStorageBus extends GuiUpgradeable @Override protected void addButtons() { - this.clear = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE ); - this.partition = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH ); - this.rwMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE ); - this.storageFilter = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY ); - this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + addButton( new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE, btn -> clear() ) ); + addButton( new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH, btn -> partition() ) ); + this.rwMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE, btn -> toggleReadWriteMode() ); + this.storageFilter = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY, btn -> toggleStorageFilter() ); + this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::actionPerformed ); - this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) ); + addButton( this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) ) ); this.addButton( this.storageFilter ); this.addButton( this.fuzzyMode ); this.addButton( this.rwMode ); - this.addButton( this.partition ); - this.addButton( this.clear ); } @Override @@ -143,40 +133,26 @@ public class GuiFluidStorageBus extends GuiUpgradeable return "guis/storagebus.png"; } - @Override - protected void actionPerformed( final GuiButton btn ) throws IOException - { - super.actionPerformed( btn ); + private void partition() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) ); + } - final boolean backwards = Mouse.isButtonDown( 1 ); + private void clear() { + NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) ); + } - try - { - if( btn == this.partition ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) ); - } - else if( btn == this.clear ) - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) ); - } - else if( btn == this.priority ) - { - NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - else if( btn == this.rwMode ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.rwMode.getSetting(), backwards ) ); - } - else if( btn == this.storageFilter ) - { - NetworkHandler.instance().sendToServer( new PacketConfigButton( this.storageFilter.getSetting(), backwards ) ); - } - } - catch( final IOException e ) - { - AELog.debug( e ); - } + private void openPriorityGui() { + NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) ); + } + + private void toggleReadWriteMode() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.rwMode.getSetting(), backwards ) ); + } + + private void toggleStorageFilter() { + final boolean backwards = minecraft.mouseHelper.isRightDown(); + NetworkHandler.instance().sendToServer( new PacketConfigButton( this.storageFilter.getSetting(), backwards ) ); } @Override diff --git a/src/main/java/appeng/fluids/client/gui/GuiFluidTerminal.java b/src/main/java/appeng/fluids/client/gui/GuiFluidTerminal.java index aa5d8ce13..f3906e552 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiFluidTerminal.java +++ b/src/main/java/appeng/fluids/client/gui/GuiFluidTerminal.java @@ -19,27 +19,9 @@ package appeng.fluids.client.gui; -import java.io.IOException; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; - -import org.lwjgl.input.Mouse; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.ClickType; -import net.minecraft.inventory.Slot; -import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.Loader; - import appeng.api.config.Settings; -import appeng.api.storage.ITerminalHost; import appeng.api.storage.data.IAEFluidStack; import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; import appeng.client.gui.AEBaseMEGui; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiScrollbar; @@ -58,6 +40,21 @@ import appeng.fluids.container.slots.IMEFluidSlot; import appeng.helpers.InventoryAction; import appeng.util.IConfigManagerHost; import appeng.util.Platform; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.util.InputMappings; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.ClickType; +import net.minecraft.inventory.container.Slot; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.client.gui.GuiUtils; + +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; /** @@ -65,44 +62,33 @@ import appeng.util.Platform; * @version rv6 - 12/05/2018 * @since rv6 12/05/2018 */ -public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfigManagerHost +public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfigManagerHost { private final List meFluidSlots = new LinkedList<>(); private final FluidRepo repo; private final IConfigManager configSrc; - private final ContainerFluidTerminal container; private final int offsetX = 9; private int rows = 6; private int perRow = 9; - protected ITerminalHost terminal; - private MEGuiTextField searchField; private GuiImgButton sortByBox; private GuiImgButton sortDirBox; - public GuiFluidTerminal( final PlayerInventory PlayerInventory, final ITerminalHost te ) - { - this( PlayerInventory, te, new ContainerFluidTerminal( PlayerInventory, te ) ); - } - - public GuiFluidTerminal( PlayerInventory PlayerInventory, final ITerminalHost te, final ContainerFluidTerminal c ) - { - super( c ); - this.terminal = te; + public GuiFluidTerminal(ContainerFluidTerminal container, PlayerInventory playerInventory, ITextComponent title) { + super(container, playerInventory, title); this.xSize = 185; this.ySize = 222; final GuiScrollbar scrollbar = new GuiScrollbar(); this.setScrollBar( scrollbar ); this.repo = new FluidRepo( scrollbar, this ); - this.configSrc = ( (IConfigurableObject) this.inventorySlots ).getConfigManager(); - ( this.container = (ContainerFluidTerminal) this.inventorySlots ).setGui( this ); + this.configSrc = container.getConfigManager(); + this.container.setGui( this ); } @Override public void init() { - this.minecraft.player.openContainer = this.inventorySlots; this.guiLeft = ( this.width - this.xSize ) / 2; this.guiTop = ( this.height - this.ySize ) / 2; @@ -115,11 +101,11 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi int offset = this.guiTop; - this.addButton( this.sortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ) ) ); + this.sortByBox = this.addButton( new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ), this::actionPerformed ) ); offset += 20; - this.addButton( this.sortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc - .getSetting( Settings.SORT_DIRECTION ) ) ); + this.sortDirBox = this.addButton( new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc + .getSetting( Settings.SORT_DIRECTION ), this::actionPerformed ) ); for( int y = 0; y < this.rows; y++ ) { @@ -127,7 +113,7 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi { SlotFluidME slot = new SlotFluidME( new InternalFluidSlotME( this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18 ) ); this.getMeFluidSlots().add( slot ); - this.inventorySlots.inventorySlots.add( slot ); + this.container.inventorySlots.add( slot ); } } this.setScrollBar(); @@ -141,30 +127,30 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi } @Override - public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY ) + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks) { this.bindTexture( this.getBackground() ); final int x_width = 197; - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 ); + GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18, 0 /* FIXME ZINDEX */ ); for( int x = 0; x < 6; x++ ) { - this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 ); + GuiUtils.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18, 0 /* FIXME ZINDEX */ ); } - this.drawTexturedModalRect( offsetX, offsetY + 16 + 6 * 18, 0, 106 - 18 - 18, x_width, 99 + 77 ); + GuiUtils.drawTexturedModalRect( offsetX, offsetY + 16 + 6 * 18, 0, 106 - 18 - 18, x_width, 99 + 77, 0 /* FIXME ZINDEX */ ); if( this.searchField != null ) { - this.searchField.drawTextBox(); + this.searchField.render(mouseX, mouseY, partialTicks); } } @Override - public void updateScreen() + public void tick() { this.repo.setPower( this.container.isPowered() ); - super.updateScreen(); + super.tick(); } @Override @@ -172,7 +158,7 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi { final Slot slot = this.getSlot( mouseX, mouseY ); - if( slot != null && slot instanceof IMEFluidSlot && slot.isEnabled() ) + if( slot instanceof IMEFluidSlot && slot.isEnabled() ) { final IMEFluidSlot fluidSlot = (IMEFluidSlot) slot; @@ -181,18 +167,19 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi final IAEFluidStack fluidStack = fluidSlot.getAEFluidStack(); final String formattedAmount = NumberFormat.getNumberInstance( Locale.US ).format( fluidStack.getStackSize() / 1000.0 ) + " B"; - final String modName = "" + TextFormatting.BLUE + TextFormatting.ITALIC + Loader.instance() - .getIndexedModList() - .get( Platform.getModId( fluidStack ) ) - .getName(); + // FIXME: Move getting the mod name to platform + final String modName = "" + TextFormatting.BLUE + TextFormatting.ITALIC + ModList.get() + .getModContainerById( Platform.getModId( fluidStack ) ) + .map(mc -> mc.getModInfo().getDisplayName()) + .orElse(null); final List list = new ArrayList<>(); - list.add( fluidStack.getFluidStack().getLocalizedName() ); + list.add( fluidStack.getFluidStack().getDisplayName().getFormattedText() ); list.add( formattedAmount ); list.add( modName ); - this.drawHoveringText( list, mouseX, mouseY ); + this.renderTooltip( list, mouseX, mouseY ); return; } @@ -200,12 +187,11 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi super.renderHoveredToolTip( mouseX, mouseY ); } - @Override - protected void actionPerformed( GuiButton btn ) throws IOException + protected void actionPerformed( Button btn ) { if( btn instanceof GuiImgButton ) { - final boolean backwards = Mouse.isButtonDown( 1 ); + final boolean backwards = minecraft.mouseHelper.isRightDown(); final GuiImgButton iBtn = (GuiImgButton) btn; if( iBtn.getSetting() != Settings.ACTIONS ) @@ -213,14 +199,7 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi final Enum cv = iBtn.getCurrentValue(); final Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() ); - try - { - NetworkHandler.instance().sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + NetworkHandler.instance().sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) ); iBtn.set( next ); } @@ -259,42 +238,55 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi } @Override - protected void keyTyped( final char character, final int key ) throws IOException - { - if( !this.checkHotbarKeys( key ) ) + public boolean charTyped(char character, int keyCode) { + if (character == ' ' && this.searchField.getText().isEmpty()) { - if( character == ' ' && this.searchField.getText().isEmpty() ) - { - return; - } + // Swallow spaces if the text field is still empty + return true; + } - if( this.searchField.textboxKeyTyped( character, key ) ) + if (this.searchField.charTyped(character, keyCode)) { + this.repo.setSearchString( this.searchField.getText() ); + this.repo.updateView(); + this.setScrollBar(); + return true; + } + + return super.charTyped(character, keyCode); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) + { + InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode); + if( !this.checkHotbarKeys(input) ) + { + if( this.searchField.keyPressed( keyCode, scanCode, p_keyPressed_3_ ) ) { this.repo.setSearchString( this.searchField.getText() ); this.repo.updateView(); this.setScrollBar(); - } - else - { - super.keyTyped( character, key ); + return true; } } + + return super.keyPressed(keyCode, scanCode, p_keyPressed_3_); } @Override - protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) throws IOException + public boolean mouseClicked( final double xCoord, final double yCoord, final int btn ) { - this.searchField.mouseClicked( xCoord, yCoord, btn ); - - if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) ) - { - this.searchField.setText( "" ); - this.repo.setSearchString( "" ); - this.repo.updateView(); - this.setScrollBar(); + if (this.searchField.mouseClicked( xCoord, yCoord, btn )) { + if (btn == 1 && this.searchField.isMouseOver(xCoord, yCoord)) { + this.searchField.setText(""); + this.repo.setSearchString(""); + this.repo.updateView(); + this.setScrollBar(); + } + return true; } - super.mouseClicked( xCoord, yCoord, btn ); + return super.mouseClicked( xCoord, yCoord, btn ); } public void postUpdate( final List list ) diff --git a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java index 52c2e8656..e2076ce4e 100644 --- a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java +++ b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java @@ -24,6 +24,7 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketFluidSlot; import appeng.fluids.util.AEFluidStack; import appeng.fluids.util.IAEFluidTank; +import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiFluidSlot extends GuiCustomSlot @@ -49,7 +50,7 @@ public class GuiFluidSlot extends GuiCustomSlot final Fluid fluid = fs.getFluid(); final FluidAttributes attributes = fluid.getAttributes(); mc.getTextureManager().bindTexture( AtlasTexture.LOCATION_BLOCKS_TEXTURE ); - final TextureAtlasSprite sprite = mc.getAtlasSpriteGetter( AtlasTexture.LOCATION_BLOCKS_TEXTURE ).apply( attributes.getStillTexture() ); + final TextureAtlasSprite sprite = mc.getAtlasSpriteGetter( AtlasTexture.LOCATION_BLOCKS_TEXTURE ).apply( attributes.getStillTexture(fs.getFluidStack()) ); // Set color for dynamic fluids // Convert int color to RGB @@ -58,7 +59,7 @@ public class GuiFluidSlot extends GuiCustomSlot final float blue = ( attributes.getColor() & 255 ) / 255.0F; RenderSystem.color3f( red, green, blue ); - this.drawTexturedModalRect( this.xPos(), this.yPos(), sprite, this.getWidth(), this.getHeight() ); + blit(xPos(), yPos(), this.getBlitOffset(), getWidth(), getHeight(), sprite); } } diff --git a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java index 5dcefe7e0..345f3ae70 100644 --- a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java +++ b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java @@ -19,36 +19,36 @@ package appeng.fluids.client.gui.widgets; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - import appeng.api.storage.data.IAEFluidStack; import appeng.api.util.AEColor; import appeng.client.gui.widgets.ITooltip; import appeng.fluids.util.IAEFluidTank; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.fluid.Fluid; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fluids.FluidAttributes; @OnlyIn( Dist.CLIENT ) -public class GuiFluidTank extends GuiButton implements ITooltip +public class GuiFluidTank extends Widget implements ITooltip { private final IAEFluidTank tank; private final int slot; - public GuiFluidTank( IAEFluidTank tank, int slot, int id, int x, int y, int w, int h ) + public GuiFluidTank(IAEFluidTank tank, int slot, int x, int y, int w, int h) { - super( id, x, y, w, h, "" ); + super( x, y, w, h, "" ); this.tank = tank; this.slot = slot; } @Override - public void drawButton( final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks ) - { + public void renderButton(int mouseX, int mouseY, float partialTicks) { if( this.visible ) { RenderSystem.disableBlend(); @@ -56,27 +56,31 @@ public class GuiFluidTank extends GuiButton implements ITooltip fill( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 ); - final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot ); - if( fluid != null && fluid.getStackSize() > 0 ) + final IAEFluidStack fluidStack = this.tank.getFluidInSlot( this.slot ); + if( fluidStack != null && fluidStack.getStackSize() > 0 ) { + Fluid fluid = fluidStack.getFluid(); + FluidAttributes attributes = fluid.getAttributes(); + + float red = ( attributes.getColor() >> 16 & 255 ) / 255.0F; + float green = ( attributes.getColor() >> 8 & 255 ) / 255.0F; + float blue = ( attributes.getColor() & 255 ) / 255.0F; + RenderSystem.color3f( red, green, blue ); + + Minecraft mc = Minecraft.getInstance(); mc.getTextureManager().bindTexture( AtlasTexture.LOCATION_BLOCKS_TEXTURE ); + final TextureAtlasSprite sprite = mc.getAtlasSpriteGetter( AtlasTexture.LOCATION_BLOCKS_TEXTURE ).apply( attributes.getStillTexture(fluidStack.getFluidStack()) ); - float red = ( fluid.getFluid().getColor() >> 16 & 255 ) / 255.0F; - float green = ( fluid.getFluid().getColor() >> 8 & 255 ) / 255.0F; - float blue = ( fluid.getFluid().getColor() & 255 ) / 255.0F; - RenderSystem.color4f( red, green, blue ); - - TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getFluid().getStill().toString() ); - final int scaledHeight = (int) ( this.height * ( (float) fluid.getStackSize() / this.tank.getTankProperties()[this.slot].getCapacity() ) ); + final int scaledHeight = (int) ( this.height * ( (float) fluidStack.getStackSize() / this.tank.getTankCapacity(this.slot) ) ); int iconHeightRemainder = scaledHeight % 16; if( iconHeightRemainder > 0 ) { - this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder, sprite, 16, iconHeightRemainder ); + blit(this.x, this.y + this.height - iconHeightRemainder, getBlitOffset(), 16, iconHeightRemainder, sprite ); } for( int i = 0; i < scaledHeight / 16; i++ ) { - this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder - ( i + 1 ) * 16, sprite, 16, 16 ); + blit( this.x, this.y + this.height - iconHeightRemainder - ( i + 1 ) * 16, getBlitOffset(), 16, 16, sprite ); } } @@ -89,7 +93,7 @@ public class GuiFluidTank extends GuiButton implements ITooltip final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot ); if( fluid != null && fluid.getStackSize() > 0 ) { - String desc = fluid.getFluid().getLocalizedName( fluid.getFluidStack() ); + String desc = fluid.getFluid().getAttributes().getDisplayName( fluid.getFluidStack() ).getFormattedText(); String amountToText = fluid.getStackSize() + "mB"; return desc + "\n" + amountToText; diff --git a/src/main/java/appeng/fluids/client/gui/widgets/GuiOptionalFluidSlot.java b/src/main/java/appeng/fluids/client/gui/widgets/GuiOptionalFluidSlot.java index c34e6830e..16f4e7085 100644 --- a/src/main/java/appeng/fluids/client/gui/widgets/GuiOptionalFluidSlot.java +++ b/src/main/java/appeng/fluids/client/gui/widgets/GuiOptionalFluidSlot.java @@ -2,11 +2,11 @@ package appeng.fluids.client.gui.widgets; -import net.minecraft.client.renderer.GlStateManager; - import appeng.api.storage.data.IAEFluidStack; import appeng.container.slot.IOptionalSlotHost; import appeng.fluids.util.IAEFluidTank; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraftforge.fml.client.gui.GuiUtils; public class GuiOptionalFluidSlot extends GuiFluidSlot @@ -57,7 +57,7 @@ public class GuiOptionalFluidSlot extends GuiFluidSlot { RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 0.4F ); } - this.drawTexturedModalRect( guileft + this.xPos() - 1, guitop + this.yPos() - 1, this.srcX - 1, this.srcY - 1, this.getWidth() + 2, - this.getHeight() + 2 ); + GuiUtils.drawTexturedModalRect( guileft + this.xPos() - 1, guitop + this.yPos() - 1, this.srcX - 1, this.srcY - 1, this.getWidth() + 2, + this.getHeight() + 2, 0 /* FIXME ZINDEX */ ); } } diff --git a/src/main/java/appeng/fluids/container/ContainerFluidFormationPlane.java b/src/main/java/appeng/fluids/container/ContainerFluidFormationPlane.java index bf284dfa9..68fdc6083 100644 --- a/src/main/java/appeng/fluids/container/ContainerFluidFormationPlane.java +++ b/src/main/java/appeng/fluids/container/ContainerFluidFormationPlane.java @@ -2,8 +2,12 @@ package appeng.fluids.container; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import appeng.api.config.SecurityPermissions; @@ -16,11 +20,25 @@ import appeng.fluids.util.IAEFluidTank; public class ContainerFluidFormationPlane extends ContainerFluidConfigurable { + + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerFluidFormationPlane::new, PartFluidFormationPlane.class, SecurityPermissions.BUILD); + + public static ContainerFluidFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartFluidFormationPlane plane; - public ContainerFluidFormationPlane(ContainerType containerType, int id, final PlayerInventory ip, final PartFluidFormationPlane te ) + public ContainerFluidFormationPlane(int id, final PlayerInventory ip, final PartFluidFormationPlane te ) { - super( containerType, id,ip, te ); + super( TYPE, id,ip, te ); this.plane = te; } diff --git a/src/main/java/appeng/fluids/container/ContainerFluidIO.java b/src/main/java/appeng/fluids/container/ContainerFluidIO.java index 94326f135..88fa051f0 100644 --- a/src/main/java/appeng/fluids/container/ContainerFluidIO.java +++ b/src/main/java/appeng/fluids/container/ContainerFluidIO.java @@ -19,11 +19,16 @@ package appeng.fluids.container; +import appeng.api.config.SecurityPermissions; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import appeng.fluids.parts.PartSharedFluidBus; import appeng.fluids.util.IAEFluidTank; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; /** @@ -33,11 +38,25 @@ import net.minecraft.inventory.container.ContainerType; */ public class ContainerFluidIO extends ContainerFluidConfigurable { + + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerFluidIO::new, PartSharedFluidBus.class, SecurityPermissions.BUILD); + + public static ContainerFluidIO fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartSharedFluidBus bus; - public ContainerFluidIO(ContainerType containerType, int id, PlayerInventory ip, PartSharedFluidBus te ) + public ContainerFluidIO(int id, PlayerInventory ip, PartSharedFluidBus te ) { - super( containerType, id,ip, te ); + super( TYPE, id,ip, te ); this.bus = te; } diff --git a/src/main/java/appeng/fluids/container/ContainerFluidInterface.java b/src/main/java/appeng/fluids/container/ContainerFluidInterface.java index 515c5cb0d..b1c8df0a2 100644 --- a/src/main/java/appeng/fluids/container/ContainerFluidInterface.java +++ b/src/main/java/appeng/fluids/container/ContainerFluidInterface.java @@ -19,31 +19,48 @@ package appeng.fluids.container; -import java.util.Collections; -import java.util.Map; - -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.IContainerListener; - import appeng.api.config.SecurityPermissions; import appeng.api.storage.data.IAEFluidStack; import appeng.api.util.IConfigManager; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartOrTileContainerHelper; import appeng.fluids.helper.DualityFluidInterface; import appeng.fluids.helper.FluidSyncHelper; import appeng.fluids.helper.IFluidInterfaceHost; import appeng.fluids.util.IAEFluidTank; import appeng.util.Platform; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.inventory.container.IContainerListener; +import net.minecraft.network.PacketBuffer; + +import java.util.Collections; +import java.util.Map; public class ContainerFluidInterface extends ContainerFluidConfigurable { + + public static ContainerType TYPE; + + private static final PartOrTileContainerHelper helper + = new PartOrTileContainerHelper<>(ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD); + + public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final DualityFluidInterface myDuality; private final FluidSyncHelper tankSync; - public ContainerFluidInterface(ContainerType containerType, int id, final PlayerInventory ip, final IFluidInterfaceHost te ) + public ContainerFluidInterface(int id, final PlayerInventory ip, final IFluidInterfaceHost te ) { - super( containerType, id,ip, te.getDualityFluidInterface().getHost() ); + super( TYPE, id,ip, te.getDualityFluidInterface().getHost() ); this.myDuality = te.getDualityFluidInterface(); this.tankSync = new FluidSyncHelper( this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS ); @@ -55,6 +72,10 @@ public class ContainerFluidInterface extends ContainerFluidConfigurable return 231; } + public IAEFluidTank getTanks() { + return myDuality.getTanks(); + } + @Override public IAEFluidTank getFluidConfigInventory() { diff --git a/src/main/java/appeng/fluids/container/ContainerFluidLevelEmitter.java b/src/main/java/appeng/fluids/container/ContainerFluidLevelEmitter.java index 91277b757..641b6880f 100644 --- a/src/main/java/appeng/fluids/container/ContainerFluidLevelEmitter.java +++ b/src/main/java/appeng/fluids/container/ContainerFluidLevelEmitter.java @@ -1,10 +1,13 @@ package appeng.fluids.container; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -19,6 +22,19 @@ import appeng.util.Platform; public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable { + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerFluidLevelEmitter::new, PartFluidLevelEmitter.class, SecurityPermissions.BUILD); + + public static ContainerFluidLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartFluidLevelEmitter lvlEmitter; @OnlyIn( Dist.CLIENT ) @@ -26,9 +42,9 @@ public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable @GuiSync( 3 ) public long EmitterValue = -1; - public ContainerFluidLevelEmitter(ContainerType containerType, int id, final PlayerInventory ip, final PartFluidLevelEmitter te ) + public ContainerFluidLevelEmitter(int id, final PlayerInventory ip, final PartFluidLevelEmitter te ) { - super( containerType, id,ip, te ); + super( TYPE, id,ip, te ); this.lvlEmitter = te; } diff --git a/src/main/java/appeng/fluids/container/ContainerFluidStorageBus.java b/src/main/java/appeng/fluids/container/ContainerFluidStorageBus.java index 7ec345f37..89df4cbf5 100644 --- a/src/main/java/appeng/fluids/container/ContainerFluidStorageBus.java +++ b/src/main/java/appeng/fluids/container/ContainerFluidStorageBus.java @@ -21,8 +21,12 @@ package appeng.fluids.container; import java.util.Iterator; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ContainerType; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.items.IItemHandler; import appeng.api.config.AccessRestriction; @@ -52,6 +56,19 @@ import appeng.util.iterators.NullIterator; public class ContainerFluidStorageBus extends ContainerFluidConfigurable { + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerFluidStorageBus::new, PartFluidStorageBus.class); + + public static ContainerFluidStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final PartFluidStorageBus storageBus; @GuiSync( 3 ) @@ -60,9 +77,9 @@ public class ContainerFluidStorageBus extends ContainerFluidConfigurable @GuiSync( 4 ) public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY; - public ContainerFluidStorageBus(ContainerType containerType, int id, PlayerInventory ip, PartFluidStorageBus te ) + public ContainerFluidStorageBus(int id, PlayerInventory ip, PartFluidStorageBus te ) { - super( containerType, id,ip, te ); + super( TYPE, id,ip, te ); this.storageBus = te; } diff --git a/src/main/java/appeng/fluids/container/ContainerFluidTerminal.java b/src/main/java/appeng/fluids/container/ContainerFluidTerminal.java index 0bc6e2624..8570a03eb 100644 --- a/src/main/java/appeng/fluids/container/ContainerFluidTerminal.java +++ b/src/main/java/appeng/fluids/container/ContainerFluidTerminal.java @@ -23,24 +23,23 @@ import java.io.IOException; import java.nio.BufferOverflowException; import javax.annotation.Nonnull; +import appeng.api.config.*; +import appeng.container.ContainerLocator; +import appeng.container.helper.PartContainerHelper; +import appeng.fluids.parts.PartFluidFormationPlane; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.IContainerListener; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import net.minecraftforge.fluids.capability.IFluidHandlerItem; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; @@ -81,6 +80,20 @@ import appeng.util.Platform; */ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver { + + public static ContainerType TYPE; + + private static final PartContainerHelper helper + = new PartContainerHelper<>(ContainerFluidFormationPlane::new, PartFluidFormationPlane.class, SecurityPermissions.BUILD); + + public static ContainerFluidFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { + return helper.fromNetwork(windowId, inv, buf); + } + + public static boolean open(PlayerEntity player, ContainerLocator locator) { + return helper.open(player, locator); + } + private final IConfigManager clientCM; private final IMEMonitor monitor; private final IItemList fluids = Api.INSTANCE.storage().getStorageChannel( IFluidStorageChannel.class ).createList(); @@ -284,14 +297,7 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa { if( crafter instanceof ServerPlayerEntity ) { - try - { - NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (ServerPlayerEntity) crafter ); - } - catch( final IOException e ) - { - AELog.debug( e ); - } + NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (ServerPlayerEntity) crafter ); } } } diff --git a/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java b/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java index 5d7d890fd..c81a572f5 100644 --- a/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java +++ b/src/main/java/appeng/fluids/parts/PartFluidFormationPlane.java @@ -6,9 +6,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerFormationPlane; +import appeng.fluids.container.ContainerFluidFormationPlane; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -188,7 +193,7 @@ public class PartFluidFormationPlane extends PartAbstractFormationPlane getContainerType() + { + return ContainerFluidFormationPlane.TYPE; + } } diff --git a/src/main/java/appeng/fluids/parts/PartFluidInterface.java b/src/main/java/appeng/fluids/parts/PartFluidInterface.java index 50b393f8e..2e6b56841 100644 --- a/src/main/java/appeng/fluids/parts/PartFluidInterface.java +++ b/src/main/java/appeng/fluids/parts/PartFluidInterface.java @@ -21,7 +21,11 @@ package appeng.fluids.parts; import java.util.EnumSet; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.fluids.container.ContainerFluidInterface; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -139,7 +143,7 @@ public class PartFluidInterface extends PartBasicState implements IGridTickable, { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, this.getTileEntity(), this.getSide(), GuiBridge.GUI_FLUID_INTERFACE ); + ContainerOpener.openContainer(ContainerFluidInterface.TYPE, p, ContainerLocator.forPart(this)); } return true; @@ -234,9 +238,9 @@ public class PartFluidInterface extends PartBasicState implements IGridTickable, return Api.INSTANCE.definitions().parts().fluidIface().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_FLUID_INTERFACE; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerFluidInterface.TYPE; + } } diff --git a/src/main/java/appeng/fluids/parts/PartFluidLevelEmitter.java b/src/main/java/appeng/fluids/parts/PartFluidLevelEmitter.java index 39b6dc4ee..80f35fb16 100644 --- a/src/main/java/appeng/fluids/parts/PartFluidLevelEmitter.java +++ b/src/main/java/appeng/fluids/parts/PartFluidLevelEmitter.java @@ -4,6 +4,10 @@ package appeng.fluids.parts; import java.util.Random; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerLevelEmitter; +import appeng.fluids.container.ContainerFluidLevelEmitter; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -327,7 +331,7 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FLUID_LEVEL_EMITTER ); + ContainerOpener.openContainer(ContainerFluidLevelEmitter.TYPE, player, ContainerLocator.forPart(this)); } return true; } diff --git a/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java b/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java index 88372b6bf..a177ce955 100644 --- a/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java +++ b/src/main/java/appeng/fluids/parts/PartFluidStorageBus.java @@ -24,7 +24,12 @@ import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.fluids.container.ContainerFluidInterface; +import appeng.fluids.container.ContainerFluidStorageBus; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -224,7 +229,7 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_STORAGEBUS_FLUID ); + ContainerOpener.openContainer(ContainerFluidStorageBus.TYPE, player, ContainerLocator.forPart(this)); } return true; } @@ -489,9 +494,9 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni return Api.INSTANCE.definitions().parts().fluidStorageBus().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_STORAGEBUS_FLUID; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerFluidStorageBus.TYPE; + } } diff --git a/src/main/java/appeng/fluids/parts/PartSharedFluidBus.java b/src/main/java/appeng/fluids/parts/PartSharedFluidBus.java index 6a00b090d..b30297d84 100644 --- a/src/main/java/appeng/fluids/parts/PartSharedFluidBus.java +++ b/src/main/java/appeng/fluids/parts/PartSharedFluidBus.java @@ -19,6 +19,10 @@ package appeng.fluids.parts; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.fluids.container.ContainerFluidIO; +import appeng.fluids.container.ContainerFluidInterface; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -107,7 +111,7 @@ public abstract class PartSharedFluidBus extends PartUpgradeable implements IGri { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS_FLUID ); + ContainerOpener.openContainer(ContainerFluidIO.TYPE, player, ContainerLocator.forPart(this)); } return true; diff --git a/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java b/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java index 1e9abf28d..4290cb502 100644 --- a/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java +++ b/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java @@ -19,6 +19,10 @@ package appeng.fluids.registries; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerFormationPlane; +import appeng.fluids.container.ContainerFluidTerminal; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -48,6 +52,6 @@ public class BasicFluidCellGuiHandler implements ICellGuiHandler @Override public void openChestGui( final PlayerEntity player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan ) { - // FIXME Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_FLUID_TERMINAL ); + ContainerOpener.openContainer(ContainerFluidTerminal.TYPE, player, ContainerLocator.forTileEntitySide((TileEntity) chest, chest.getUp())); } } diff --git a/src/main/java/appeng/fluids/tile/TileFluidInterface.java b/src/main/java/appeng/fluids/tile/TileFluidInterface.java index 23deea40c..00db4b5e1 100644 --- a/src/main/java/appeng/fluids/tile/TileFluidInterface.java +++ b/src/main/java/appeng/fluids/tile/TileFluidInterface.java @@ -23,6 +23,8 @@ import java.util.EnumSet; import javax.annotation.Nullable; +import appeng.fluids.container.ContainerFluidInterface; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -182,9 +184,9 @@ public class TileFluidInterface extends AENetworkTile implements IGridTickable, return Api.INSTANCE.definitions().blocks().fluidIface().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_FLUID_INTERFACE; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerFluidInterface.TYPE; + } } diff --git a/src/main/java/appeng/helpers/IPriorityHost.java b/src/main/java/appeng/helpers/IPriorityHost.java index 33299ec3a..0e5c0ee0c 100644 --- a/src/main/java/appeng/helpers/IPriorityHost.java +++ b/src/main/java/appeng/helpers/IPriorityHost.java @@ -19,6 +19,7 @@ package appeng.helpers; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; @@ -39,6 +40,9 @@ public interface IPriorityHost ItemStack getItemStackRepresentation(); - // FIXME Needs to be wired up to the static method in containers somehow - // FIXME GuiBridge getGuiBridge(); + /** + * Used to show the user interface of this part when returning from the priority GUI. + */ + ContainerType getContainerType(); + } diff --git a/src/main/java/appeng/items/materials/ItemMaterial.java b/src/main/java/appeng/items/materials/ItemMaterial.java index 172a0b721..15c7f39f3 100644 --- a/src/main/java/appeng/items/materials/ItemMaterial.java +++ b/src/main/java/appeng/items/materials/ItemMaterial.java @@ -30,6 +30,7 @@ import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; +import appeng.entity.EntitySingularity; import com.google.common.base.Preconditions; import net.minecraft.client.util.ITooltipFlag; diff --git a/src/main/java/appeng/items/tools/ToolNetworkTool.java b/src/main/java/appeng/items/tools/ToolNetworkTool.java index a9dfac7e8..f400b8d29 100644 --- a/src/main/java/appeng/items/tools/ToolNetworkTool.java +++ b/src/main/java/appeng/items/tools/ToolNetworkTool.java @@ -19,6 +19,10 @@ package appeng.items.tools; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerNetworkStatus; +import appeng.container.implementations.ContainerNetworkTool; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; @@ -161,11 +165,11 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench if( te instanceof IGridHost ) { - // FIXME Platform.openGUI( p, te, AEPartLocation.fromFacing( side ), GuiBridge.GUI_NETWORK_STATUS ); + ContainerOpener.openContainer(ContainerNetworkStatus.TYPE, p, ContainerLocator.forTileEntitySide(te, side)); } else { - // FIXME Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_NETWORK_TOOL ); + ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(hand)); } return true; @@ -178,7 +182,7 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench } else { - // FIXME Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_NETWORK_TOOL ); + ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(hand)); } return false; diff --git a/src/main/java/appeng/items/tools/powered/ToolPortableCell.java b/src/main/java/appeng/items/tools/powered/ToolPortableCell.java index e5ae9dc1f..09fcec51a 100644 --- a/src/main/java/appeng/items/tools/powered/ToolPortableCell.java +++ b/src/main/java/appeng/items/tools/powered/ToolPortableCell.java @@ -22,6 +22,9 @@ package appeng.items.tools.powered; import java.util.List; import java.util.Set; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerMEPortableCell; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; @@ -69,7 +72,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell< @Override public ActionResult onItemRightClick( final World w, final PlayerEntity player, final Hand hand ) { - // FIXME Platform.openGUI( player, null, AEPartLocation.INTERNAL, GuiBridge.GUI_PORTABLE_CELL ); + ContainerOpener.openContainer(ContainerMEPortableCell.TYPE, player, ContainerLocator.forHand(hand)); return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) ); } diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index da40c5a59..a4ebffc1d 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -61,7 +61,7 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless @Override public ActionResult onItemRightClick( final World w, final PlayerEntity player, final Hand hand ) { - Api.INSTANCE.registries().wireless().openWirelessTerminalGui( player.getHeldItem( hand ), w, player ); + Api.INSTANCE.registries().wireless().openWirelessTerminalGui( player.getHeldItem( hand ), w, player, hand ); return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) ); } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java index df784d4d4..5b2dc116a 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java @@ -19,6 +19,9 @@ package appeng.items.tools.quartz; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerQuartzKnife; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -53,7 +56,7 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem { if( Platform.isServer() ) { -// FIXME Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_QUARTZ_KNIFE ); + ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, context.getPlayer(), ContainerLocator.forHand(context.getHand())); } return ActionResultType.SUCCESS; } @@ -63,7 +66,7 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem { if( Platform.isServer() ) { -// FIXME Platform.openGUI( p, null, AEPartLocation.INTERNAL, GuiBridge.GUI_QUARTZ_KNIFE ); + ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, p, ContainerLocator.forHand(hand)); } p.swingArm( hand ); return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) ); diff --git a/src/main/java/appeng/parts/automation/PartExportBus.java b/src/main/java/appeng/parts/automation/PartExportBus.java index 167c45397..938e6c1e9 100644 --- a/src/main/java/appeng/parts/automation/PartExportBus.java +++ b/src/main/java/appeng/parts/automation/PartExportBus.java @@ -19,6 +19,10 @@ package appeng.parts.automation; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerUpgradeable; +import appeng.fluids.container.ContainerFluidInterface; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -220,7 +224,7 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS ); + ContainerOpener.openContainer(ContainerUpgradeable.TYPE, player, ContainerLocator.forPart(this)); } return true; } diff --git a/src/main/java/appeng/parts/automation/PartFormationPlane.java b/src/main/java/appeng/parts/automation/PartFormationPlane.java index aaf2b8b69..54756eba2 100644 --- a/src/main/java/appeng/parts/automation/PartFormationPlane.java +++ b/src/main/java/appeng/parts/automation/PartFormationPlane.java @@ -23,9 +23,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerFormationPlane; +import appeng.fluids.container.ContainerFluidInterface; import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.*; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -195,7 +200,7 @@ public class PartFormationPlane extends PartAbstractFormationPlane { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FORMATION_PLANE ); + ContainerOpener.openContainer(ContainerFormationPlane.TYPE, player, ContainerLocator.forPart(this)); } return true; } @@ -378,11 +383,11 @@ public class PartFormationPlane extends PartAbstractFormationPlane return Api.INSTANCE.definitions().parts().formationPlane().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_FORMATION_PLANE; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerFormationPlane.TYPE; + } private int countEntitesAround( World world, BlockPos pos ) { diff --git a/src/main/java/appeng/parts/automation/PartImportBus.java b/src/main/java/appeng/parts/automation/PartImportBus.java index 50a701204..789f0e2bc 100644 --- a/src/main/java/appeng/parts/automation/PartImportBus.java +++ b/src/main/java/appeng/parts/automation/PartImportBus.java @@ -19,6 +19,10 @@ package appeng.parts.automation; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerUpgradeable; +import appeng.fluids.container.ContainerFluidInterface; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Items; import net.minecraft.item.ItemStack; @@ -131,7 +135,7 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS ); + ContainerOpener.openContainer(ContainerUpgradeable.TYPE, player, ContainerLocator.forPart(this)); } return true; } diff --git a/src/main/java/appeng/parts/automation/PartLevelEmitter.java b/src/main/java/appeng/parts/automation/PartLevelEmitter.java index ad8c46656..f3a4373e1 100644 --- a/src/main/java/appeng/parts/automation/PartLevelEmitter.java +++ b/src/main/java/appeng/parts/automation/PartLevelEmitter.java @@ -22,6 +22,9 @@ package appeng.parts.automation; import java.util.Collection; import java.util.Random; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerLevelEmitter; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; @@ -461,7 +464,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_LEVEL_EMITTER ); + ContainerOpener.openContainer(ContainerLevelEmitter.TYPE, player, ContainerLocator.forPart(this)); } return true; } diff --git a/src/main/java/appeng/parts/misc/PartInterface.java b/src/main/java/appeng/parts/misc/PartInterface.java index f9bbba72f..16112d032 100644 --- a/src/main/java/appeng/parts/misc/PartInterface.java +++ b/src/main/java/appeng/parts/misc/PartInterface.java @@ -22,10 +22,14 @@ package appeng.parts.misc; import java.util.EnumSet; import java.util.List; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerInterface; import com.google.common.collect.ImmutableSet; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.CraftingInventory; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -177,7 +181,7 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto { if( Platform.isServer() ) { - // FIXME Platform.openGUI( p, this.getTileEntity(), this.getSide(), GuiBridge.GUI_INTERFACE ); + ContainerOpener.openContainer(ContainerInterface.TYPE, p, ContainerLocator.forPart(this)); } return true; } @@ -307,9 +311,9 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto return Api.INSTANCE.definitions().parts().iface().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_INTERFACE; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerInterface.TYPE; + } } diff --git a/src/main/java/appeng/parts/misc/PartStorageBus.java b/src/main/java/appeng/parts/misc/PartStorageBus.java index 6760e8c79..0f667fc89 100644 --- a/src/main/java/appeng/parts/misc/PartStorageBus.java +++ b/src/main/java/appeng/parts/misc/PartStorageBus.java @@ -23,7 +23,12 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerStorageBus; +import appeng.fluids.container.ContainerFluidInterface; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -316,7 +321,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_STORAGEBUS ); + ContainerOpener.openContainer(ContainerStorageBus.TYPE, player, ContainerLocator.forPart(this)); } return true; } @@ -646,9 +651,9 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC return Api.INSTANCE.definitions().parts().storageBus().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_STORAGEBUS; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerStorageBus.TYPE; + } } diff --git a/src/main/java/appeng/parts/p2p/PartP2PItems.java b/src/main/java/appeng/parts/p2p/PartP2PItems.java index 37d826c26..8ab77c006 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PItems.java +++ b/src/main/java/appeng/parts/p2p/PartP2PItems.java @@ -49,6 +49,8 @@ import appeng.me.cache.helpers.TunnelCollection; import appeng.util.Platform; import appeng.util.inv.WrapperChainedItemHandler; +import javax.annotation.Nonnull; + public class PartP2PItems extends PartP2PTunnel implements IItemHandler, IGridTickable { @@ -133,9 +135,10 @@ public class PartP2PItems extends PartP2PTunnel implements IItemHa final Direction facing = this.getSide().getFacing(); final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( facing ) ); - if( te != null && te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() ) ) + if( te != null ) { - ret = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() ); + ret = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() ) + .orElse(ret); } } this.partVisited = false; @@ -249,6 +252,11 @@ public class PartP2PItems extends PartP2PTunnel implements IItemHa return this.getDestination().getSlots(); } + @Override + public boolean isItemValid(int slot, @Nonnull ItemStack stack) { + return this.getDestination().isItemValid(slot, stack); + } + @Override public ItemStack getStackInSlot( final int i ) { diff --git a/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java b/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java index 43e356b77..026a9faf6 100644 --- a/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java +++ b/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java @@ -19,6 +19,10 @@ package appeng.parts.reporting; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.ContainerInscriber; +import appeng.container.implementations.ContainerInterfaceTerminal; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; @@ -57,7 +61,7 @@ public class PartInterfaceTerminal extends AbstractPartDisplay { if( Platform.isServer() ) { - // FIXME Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_INTERFACE_TERMINAL ); + ContainerOpener.openContainer(ContainerInterfaceTerminal.TYPE, player, ContainerLocator.forPart(this)); } } return true; diff --git a/src/main/java/appeng/recipes/AEItemResolver.java b/src/main/java/appeng/recipes/AEItemResolver.java index 646dbaec8..6d807c726 100644 --- a/src/main/java/appeng/recipes/AEItemResolver.java +++ b/src/main/java/appeng/recipes/AEItemResolver.java @@ -129,13 +129,14 @@ public class AEItemResolver implements ISubItemResolver if( itemName.startsWith( "material." ) ) { - final String materialName = itemName.substring( itemName.indexOf( '.' ) + 1 ); - final MaterialType mt = MaterialType.valueOf( materialName.toUpperCase() ); - // itemName = itemName.substring( 0, itemName.indexOf( "." ) ); - if( mt.getItemInstance() == ItemMaterial.instance && mt.getDamageValue() >= 0 && mt.isRegistered() ) - { - return new ResolverResult( "material", mt.getDamageValue() ); - } + // FIXME entire class is redundant i think +// FIXME final String materialName = itemName.substring( itemName.indexOf( '.' ) + 1 ); +// FIXME final MaterialType mt = MaterialType.valueOf( materialName.toUpperCase() ); +// FIXME // itemName = itemName.substring( 0, itemName.indexOf( "." ) ); +// FIXME if( mt.getItemInstance() == ItemMaterial.instance && mt.getDamageValue() >= 0 && mt.isRegistered() ) +// FIXME { +// FIXME return new ResolverResult( "material", mt.getDamageValue() ); +// FIXME } } if( itemName.startsWith( "part." ) ) diff --git a/src/main/java/appeng/server/AECommand.java b/src/main/java/appeng/server/AECommand.java index 4d274a1db..7176f9691 100644 --- a/src/main/java/appeng/server/AECommand.java +++ b/src/main/java/appeng/server/AECommand.java @@ -19,94 +19,35 @@ package appeng.server; -import com.google.common.base.Joiner; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import net.minecraft.command.CommandSource; +import net.minecraftforge.fml.server.ServerLifecycleHooks; -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.server.MinecraftServer; +import static net.minecraft.command.Commands.literal; -public final class AECommand extends CommandBase -{ - private final MinecraftServer srv; +public final class AECommand { - public AECommand( final MinecraftServer server ) - { - this.srv = server; - } + public void register(CommandDispatcher dispatcher) { - @Override - public int getRequiredPermissionLevel() - { - return 0; - } + LiteralArgumentBuilder builder = literal("ae2"); + for (Commands command : Commands.values()) { + add(builder, command); + } - @Override - public String getName() - { - return "ae2"; - } + dispatcher.register(builder); + } - @Override - public String getUsage( final ICommandSender icommandsender ) - { - return "commands.ae2.usage"; - } + private void add(LiteralArgumentBuilder builder, Commands subCommand) { + + builder.then(literal(subCommand.name().toLowerCase()) + .requires(src -> src.hasPermissionLevel(subCommand.level)) + .executes(ctx -> { + subCommand.command.call(ServerLifecycleHooks.getCurrentServer(), new String[0], ctx.getSource()); + return 1; + })); + + } - @Override - public void execute( final MinecraftServer server, final ICommandSender sender, final String[] args ) throws CommandException - { - if( args.length == 0 ) - { - throw new WrongUsageException( "commands.ae2.usage" ); - } - else if( "help".equals( args[0] ) ) - { - try - { - if( args.length > 1 ) - { - final Commands c = Commands.valueOf( args[1] ); - throw new WrongUsageException( c.command.getHelp( this.srv ) ); - } - } - catch( final WrongUsageException wrong ) - { - throw wrong; - } - catch( final Throwable er ) - { - throw new WrongUsageException( "commands.ae2.usage" ); - } - } - else if( "list".equals( args[0] ) ) - { - throw new WrongUsageException( Joiner.on( ", " ).join( Commands.values() ) ); - } - else - { - try - { - final Commands c = Commands.valueOf( args[0] ); - if( sender.canUseCommand( c.level, this.getName() ) ) - { - c.command.call( this.srv, args, sender ); - } - else - { - throw new WrongUsageException( "commands.ae2.permissions" ); - } - } - catch( final WrongUsageException wrong ) - { - throw wrong; - } - catch( final Throwable er ) - { - throw new WrongUsageException( "commands.ae2.usage" ); - } - } - } } diff --git a/src/main/java/appeng/server/ISubCommand.java b/src/main/java/appeng/server/ISubCommand.java index 4abd9ddec..bbbe45735 100644 --- a/src/main/java/appeng/server/ISubCommand.java +++ b/src/main/java/appeng/server/ISubCommand.java @@ -19,7 +19,8 @@ package appeng.server; -import net.minecraft.command.ICommandSender; +import net.minecraft.command.CommandSource; +import net.minecraft.command.CommandSource; import net.minecraft.server.MinecraftServer; @@ -28,5 +29,5 @@ public interface ISubCommand String getHelp( MinecraftServer srv ); - void call( MinecraftServer srv, String[] args, ICommandSender sender ); + void call( MinecraftServer srv, String[] args, CommandSource sender ); } diff --git a/src/main/java/appeng/server/subcommands/ChunkLogger.java b/src/main/java/appeng/server/subcommands/ChunkLogger.java index 33730fa6f..47c15d639 100644 --- a/src/main/java/appeng/server/subcommands/ChunkLogger.java +++ b/src/main/java/appeng/server/subcommands/ChunkLogger.java @@ -19,12 +19,12 @@ package appeng.server.subcommands; -import net.minecraft.command.ICommandSender; +import net.minecraft.command.CommandSource; import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.ChunkEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; import appeng.core.AEConfig; import appeng.core.AELog; @@ -37,16 +37,6 @@ public class ChunkLogger implements ISubCommand private boolean enabled = false; - @SubscribeEvent - public void onChunkLoadEvent( final ChunkEvent.Load event ) - { - if( !event.getWorld().isRemote ) - { - AELog.info( "Chunk Loaded: " + event.getChunk().x + ", " + event.getChunk().z ); - this.displayStack(); - } - } - private void displayStack() { if( AEConfig.instance().isFeatureEnabled( AEFeature.CHUNK_LOGGER_TRACE ) ) @@ -66,12 +56,22 @@ public class ChunkLogger implements ISubCommand } } + @SubscribeEvent + public void onChunkLoadEvent( final ChunkEvent.Load event ) + { + if( !event.getWorld().isRemote() ) + { + AELog.info( "Chunk Loaded: " + event.getChunk().getPos().x + ", " + event.getChunk().getPos().z ); + this.displayStack(); + } + } + @SubscribeEvent public void onChunkUnloadEvent( final ChunkEvent.Unload unload ) { - if( !unload.getWorld().isRemote ) + if( !unload.getWorld().isRemote() ) { - AELog.info( "Chunk Unloaded: " + unload.getChunk().x + ", " + unload.getChunk().z ); + AELog.info( "Chunk Unloaded: " + unload.getChunk().getPos().x + ", " + unload.getChunk().getPos().z ); this.displayStack(); } } @@ -83,19 +83,19 @@ public class ChunkLogger implements ISubCommand } @Override - public void call( final MinecraftServer srv, final String[] data, final ICommandSender sender ) + public void call( final MinecraftServer srv, final String[] data, final CommandSource sender ) { this.enabled = !this.enabled; if( this.enabled ) { MinecraftForge.EVENT_BUS.register( this ); - sender.sendMessage( new TranslationTextComponent( "commands.ae2.ChunkLoggerOn" ) ); + sender.sendFeedback( new TranslationTextComponent( "commands.ae2.ChunkLoggerOn" ), true ); } else { MinecraftForge.EVENT_BUS.unregister( this ); - sender.sendMessage( new TranslationTextComponent( "commands.ae2.ChunkLoggerOff" ) ); + sender.sendFeedback( new TranslationTextComponent( "commands.ae2.ChunkLoggerOff" ), true ); } } } diff --git a/src/main/java/appeng/server/subcommands/Supporters.java b/src/main/java/appeng/server/subcommands/Supporters.java index 2ddcaf449..eda9ec699 100644 --- a/src/main/java/appeng/server/subcommands/Supporters.java +++ b/src/main/java/appeng/server/subcommands/Supporters.java @@ -21,7 +21,7 @@ package appeng.server.subcommands; import com.google.common.base.Joiner; -import net.minecraft.command.ICommandSender; +import net.minecraft.command.CommandSource; import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.StringTextComponent; @@ -38,9 +38,9 @@ public class Supporters implements ISubCommand } @Override - public void call( final MinecraftServer srv, final String[] data, final ICommandSender sender ) + public void call( final MinecraftServer srv, final String[] data, final CommandSource sender ) { final String[] who = { "Stig Halvorsen", "Josh Ricker", "Jenny \"Othlon\" Sutherland", "Hristo Bogdanov", "BevoLJ" }; - sender.sendMessage( new StringTextComponent( "Special thanks to " + Joiner.on( ", " ).join( who ) ) ); + sender.sendFeedback( new StringTextComponent( "Special thanks to " + Joiner.on( ", " ).join( who ) ), true ); } } diff --git a/src/main/java/appeng/services/VersionChecker.java b/src/main/java/appeng/services/VersionChecker.java index 0db321b69..9c541be1d 100644 --- a/src/main/java/appeng/services/VersionChecker.java +++ b/src/main/java/appeng/services/VersionChecker.java @@ -26,8 +26,6 @@ import javax.annotation.Nonnull; import com.google.common.base.Preconditions; import net.minecraft.nbt.CompoundNBT; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.event.FMLInterModComms; import appeng.core.AEConfig; import appeng.core.AELog; @@ -39,6 +37,8 @@ import appeng.services.version.VersionFetcher; import appeng.services.version.VersionParser; import appeng.services.version.github.FormattedRelease; import appeng.services.version.github.ReleaseFetcher; +import net.minecraftforge.fml.InterModComms; +import net.minecraftforge.fml.ModList; /** @@ -63,6 +63,7 @@ import appeng.services.version.github.ReleaseFetcher; * Only after all that cases, if the external version is higher than the local, * use Version Checker Mod and post several information needed for it to update the mod. */ +// FIXME: VersionChecker doesn't actually exist in 1.15 public final class VersionChecker implements Runnable { private static final int SEC_TO_HOUR = 3600; @@ -86,11 +87,8 @@ public final class VersionChecker implements Runnable // persist the config this.config.save(); - // retrieve data - final String rawLastCheck = this.config.lastCheck(); - // process data - final long lastCheck = Long.parseLong( rawLastCheck ); + final long lastCheck = this.config.lastCheck(); final Date now = new Date(); final long nowInMs = now.getTime(); final long intervalInMs = this.config.interval() * SEC_TO_HOUR * MS_TO_SEC; @@ -177,7 +175,7 @@ public final class VersionChecker implements Runnable */ private void interactWithVersionCheckerMod( @Nonnull final String modFormatted, @Nonnull final String ghFormatted, @Nonnull final String changelog ) { - if( Loader.isModLoaded( "VersionChecker" ) ) + if( ModList.get().isLoaded( "VersionChecker" ) ) { final CompoundNBT versionInf = new CompoundNBT(); versionInf.putString("modDisplayName", AppEng.MOD_NAME); @@ -192,7 +190,7 @@ public final class VersionChecker implements Runnable } versionInf.putString("newFileName", "appliedenergistics2-" + ghFormatted + ".jar"); - FMLInterModComms.sendRuntimeMessage( AppEng.instance(), "VersionChecker", "addUpdate", versionInf ); + InterModComms.sendTo( "VersionChecker", "addUpdate", () -> versionInf ); AELog.info( "Reported new version to VersionChecker mod." ); } diff --git a/src/main/java/appeng/services/export/ModListChecker.java b/src/main/java/appeng/services/export/ModListChecker.java index 2fff4921b..81c7b44c9 100644 --- a/src/main/java/appeng/services/export/ModListChecker.java +++ b/src/main/java/appeng/services/export/ModListChecker.java @@ -27,7 +27,7 @@ import com.google.common.base.Preconditions; import org.apache.commons.codec.digest.DigestUtils; -import net.minecraftforge.fml.common.ModContainer; +import net.minecraftforge.fml.commons.ModContainer; /** diff --git a/src/main/java/appeng/services/version/VersionCheckerConfig.java b/src/main/java/appeng/services/version/VersionCheckerConfig.java index 996d76509..c3d660671 100644 --- a/src/main/java/appeng/services/version/VersionCheckerConfig.java +++ b/src/main/java/appeng/services/version/VersionCheckerConfig.java @@ -19,75 +19,44 @@ package appeng.services.version; -import java.io.File; import java.util.Date; -import javax.annotation.Nonnull; - -import com.google.common.base.Preconditions; - -import net.minecraftforge.common.config.Configuration; - +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.config.ModConfig; +import org.apache.commons.lang3.tuple.Pair; /** * Separate config file to handle the version checker */ public final class VersionCheckerConfig { + private static final int DEFAULT_INTERVAL_HOURS = 24; private static final int MIN_INTERVAL_HOURS = 0; private static final int MAX_INTERVAL_HOURS = 7 * 24; - @Nonnull - private final Configuration config; + private final Config config; - private final boolean isEnabled; + private final ForgeConfigSpec spec; - @Nonnull - private final String lastCheck; - private final int interval; - - @Nonnull - private final String level; - - private final boolean shouldNotifyPlayer; - private final boolean shouldPostChangelog; - - /** - * @param file requires fully qualified file in which the config is saved - */ - public VersionCheckerConfig( @Nonnull final File file ) + private VersionCheckerConfig(final Config config, ForgeConfigSpec spec) { - Preconditions.checkNotNull( file ); - Preconditions.checkState( !file.isDirectory() ); - - this.config = new Configuration( file ); - - // initializes default values by caching - this.isEnabled = this.config.getBoolean( "enabled", "general", true, "If true, the version checker is enabled. Acts as a master switch." ); - - this.lastCheck = this.config.getString( "lastCheck", "cache", "0", - "The number of milliseconds since January 1, 1970, 00:00:00 GMT of the last successful check." ); - this.interval = this.config.getInt( "interval", "cache", DEFAULT_INTERVAL_HOURS, MIN_INTERVAL_HOURS, MAX_INTERVAL_HOURS, - "Waits as many hours, until it checks again." ); - - this.level = this.config.getString( "level", "channel", "Beta", - "Determines the channel level which should be checked for updates. Can be either Stable, Beta or Alpha." ); - - this.shouldNotifyPlayer = this.config.getBoolean( "notify", "client", true, - "If true, the player is getting a notification, that a new version is available." ); - this.shouldPostChangelog = this.config.getBoolean( "changelog", "client", true, - "If true, the player is getting a notification including changelog. Only happens if notification are enabled." ); + this.config = config; + this.spec = spec; } public boolean isVersionCheckingEnabled() { - return this.isEnabled; + return config.isEnabled.get(); } - public String lastCheck() + public long lastCheck() { - return this.lastCheck; + return config.lastCheck.get(); } /** @@ -97,38 +66,93 @@ public final class VersionCheckerConfig { final Date now = new Date(); final long nowInMs = now.getTime(); - final String nowAsString = Long.toString( nowInMs ); - - this.config.get( "cache", "lastCheck", "0" ).set( nowAsString ); - - this.config.save(); + this.config.lastCheck.set(nowInMs); } public int interval() { - return this.interval; + return config.interval.get(); } public String level() { - return this.level; + return config.level.get(); } public boolean shouldNotifyPlayer() { - return this.shouldNotifyPlayer; + return config.shouldNotifyPlayer.get(); } public boolean shouldPostChangelog() { - return this.shouldPostChangelog; + return config.shouldPostChangelog.get(); } public void save() { - if( this.config.hasChanged() ) - { - this.config.save(); + spec.save(); + } + + public static VersionCheckerConfig create() { + final Pair specPair = new ForgeConfigSpec.Builder().configure(Config::new); + Config config = specPair.getLeft(); + ForgeConfigSpec spec = specPair.getRight(); + + ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, spec); + + return new VersionCheckerConfig(config, spec); + } + + private static class Config { + + final ConfigValue isEnabled; + + final ConfigValue lastCheck; + + final ConfigValue interval; + + final ConfigValue level; + + final ForgeConfigSpec.BooleanValue shouldNotifyPlayer; + + final ForgeConfigSpec.BooleanValue shouldPostChangelog; + + public Config(ForgeConfigSpec.Builder builder) { + // initializes default values by caching + builder.push("general"); + this.isEnabled = builder + .comment("If true, the version checker is enabled. Acts as a master switch.") + .define("enabled", true); + builder.pop(); + + builder.push("cache"); + this.lastCheck = builder + .comment("The number of milliseconds since January 1, 1970, 00:00:00 GMT of the last successful check.") + .define("lastCheck", 0L); + this.interval = builder + .comment("Waits as many hours, until it checks again.") + .define( "interval", DEFAULT_INTERVAL_HOURS, val -> { + if (!(val instanceof Integer)) { + return false; + } + int intVal = (Integer) val; + return (intVal >= MIN_INTERVAL_HOURS) && (intVal <= MAX_INTERVAL_HOURS); + }); + builder.pop(); + + builder.push("channel"); + this.level = builder.comment("Determines the channel level which should be checked for updates. Can be either Stable, Beta or Alpha.") + .define("level", "Beta"); + builder.pop(); + + builder.push("client"); + this.shouldNotifyPlayer = builder.comment("If true, the player is getting a notification, that a new version is available.") + .define("notify", true); + this.shouldPostChangelog = builder.comment("If true, the player is getting a notification including changelog. Only happens if notification are enabled.") + .define("changelog", true); + builder.pop(); } } + } diff --git a/src/main/java/appeng/spatial/BiomeGenStorage.java b/src/main/java/appeng/spatial/BiomeGenStorage.java index a831b20cc..98b76eb4f 100644 --- a/src/main/java/appeng/spatial/BiomeGenStorage.java +++ b/src/main/java/appeng/spatial/BiomeGenStorage.java @@ -20,6 +20,8 @@ package appeng.spatial; import net.minecraft.world.biome.Biome; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public class BiomeGenStorage extends Biome @@ -27,15 +29,20 @@ public class BiomeGenStorage extends Biome public BiomeGenStorage() { - super( new BiomeProperties( "Storage Cell" ).setBaseBiome( "void" ).setRainDisabled().setTemperature( -100 ) ); - - this.decorator.treesPerChunk = 0; - this.decorator.flowersPerChunk = 0; - this.decorator.grassPerChunk = 0; - - this.spawnableMonsterList.clear(); - this.spawnableCreatureList.clear(); - this.spawnableWaterCreatureList.clear(); - this.spawnableCaveCreatureList.clear(); + super( new Biome.Builder().precipitation(RainType.NONE).temperature(-100).parent(null) ); +// FIXME this.decorator.treesPerChunk = 0; +// FIXME this.decorator.flowersPerChunk = 0; +// FIXME this.decorator.grassPerChunk = 0; +// FIXME +// FIXME this.spawnableMonsterList.clear(); +// FIXME this.spawnableCreatureList.clear(); +// FIXME this.spawnableWaterCreatureList.clear(); +// FIXME this.spawnableCaveCreatureList.clear(); } + + @OnlyIn(Dist.CLIENT) + public int getSkyColor() { + return 0; + } + } diff --git a/src/main/java/appeng/spatial/StorageWorldProvider.java b/src/main/java/appeng/spatial/StorageWorldProvider.java index ca2645571..f78ca7056 100644 --- a/src/main/java/appeng/spatial/StorageWorldProvider.java +++ b/src/main/java/appeng/spatial/StorageWorldProvider.java @@ -25,6 +25,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.dimension.Dimension; +import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.gen.ChunkGenerator; import net.minecraftforge.client.IRenderHandler; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/appeng/tile/misc/TileInterface.java b/src/main/java/appeng/tile/misc/TileInterface.java index 61812c627..8f0f8f32a 100644 --- a/src/main/java/appeng/tile/misc/TileInterface.java +++ b/src/main/java/appeng/tile/misc/TileInterface.java @@ -25,10 +25,12 @@ import java.util.List; import javax.annotation.Nullable; +import appeng.container.implementations.ContainerInterface; import appeng.core.Api; import com.google.common.collect.ImmutableSet; import net.minecraft.inventory.CraftingInventory; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; @@ -360,9 +362,9 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II return Api.INSTANCE.definitions().blocks().iface().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_INTERFACE; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerInterface.TYPE; + } } diff --git a/src/main/java/appeng/tile/storage/TileChest.java b/src/main/java/appeng/tile/storage/TileChest.java index 1ff126580..52fc440db 100644 --- a/src/main/java/appeng/tile/storage/TileChest.java +++ b/src/main/java/appeng/tile/storage/TileChest.java @@ -26,8 +26,11 @@ import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import appeng.container.implementations.ContainerMEMonitorable; import appeng.core.Api; +import appeng.fluids.container.ContainerFluidTerminal; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; @@ -943,22 +946,22 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal return Api.INSTANCE.definitions().blocks().chest().maybeStack( 1 ).orElse( ItemStack.EMPTY ); } -// FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME this.updateHandler(); -// FIXME if( this.cellHandler != null ) -// FIXME { -// FIXME if( this.cellHandler.getChannel() == Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ) ) -// FIXME { -// FIXME return GuiBridge.GUI_ME; -// FIXME } -// FIXME if( this.cellHandler.getChannel() == Api.INSTANCE.storage().getStorageChannel( IFluidStorageChannel.class ) ) -// FIXME { -// FIXME return GuiBridge.GUI_FLUID_TERMINAL; -// FIXME } -// FIXME } -// FIXME return null; -// FIXME } + @Override + public ContainerType getContainerType() + { + this.updateHandler(); + if( this.cellHandler != null ) + { + if( this.cellHandler.getChannel() == Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class ) ) + { + return ContainerMEMonitorable.TYPE; + } + if( this.cellHandler.getChannel() == Api.INSTANCE.storage().getStorageChannel( IFluidStorageChannel.class ) ) + { + return ContainerFluidTerminal.TYPE; + } + } + return null; + } } diff --git a/src/main/java/appeng/tile/storage/TileDrive.java b/src/main/java/appeng/tile/storage/TileDrive.java index e429e47b0..b69abfff7 100644 --- a/src/main/java/appeng/tile/storage/TileDrive.java +++ b/src/main/java/appeng/tile/storage/TileDrive.java @@ -29,7 +29,9 @@ import java.util.Map; import appeng.block.AEBaseTileBlock; import appeng.block.storage.DriveSlotsState; +import appeng.container.implementations.ContainerDrive; import appeng.core.Api; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; @@ -426,9 +428,9 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior } - // FIXME @Override -// FIXME public GuiBridge getGuiBridge() -// FIXME { -// FIXME return GuiBridge.GUI_DRIVE; -// FIXME } + @Override + public ContainerType getContainerType() + { + return ContainerDrive.TYPE; + } } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 93f22b604..6f23e330a 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -19,10 +19,7 @@ package appeng.util; -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.SecurityPermissions; +import appeng.api.config.*; import appeng.api.definitions.IItemDefinition; import appeng.api.features.AEFeature; import appeng.api.implementations.items.IAEItemPowerStorage; @@ -69,6 +66,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.CraftingInventory; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -88,9 +86,12 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fml.common.thread.SidedThreadGroups; import net.minecraftforge.fml.loading.FMLEnvironment; +import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.registries.ForgeRegistries; +import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.text.DecimalFormat; import java.util.*; @@ -141,36 +142,36 @@ public class Platform return RANDOM_GENERATOR.nextFloat(); } -// /** -// * This displays the value for encoded longs ( double *100 ) -// * -// * @param n to be formatted long value -// * @param isRate if true it adds a /t to the formatted string -// * -// * @return formatted long value -// */ -// public static String formatPowerLong( final long n, final boolean isRate ) -// { -// double p = ( (double) n ) / 100; -// -// final PowerUnits displayUnits = AEConfig.instance().selectedPowerUnit(); -// p = PowerUnits.AE.convertTo( displayUnits, p ); -// -// final String[] preFixes = { "k", "M", "G", "T", "P", "T", "P", "E", "Z", "Y" }; -// String unitName = displayUnits.name(); -// -// String level = ""; -// int offset = 0; -// while( p > 1000 && offset < preFixes.length ) -// { -// p /= 1000; -// level = preFixes[offset]; -// offset++; -// } -// -// final DecimalFormat df = new DecimalFormat( "#.##" ); -// return df.format( p ) + ' ' + level + unitName + ( isRate ? "/t" : "" ); -// } + /** + * This displays the value for encoded longs ( double *100 ) + * + * @param n to be formatted long value + * @param isRate if true it adds a /t to the formatted string + * + * @return formatted long value + */ + public static String formatPowerLong( final long n, final boolean isRate ) + { + double p = ( (double) n ) / 100; + + final PowerUnits displayUnits = AEConfig.instance().selectedPowerUnit(); + p = PowerUnits.AE.convertTo( displayUnits, p ); + + final String[] preFixes = { "k", "M", "G", "T", "P", "T", "P", "E", "Z", "Y" }; + String unitName = displayUnits.name(); + + String level = ""; + int offset = 0; + while( p > 1000 && offset < preFixes.length ) + { + p /= 1000; + level = preFixes[offset]; + offset++; + } + + final DecimalFormat df = new DecimalFormat( "#.##" ); + return df.format( p ) + ' ' + level + unitName + ( isRate ? "/t" : "" ); + } public static AEPartLocation crossProduct( final AEPartLocation forward, final AEPartLocation up ) { @@ -324,15 +325,13 @@ public class Platform return false; } -// public static void openGUI(@Nonnull final PlayerEntity p, @Nullable final TileEntity tile, @Nullable final AEPartLocation side, @Nonnull final GuiBridge type ) +// public static void openGUI(@Nonnull final PlayerEntity p, @Nullable final TileEntity tile, @Nullable final AEPartLocation side, @Nonnull final ContainerType type ) // { // if( isClient() ) // { // return; // } // -// tile.getCapability(AEProtectedGui.class, side.getFacing()) -// // int x = (int) p.getPosX(); // int y = (int) p.getPosY(); // int z = (int) p.getPosZ(); @@ -347,6 +346,7 @@ public class Platform // { // if( tile == null && type.getType() == GuiHostType.ITEM ) // { +// NetworkHooks.openGui(p, ); // // FIXME NetworkHooks.openGui // // p.openGui( AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), p.inventory.currentItem, 0, 0 ); // } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 24b06e48b..abab2dfae 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,6 +1,8 @@ # GUI rendering protected net.minecraft.client.gui.screen.inventory.ContainerScreen func_146977_a(Lnet/minecraft/inventory/container/Slot;)V # drawSlot -#public net.minecraft.client.gui.widget.TextFieldWidget func_146188_c(IIII)V # drawSelectionBox +public net.minecraft.client.gui.widget.TextFieldWidget func_146188_c(IIII)V # drawSelectionBox +public net.minecraft.client.gui.widget.TextFieldWidget func_146208_g()I # getMaxStringLength + protected net.minecraft.inventory.container.Container field_75149_d # listeners # Reusing RedstoneParticle for ChargedOreFX diff --git a/src/main/resources/assets/appliedenergistics2/particles/assembler_fx.json b/src/main/resources/assets/appliedenergistics2/particles/assembler_fx.json new file mode 100644 index 000000000..7a73a41bf --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/particles/assembler_fx.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/particles/crafting_fx.json b/src/main/resources/assets/appliedenergistics2/particles/crafting_fx.json new file mode 100644 index 000000000..ad2e7618c --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/particles/crafting_fx.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "appliedenergistics2:particles/energy" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/particles/lightning_arc_fx.json b/src/main/resources/assets/appliedenergistics2/particles/lightning_arc_fx.json new file mode 100644 index 000000000..ca698ca44 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/particles/lightning_arc_fx.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "minecraft:generic_0" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/particles/matter_cannon_fx.json b/src/main/resources/assets/appliedenergistics2/particles/matter_cannon_fx.json new file mode 100644 index 000000000..338b997f9 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/particles/matter_cannon_fx.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "appliedenergistics2:particles/matter_cannon" + ] +} \ No newline at end of file