From 80b07bc4b3f919d7a862e99bf7260d0a2ef09d2d Mon Sep 17 00:00:00 2001 From: Richard Freimer Date: Mon, 13 May 2019 11:43:42 -0400 Subject: [PATCH] Code cleanup (#5468) * remove direct guava predicates from BlockStateMachine * cleanup blockstatebasic * fix a large number of e.printStacktrace calls, narrow ComputerIntegration exception signature * fix simple todos, remove invalid todos, unify some duplicate rendering code * use a generic method to get around unchecked warning * remove some redundant uses of hasCapability * experimental OptionalCapability class. not in use yet * nullable checks/annotations & remove duplicate field controlType in factory TE * Inline various redundant variables * Remove unused list * Cleanup BlockStateGenerator * Replace string constants with pointers to the proper mod id constant * As 9.7.5 breaks backwards compat API wise for the DynamicNetwork this is as good a time as any to remove this deprecated method * Use two argument constructor instead of appending a ':' inbetween * Convert other BlockState type classes to using suppliers for tile entity creation --- build.gradle | 2 + gradle.properties | 1 + .../api/transmitters/DynamicNetwork.java | 10 -- .../java/mekanism/client/ClientProxy.java | 24 ++-- .../client/render/MekanismRenderer.java | 49 +++++--- .../client/render/RenderResizableCuboid.java | 2 - .../client/render/RenderTickHandler.java | 3 - .../client/render/entity/RenderFlame.java | 3 +- .../item/MekanismItemStackRenderer.java | 2 +- .../client/render/obj/MekanismOBJLoader.java | 4 +- .../client/render/obj/OBJBakedModelBase.java | 9 +- .../client/render/obj/TransmitterModel.java | 17 +-- .../particle/TieredParticleDigging.java | 2 +- .../RenderChemicalCrystallizer.java | 17 +-- .../RenderChemicalDissolutionChamber.java | 16 +-- .../render/tileentity/RenderEnergyCube.java | 2 +- .../render/tileentity/RenderGasTank.java | 2 +- .../RenderQuantumEntangloporter.java | 17 +-- .../tileentity/RenderResistiveHeater.java | 16 +-- .../RenderRotaryCondensentrator.java | 16 +-- .../render/tileentity/RenderSecurityDesk.java | 16 +-- .../tileentity/RenderSeismicVibrator.java | 16 +-- .../RenderSolarNeutronActivator.java | 16 +-- .../transmitter/RenderTransmitterBase.java | 4 +- .../client/sound/FlamethrowerSound.java | 7 +- .../mekanism/client/sound/GasMaskSound.java | 3 +- .../mekanism/client/sound/JetpackSound.java | 3 +- .../mekanism/client/sound/SoundHandler.java | 17 ++- .../mekanism/common/BoxBlacklistParser.java | 1 + .../java/mekanism/common/InfuseStorage.java | 10 ++ src/main/java/mekanism/common/Mekanism.java | 16 +-- .../java/mekanism/common/MekanismFluids.java | 8 +- .../java/mekanism/common/PacketHandler.java | 76 ++++++----- .../java/mekanism/common/base/IFactory.java | 3 +- .../mekanism/common/block/BlockBasic.java | 21 ++-- .../common/block/BlockEnergyCube.java | 5 +- .../mekanism/common/block/BlockGasTank.java | 5 +- .../common/block/BlockPlasticFence.java | 2 +- .../common/block/states/BlockStateBasic.java | 110 +++++++--------- .../block/states/BlockStateCardboardBox.java | 3 +- .../block/states/BlockStateMachine.java | 119 ++++++++---------- .../block/states/BlockStatePlastic.java | 3 +- .../block/states/BlockStateTransmitter.java | 3 +- .../common/block/states/BlockStateUtils.java | 12 ++ .../CapabilityWrapperManager.java | 4 +- .../common/content/transporter/InvStack.java | 2 +- .../common/frequency/FrequencyManager.java | 11 +- .../common/integration/WailaDataProvider.java | 2 +- .../integration/computer/CCPeripheral.java | 3 - .../computer/IComputerIntegration.java | 2 +- .../multipart/MultipartMekanism.java | 3 +- .../container/ContainerMekanism.java | 1 - .../common/item/ItemBlockEnergyCube.java | 12 +- .../common/item/ItemBlockGasTank.java | 12 +- .../common/item/ItemConfigurator.java | 4 +- .../common/item/ItemCraftingFormula.java | 8 +- .../common/item/ItemWalkieTalkie.java | 6 +- .../common/network/PacketDigitalMinerGui.java | 3 +- .../common/network/PacketDropperUse.java | 3 +- .../network/PacketFlamethrowerData.java | 1 + .../common/network/PacketItemStack.java | 3 +- .../common/network/PacketJetpackData.java | 1 + .../network/PacketLogisticalSorterGui.java | 3 +- .../network/PacketOredictionificatorGui.java | 3 +- .../common/network/PacketScubaTankData.java | 1 + .../common/network/PacketTileEntity.java | 3 +- .../mekanism/common/recipe/RecipeHandler.java | 3 +- .../common/recipe/ShapedMekanismRecipe.java | 2 +- .../recipe/ShapelessMekanismRecipe.java | 2 +- .../tile/TileEntityAdvancedBoundingBlock.java | 2 +- .../common/tile/TileEntityBoilerValve.java | 2 +- .../common/tile/TileEntityChanceMachine.java | 2 +- .../common/tile/TileEntityDigitalMiner.java | 2 +- .../common/tile/TileEntityElectricPump.java | 2 +- .../tile/TileEntityElectrolyticSeparator.java | 2 +- .../common/tile/TileEntityEnergyCube.java | 2 +- .../common/tile/TileEntityFactory.java | 32 +++-- .../tile/TileEntityFluidicPlenisher.java | 2 +- .../common/tile/TileEntityGasTank.java | 2 +- .../tile/TileEntityInductionCasing.java | 2 +- .../common/tile/TileEntityLaserAmplifier.java | 2 +- .../tile/TileEntityLogisticalSorter.java | 2 +- .../tile/TileEntityMetallurgicInfuser.java | 14 ++- .../mekanism/common/tile/TileEntityPRC.java | 5 +- .../tile/TileEntityQuantumEntangloporter.java | 2 +- .../tile/TileEntityResistiveHeater.java | 2 +- .../common/tile/TileEntityTeleporter.java | 2 +- .../TileEntityThermalEvaporationBlock.java | 2 +- .../TileEntityAdvancedElectricMachine.java | 2 +- .../TileEntityDoubleElectricMachine.java | 2 +- .../prefab/TileEntityElectricMachine.java | 2 +- .../common/tile/prefab/TileEntityMachine.java | 7 +- .../prefab/TileEntityUpgradeableMachine.java | 5 +- .../transmitter/TileEntityUniversalCable.java | 31 ++--- .../java/mekanism/common/util/CableUtils.java | 43 ++++--- .../mekanism/common/util/CapabilityUtils.java | 77 ++++++++++++ .../mekanism/common/util/InventoryUtils.java | 1 - .../common/util/ItemRegistryUtils.java | 3 +- .../mekanism/common/util/MekanismUtils.java | 4 +- .../client/GeneratorsClientProxy.java | 10 +- .../client/gui/GuiGeneratorsConfig.java | 3 +- .../render/RenderAdvancedSolarGenerator.java | 16 +-- .../client/render/RenderWindGenerator.java | 16 +-- .../block/states/BlockStateGenerator.java | 68 ++++------ .../block/states/BlockStateReactor.java | 30 ++--- .../common/tile/TileEntityBioGenerator.java | 2 +- .../common/tile/TileEntityGasGenerator.java | 2 +- .../common/tile/TileEntityHeatGenerator.java | 2 +- .../common/tile/TileEntitySolarGenerator.java | 2 +- .../common/tile/TileEntityWindGenerator.java | 2 +- .../reactor/TileEntityReactorController.java | 2 +- .../TileEntityReactorLogicAdapter.java | 2 +- .../tile/turbine/TileEntityTurbineValve.java | 2 +- .../tools/client/ToolsClientProxy.java | 3 +- .../tools/client/gui/GuiToolsConfig.java | 3 +- 115 files changed, 583 insertions(+), 633 deletions(-) create mode 100644 src/main/java/mekanism/common/block/states/BlockStateUtils.java diff --git a/build.gradle b/build.gradle index 7eac8e2ce..c0a07aade 100644 --- a/build.gradle +++ b/build.gradle @@ -114,6 +114,8 @@ minecraft { } dependencies { + compileOnly "org.jetbrains:annotations:${jb_annotations}" + deobfCompile "MCMultiPart2:MCMultiPart:${mcmp_version}" compileOnly "mezz.jei:jei_${minecraft_version}:${jei_version}:api" runtime "mezz.jei:jei_${minecraft_version}:${jei_version}" diff --git a/gradle.properties b/gradle.properties index 42645ec3c..e63ae8d00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,3 +16,4 @@ crafttweaker_version=4.1.15.527 computercraft_version=1.80pr1 top_version=1.12-1.4.23-16 ae2_version=rv6-stable-6 +jb_annotations=17.0.0 \ No newline at end of file diff --git a/src/main/java/mekanism/api/transmitters/DynamicNetwork.java b/src/main/java/mekanism/api/transmitters/DynamicNetwork.java index df2c06ce5..477c99bb6 100644 --- a/src/main/java/mekanism/api/transmitters/DynamicNetwork.java +++ b/src/main/java/mekanism/api/transmitters/DynamicNetwork.java @@ -2,7 +2,6 @@ package mekanism.api.transmitters; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -22,7 +21,6 @@ import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.Event; -import org.apache.commons.lang3.tuple.Pair; public abstract class DynamicNetwork, BUFFER> implements IClientTicker, INetworkDataHandler { @@ -280,14 +278,6 @@ public abstract class DynamicNetwork> getAcceptors(Object data) { - return Collections.emptySet(); - } - public void tick() { onUpdate(); } diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index ca40ec276..5d3025369 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -407,7 +407,7 @@ public class ClientProxy extends CommonProxy { } private ModelResourceLocation getInventoryMRL(String type) { - return new ModelResourceLocation("mekanism:" + type, "inventory"); + return new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, type), "inventory"); } @Override @@ -428,8 +428,8 @@ public class ClientProxy extends CommonProxy { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.ObsidianTNT), 0, getInventoryMRL("ObsidianTNT")); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.SaltBlock), 0, getInventoryMRL("SaltBlock")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.CardboardBox), 0, new ModelResourceLocation("mekanism:CardboardBox", "storage=false")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.CardboardBox), 1, new ModelResourceLocation("mekanism:CardboardBox", "storage=true")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.CardboardBox), 0, new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "CardboardBox"), "storage=false")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.CardboardBox), 1, new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "CardboardBox"), "storage=true")); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.EnergyCube), 0, getInventoryMRL("EnergyCube")); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.MachineBlock), 4, getInventoryMRL("digital_miner")); @@ -567,21 +567,21 @@ public class ClientProxy extends CommonProxy { } for (EnumColor color : EnumColor.DYES) { - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.PlasticBlock), color.getMetaValue(), new ModelResourceLocation("mekanism:plastic_block", "type=plastic")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.SlickPlasticBlock), color.getMetaValue(), new ModelResourceLocation("mekanism:plastic_block", "type=slick")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.GlowPlasticBlock), color.getMetaValue(), new ModelResourceLocation("mekanism:plastic_block", "type=glow")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.ReinforcedPlasticBlock), color.getMetaValue(), new ModelResourceLocation("mekanism:plastic_block", "type=reinforced")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.RoadPlasticBlock), color.getMetaValue(), new ModelResourceLocation("mekanism:plastic_block", "type=road")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.PlasticBlock), color.getMetaValue(), new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "plastic_block"), "type=plastic")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.SlickPlasticBlock), color.getMetaValue(), new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "plastic_block"), "type=slick")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.GlowPlasticBlock), color.getMetaValue(), new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "plastic_block"), "type=glow")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.ReinforcedPlasticBlock), color.getMetaValue(), new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "plastic_block"), "type=reinforced")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.RoadPlasticBlock), color.getMetaValue(), new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "plastic_block"), "type=road")); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.PlasticFence), color.getMetaValue(), getInventoryMRL("PlasticFence")); } for (EnumOreType ore : EnumOreType.values()) { - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.OreBlock), ore.ordinal(), new ModelResourceLocation("mekanism:OreBlock", "type=" + ore.getName())); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MekanismBlocks.OreBlock), ore.ordinal(), new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "OreBlock"), "type=" + ore.getName())); } ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(MekanismBlocks.GasTank), stack -> { GasTankTier tier = GasTankTier.values()[((ItemBlockGasTank) stack.getItem()).getBaseTier(stack).ordinal()]; - ResourceLocation baseLocation = new ResourceLocation("mekanism", "GasTank"); + ResourceLocation baseLocation = new ResourceLocation(Mekanism.MODID, "GasTank"); return new ModelResourceLocation(baseLocation, "facing=north,tier=" + tier); }); @@ -659,11 +659,11 @@ public class ClientProxy extends CommonProxy { return ItemCraftingFormula.MODEL; }); - OBJLoader.INSTANCE.addDomain("mekanism"); + OBJLoader.INSTANCE.addDomain(Mekanism.MODID); } public void registerItemRender(Item item) { - MekanismRenderer.registerItemRender("mekanism", item); + MekanismRenderer.registerItemRender(Mekanism.MODID, item); } private String getProperties(List entries) { diff --git a/src/main/java/mekanism/client/render/MekanismRenderer.java b/src/main/java/mekanism/client/render/MekanismRenderer.java index 0a5969a79..549ee8963 100644 --- a/src/main/java/mekanism/client/render/MekanismRenderer.java +++ b/src/main/java/mekanism/client/render/MekanismRenderer.java @@ -1,9 +1,7 @@ package mekanism.client.render; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import mekanism.api.EnumColor; import mekanism.api.gas.Gas; @@ -17,7 +15,10 @@ import mekanism.client.render.tileentity.RenderFluidTank; import mekanism.client.render.tileentity.RenderThermalEvaporationController; import mekanism.client.render.transmitter.RenderLogisticalTransporter; import mekanism.client.render.transmitter.RenderMechanicalPipe; +import mekanism.common.Mekanism; import mekanism.common.base.IMetaItem; +import mekanism.common.base.ISideConfiguration; +import mekanism.common.tile.prefab.TileEntityBasicBlock; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; @@ -34,6 +35,7 @@ import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.TextureStitchEvent; @@ -56,7 +58,7 @@ public class MekanismRenderer { public static float GAS_RENDER_BASE = 0.2F; public static Map overlays = new HashMap<>(); public static int[] directionMap = new int[]{3, 0, 1, 2}; - public static RenderConfigurableMachine machineRenderer = new RenderConfigurableMachine(); + private static RenderConfigurableMachine machineRenderer = new RenderConfigurableMachine(); public static TextureAtlasSprite missingIcon; private static float lightmapLastX; private static float lightmapLastY; @@ -68,20 +70,22 @@ public class MekanismRenderer { MinecraftForge.EVENT_BUS.register(new MekanismRenderer()); } + @SuppressWarnings("unchecked") + public static RenderConfigurableMachine machineRenderer() { + return machineRenderer; + } + public static void registerItemRender(String domain, Item item) { if (item instanceof IMetaItem) { IMetaItem metaItem = (IMetaItem) item; - List variants = new ArrayList<>(); for (int i = 0; i < metaItem.getVariants(); i++) { if (metaItem.getTexture(i) == null) { continue; } - ModelResourceLocation loc = new ModelResourceLocation(domain + ":" + metaItem.getTexture(i), - "inventory"); + ModelResourceLocation loc = new ModelResourceLocation(new ResourceLocation(domain, metaItem.getTexture(i)), "inventory"); ModelLoader.setCustomModelResourceLocation(item, i, loc); - variants.add(loc); - ModelBakery.registerItemVariants(item, new ResourceLocation(domain + ":" + metaItem.getTexture(i))); + ModelBakery.registerItemVariants(item, new ResourceLocation(domain, metaItem.getTexture(i))); } return; @@ -325,21 +329,38 @@ public class MekanismRenderer { return TextureMap.LOCATION_BLOCKS_TEXTURE; } + public static void glRotateForFacing(TileEntityBasicBlock tileEntity) { + switch (tileEntity.facing) /*TODO: switch the enum*/ { + case NORTH: + GlStateManager.rotate(0, 0.0F, 1.0F, 0.0F); + break; + case SOUTH: + GlStateManager.rotate(180, 0.0F, 1.0F, 0.0F); + break; + case WEST: + GlStateManager.rotate(90, 0.0F, 1.0F, 0.0F); + break; + case EAST: + GlStateManager.rotate(270, 0.0F, 1.0F, 0.0F); + break; + } + } + @SubscribeEvent public void onStitch(TextureStitchEvent.Pre event) { for (EnumColor color : EnumColor.values()) { - colors[color.ordinal()] = event.getMap().registerSprite(new ResourceLocation("mekanism:blocks/overlay/overlay_" + color.unlocalizedName)); + colors[color.ordinal()] = event.getMap().registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/overlay/overlay_" + color.unlocalizedName)); } for (TransmissionType type : TransmissionType.values()) { - overlays.put(type, event.getMap().registerSprite(new ResourceLocation("mekanism:blocks/overlay/" + type.getTransmission() + "Overlay"))); + overlays.put(type, event.getMap().registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/overlay/" + type.getTransmission() + "Overlay"))); } - energyIcon = event.getMap().registerSprite(new ResourceLocation("mekanism:blocks/liquid/LiquidEnergy")); - heatIcon = event.getMap().registerSprite(new ResourceLocation("mekanism:blocks/liquid/LiquidHeat")); - laserIcon = event.getMap().registerSprite(new ResourceLocation("mekanism:blocks/Laser")); + energyIcon = event.getMap().registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/liquid/LiquidEnergy")); + heatIcon = event.getMap().registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/liquid/LiquidHeat")); + laserIcon = event.getMap().registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/Laser")); - event.getMap().registerSprite(new ResourceLocation("mekanism:blocks/liquid/LiquidHeavyWater")); + event.getMap().registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/liquid/LiquidHeavyWater")); TransmitterModel.registerIcons(event.getMap()); diff --git a/src/main/java/mekanism/client/render/RenderResizableCuboid.java b/src/main/java/mekanism/client/render/RenderResizableCuboid.java index 9c4914436..dad4b1fb1 100644 --- a/src/main/java/mekanism/client/render/RenderResizableCuboid.java +++ b/src/main/java/mekanism/client/render/RenderResizableCuboid.java @@ -518,8 +518,6 @@ public class RenderResizableCuboid { /** * A way to automatically generate the different positions given the same arguments. - * - * @param rotation TODO */ private List getRenderInfos(float[] uv, double sizeU, double sizeV, double textureSizeU, double textureSizeV, double textureOffsetU, double textureOffsetV) { List infos = new ArrayList<>(); diff --git a/src/main/java/mekanism/client/render/RenderTickHandler.java b/src/main/java/mekanism/client/render/RenderTickHandler.java index e68c73a33..9b9074e28 100644 --- a/src/main/java/mekanism/client/render/RenderTickHandler.java +++ b/src/main/java/mekanism/client/render/RenderTickHandler.java @@ -117,7 +117,6 @@ public class RenderTickHandler { } // Traverse a copy of jetpack state and do animations - // TODO: This means we're making a full copy of the state per render....might need to revisit for (UUID uuid : Mekanism.playerState.getActiveJetpacks()) { EntityPlayer p = mc.world.getPlayerEntityByUUID(uuid); @@ -157,7 +156,6 @@ public class RenderTickHandler { } // Traverse a copy of gasmask state and do animations - // TODO: This means we're making a full copy of the state per render....might need to revisit if (world.getWorldTime() % 4 == 0) { for (UUID uuid : Mekanism.playerState.getActiveGasmasks()) { EntityPlayer p = mc.world.getPlayerEntityByUUID(uuid); @@ -179,7 +177,6 @@ public class RenderTickHandler { } // Traverse a copy of flamethrower state and do animations - // TODO: This means we're making a full copy of the state per render....might need to revisit if (world.getWorldTime() % 4 == 0) { for (EntityPlayer p : world.playerEntities) { if (!Mekanism.playerState.isFlamethrowerOn(p) && !p.isSwingInProgress) { diff --git a/src/main/java/mekanism/client/render/entity/RenderFlame.java b/src/main/java/mekanism/client/render/entity/RenderFlame.java index 8344262a6..ee670e9d0 100644 --- a/src/main/java/mekanism/client/render/entity/RenderFlame.java +++ b/src/main/java/mekanism/client/render/entity/RenderFlame.java @@ -2,6 +2,7 @@ package mekanism.client.render.entity; import javax.annotation.Nonnull; import mekanism.client.render.MekanismRenderer; +import mekanism.common.Mekanism; import mekanism.common.entity.EntityFlame; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -78,6 +79,6 @@ public class RenderFlame extends Render { @Override protected ResourceLocation getEntityTexture(@Nonnull EntityFlame entity) { - return new ResourceLocation("mekanism:render/Flame.png"); + return new ResourceLocation(Mekanism.MODID, "render/Flame.png"); } } diff --git a/src/main/java/mekanism/client/render/item/MekanismItemStackRenderer.java b/src/main/java/mekanism/client/render/item/MekanismItemStackRenderer.java index e92cf4a65..e0fabe6d2 100644 --- a/src/main/java/mekanism/client/render/item/MekanismItemStackRenderer.java +++ b/src/main/java/mekanism/client/render/item/MekanismItemStackRenderer.java @@ -63,7 +63,7 @@ public abstract class MekanismItemStackRenderer extends TileEntityItemStackRende GlStateManager.enableLight(1); GlStateManager.enableColorMaterial(); GlStateManager.colorMaterial(1032, 5634); - GlStateManager.enableCull();//TODO: This line was not in generators does it matter + GlStateManager.enableCull(); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); GlStateManager.popMatrix(); diff --git a/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java b/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java index 1cfb8309d..6d2091ed9 100644 --- a/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java +++ b/src/main/java/mekanism/client/render/obj/MekanismOBJLoader.java @@ -42,7 +42,7 @@ public class MekanismOBJLoader implements ICustomModelLoader { IRegistry modelRegistry = event.getModelRegistry(); for (String s : OBJ_RENDERS) { - ModelResourceLocation model = new ModelResourceLocation("mekanism:" + s, "inventory"); + ModelResourceLocation model = new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, s), "inventory"); IBakedModel bakedModel = modelRegistry.getObject(model); modelRegistry.putObject(model, createBakedObjItemModel(bakedModel, "mekanism:models/block/" + s + ".obj.mek", new OBJState(Lists.newArrayList(OBJModel.Group.ALL), true), DefaultVertexFormats.ITEM)); @@ -73,7 +73,7 @@ public class MekanismOBJLoader implements ICustomModelLoader { builder.put("missingno", missing); return new GlowPanelModel(existingModel, objModel, state, format, builder.build(), new HashMap<>()); } catch (Exception e) { - e.printStackTrace(); + Mekanism.logger.error("Failed to load OBJ", e); } return null; } diff --git a/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java b/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java index 5ca1bae59..33ba33659 100644 --- a/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java +++ b/src/main/java/mekanism/client/render/obj/OBJBakedModelBase.java @@ -15,6 +15,7 @@ import java.util.Set; import javax.annotation.Nonnull; import javax.vecmath.Matrix4f; import mekanism.client.render.MekanismRenderer; +import mekanism.common.Mekanism; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; @@ -104,8 +105,8 @@ public abstract class OBJBakedModelBase extends OBJBakedModel { f_textures.setAccessible(true); } return (ImmutableMap) f_textures.get(model); - } catch (Exception e) { - e.printStackTrace(); + } catch (ReflectiveOperationException | ClassCastException e) { + Mekanism.logger.error("Could not get private field textures", e); } return null; } @@ -206,8 +207,8 @@ public abstract class OBJBakedModelBase extends OBJBakedModel { m_updateStateVisibilityMap.setAccessible(true); } m_updateStateVisibilityMap.invoke(this, state); - } catch (Exception e) { - e.printStackTrace(); + } catch (ReflectiveOperationException | ClassCastException e) { + Mekanism.logger.error("Could not get private field updateStateVisibilityMap", e); } } diff --git a/src/main/java/mekanism/client/render/obj/TransmitterModel.java b/src/main/java/mekanism/client/render/obj/TransmitterModel.java index 132dfc4e5..e877f9056 100644 --- a/src/main/java/mekanism/client/render/obj/TransmitterModel.java +++ b/src/main/java/mekanism/client/render/obj/TransmitterModel.java @@ -12,6 +12,7 @@ import java.util.Set; import javax.annotation.Nonnull; import javax.vecmath.Matrix4f; import javax.vecmath.Vector3f; +import mekanism.common.Mekanism; import mekanism.common.block.property.PropertyColor; import mekanism.common.block.property.PropertyConnection; import mekanism.common.config.MekanismConfig; @@ -83,15 +84,15 @@ public class TransmitterModel extends OBJBakedModelBase { } public static void registerIcons(TextureMap map) { - transporter_center[0] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/LogisticalTransporterGlass")); - transporter_center_color[0] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/LogisticalTransporterGlassColored")); - transporter_side[0] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/LogisticalTransporterVerticalGlass")); - transporter_side_color[0] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/LogisticalTransporterVerticalGlassColored")); + transporter_center[0] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/LogisticalTransporterGlass")); + transporter_center_color[0] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/LogisticalTransporterGlassColored")); + transporter_side[0] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/LogisticalTransporterVerticalGlass")); + transporter_side_color[0] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/LogisticalTransporterVerticalGlassColored")); - transporter_center[1] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/opaque/LogisticalTransporterGlass")); - transporter_center_color[1] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/opaque/LogisticalTransporterGlassColored")); - transporter_side[1] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/opaque/LogisticalTransporterVerticalGlass")); - transporter_side_color[1] = map.registerSprite(new ResourceLocation("mekanism:blocks/models/multipart/opaque/LogisticalTransporterVerticalGlassColored")); + transporter_center[1] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/opaque/LogisticalTransporterGlass")); + transporter_center_color[1] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/opaque/LogisticalTransporterGlassColored")); + transporter_side[1] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/opaque/LogisticalTransporterVerticalGlass")); + transporter_side_color[1] = map.registerSprite(new ResourceLocation(Mekanism.MODID, "blocks/models/multipart/opaque/LogisticalTransporterVerticalGlassColored")); } public static void clearCache() { diff --git a/src/main/java/mekanism/client/render/particle/TieredParticleDigging.java b/src/main/java/mekanism/client/render/particle/TieredParticleDigging.java index bc84a616a..ed9964e8e 100644 --- a/src/main/java/mekanism/client/render/particle/TieredParticleDigging.java +++ b/src/main/java/mekanism/client/render/particle/TieredParticleDigging.java @@ -15,7 +15,7 @@ public class TieredParticleDigging extends ParticleDigging { @Nullable private final EnumColor color; - public TieredParticleDigging(World world, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, IBlockState state, EnumColor color) { + public TieredParticleDigging(World world, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, IBlockState state, @Nullable EnumColor color) { super(world, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, state); this.color = color; } diff --git a/src/main/java/mekanism/client/render/tileentity/RenderChemicalCrystallizer.java b/src/main/java/mekanism/client/render/tileentity/RenderChemicalCrystallizer.java index fb464082d..3410a8115 100644 --- a/src/main/java/mekanism/client/render/tileentity/RenderChemicalCrystallizer.java +++ b/src/main/java/mekanism/client/render/tileentity/RenderChemicalCrystallizer.java @@ -21,25 +21,12 @@ public class RenderChemicalCrystallizer extends TileEntitySpecialRenderer @Override public void render(TileEntityGasTank tileEntity, double x, double y, double z, float partialTick, int destroyStage, float alpha) { - MekanismRenderer.machineRenderer.render(tileEntity, x, y, z, partialTick, destroyStage, alpha); + MekanismRenderer.machineRenderer().render(tileEntity, x, y, z, partialTick, destroyStage, alpha); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/render/tileentity/RenderQuantumEntangloporter.java b/src/main/java/mekanism/client/render/tileentity/RenderQuantumEntangloporter.java index 34f3d02f5..94c264ed3 100644 --- a/src/main/java/mekanism/client/render/tileentity/RenderQuantumEntangloporter.java +++ b/src/main/java/mekanism/client/render/tileentity/RenderQuantumEntangloporter.java @@ -22,25 +22,12 @@ public class RenderQuantumEntangloporter extends TileEntitySpecialRenderer ext if (contentsModel == null) { try { contentsModel = (OBJModel) OBJLoader.INSTANCE.loadModel(MekanismUtils.getResource(ResourceType.MODEL, "transmitter_contents.obj")); - contentsMap = buildModelMap(contentsModel); } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException(e); } + contentsMap = buildModelMap(contentsModel); } } diff --git a/src/main/java/mekanism/client/sound/FlamethrowerSound.java b/src/main/java/mekanism/client/sound/FlamethrowerSound.java index 30c1371f5..73b0ac473 100644 --- a/src/main/java/mekanism/client/sound/FlamethrowerSound.java +++ b/src/main/java/mekanism/client/sound/FlamethrowerSound.java @@ -1,6 +1,7 @@ package mekanism.client.sound; import mekanism.client.ClientTickHandler; +import mekanism.common.Mekanism; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; @@ -9,9 +10,9 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class FlamethrowerSound extends PlayerSound { - private static ResourceLocation IDLE_SOUND = new ResourceLocation("mekanism", "item.flamethrower.idle"); - private static ResourceLocation ON_SOUND = new ResourceLocation("mekanism", "item.flamethrower.active"); - private static ResourceLocation OFF_SOUND = new ResourceLocation("mekanism", "item.flamethrower.active"); + private static ResourceLocation IDLE_SOUND = new ResourceLocation(Mekanism.MODID, "item.flamethrower.idle"); + private static ResourceLocation ON_SOUND = new ResourceLocation(Mekanism.MODID, "item.flamethrower.active"); + private static ResourceLocation OFF_SOUND = new ResourceLocation(Mekanism.MODID, "item.flamethrower.active"); private boolean inUse; diff --git a/src/main/java/mekanism/client/sound/GasMaskSound.java b/src/main/java/mekanism/client/sound/GasMaskSound.java index b620d6722..4f5e849b9 100644 --- a/src/main/java/mekanism/client/sound/GasMaskSound.java +++ b/src/main/java/mekanism/client/sound/GasMaskSound.java @@ -1,6 +1,7 @@ package mekanism.client.sound; import mekanism.client.ClientTickHandler; +import mekanism.common.Mekanism; import mekanism.common.item.ItemGasMask; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; @@ -10,7 +11,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GasMaskSound extends PlayerSound { - private static final ResourceLocation SOUND = new ResourceLocation("mekanism", "item.gasMask"); + private static final ResourceLocation SOUND = new ResourceLocation(Mekanism.MODID, "item.gasMask"); public GasMaskSound(EntityPlayer player) { super(player, SOUND); diff --git a/src/main/java/mekanism/client/sound/JetpackSound.java b/src/main/java/mekanism/client/sound/JetpackSound.java index 406538e54..a19044e83 100644 --- a/src/main/java/mekanism/client/sound/JetpackSound.java +++ b/src/main/java/mekanism/client/sound/JetpackSound.java @@ -1,6 +1,7 @@ package mekanism.client.sound; import mekanism.client.ClientTickHandler; +import mekanism.common.Mekanism; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; @@ -9,7 +10,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class JetpackSound extends PlayerSound { - private static final ResourceLocation SOUND = new ResourceLocation("mekanism", "item.jetpack"); + private static final ResourceLocation SOUND = new ResourceLocation(Mekanism.MODID, "item.jetpack"); public JetpackSound(EntityPlayer player) { super(player, SOUND); diff --git a/src/main/java/mekanism/client/sound/SoundHandler.java b/src/main/java/mekanism/client/sound/SoundHandler.java index ad36d42dc..d091486fc 100644 --- a/src/main/java/mekanism/client/sound/SoundHandler.java +++ b/src/main/java/mekanism/client/sound/SoundHandler.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import mekanism.common.Mekanism; import mekanism.common.Upgrade; import mekanism.common.base.IUpgradeTile; import mekanism.common.config.MekanismConfig; @@ -85,11 +86,15 @@ public class SoundHandler { if (s == null || !Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(s)) { // No sound playing, start one up - we assume that tile sounds will play until explicitly stopped s = new PositionedSoundRecord(soundLoc, SoundCategory.BLOCKS, (float) (volume * MekanismConfig.current().client.baseSoundVolume.val()), 1.0f, - true, 0, ISound.AttenuationType.LINEAR, pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f); - - // Force the underlying sound to get initialized - // TODO: Understand what this is doing exactly - s.createAccessor(Minecraft.getMinecraft().getSoundHandler()); + true, 0, ISound.AttenuationType.LINEAR, pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f) { + @Override + public float getVolume() { + if (this.sound == null) { + this.createAccessor(Minecraft.getMinecraft().getSoundHandler()); + } + return super.getVolume(); + } + }; // Start the sound playSound(s); @@ -123,7 +128,7 @@ public class SoundHandler { // Ignore any sound event outside this mod namespace ResourceLocation soundLoc = event.getSound().getSoundLocation(); - if (!soundLoc.getNamespace().equals("mekanism")) { + if (!soundLoc.getNamespace().equals(Mekanism.MODID)) { return; } diff --git a/src/main/java/mekanism/common/BoxBlacklistParser.java b/src/main/java/mekanism/common/BoxBlacklistParser.java index 615aaebaf..c4ec8c248 100644 --- a/src/main/java/mekanism/common/BoxBlacklistParser.java +++ b/src/main/java/mekanism/common/BoxBlacklistParser.java @@ -26,6 +26,7 @@ public final class BoxBlacklistParser { } } + @SuppressWarnings("ResultOfMethodCallIgnored") private static void generateFiles() throws IOException { mekanismDir.mkdirs(); if (!boxBlacklistFile.exists()) { diff --git a/src/main/java/mekanism/common/InfuseStorage.java b/src/main/java/mekanism/common/InfuseStorage.java index 263fc5937..723d4db5a 100644 --- a/src/main/java/mekanism/common/InfuseStorage.java +++ b/src/main/java/mekanism/common/InfuseStorage.java @@ -1,5 +1,6 @@ package mekanism.common; +import javax.annotation.Nonnull; import mekanism.api.infuse.InfuseObject; import mekanism.api.infuse.InfuseRegistry; import mekanism.api.infuse.InfuseType; @@ -21,6 +22,15 @@ public class InfuseStorage implements ISustainedData { amount = infuseAmount; } + /** + * Replace this instance's properties with that from another + * @param other the instance to copy from + */ + public void copyFrom(@Nonnull InfuseStorage other) { + this.type = other.getType(); + this.amount = other.getAmount(); + } + public boolean contains(InfuseStorage storage) { return type == storage.type && amount >= storage.amount; } diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 067bdec51..acadd8c49 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -785,13 +785,13 @@ public class Mekanism { Mekanism.proxy.preInit(); //Register infuses - InfuseRegistry.registerInfuseType(new InfuseType("CARBON", new ResourceLocation("mekanism:blocks/infuse/Carbon")).setTranslationKey("carbon")); - InfuseRegistry.registerInfuseType(new InfuseType("TIN", new ResourceLocation("mekanism:blocks/infuse/Tin")).setTranslationKey("tin")); - InfuseRegistry.registerInfuseType(new InfuseType("DIAMOND", new ResourceLocation("mekanism:blocks/infuse/Diamond")).setTranslationKey("diamond")); - InfuseRegistry.registerInfuseType(new InfuseType("REDSTONE", new ResourceLocation("mekanism:blocks/infuse/Redstone")).setTranslationKey("redstone")); - InfuseRegistry.registerInfuseType(new InfuseType("FUNGI", new ResourceLocation("mekanism:blocks/infuse/Fungi")).setTranslationKey("fungi")); - InfuseRegistry.registerInfuseType(new InfuseType("BIO", new ResourceLocation("mekanism:blocks/infuse/Bio")).setTranslationKey("bio")); - InfuseRegistry.registerInfuseType(new InfuseType("OBSIDIAN", new ResourceLocation("mekanism:blocks/infuse/Obsidian")).setTranslationKey("obsidian")); + InfuseRegistry.registerInfuseType(new InfuseType("CARBON", new ResourceLocation(Mekanism.MODID, "blocks/infuse/Carbon")).setTranslationKey("carbon")); + InfuseRegistry.registerInfuseType(new InfuseType("TIN", new ResourceLocation(Mekanism.MODID, "blocks/infuse/Tin")).setTranslationKey("tin")); + InfuseRegistry.registerInfuseType(new InfuseType("DIAMOND", new ResourceLocation(Mekanism.MODID, "blocks/infuse/Diamond")).setTranslationKey("diamond")); + InfuseRegistry.registerInfuseType(new InfuseType("REDSTONE", new ResourceLocation(Mekanism.MODID, "blocks/infuse/Redstone")).setTranslationKey("redstone")); + InfuseRegistry.registerInfuseType(new InfuseType("FUNGI", new ResourceLocation(Mekanism.MODID, "blocks/infuse/Fungi")).setTranslationKey("fungi")); + InfuseRegistry.registerInfuseType(new InfuseType("BIO", new ResourceLocation(Mekanism.MODID, "blocks/infuse/Bio")).setTranslationKey("bio")); + InfuseRegistry.registerInfuseType(new InfuseType("OBSIDIAN", new ResourceLocation(Mekanism.MODID, "blocks/infuse/Obsidian")).setTranslationKey("obsidian")); Capabilities.registerCapabilities(); @@ -1005,7 +1005,7 @@ public class Mekanism { @SubscribeEvent public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { - if (event.getModID().equals("mekanism")) { + if (event.getModID().equals(Mekanism.MODID)) { proxy.loadConfiguration(); proxy.onConfigSync(false); } diff --git a/src/main/java/mekanism/common/MekanismFluids.java b/src/main/java/mekanism/common/MekanismFluids.java index 6a546d587..90b217981 100644 --- a/src/main/java/mekanism/common/MekanismFluids.java +++ b/src/main/java/mekanism/common/MekanismFluids.java @@ -19,10 +19,10 @@ public class MekanismFluids { public static final Gas SulfuricAcid = new Gas("sulfuricacid", 0x82802B); public static final Gas HydrogenChloride = new Gas("hydrogenchloride", 0xA8F1E9); - public static final Fluid HeavyWater = new Fluid("heavywater", new ResourceLocation("mekanism:blocks/liquid/LiquidHeavyWater"), - new ResourceLocation("mekanism:blocks/liquid/LiquidHeavyWater")); - public static final Fluid Steam = new Fluid("steam", new ResourceLocation("mekanism:blocks/liquid/LiquidSteam"), - new ResourceLocation("mekanism:blocks/liquid/LiquidSteam")).setGaseous(true); + public static final Fluid HeavyWater = new Fluid("heavywater", new ResourceLocation(Mekanism.MODID, "blocks/liquid/LiquidHeavyWater"), + new ResourceLocation(Mekanism.MODID, "blocks/liquid/LiquidHeavyWater")); + public static final Fluid Steam = new Fluid("steam", new ResourceLocation(Mekanism.MODID, "blocks/liquid/LiquidSteam"), + new ResourceLocation(Mekanism.MODID, "blocks/liquid/LiquidSteam")).setGaseous(true); //Internal gases public static final Gas LiquidOsmium = new Gas("liquidosmium", 0x52bdca); diff --git a/src/main/java/mekanism/common/PacketHandler.java b/src/main/java/mekanism/common/PacketHandler.java index 8a6c8ddaf..8a5c44df3 100644 --- a/src/main/java/mekanism/common/PacketHandler.java +++ b/src/main/java/mekanism/common/PacketHandler.java @@ -97,48 +97,44 @@ public class PacketHandler { * @param output - the output stream to write to */ public static void encode(Object[] dataValues, ByteBuf output) { - try { - for (Object data : dataValues) { - if (data instanceof Byte) { - output.writeByte((Byte) data); - } else if (data instanceof Integer) { - output.writeInt((Integer) data); - } else if (data instanceof Short) { - output.writeShort((Short) data); - } else if (data instanceof Long) { - output.writeLong((Long) data); - } else if (data instanceof Boolean) { - output.writeBoolean((Boolean) data); - } else if (data instanceof Double) { - output.writeDouble((Double) data); - } else if (data instanceof Float) { - output.writeFloat((Float) data); - } else if (data instanceof String) { - writeString(output, (String) data); - } else if (data instanceof EnumFacing) { - output.writeInt(((EnumFacing) data).ordinal()); - } else if (data instanceof ItemStack) { - writeStack(output, (ItemStack) data); - } else if (data instanceof NBTTagCompound) { - writeNBT(output, (NBTTagCompound) data); - } else if (data instanceof int[]) { - for (int i : (int[]) data) { - output.writeInt(i); - } - } else if (data instanceof byte[]) { - for (byte b : (byte[]) data) { - output.writeByte(b); - } - } else if (data instanceof ArrayList) { - encode(((ArrayList) data).toArray(), output); - } else if (data instanceof NonNullList) { - encode(((NonNullList) data).toArray(), output); - } else { - throw new RuntimeException("Un-encodable data passed to encode(): " + data + ", full data: " + Arrays.toString(dataValues)); + for (Object data : dataValues) { + if (data instanceof Byte) { + output.writeByte((Byte) data); + } else if (data instanceof Integer) { + output.writeInt((Integer) data); + } else if (data instanceof Short) { + output.writeShort((Short) data); + } else if (data instanceof Long) { + output.writeLong((Long) data); + } else if (data instanceof Boolean) { + output.writeBoolean((Boolean) data); + } else if (data instanceof Double) { + output.writeDouble((Double) data); + } else if (data instanceof Float) { + output.writeFloat((Float) data); + } else if (data instanceof String) { + writeString(output, (String) data); + } else if (data instanceof EnumFacing) { + output.writeInt(((EnumFacing) data).ordinal()); + } else if (data instanceof ItemStack) { + writeStack(output, (ItemStack) data); + } else if (data instanceof NBTTagCompound) { + writeNBT(output, (NBTTagCompound) data); + } else if (data instanceof int[]) { + for (int i : (int[]) data) { + output.writeInt(i); } + } else if (data instanceof byte[]) { + for (byte b : (byte[]) data) { + output.writeByte(b); + } + } else if (data instanceof ArrayList) { + encode(((ArrayList) data).toArray(), output); + } else if (data instanceof NonNullList) { + encode(((NonNullList) data).toArray(), output); + } else { + throw new RuntimeException("Un-encodable data passed to encode(): " + data + ", full data: " + Arrays.toString(dataValues)); } - } catch (Exception e) { - Mekanism.logger.error("Error while encoding packet data.", e); } } diff --git a/src/main/java/mekanism/common/base/IFactory.java b/src/main/java/mekanism/common/base/IFactory.java index 98ad6107a..391d05f8f 100644 --- a/src/main/java/mekanism/common/base/IFactory.java +++ b/src/main/java/mekanism/common/base/IFactory.java @@ -7,6 +7,7 @@ import javax.annotation.Nullable; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; import mekanism.common.InfuseStorage; +import mekanism.common.Mekanism; import mekanism.common.block.states.BlockStateMachine.MachineType; import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler.Recipe; @@ -92,7 +93,7 @@ public interface IFactory { RecipeType(String s, String s1, MachineType t, MachineFuelType ft, boolean b1, Recipe r) { name = s; - sound = new SoundEvent(new ResourceLocation("mekanism", "tile.machine." + s1)); + sound = new SoundEvent(new ResourceLocation(Mekanism.MODID, "tile.machine." + s1)); type = t; fuelType = ft; fuelSpeed = b1; diff --git a/src/main/java/mekanism/common/block/BlockBasic.java b/src/main/java/mekanism/common/block/BlockBasic.java index d72669d42..9763f81a0 100644 --- a/src/main/java/mekanism/common/block/BlockBasic.java +++ b/src/main/java/mekanism/common/block/BlockBasic.java @@ -1,5 +1,6 @@ package mekanism.common.block; +import java.util.Objects; import java.util.UUID; import javax.annotation.Nonnull; import mekanism.api.Coord4D; @@ -517,7 +518,7 @@ public abstract class BlockBasic extends BlockTileDrops { @Override public boolean hasTileEntity(IBlockState state) { BasicBlockType type = BasicBlockType.get(state); - return type != null && type.tileEntityClass != null; + return type != null && type.tileEntitySupplier != null; } @Override @@ -525,13 +526,14 @@ public abstract class BlockBasic extends BlockTileDrops { if (BasicBlockType.get(state) == null) { return null; } - return BasicBlockType.get(state).create(); + return Objects.requireNonNull(BasicBlockType.get(state)).create(); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { - if (world.getTileEntity(pos) instanceof TileEntityBasicBlock) { - TileEntityBasicBlock tileEntity = (TileEntityBasicBlock) world.getTileEntity(pos); + TileEntity te = world.getTileEntity(pos); + if (te instanceof TileEntityBasicBlock) { + TileEntityBasicBlock tileEntity = (TileEntityBasicBlock) te; int side = MathHelper.floor((placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; int height = Math.round(placer.rotationPitch); int change = 3; @@ -573,13 +575,12 @@ public abstract class BlockBasic extends BlockTileDrops { world.checkLightFor(EnumSkyBlock.BLOCK, pos); world.checkLightFor(EnumSkyBlock.SKY, pos); - if (!world.isRemote && world.getTileEntity(pos) != null) { - TileEntity tileEntity = world.getTileEntity(pos); - if (tileEntity instanceof IMultiblock) { - ((IMultiblock) tileEntity).doUpdate(); + if (!world.isRemote && te != null) { + if (te instanceof IMultiblock) { + ((IMultiblock) te).doUpdate(); } - if (tileEntity instanceof IStructuralMultiblock) { - ((IStructuralMultiblock) tileEntity).doUpdate(); + if (te instanceof IStructuralMultiblock) { + ((IStructuralMultiblock) te).doUpdate(); } } } diff --git a/src/main/java/mekanism/common/block/BlockEnergyCube.java b/src/main/java/mekanism/common/block/BlockEnergyCube.java index cffa00e9f..18ca86336 100644 --- a/src/main/java/mekanism/common/block/BlockEnergyCube.java +++ b/src/main/java/mekanism/common/block/BlockEnergyCube.java @@ -232,9 +232,8 @@ public class BlockEnergyCube extends BlockMekanismContainer { securityItem.setOwnerUUID(itemStack, ((ISecurityTile) tileEntity).getSecurity().getOwnerUUID()); securityItem.setSecurity(itemStack, ((ISecurityTile) tileEntity).getSecurity().getMode()); } - ISideConfiguration config = tileEntity; - config.getConfig().write(ItemDataUtils.getDataMap(itemStack)); - config.getEjector().write(ItemDataUtils.getDataMap(itemStack)); + ((ISideConfiguration) tileEntity).getConfig().write(ItemDataUtils.getDataMap(itemStack)); + ((ISideConfiguration) tileEntity).getEjector().write(ItemDataUtils.getDataMap(itemStack)); } ITierItem tierItem = (ITierItem) itemStack.getItem(); diff --git a/src/main/java/mekanism/common/block/BlockGasTank.java b/src/main/java/mekanism/common/block/BlockGasTank.java index 1e2b0f636..8e59233b1 100644 --- a/src/main/java/mekanism/common/block/BlockGasTank.java +++ b/src/main/java/mekanism/common/block/BlockGasTank.java @@ -207,9 +207,8 @@ public class BlockGasTank extends BlockMekanismContainer { securityItem.setOwnerUUID(itemStack, ((ISecurityTile) tileEntity).getSecurity().getOwnerUUID()); securityItem.setSecurity(itemStack, ((ISecurityTile) tileEntity).getSecurity().getMode()); } - ISideConfiguration config = tileEntity; - config.getConfig().write(ItemDataUtils.getDataMap(itemStack)); - config.getEjector().write(ItemDataUtils.getDataMap(itemStack)); + ((ISideConfiguration) tileEntity).getConfig().write(ItemDataUtils.getDataMap(itemStack)); + ((ISideConfiguration) tileEntity).getEjector().write(ItemDataUtils.getDataMap(itemStack)); } ITierItem tierItem = (ITierItem) itemStack.getItem(); tierItem.setBaseTier(itemStack, tileEntity.tier.getBaseTier()); diff --git a/src/main/java/mekanism/common/block/BlockPlasticFence.java b/src/main/java/mekanism/common/block/BlockPlasticFence.java index 5662caec6..7f9915a06 100644 --- a/src/main/java/mekanism/common/block/BlockPlasticFence.java +++ b/src/main/java/mekanism/common/block/BlockPlasticFence.java @@ -63,7 +63,7 @@ public class BlockPlasticFence extends BlockFence { properties += "north=" + state.getValue(NORTH) + ","; properties += "south=" + state.getValue(SOUTH) + ","; properties += "west=" + state.getValue(WEST); - ResourceLocation baseLocation = new ResourceLocation("mekanism", "PlasticFence"); + ResourceLocation baseLocation = new ResourceLocation(Mekanism.MODID, "PlasticFence"); return new ModelResourceLocation(baseLocation, properties); } } diff --git a/src/main/java/mekanism/common/block/states/BlockStateBasic.java b/src/main/java/mekanism/common/block/states/BlockStateBasic.java index fb32697b9..095fd153a 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateBasic.java +++ b/src/main/java/mekanism/common/block/states/BlockStateBasic.java @@ -1,8 +1,9 @@ package mekanism.common.block.states; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import java.util.Locale; +import java.util.Objects; +import java.util.function.Predicate; +import java.util.function.Supplier; import javax.annotation.Nonnull; import javax.annotation.Nullable; import mekanism.common.Mekanism; @@ -59,7 +60,7 @@ public class BlockStateBasic extends ExtendedBlockState { public PropertyEnum getProperty() { if (predicatedProperty == null) { - predicatedProperty = PropertyEnum.create("type", BasicBlockType.class, new BasicBlockPredicate(this)); + predicatedProperty = PropertyEnum.create("type", BasicBlockType.class, it->Objects.requireNonNull(it).blockType==this); } return predicatedProperty; } @@ -71,70 +72,62 @@ public class BlockStateBasic extends ExtendedBlockState { case BASIC_BLOCK_2: return MekanismBlocks.BasicBlock2; default: - return null; + throw new IllegalStateException(); } } } public enum BasicBlockType implements IStringSerializable { - OSMIUM_BLOCK(BasicBlock.BASIC_BLOCK_1, 0, "OsmiumBlock", null, false, Predicates.alwaysFalse(), false, false, true), - BRONZE_BLOCK(BasicBlock.BASIC_BLOCK_1, 1, "BronzeBlock", null, false, Predicates.alwaysFalse(), false, false, true), - REFINED_OBSIDIAN(BasicBlock.BASIC_BLOCK_1, 2, "RefinedObsidian", null, false, Predicates.alwaysFalse(), false, false, true), - COAL_BLOCK(BasicBlock.BASIC_BLOCK_1, 3, "CharcoalBlock", null, false, Predicates.alwaysFalse(), false, false, false), - REFINED_GLOWSTONE(BasicBlock.BASIC_BLOCK_1, 4, "RefinedGlowstone", null, false, Predicates.alwaysFalse(), false, false, true), - STEEL_BLOCK(BasicBlock.BASIC_BLOCK_1, 5, "SteelBlock", null, false, Predicates.alwaysFalse(), false, false, true), - BIN(BasicBlock.BASIC_BLOCK_1, 6, "Bin", TileEntityBin.class, true, Plane.HORIZONTAL, true, true, false, true), - TELEPORTER_FRAME(BasicBlock.BASIC_BLOCK_1, 7, "TeleporterFrame", null, true, Predicates.alwaysFalse(), false, false, false), - STEEL_CASING(BasicBlock.BASIC_BLOCK_1, 8, "SteelCasing", null, true, Predicates.alwaysFalse(), false, false, false), - DYNAMIC_TANK(BasicBlock.BASIC_BLOCK_1, 9, "DynamicTank", TileEntityDynamicTank.class, true, Predicates.alwaysFalse(), false, false, false), - STRUCTURAL_GLASS(BasicBlock.BASIC_BLOCK_1, 10, "StructuralGlass", TileEntityStructuralGlass.class, true, Predicates.alwaysFalse(), false, false, false), - DYNAMIC_VALVE(BasicBlock.BASIC_BLOCK_1, 11, "DynamicValve", TileEntityDynamicValve.class, true, Predicates.alwaysFalse(), false, false, false), - COPPER_BLOCK(BasicBlock.BASIC_BLOCK_1, 12, "CopperBlock", null, false, Predicates.alwaysFalse(), false, false, true), - TIN_BLOCK(BasicBlock.BASIC_BLOCK_1, 13, "TinBlock", null, false, Predicates.alwaysFalse(), false, false, true), - THERMAL_EVAPORATION_CONTROLLER(BasicBlock.BASIC_BLOCK_1, 14, "ThermalEvaporationController", TileEntityThermalEvaporationController.class, true, Plane.HORIZONTAL, true, false, false), - THERMAL_EVAPORATION_VALVE(BasicBlock.BASIC_BLOCK_1, 15, "ThermalEvaporationValve", TileEntityThermalEvaporationValve.class, true, Predicates.alwaysFalse(), false, false, false), - THERMAL_EVAPORATION_BLOCK(BasicBlock.BASIC_BLOCK_2, 0, "ThermalEvaporationBlock", TileEntityThermalEvaporationBlock.class, true, Predicates.alwaysFalse(), false, false, false), - INDUCTION_CASING(BasicBlock.BASIC_BLOCK_2, 1, "InductionCasing", TileEntityInductionCasing.class, true, Predicates.alwaysFalse(), false, false, false), - INDUCTION_PORT(BasicBlock.BASIC_BLOCK_2, 2, "InductionPort", TileEntityInductionPort.class, true, Predicates.alwaysFalse(), true, false, false), - INDUCTION_CELL(BasicBlock.BASIC_BLOCK_2, 3, "InductionCell", TileEntityInductionCell.class, true, Predicates.alwaysFalse(), false, true, false), - INDUCTION_PROVIDER(BasicBlock.BASIC_BLOCK_2, 4, "InductionProvider", TileEntityInductionProvider.class, true, Predicates.alwaysFalse(), false, true, false), - SUPERHEATING_ELEMENT(BasicBlock.BASIC_BLOCK_2, 5, "SuperheatingElement", TileEntitySuperheatingElement.class, true, Predicates.alwaysFalse(), false, false, false), - PRESSURE_DISPERSER(BasicBlock.BASIC_BLOCK_2, 6, "PressureDisperser", TileEntityPressureDisperser.class, true, Predicates.alwaysFalse(), false, false, false), - BOILER_CASING(BasicBlock.BASIC_BLOCK_2, 7, "BoilerCasing", TileEntityBoilerCasing.class, true, Predicates.alwaysFalse(), false, false, false), - BOILER_VALVE(BasicBlock.BASIC_BLOCK_2, 8, "BoilerValve", TileEntityBoilerValve.class, true, Predicates.alwaysFalse(), false, false, false), - SECURITY_DESK(BasicBlock.BASIC_BLOCK_2, 9, "SecurityDesk", TileEntitySecurityDesk.class, true, Plane.HORIZONTAL, false, false, false); + OSMIUM_BLOCK(BasicBlock.BASIC_BLOCK_1, 0, "OsmiumBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + BRONZE_BLOCK(BasicBlock.BASIC_BLOCK_1, 1, "BronzeBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + REFINED_OBSIDIAN(BasicBlock.BASIC_BLOCK_1, 2, "RefinedObsidian", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + COAL_BLOCK(BasicBlock.BASIC_BLOCK_1, 3, "CharcoalBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, false), + REFINED_GLOWSTONE(BasicBlock.BASIC_BLOCK_1, 4, "RefinedGlowstone", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + STEEL_BLOCK(BasicBlock.BASIC_BLOCK_1, 5, "SteelBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + BIN(BasicBlock.BASIC_BLOCK_1, 6, "Bin", TileEntityBin::new, true, Plane.HORIZONTAL, true, true, false, true), + TELEPORTER_FRAME(BasicBlock.BASIC_BLOCK_1, 7, "TeleporterFrame", null, true, BlockStateUtils.NO_ROTATION, false, false, false), + STEEL_CASING(BasicBlock.BASIC_BLOCK_1, 8, "SteelCasing", null, true, BlockStateUtils.NO_ROTATION, false, false, false), + DYNAMIC_TANK(BasicBlock.BASIC_BLOCK_1, 9, "DynamicTank", TileEntityDynamicTank::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + STRUCTURAL_GLASS(BasicBlock.BASIC_BLOCK_1, 10, "StructuralGlass", TileEntityStructuralGlass::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + DYNAMIC_VALVE(BasicBlock.BASIC_BLOCK_1, 11, "DynamicValve", TileEntityDynamicValve::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + COPPER_BLOCK(BasicBlock.BASIC_BLOCK_1, 12, "CopperBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + TIN_BLOCK(BasicBlock.BASIC_BLOCK_1, 13, "TinBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + THERMAL_EVAPORATION_CONTROLLER(BasicBlock.BASIC_BLOCK_1, 14, "ThermalEvaporationController", TileEntityThermalEvaporationController::new, true, Plane.HORIZONTAL, true, false, false), + THERMAL_EVAPORATION_VALVE(BasicBlock.BASIC_BLOCK_1, 15, "ThermalEvaporationValve", TileEntityThermalEvaporationValve::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + THERMAL_EVAPORATION_BLOCK(BasicBlock.BASIC_BLOCK_2, 0, "ThermalEvaporationBlock", TileEntityThermalEvaporationBlock::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + INDUCTION_CASING(BasicBlock.BASIC_BLOCK_2, 1, "InductionCasing", TileEntityInductionCasing::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + INDUCTION_PORT(BasicBlock.BASIC_BLOCK_2, 2, "InductionPort", TileEntityInductionPort::new, true, BlockStateUtils.NO_ROTATION, true, false, false), + INDUCTION_CELL(BasicBlock.BASIC_BLOCK_2, 3, "InductionCell", TileEntityInductionCell::new, true, BlockStateUtils.NO_ROTATION, false, true, false), + INDUCTION_PROVIDER(BasicBlock.BASIC_BLOCK_2, 4, "InductionProvider", TileEntityInductionProvider::new, true, BlockStateUtils.NO_ROTATION, false, true, false), + SUPERHEATING_ELEMENT(BasicBlock.BASIC_BLOCK_2, 5, "SuperheatingElement", TileEntitySuperheatingElement::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + PRESSURE_DISPERSER(BasicBlock.BASIC_BLOCK_2, 6, "PressureDisperser", TileEntityPressureDisperser::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + BOILER_CASING(BasicBlock.BASIC_BLOCK_2, 7, "BoilerCasing", TileEntityBoilerCasing::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + BOILER_VALVE(BasicBlock.BASIC_BLOCK_2, 8, "BoilerValve", TileEntityBoilerValve::new, true, BlockStateUtils.NO_ROTATION, false, false, false), + SECURITY_DESK(BasicBlock.BASIC_BLOCK_2, 9, "SecurityDesk", TileEntitySecurityDesk::new, true, Plane.HORIZONTAL, false, false, false); + @Nonnull public BasicBlock blockType; public int meta; public String name; - public Class tileEntityClass; - public boolean isElectric; + public Supplier tileEntitySupplier; public boolean hasDescription; public Predicate facingPredicate; public boolean activable; public boolean tiers; public boolean isBeaconBase; - public boolean hasRedstoneOutput = false; + public boolean hasRedstoneOutput; - BasicBlockType(BasicBlock block, int metadata, String s, Class tileClass, boolean hasDesc, Predicate facingAllowed, + BasicBlockType(@Nonnull BasicBlock block, int metadata, String s, Supplier tileClass, boolean hasDesc, Predicate facingAllowed, boolean activeState, boolean t, boolean beaconBase) { - blockType = block; - meta = metadata; - name = s; - tileEntityClass = tileClass; - hasDescription = hasDesc; - facingPredicate = facingAllowed; - activable = activeState; - tiers = t; - isBeaconBase = beaconBase; + this(block, metadata, s, tileClass, hasDesc, facingAllowed, activeState, t, beaconBase, false); } - BasicBlockType(BasicBlock block, int metadata, String s, Class tileClass, boolean hasDesc, Predicate facingAllowed, + BasicBlockType(@Nonnull BasicBlock block, int metadata, String s, Supplier tileClass, boolean hasDesc, Predicate facingAllowed, boolean activeState, boolean t, boolean beaconBase, boolean hasRedstoneOutput) { blockType = block; meta = metadata; name = s; - tileEntityClass = tileClass; + tileEntitySupplier = tileClass; hasDescription = hasDesc; facingPredicate = facingAllowed; activable = activeState; @@ -183,12 +176,7 @@ public class BlockStateBasic extends ExtendedBlockState { } public TileEntity create() { - try { - return tileEntityClass.newInstance(); - } catch (Exception e) { - Mekanism.logger.error("Unable to indirectly create tile entity.", e); - return null; - } + return this.tileEntitySupplier != null ? this.tileEntitySupplier.get() : null; } @Override @@ -205,11 +193,11 @@ public class BlockStateBasic extends ExtendedBlockState { } public boolean canRotateTo(EnumFacing side) { - return facingPredicate.apply(side); + return facingPredicate.test(side); } public boolean hasRotations() { - return !facingPredicate.equals(Predicates.alwaysFalse()); + return !facingPredicate.equals(BlockStateUtils.NO_ROTATION); } public boolean hasActiveTexture() { @@ -217,20 +205,6 @@ public class BlockStateBasic extends ExtendedBlockState { } } - public static class BasicBlockPredicate implements Predicate { - - public BasicBlock basicBlock; - - public BasicBlockPredicate(BasicBlock type) { - basicBlock = type; - } - - @Override - public boolean apply(BasicBlockType input) { - return input.blockType == basicBlock; - } - } - public static class BasicBlockStateMapper extends StateMapperBase { @Nonnull @@ -274,7 +248,7 @@ public class BlockStateBasic extends ExtendedBlockState { if (builder.length() == 0) { builder.append("normal"); } - ResourceLocation baseLocation = new ResourceLocation("mekanism", nameOverride != null ? nameOverride : type.getName()); + ResourceLocation baseLocation = new ResourceLocation(Mekanism.MODID, nameOverride != null ? nameOverride : type.getName()); return new ModelResourceLocation(baseLocation, builder.toString()); } } diff --git a/src/main/java/mekanism/common/block/states/BlockStateCardboardBox.java b/src/main/java/mekanism/common/block/states/BlockStateCardboardBox.java index c26ba5262..630e7672a 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateCardboardBox.java +++ b/src/main/java/mekanism/common/block/states/BlockStateCardboardBox.java @@ -1,6 +1,7 @@ package mekanism.common.block.states; import javax.annotation.Nonnull; +import mekanism.common.Mekanism; import mekanism.common.block.BlockCardboardBox; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockStateContainer; @@ -23,7 +24,7 @@ public class BlockStateCardboardBox extends BlockStateContainer { @Override protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState state) { String property = "storage=" + state.getValue(storageProperty); - ResourceLocation baseLocation = new ResourceLocation("mekanism", "CardboardBox"); + ResourceLocation baseLocation = new ResourceLocation(Mekanism.MODID, "CardboardBox"); return new ModelResourceLocation(baseLocation, property); } } diff --git a/src/main/java/mekanism/common/block/states/BlockStateMachine.java b/src/main/java/mekanism/common/block/states/BlockStateMachine.java index 129cb9296..49374cbe5 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateMachine.java +++ b/src/main/java/mekanism/common/block/states/BlockStateMachine.java @@ -1,11 +1,11 @@ package mekanism.common.block.states; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.function.Predicate; +import java.util.function.Supplier; import javax.annotation.Nonnull; import mekanism.common.Mekanism; import mekanism.common.MekanismBlocks; @@ -90,7 +90,7 @@ public class BlockStateMachine extends ExtendedBlockState { public PropertyEnum getProperty() { if (machineTypeProperty == null) { - machineTypeProperty = PropertyEnum.create("type", MachineType.class, new MachineBlockPredicate(this)); + machineTypeProperty = PropertyEnum.create("type", MachineType.class, input-> input != null && input.typeBlock == this && input.isValidMachine()); } return machineTypeProperty; } @@ -110,51 +110,51 @@ public class BlockStateMachine extends ExtendedBlockState { } public enum MachineType implements IStringSerializable, IBlockType { - ENRICHMENT_CHAMBER(MachineBlock.MACHINE_BLOCK_1, 0, "EnrichmentChamber", 3, TileEntityEnrichmentChamber.class, true, false, true, Plane.HORIZONTAL, true), - OSMIUM_COMPRESSOR(MachineBlock.MACHINE_BLOCK_1, 1, "OsmiumCompressor", 4, TileEntityOsmiumCompressor.class, true, false, true, Plane.HORIZONTAL, true), - COMBINER(MachineBlock.MACHINE_BLOCK_1, 2, "Combiner", 5, TileEntityCombiner.class, true, false, true, Plane.HORIZONTAL, true), - CRUSHER(MachineBlock.MACHINE_BLOCK_1, 3, "Crusher", 6, TileEntityCrusher.class, true, false, true, Plane.HORIZONTAL, true), - DIGITAL_MINER(MachineBlock.MACHINE_BLOCK_1, 4, "DigitalMiner", 2, TileEntityDigitalMiner.class, true, true, true, Plane.HORIZONTAL, true), - BASIC_FACTORY(MachineBlock.MACHINE_BLOCK_1, 5, "Factory", 11, TileEntityFactory.class, true, false, true, Plane.HORIZONTAL, true, FactoryTier.BASIC), - ADVANCED_FACTORY(MachineBlock.MACHINE_BLOCK_1, 6, "Factory", 11, TileEntityAdvancedFactory.class, true, false, true, Plane.HORIZONTAL, true, FactoryTier.ADVANCED), - ELITE_FACTORY(MachineBlock.MACHINE_BLOCK_1, 7, "Factory", 11, TileEntityEliteFactory.class, true, false, true, Plane.HORIZONTAL, true, FactoryTier.ELITE), - METALLURGIC_INFUSER(MachineBlock.MACHINE_BLOCK_1, 8, "MetallurgicInfuser", 12, TileEntityMetallurgicInfuser.class, true, true, true, Plane.HORIZONTAL, false), - PURIFICATION_CHAMBER(MachineBlock.MACHINE_BLOCK_1, 9, "PurificationChamber", 15, TileEntityPurificationChamber.class, true, false, true, Plane.HORIZONTAL, true), - ENERGIZED_SMELTER(MachineBlock.MACHINE_BLOCK_1, 10, "EnergizedSmelter", 16, TileEntityEnergizedSmelter.class, true, false, true, Plane.HORIZONTAL, true), - TELEPORTER(MachineBlock.MACHINE_BLOCK_1, 11, "Teleporter", 13, TileEntityTeleporter.class, true, false, false, Predicates.alwaysFalse(), false), - ELECTRIC_PUMP(MachineBlock.MACHINE_BLOCK_1, 12, "ElectricPump", 17, TileEntityElectricPump.class, true, true, false, Plane.HORIZONTAL, false), - PERSONAL_CHEST(MachineBlock.MACHINE_BLOCK_1, 13, "PersonalChest", -1, TileEntityPersonalChest.class, true, true, false, Plane.HORIZONTAL, false), - CHARGEPAD(MachineBlock.MACHINE_BLOCK_1, 14, "Chargepad", -1, TileEntityChargepad.class, true, true, false, Plane.HORIZONTAL, false), - LOGISTICAL_SORTER(MachineBlock.MACHINE_BLOCK_1, 15, "LogisticalSorter", 59, TileEntityLogisticalSorter.class, false, true, false, Predicates.alwaysTrue(), true), - ROTARY_CONDENSENTRATOR(MachineBlock.MACHINE_BLOCK_2, 0, "RotaryCondensentrator", 7, TileEntityRotaryCondensentrator.class, true, true, false, Plane.HORIZONTAL, false), - CHEMICAL_OXIDIZER(MachineBlock.MACHINE_BLOCK_2, 1, "ChemicalOxidizer", 29, TileEntityChemicalOxidizer.class, true, true, true, Plane.HORIZONTAL, true), - CHEMICAL_INFUSER(MachineBlock.MACHINE_BLOCK_2, 2, "ChemicalInfuser", 30, TileEntityChemicalInfuser.class, true, true, false, Plane.HORIZONTAL, true), - CHEMICAL_INJECTION_CHAMBER(MachineBlock.MACHINE_BLOCK_2, 3, "ChemicalInjectionChamber", 31, TileEntityChemicalInjectionChamber.class, true, false, true, Plane.HORIZONTAL, true), - ELECTROLYTIC_SEPARATOR(MachineBlock.MACHINE_BLOCK_2, 4, "ElectrolyticSeparator", 32, TileEntityElectrolyticSeparator.class, true, true, false, Plane.HORIZONTAL, true), - PRECISION_SAWMILL(MachineBlock.MACHINE_BLOCK_2, 5, "PrecisionSawmill", 34, TileEntityPrecisionSawmill.class, true, false, true, Plane.HORIZONTAL, true), - CHEMICAL_DISSOLUTION_CHAMBER(MachineBlock.MACHINE_BLOCK_2, 6, "ChemicalDissolutionChamber", 35, TileEntityChemicalDissolutionChamber.class, true, true, true, Plane.HORIZONTAL, true), - CHEMICAL_WASHER(MachineBlock.MACHINE_BLOCK_2, 7, "ChemicalWasher", 36, TileEntityChemicalWasher.class, true, true, false, Plane.HORIZONTAL, true), - CHEMICAL_CRYSTALLIZER(MachineBlock.MACHINE_BLOCK_2, 8, "ChemicalCrystallizer", 37, TileEntityChemicalCrystallizer.class, true, true, true, Plane.HORIZONTAL, true), - SEISMIC_VIBRATOR(MachineBlock.MACHINE_BLOCK_2, 9, "SeismicVibrator", 39, TileEntitySeismicVibrator.class, true, true, false, Plane.HORIZONTAL, true), - PRESSURIZED_REACTION_CHAMBER(MachineBlock.MACHINE_BLOCK_2, 10, "PressurizedReactionChamber", 40, TileEntityPRC.class, true, true, false, Plane.HORIZONTAL, true), - FLUID_TANK(MachineBlock.MACHINE_BLOCK_2, 11, "FluidTank", 41, TileEntityFluidTank.class, false, true, false, Predicates.alwaysFalse(), true), - FLUIDIC_PLENISHER(MachineBlock.MACHINE_BLOCK_2, 12, "FluidicPlenisher", 42, TileEntityFluidicPlenisher.class, true, true, false, Plane.HORIZONTAL, true), - LASER(MachineBlock.MACHINE_BLOCK_2, 13, "Laser", -1, TileEntityLaser.class, true, true, false, Predicates.alwaysTrue(), false), - LASER_AMPLIFIER(MachineBlock.MACHINE_BLOCK_2, 14, "LaserAmplifier", 44, TileEntityLaserAmplifier.class, false, true, false, Predicates.alwaysTrue(), true), - LASER_TRACTOR_BEAM(MachineBlock.MACHINE_BLOCK_2, 15, "LaserTractorBeam", 45, TileEntityLaserTractorBeam.class, false, true, false, Predicates.alwaysTrue(), true), - QUANTUM_ENTANGLOPORTER(MachineBlock.MACHINE_BLOCK_3, 0, "QuantumEntangloporter", 46, TileEntityQuantumEntangloporter.class, true, false, false, Predicates.alwaysTrue(), false), - SOLAR_NEUTRON_ACTIVATOR(MachineBlock.MACHINE_BLOCK_3, 1, "SolarNeutronActivator", 47, TileEntitySolarNeutronActivator.class, false, true, false, Plane.HORIZONTAL, true), - AMBIENT_ACCUMULATOR(MachineBlock.MACHINE_BLOCK_3, 2, "AmbientAccumulator", 48, TileEntityAmbientAccumulator.class, true, false, false, Predicates.alwaysFalse(), true), - OREDICTIONIFICATOR(MachineBlock.MACHINE_BLOCK_3, 3, "Oredictionificator", 52, TileEntityOredictionificator.class, false, false, false, Plane.HORIZONTAL, true), - RESISTIVE_HEATER(MachineBlock.MACHINE_BLOCK_3, 4, "ResistiveHeater", 53, TileEntityResistiveHeater.class, true, false, false, Plane.HORIZONTAL, true), - FORMULAIC_ASSEMBLICATOR(MachineBlock.MACHINE_BLOCK_3, 5, "FormulaicAssemblicator", 56, TileEntityFormulaicAssemblicator.class, true, false, true, Plane.HORIZONTAL, true), - FUELWOOD_HEATER(MachineBlock.MACHINE_BLOCK_3, 6, "FuelwoodHeater", 58, TileEntityFuelwoodHeater.class, false, false, false, Plane.HORIZONTAL, true); + ENRICHMENT_CHAMBER(MachineBlock.MACHINE_BLOCK_1, 0, "EnrichmentChamber", 3, TileEntityEnrichmentChamber::new, true, false, true, Plane.HORIZONTAL, true), + OSMIUM_COMPRESSOR(MachineBlock.MACHINE_BLOCK_1, 1, "OsmiumCompressor", 4, TileEntityOsmiumCompressor::new, true, false, true, Plane.HORIZONTAL, true), + COMBINER(MachineBlock.MACHINE_BLOCK_1, 2, "Combiner", 5, TileEntityCombiner::new, true, false, true, Plane.HORIZONTAL, true), + CRUSHER(MachineBlock.MACHINE_BLOCK_1, 3, "Crusher", 6, TileEntityCrusher::new, true, false, true, Plane.HORIZONTAL, true), + DIGITAL_MINER(MachineBlock.MACHINE_BLOCK_1, 4, "DigitalMiner", 2, TileEntityDigitalMiner::new, true, true, true, Plane.HORIZONTAL, true), + BASIC_FACTORY(MachineBlock.MACHINE_BLOCK_1, 5, "Factory", 11, TileEntityFactory::new, true, false, true, Plane.HORIZONTAL, true, FactoryTier.BASIC), + ADVANCED_FACTORY(MachineBlock.MACHINE_BLOCK_1, 6, "Factory", 11, TileEntityAdvancedFactory::new, true, false, true, Plane.HORIZONTAL, true, FactoryTier.ADVANCED), + ELITE_FACTORY(MachineBlock.MACHINE_BLOCK_1, 7, "Factory", 11, TileEntityEliteFactory::new, true, false, true, Plane.HORIZONTAL, true, FactoryTier.ELITE), + METALLURGIC_INFUSER(MachineBlock.MACHINE_BLOCK_1, 8, "MetallurgicInfuser", 12, TileEntityMetallurgicInfuser::new, true, true, true, Plane.HORIZONTAL, false), + PURIFICATION_CHAMBER(MachineBlock.MACHINE_BLOCK_1, 9, "PurificationChamber", 15, TileEntityPurificationChamber::new, true, false, true, Plane.HORIZONTAL, true), + ENERGIZED_SMELTER(MachineBlock.MACHINE_BLOCK_1, 10, "EnergizedSmelter", 16, TileEntityEnergizedSmelter::new, true, false, true, Plane.HORIZONTAL, true), + TELEPORTER(MachineBlock.MACHINE_BLOCK_1, 11, "Teleporter", 13, TileEntityTeleporter::new, true, false, false, BlockStateUtils.NO_ROTATION, false), + ELECTRIC_PUMP(MachineBlock.MACHINE_BLOCK_1, 12, "ElectricPump", 17, TileEntityElectricPump::new, true, true, false, Plane.HORIZONTAL, false), + PERSONAL_CHEST(MachineBlock.MACHINE_BLOCK_1, 13, "PersonalChest", -1, TileEntityPersonalChest::new, true, true, false, Plane.HORIZONTAL, false), + CHARGEPAD(MachineBlock.MACHINE_BLOCK_1, 14, "Chargepad", -1, TileEntityChargepad::new, true, true, false, Plane.HORIZONTAL, false), + LOGISTICAL_SORTER(MachineBlock.MACHINE_BLOCK_1, 15, "LogisticalSorter", 59, TileEntityLogisticalSorter::new, false, true, false, BlockStateUtils.ALL_FACINGS, true), + ROTARY_CONDENSENTRATOR(MachineBlock.MACHINE_BLOCK_2, 0, "RotaryCondensentrator", 7, TileEntityRotaryCondensentrator::new, true, true, false, Plane.HORIZONTAL, false), + CHEMICAL_OXIDIZER(MachineBlock.MACHINE_BLOCK_2, 1, "ChemicalOxidizer", 29, TileEntityChemicalOxidizer::new, true, true, true, Plane.HORIZONTAL, true), + CHEMICAL_INFUSER(MachineBlock.MACHINE_BLOCK_2, 2, "ChemicalInfuser", 30, TileEntityChemicalInfuser::new, true, true, false, Plane.HORIZONTAL, true), + CHEMICAL_INJECTION_CHAMBER(MachineBlock.MACHINE_BLOCK_2, 3, "ChemicalInjectionChamber", 31, TileEntityChemicalInjectionChamber::new, true, false, true, Plane.HORIZONTAL, true), + ELECTROLYTIC_SEPARATOR(MachineBlock.MACHINE_BLOCK_2, 4, "ElectrolyticSeparator", 32, TileEntityElectrolyticSeparator::new, true, true, false, Plane.HORIZONTAL, true), + PRECISION_SAWMILL(MachineBlock.MACHINE_BLOCK_2, 5, "PrecisionSawmill", 34, TileEntityPrecisionSawmill::new, true, false, true, Plane.HORIZONTAL, true), + CHEMICAL_DISSOLUTION_CHAMBER(MachineBlock.MACHINE_BLOCK_2, 6, "ChemicalDissolutionChamber", 35, TileEntityChemicalDissolutionChamber::new, true, true, true, Plane.HORIZONTAL, true), + CHEMICAL_WASHER(MachineBlock.MACHINE_BLOCK_2, 7, "ChemicalWasher", 36, TileEntityChemicalWasher::new, true, true, false, Plane.HORIZONTAL, true), + CHEMICAL_CRYSTALLIZER(MachineBlock.MACHINE_BLOCK_2, 8, "ChemicalCrystallizer", 37, TileEntityChemicalCrystallizer::new, true, true, true, Plane.HORIZONTAL, true), + SEISMIC_VIBRATOR(MachineBlock.MACHINE_BLOCK_2, 9, "SeismicVibrator", 39, TileEntitySeismicVibrator::new, true, true, false, Plane.HORIZONTAL, true), + PRESSURIZED_REACTION_CHAMBER(MachineBlock.MACHINE_BLOCK_2, 10, "PressurizedReactionChamber", 40, TileEntityPRC::new, true, true, false, Plane.HORIZONTAL, true), + FLUID_TANK(MachineBlock.MACHINE_BLOCK_2, 11, "FluidTank", 41, TileEntityFluidTank::new, false, true, false, BlockStateUtils.NO_ROTATION, true), + FLUIDIC_PLENISHER(MachineBlock.MACHINE_BLOCK_2, 12, "FluidicPlenisher", 42, TileEntityFluidicPlenisher::new, true, true, false, Plane.HORIZONTAL, true), + LASER(MachineBlock.MACHINE_BLOCK_2, 13, "Laser", -1, TileEntityLaser::new, true, true, false, BlockStateUtils.ALL_FACINGS, false), + LASER_AMPLIFIER(MachineBlock.MACHINE_BLOCK_2, 14, "LaserAmplifier", 44, TileEntityLaserAmplifier::new, false, true, false, BlockStateUtils.ALL_FACINGS, true), + LASER_TRACTOR_BEAM(MachineBlock.MACHINE_BLOCK_2, 15, "LaserTractorBeam", 45, TileEntityLaserTractorBeam::new, false, true, false, BlockStateUtils.ALL_FACINGS, true), + QUANTUM_ENTANGLOPORTER(MachineBlock.MACHINE_BLOCK_3, 0, "QuantumEntangloporter", 46, TileEntityQuantumEntangloporter::new, true, false, false, BlockStateUtils.ALL_FACINGS, false), + SOLAR_NEUTRON_ACTIVATOR(MachineBlock.MACHINE_BLOCK_3, 1, "SolarNeutronActivator", 47, TileEntitySolarNeutronActivator::new, false, true, false, Plane.HORIZONTAL, true), + AMBIENT_ACCUMULATOR(MachineBlock.MACHINE_BLOCK_3, 2, "AmbientAccumulator", 48, TileEntityAmbientAccumulator::new, true, false, false, BlockStateUtils.NO_ROTATION, true), + OREDICTIONIFICATOR(MachineBlock.MACHINE_BLOCK_3, 3, "Oredictionificator", 52, TileEntityOredictionificator::new, false, false, false, Plane.HORIZONTAL, true), + RESISTIVE_HEATER(MachineBlock.MACHINE_BLOCK_3, 4, "ResistiveHeater", 53, TileEntityResistiveHeater::new, true, false, false, Plane.HORIZONTAL, true), + FORMULAIC_ASSEMBLICATOR(MachineBlock.MACHINE_BLOCK_3, 5, "FormulaicAssemblicator", 56, TileEntityFormulaicAssemblicator::new, true, false, true, Plane.HORIZONTAL, true), + FUELWOOD_HEATER(MachineBlock.MACHINE_BLOCK_3, 6, "FuelwoodHeater", 58, TileEntityFuelwoodHeater::new, false, false, false, Plane.HORIZONTAL, true); public MachineBlock typeBlock; public int meta; public String blockName; public int guiId; - public Class tileEntityClass; + public Supplier tileEntitySupplier; public boolean isElectric; public boolean hasModel; public boolean supportsUpgrades; @@ -162,18 +162,18 @@ public class BlockStateMachine extends ExtendedBlockState { public boolean activable; public FactoryTier factoryTier; - MachineType(MachineBlock block, int i, String s, int j, Class tileClass, boolean electric, boolean model, boolean upgrades, + MachineType(MachineBlock block, int i, String s, int j, Supplier tileClass, boolean electric, boolean model, boolean upgrades, Predicate predicate, boolean hasActiveTexture) { this(block, i, s, j, tileClass, electric, model, upgrades, predicate, hasActiveTexture, null); } - MachineType(MachineBlock block, int i, String s, int j, Class tileClass, boolean electric, boolean model, boolean upgrades, + MachineType(MachineBlock block, int i, String s, int j, Supplier tileClass, boolean electric, boolean model, boolean upgrades, Predicate predicate, boolean hasActiveTexture, FactoryTier factoryTier) { typeBlock = block; meta = i; blockName = s; guiId = j; - tileEntityClass = tileClass; + tileEntitySupplier = tileClass; isElectric = electric; hasModel = model; supportsUpgrades = upgrades; @@ -228,12 +228,7 @@ public class BlockStateMachine extends ExtendedBlockState { } public TileEntity create() { - try { - return tileEntityClass.newInstance(); - } catch (Exception e) { - Mekanism.logger.error("Unable to indirectly create tile entity.", e); - return null; - } + return this.tileEntitySupplier != null ? this.tileEntitySupplier.get() : null; } public double getUsage() { @@ -391,11 +386,11 @@ public class BlockStateMachine extends ExtendedBlockState { } public boolean canRotateTo(EnumFacing side) { - return facingPredicate.apply(side); + return facingPredicate.test(side); } public boolean hasRotations() { - return !facingPredicate.equals(Predicates.alwaysFalse()); + return !facingPredicate.equals(BlockStateUtils.NO_ROTATION); } public boolean hasActiveTexture() { @@ -407,20 +402,6 @@ public class BlockStateMachine extends ExtendedBlockState { } } - public static class MachineBlockPredicate implements Predicate { - - public MachineBlock machineBlock; - - public MachineBlockPredicate(MachineBlock type) { - machineBlock = type; - } - - @Override - public boolean apply(MachineType input) { - return input.typeBlock == machineBlock && input.isValidMachine(); - } - } - public static class MachineBlockStateMapper extends StateMapperBase { @Nonnull @@ -458,7 +439,7 @@ public class BlockStateMachine extends ExtendedBlockState { if (builder.length() == 0) { builder.append("normal"); } - ResourceLocation baseLocation = new ResourceLocation("mekanism", nameOverride != null ? nameOverride : type.getName()); + ResourceLocation baseLocation = new ResourceLocation(Mekanism.MODID, nameOverride != null ? nameOverride : type.getName()); return new ModelResourceLocation(baseLocation, builder.toString()); } } diff --git a/src/main/java/mekanism/common/block/states/BlockStatePlastic.java b/src/main/java/mekanism/common/block/states/BlockStatePlastic.java index 9b86665f2..9f2f0ba31 100644 --- a/src/main/java/mekanism/common/block/states/BlockStatePlastic.java +++ b/src/main/java/mekanism/common/block/states/BlockStatePlastic.java @@ -2,6 +2,7 @@ package mekanism.common.block.states; import java.util.Locale; import javax.annotation.Nonnull; +import mekanism.common.Mekanism; import mekanism.common.block.BlockPlastic; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; @@ -40,7 +41,7 @@ public class BlockStatePlastic extends BlockStateContainer { protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState state) { PlasticBlockType type = ((BlockPlastic) state.getBlock()).type; String property = "type=" + type.getName(); - ResourceLocation baseLocation = new ResourceLocation("mekanism", "plastic_block"); + ResourceLocation baseLocation = new ResourceLocation(Mekanism.MODID, "plastic_block"); return new ModelResourceLocation(baseLocation, property); } } diff --git a/src/main/java/mekanism/common/block/states/BlockStateTransmitter.java b/src/main/java/mekanism/common/block/states/BlockStateTransmitter.java index a390a29bb..6a9d4765c 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateTransmitter.java +++ b/src/main/java/mekanism/common/block/states/BlockStateTransmitter.java @@ -3,6 +3,7 @@ package mekanism.common.block.states; import java.util.Locale; import javax.annotation.Nonnull; import mekanism.api.transmitters.TransmissionType; +import mekanism.common.Mekanism; import mekanism.common.block.BlockTransmitter; import mekanism.common.block.property.PropertyColor; import mekanism.common.block.property.PropertyConnection; @@ -111,7 +112,7 @@ public class BlockStateTransmitter extends ExtendedBlockState { if (builder.length() == 0) { builder.append("normal"); } - ResourceLocation baseLocation = new ResourceLocation("mekanism", nameOverride != null ? nameOverride : type.getName()); + ResourceLocation baseLocation = new ResourceLocation(Mekanism.MODID, nameOverride != null ? nameOverride : type.getName()); return new ModelResourceLocation(baseLocation, builder.toString()); } } diff --git a/src/main/java/mekanism/common/block/states/BlockStateUtils.java b/src/main/java/mekanism/common/block/states/BlockStateUtils.java new file mode 100644 index 000000000..18ebd0336 --- /dev/null +++ b/src/main/java/mekanism/common/block/states/BlockStateUtils.java @@ -0,0 +1,12 @@ +package mekanism.common.block.states; + +import java.util.function.Predicate; +import net.minecraft.util.EnumFacing; + +/** + * Created by Thiakil on 18/04/2019. + */ +public class BlockStateUtils { + public static final Predicate ALL_FACINGS = enumFacing -> true; + public static final Predicate NO_ROTATION = enumFacing -> false; +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/capabilities/CapabilityWrapperManager.java b/src/main/java/mekanism/common/capabilities/CapabilityWrapperManager.java index f18ec52fa..0d23cfee9 100644 --- a/src/main/java/mekanism/common/capabilities/CapabilityWrapperManager.java +++ b/src/main/java/mekanism/common/capabilities/CapabilityWrapperManager.java @@ -22,8 +22,8 @@ public class CapabilityWrapperManager { WRAPPER wrapper = wrapperClass.getConstructor(typeClass, EnumFacing.class).newInstance(impl, facing); wrappers.put(facing, wrapper); } - } catch (Exception e) { - e.printStackTrace(); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); } return wrappers.get(facing); diff --git a/src/main/java/mekanism/common/content/transporter/InvStack.java b/src/main/java/mekanism/common/content/transporter/InvStack.java index 353564eb9..b6666d4da 100644 --- a/src/main/java/mekanism/common/content/transporter/InvStack.java +++ b/src/main/java/mekanism/common/content/transporter/InvStack.java @@ -12,7 +12,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.items.IItemHandler; /** - * An InvStack attaches to an inventory and tracks a specific homogenous item in a variable amount of slots. An InvStack can either track the entirety of these slots or + * An InvStack attaches to an inventory and tracks a specific homogeneous item in a variable amount of slots. An InvStack can either track the entirety of these slots or * portions of their contents. Utility methods in this class allow for the strategic removal of clustered items from inventories. * * @author aidancbrady diff --git a/src/main/java/mekanism/common/frequency/FrequencyManager.java b/src/main/java/mekanism/common/frequency/FrequencyManager.java index d050922d2..25b78f6fd 100644 --- a/src/main/java/mekanism/common/frequency/FrequencyManager.java +++ b/src/main/java/mekanism/common/frequency/FrequencyManager.java @@ -11,6 +11,7 @@ import java.util.UUID; import javax.annotation.Nonnull; import mekanism.api.Coord4D; import mekanism.api.TileNetworkList; +import mekanism.common.Mekanism; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; @@ -202,8 +203,8 @@ public class FrequencyManager { freq.read(dataStream); ret.add(freq); } - } catch (Exception e) { - e.printStackTrace(); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); } return ret; } @@ -237,7 +238,7 @@ public class FrequencyManager { @Override public void readFromNBT(@Nonnull NBTTagCompound nbtTags) { try { - String frequencyClass = nbtTags.getString("frequencyClass"); + String frequencyClass = nbtTags.getString("frequencyClass");//todo fix this using a classname from nbt! if (nbtTags.hasKey("ownerUUID")) { loadedOwner = UUID.fromString(nbtTags.getString("ownerUUID")); } @@ -249,8 +250,8 @@ public class FrequencyManager { Frequency freq = (Frequency) c.newInstance(compound); loadedFrequencies.add(freq); } - } catch (Exception e) { - e.printStackTrace(); + } catch (ReflectiveOperationException e) { + Mekanism.logger.error("Couldn't load frequency data", e); } } diff --git a/src/main/java/mekanism/common/integration/WailaDataProvider.java b/src/main/java/mekanism/common/integration/WailaDataProvider.java index a7c5b5639..eedae44ee 100644 --- a/src/main/java/mekanism/common/integration/WailaDataProvider.java +++ b/src/main/java/mekanism/common/integration/WailaDataProvider.java @@ -75,7 +75,7 @@ public class WailaDataProvider implements IWailaDataProvider { } else if (tile instanceof TileEntityBoundingBlock) { TileEntityBoundingBlock bound = (TileEntityBoundingBlock) tile; Coord4D coord = new Coord4D(bound.getPos(), tile.getWorld()); - //TODO: Switch to IItemHandler though there is no good way to get the name of an IItemHandler + //TODO: Switch to a smarter way to get the main tile's name - i.e. block name if (bound.receivedCoords && coord.getTileEntity(tile.getWorld()) instanceof IInventory) { currenttip.set(0, EnumColor.WHITE + ((IInventory) coord.getTileEntity(tile.getWorld())).getName()); } diff --git a/src/main/java/mekanism/common/integration/computer/CCPeripheral.java b/src/main/java/mekanism/common/integration/computer/CCPeripheral.java index e42e2758c..e7ff588cc 100644 --- a/src/main/java/mekanism/common/integration/computer/CCPeripheral.java +++ b/src/main/java/mekanism/common/integration/computer/CCPeripheral.java @@ -45,9 +45,6 @@ public class CCPeripheral implements IPeripheral { return computerTile.invoke(method, arguments); } catch (NoSuchMethodException e) { return new Object[]{"Unknown command."}; - } catch (Exception e) { - e.printStackTrace(); - return new Object[]{"Error."}; } } diff --git a/src/main/java/mekanism/common/integration/computer/IComputerIntegration.java b/src/main/java/mekanism/common/integration/computer/IComputerIntegration.java index 11c2dafbd..d919c6bbc 100644 --- a/src/main/java/mekanism/common/integration/computer/IComputerIntegration.java +++ b/src/main/java/mekanism/common/integration/computer/IComputerIntegration.java @@ -9,5 +9,5 @@ public interface IComputerIntegration extends IInventory { String[] getMethods(); - Object[] invoke(int method, Object[] args) throws Exception; + Object[] invoke(int method, Object[] args) throws NoSuchMethodException; } \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/multipart/MultipartMekanism.java b/src/main/java/mekanism/common/integration/multipart/MultipartMekanism.java index b3147f657..b850721a0 100644 --- a/src/main/java/mekanism/common/integration/multipart/MultipartMekanism.java +++ b/src/main/java/mekanism/common/integration/multipart/MultipartMekanism.java @@ -22,6 +22,7 @@ import mcmultipart.api.ref.MCMPCapabilities; import mcmultipart.api.slot.EnumCenterSlot; import mcmultipart.api.world.IMultipartBlockAccess; import mcmultipart.multipart.MultipartRegistry; +import mekanism.common.Mekanism; import mekanism.common.MekanismBlocks; import mekanism.common.block.BlockTransmitter; import mekanism.common.block.states.BlockStateMachine.MachineType; @@ -145,7 +146,7 @@ public class MultipartMekanism implements IMCMPAddon { } private void register(AttachCapabilitiesEvent e, String id) { - e.addCapability(new ResourceLocation("mekanism:" + id), new ICapabilityProvider() { + e.addCapability(new ResourceLocation(Mekanism.MODID, id), new ICapabilityProvider() { private MultipartTile tile; @Override diff --git a/src/main/java/mekanism/common/inventory/container/ContainerMekanism.java b/src/main/java/mekanism/common/inventory/container/ContainerMekanism.java index 746472758..030a2c8a2 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerMekanism.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerMekanism.java @@ -11,7 +11,6 @@ public abstract class ContainerMekanism e protected TILE tileEntity; - //TODO: Change InventoryPlayer to IInventory? protected ContainerMekanism(TILE tile, InventoryPlayer inventory) { this.tileEntity = tile; if (shouldAddSlots()) { diff --git a/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java b/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java index e7d715be9..318ef3800 100644 --- a/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java +++ b/src/main/java/mekanism/common/item/ItemBlockEnergyCube.java @@ -121,18 +121,16 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IS if (tileEntity.tier == EnergyCubeTier.CREATIVE) { tileEntity.configComponent.fillConfig(TransmissionType.ENERGY, tileEntity.getEnergy() > 0 ? 2 : 1); } - ISecurityTile security = tileEntity; - security.getSecurity().setOwnerUUID(getOwnerUUID(stack)); + ((ISecurityTile) tileEntity).getSecurity().setOwnerUUID(getOwnerUUID(stack)); if (hasSecurity(stack)) { - security.getSecurity().setMode(getSecurity(stack)); + ((ISecurityTile) tileEntity).getSecurity().setMode(getSecurity(stack)); } if (getOwnerUUID(stack) == null) { - security.getSecurity().setOwnerUUID(player.getUniqueID()); + ((ISecurityTile) tileEntity).getSecurity().setOwnerUUID(player.getUniqueID()); } - ISideConfiguration config = tileEntity; if (ItemDataUtils.hasData(stack, "sideDataStored")) { - config.getConfig().read(ItemDataUtils.getDataMap(stack)); - config.getEjector().read(ItemDataUtils.getDataMap(stack)); + ((ISideConfiguration) tileEntity).getConfig().read(ItemDataUtils.getDataMap(stack)); + ((ISideConfiguration) tileEntity).getEjector().read(ItemDataUtils.getDataMap(stack)); } ((ISustainedInventory) tileEntity).setInventory(getInventory(stack)); if (!world.isRemote) { diff --git a/src/main/java/mekanism/common/item/ItemBlockGasTank.java b/src/main/java/mekanism/common/item/ItemBlockGasTank.java index bf2f5c4f4..44fd31c3e 100644 --- a/src/main/java/mekanism/common/item/ItemBlockGasTank.java +++ b/src/main/java/mekanism/common/item/ItemBlockGasTank.java @@ -88,20 +88,18 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI tileEntity.tier = GasTankTier.values()[getBaseTier(stack).ordinal()]; tileEntity.gasTank.setMaxGas(tileEntity.tier.getStorage()); tileEntity.gasTank.setGas(getGas(stack)); - ISecurityTile security = tileEntity; - security.getSecurity().setOwnerUUID(getOwnerUUID(stack)); + ((ISecurityTile) tileEntity).getSecurity().setOwnerUUID(getOwnerUUID(stack)); if (hasSecurity(stack)) { - security.getSecurity().setMode(getSecurity(stack)); + ((ISecurityTile) tileEntity).getSecurity().setMode(getSecurity(stack)); } if (getOwnerUUID(stack) == null) { - security.getSecurity().setOwnerUUID(player.getUniqueID()); + ((ISecurityTile) tileEntity).getSecurity().setOwnerUUID(player.getUniqueID()); } - ISideConfiguration config = tileEntity; if (ItemDataUtils.hasData(stack, "sideDataStored")) { - config.getConfig().read(ItemDataUtils.getDataMap(stack)); - config.getEjector().read(ItemDataUtils.getDataMap(stack)); + ((ISideConfiguration) tileEntity).getConfig().read(ItemDataUtils.getDataMap(stack)); + ((ISideConfiguration) tileEntity).getEjector().read(ItemDataUtils.getDataMap(stack)); } ((ISustainedInventory) tileEntity).setInventory(getInventory(stack)); diff --git a/src/main/java/mekanism/common/item/ItemConfigurator.java b/src/main/java/mekanism/common/item/ItemConfigurator.java index 152586498..8cd13c136 100644 --- a/src/main/java/mekanism/common/item/ItemConfigurator.java +++ b/src/main/java/mekanism/common/item/ItemConfigurator.java @@ -133,9 +133,7 @@ public class ItemConfigurator extends ItemEnergized implements IMekWrench, ITool } else if (getState(stack) == ConfiguratorMode.EMPTY) { //Empty if (tile instanceof TileEntityContainerBlock) { if (SecurityUtils.canAccess(player, tile)) { - //TODO: Switch this to an IItemHandler - // It isn't a simple switch to IItemHandlerModifiable as then it makes the empty mode only work - // when it is done on a side configured to work as an IItemHandler. + //TODO: Switch this to items being handled by TECB, energy handled here (via lambdas?) IInventory inv = (IInventory) tile; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack slotStack = inv.getStackInSlot(i); diff --git a/src/main/java/mekanism/common/item/ItemCraftingFormula.java b/src/main/java/mekanism/common/item/ItemCraftingFormula.java index 4342bdc2f..5399b9d26 100644 --- a/src/main/java/mekanism/common/item/ItemCraftingFormula.java +++ b/src/main/java/mekanism/common/item/ItemCraftingFormula.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import javax.annotation.Nonnull; import mekanism.api.EnumColor; +import mekanism.common.Mekanism; import mekanism.common.util.InventoryUtils; import mekanism.common.util.ItemDataUtils; import mekanism.common.util.LangUtils; @@ -18,15 +19,16 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ItemCraftingFormula extends ItemMekanism { - public static ModelResourceLocation MODEL = new ModelResourceLocation("mekanism:CraftingFormula", "inventory"); - public static ModelResourceLocation INVALID_MODEL = new ModelResourceLocation("mekanism:CraftingFormulaInvalid", "inventory"); - public static ModelResourceLocation ENCODED_MODEL = new ModelResourceLocation("mekanism:CraftingFormulaEncoded", "inventory"); + public static ModelResourceLocation MODEL = new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "CraftingFormula"), "inventory"); + public static ModelResourceLocation INVALID_MODEL = new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "CraftingFormulaInvalid"), "inventory"); + public static ModelResourceLocation ENCODED_MODEL = new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "CraftingFormulaEncoded"), "inventory"); @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/mekanism/common/item/ItemWalkieTalkie.java b/src/main/java/mekanism/common/item/ItemWalkieTalkie.java index c78653c9c..5bd6c0323 100644 --- a/src/main/java/mekanism/common/item/ItemWalkieTalkie.java +++ b/src/main/java/mekanism/common/item/ItemWalkieTalkie.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import javax.annotation.Nonnull; import mekanism.api.EnumColor; +import mekanism.common.Mekanism; import mekanism.common.base.IItemNetwork; import mekanism.common.config.MekanismConfig; import mekanism.common.util.ItemDataUtils; @@ -17,6 +18,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.relauncher.Side; @@ -24,7 +26,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class ItemWalkieTalkie extends ItemMekanism implements IItemNetwork { - public static ModelResourceLocation OFF_MODEL = new ModelResourceLocation("mekanism:WalkieTalkie", "inventory"); + public static ModelResourceLocation OFF_MODEL = new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "WalkieTalkie"), "inventory"); public static Map CHANNEL_MODELS = new HashMap<>(); @@ -34,7 +36,7 @@ public class ItemWalkieTalkie extends ItemMekanism implements IItemNetwork { } public static ModelResourceLocation getModel(int channel) { - CHANNEL_MODELS.computeIfAbsent(channel, c -> new ModelResourceLocation("mekanism:WalkieTalkie_ch" + c, "inventory")); + CHANNEL_MODELS.computeIfAbsent(channel, c -> new ModelResourceLocation(new ResourceLocation(Mekanism.MODID, "WalkieTalkie_ch" + c), "inventory")); return CHANNEL_MODELS.get(channel); } diff --git a/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java b/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java index bfc4e6ad1..b8377175f 100644 --- a/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java +++ b/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java @@ -40,7 +40,6 @@ public class PacketDigitalMinerGui implements IMessageHandler { if (!player.world.isRemote) { World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(message.coord4D.dimensionId); - if (message.coord4D.getTileEntity(worldServer) instanceof TileEntityDigitalMiner) { DigitalMinerGuiMessage.openServerGui(message.packetType, message.guiType, worldServer, (EntityPlayerMP) player, message.coord4D, message.index); } @@ -55,7 +54,7 @@ public class PacketDigitalMinerGui implements IMessageHandler { if (!player.world.isRemote) { World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(message.coord4D.dimensionId); - if (message.coord4D.getTileEntity(worldServer) instanceof TileEntityLogisticalSorter) { LogisticalSorterGuiMessage.openServerGui(message.packetType, message.guiType, worldServer, (EntityPlayerMP) player, message.coord4D, message.index); } @@ -51,7 +50,7 @@ public class PacketLogisticalSorterGui implements IMessageHandler { if (!player.world.isRemote) { World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(message.coord4D.dimensionId); - if (message.coord4D.getTileEntity(worldServer) instanceof TileEntityOredictionificator) { OredictionificatorGuiMessage.openServerGui(message.packetType, message.guiType, worldServer, (EntityPlayerMP) player, message.coord4D, message.index); } @@ -49,7 +48,7 @@ public class PacketOredictionificatorGui implements IMessageHandler values() { + public static Iterable values() { return values; } diff --git a/src/main/java/mekanism/common/recipe/ShapedMekanismRecipe.java b/src/main/java/mekanism/common/recipe/ShapedMekanismRecipe.java index ab617e219..8039ef18e 100644 --- a/src/main/java/mekanism/common/recipe/ShapedMekanismRecipe.java +++ b/src/main/java/mekanism/common/recipe/ShapedMekanismRecipe.java @@ -79,7 +79,7 @@ public class ShapedMekanismRecipe extends ShapedOreRecipe { return null; } } - return new ShapedMekanismRecipe(null, result, ret); //TODO Find out correct value for group + return new ShapedMekanismRecipe(null, result, ret); } // Copy of net.minecraftforge.oredict.ShapedOreRecipe diff --git a/src/main/java/mekanism/common/recipe/ShapelessMekanismRecipe.java b/src/main/java/mekanism/common/recipe/ShapelessMekanismRecipe.java index 84827266a..d3aaa30a6 100644 --- a/src/main/java/mekanism/common/recipe/ShapelessMekanismRecipe.java +++ b/src/main/java/mekanism/common/recipe/ShapelessMekanismRecipe.java @@ -67,7 +67,7 @@ public class ShapelessMekanismRecipe extends ShapelessOreRecipe { return null; } } - return new ShapelessMekanismRecipe(null, result, ret); //TODO Find out correct value for group + return new ShapelessMekanismRecipe(null, result, ret); } // Copy of net.minecraftforge.oredict.ShapelessOreRecipe diff --git a/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java b/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java index b943b12f0..c9fd30efe 100644 --- a/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java @@ -358,7 +358,7 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { IAdvancedBoundingBlock inv = getInv(); if (inv == null) { return new Object[]{}; diff --git a/src/main/java/mekanism/common/tile/TileEntityBoilerValve.java b/src/main/java/mekanism/common/tile/TileEntityBoilerValve.java index 6d7fa3a57..f60c56f5c 100644 --- a/src/main/java/mekanism/common/tile/TileEntityBoilerValve.java +++ b/src/main/java/mekanism/common/tile/TileEntityBoilerValve.java @@ -121,7 +121,7 @@ public class TileEntityBoilerValve extends TileEntityBoilerCasing implements IFl } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { if (method == 0) { return new Object[]{structure != null}; } else { diff --git a/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java b/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java index 83c4a6591..746053d8e 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java +++ b/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java @@ -136,7 +136,7 @@ public abstract class TileEntityChanceMachine 0) { if (method == 0) { if (!(arguments[0] instanceof String)) { diff --git a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java index e6a1baf87..9d005329f 100644 --- a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java +++ b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java @@ -1,6 +1,7 @@ package mekanism.common.tile; import io.netty.buffer.ByteBuf; +import java.util.Objects; import javax.annotation.Nonnull; import mekanism.api.EnumColor; import mekanism.api.IConfigCardAccess; @@ -39,6 +40,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fml.common.FMLCommonHandler; +import org.jetbrains.annotations.Contract; public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine implements IComputerIntegration, ISideConfiguration, IConfigCardAccess, ITierUpgradeable, ISustainedData { @@ -123,7 +125,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i world.setBlockToAir(getPos()); world.setBlockState(getPos(), MekanismBlocks.MachineBlock.getStateFromMeta(5), 3); - TileEntityFactory factory = (TileEntityFactory) world.getTileEntity(getPos()); + TileEntityFactory factory = Objects.requireNonNull((TileEntityFactory) world.getTileEntity(getPos())); RecipeType type = RecipeType.INFUSING; //Basic @@ -140,7 +142,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i //Machine factory.progress[0] = operatingTicks; factory.setActive(isActive); - factory.controlType = controlType; + factory.setControlType(getControlType()); factory.prevEnergy = prevEnergy; factory.upgradeComponent.readFrom(upgradeComponent); factory.upgradeComponent.setUpgradeSlot(0); @@ -156,7 +158,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i } //Infuser - factory.infuseStored = infuseStored; + factory.infuseStored.copyFrom(infuseStored); factory.inventory.set(5, inventory.get(2)); factory.inventory.set(1, inventory.get(4)); @@ -185,7 +187,8 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i if (slotID == 3) { return false; } else if (slotID == 1) { - return InfuseRegistry.getObject(itemstack) != null && (infuseStored.getType() == null || infuseStored.getType() == InfuseRegistry.getObject(itemstack).type); + InfuseObject infuseObject = InfuseRegistry.getObject(itemstack); + return infuseObject != null && (infuseStored.getType() == null || infuseStored.getType() == infuseObject.type); } else if (slotID == 0) { return itemstack.getItem() == MekanismItems.SpeedUpgrade || itemstack.getItem() == MekanismItems.EnergyUpgrade; } else if (slotID == 2) { @@ -209,6 +212,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i ejectorComponent.outputItems(); } + @Contract("null -> false") public boolean canOperate(MetallurgicInfuserRecipe recipe) { return recipe != null && recipe.canOperate(inventory, 2, 3, infuseStored); } @@ -281,7 +285,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { switch (method) { case 0: return new Object[]{getEnergy()}; diff --git a/src/main/java/mekanism/common/tile/TileEntityPRC.java b/src/main/java/mekanism/common/tile/TileEntityPRC.java index fce225196..49a84e35d 100644 --- a/src/main/java/mekanism/common/tile/TileEntityPRC.java +++ b/src/main/java/mekanism/common/tile/TileEntityPRC.java @@ -12,6 +12,7 @@ import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; import mekanism.api.gas.IGasHandler; import mekanism.api.transmitters.TransmissionType; +import mekanism.common.Mekanism; import mekanism.common.SideData; import mekanism.common.Upgrade; import mekanism.common.base.FluidHandlerWrapper; @@ -57,7 +58,7 @@ public class TileEntityPRC extends TileEntityBasicMachine 0) { toDraw -= takeEnergy(received, true); } - storage.setEnergy(storage.getEnergy() - toDraw); - } else if (MekanismUtils.useTesla() && CapabilityUtils.hasCapability(outputter, Capabilities.TESLA_PRODUCER_CAPABILITY, side.getOpposite())) { - ITeslaProducer producer = CapabilityUtils.getCapability(outputter, Capabilities.TESLA_PRODUCER_CAPABILITY, side.getOpposite()); - double toDraw = producer.takePower(MekanismUtils.clampToInt(canDraw * MekanismConfig.current().general.TO_TESLA.val()), true) + strictStorage.setEnergy(strictStorage.getEnergy() - toDraw); + } else if (MekanismUtils.useTesla() && (teslaProducer = CapabilityUtils.getCapability(outputter, Capabilities.TESLA_PRODUCER_CAPABILITY, side.getOpposite())) != null) { + double toDraw = teslaProducer.takePower(MekanismUtils.clampToInt(canDraw * MekanismConfig.current().general.TO_TESLA.val()), true) * MekanismConfig.current().general.FROM_TESLA.val(); if (toDraw > 0) { toDraw -= takeEnergy(toDraw, true); } - producer.takePower(Math.round(toDraw * MekanismConfig.current().general.TO_TESLA.val()), false); - } else if (MekanismUtils.useForge() && CapabilityUtils.hasCapability(outputter, CapabilityEnergy.ENERGY, side.getOpposite())) { - IEnergyStorage storage = CapabilityUtils.getCapability(outputter, CapabilityEnergy.ENERGY, side.getOpposite()); - double toDraw = storage.extractEnergy(MekanismUtils.clampToInt(canDraw * MekanismConfig.current().general.TO_FORGE.val()), true) + teslaProducer.takePower(Math.round(toDraw * MekanismConfig.current().general.TO_TESLA.val()), false); + } else if (MekanismUtils.useForge() && (forgeStorage = CapabilityUtils.getCapability(outputter, CapabilityEnergy.ENERGY, side.getOpposite())) != null) { + double toDraw = forgeStorage.extractEnergy(MekanismUtils.clampToInt(canDraw * MekanismConfig.current().general.TO_FORGE.val()), true) * MekanismConfig.current().general.FROM_FORGE.val(); if (toDraw > 0) { toDraw -= takeEnergy(toDraw, true); } - storage.extractEnergy(MekanismUtils.clampToInt(toDraw * MekanismConfig.current().general.TO_TESLA.val()), false); + forgeStorage.extractEnergy(MekanismUtils.clampToInt(toDraw * MekanismConfig.current().general.TO_TESLA.val()), false); } else if (MekanismUtils.useRF() && outputter instanceof IEnergyProvider) { - double toDraw = ((IEnergyProvider) outputter).extractEnergy(side.getOpposite(), + IEnergyProvider rfProvider = (IEnergyProvider) outputter; + double toDraw = rfProvider.extractEnergy(side.getOpposite(), MekanismUtils.clampToInt(canDraw * MekanismConfig.current().general.TO_RF.val()), true) * MekanismConfig.current().general.FROM_RF.val(); if (toDraw > 0) { toDraw -= takeEnergy(toDraw, true); } - ((IEnergyProvider) outputter).extractEnergy(side.getOpposite(), MekanismUtils.clampToInt(toDraw * MekanismConfig.current().general.TO_RF.val()), false); + rfProvider.extractEnergy(side.getOpposite(), MekanismUtils.clampToInt(toDraw * MekanismConfig.current().general.TO_RF.val()), false); } else if (MekanismUtils.useIC2()) { IEnergyTile tile = EnergyNet.instance.getSubTile(outputter.getWorld(), outputter.getPos()); if (tile instanceof IEnergySource) { diff --git a/src/main/java/mekanism/common/util/CableUtils.java b/src/main/java/mekanism/common/util/CableUtils.java index 82ecbba83..9634baffe 100644 --- a/src/main/java/mekanism/common/util/CableUtils.java +++ b/src/main/java/mekanism/common/util/CableUtils.java @@ -6,7 +6,9 @@ import cofh.redstoneflux.api.IEnergyReceiver; import java.util.HashSet; import java.util.Set; import mekanism.api.Coord4D; +import mekanism.api.energy.IStrictEnergyAcceptor; import mekanism.api.energy.IStrictEnergyOutputter; +import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.TransmissionType; import mekanism.common.base.EnergyAcceptorWrapper; import mekanism.common.base.IEnergyWrapper; @@ -18,12 +20,14 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.energy.IEnergyStorage; public final class CableUtils { public static boolean isCable(TileEntity tileEntity) { - if (CapabilityUtils.hasCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null)) { - return TransmissionType.checkTransmissionType(CapabilityUtils.getCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null), TransmissionType.ENERGY); + IGridTransmitter gridTransmitter = CapabilityUtils.getCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, null); + if (gridTransmitter != null) { + return TransmissionType.checkTransmissionType(gridTransmitter, TransmissionType.ENERGY); } return false; } @@ -71,19 +75,24 @@ public final class CableUtils { if (tileEntity == null) { return false; } - if (CapabilityUtils.hasCapability(tileEntity, Capabilities.ENERGY_OUTPUTTER_CAPABILITY, side.getOpposite())) { - IStrictEnergyOutputter outputter = CapabilityUtils.getCapability(tileEntity, Capabilities.ENERGY_OUTPUTTER_CAPABILITY, side.getOpposite()); - if (outputter != null && outputter.canOutputEnergy(side.getOpposite())) { - return true; - } - } - if (MekanismUtils.useTesla() && CapabilityUtils.hasCapability(tileEntity, Capabilities.TESLA_PRODUCER_CAPABILITY, side.getOpposite())) { + + EnumFacing opposite = side.getOpposite(); + + IStrictEnergyOutputter outputter = CapabilityUtils.getCapability(tileEntity, Capabilities.ENERGY_OUTPUTTER_CAPABILITY, opposite); + if (outputter != null && outputter.canOutputEnergy(opposite)) { return true; } - if (MekanismUtils.useForge() && CapabilityUtils.hasCapability(tileEntity, CapabilityEnergy.ENERGY, side.getOpposite())) { - return CapabilityUtils.getCapability(tileEntity, CapabilityEnergy.ENERGY, side.getOpposite()).canExtract(); + + if (MekanismUtils.useTesla() && CapabilityUtils.hasCapability(tileEntity, Capabilities.TESLA_PRODUCER_CAPABILITY, opposite)) { + return true; } - if (MekanismUtils.useRF() && tileEntity instanceof IEnergyProvider && ((IEnergyConnection) tileEntity).canConnectEnergy(side.getOpposite())) { + + IEnergyStorage forgeStorage; + if (MekanismUtils.useForge() && (forgeStorage = CapabilityUtils.getCapability(tileEntity, CapabilityEnergy.ENERGY, opposite))!=null) { + return forgeStorage.canExtract(); + } + + if (MekanismUtils.useRF() && tileEntity instanceof IEnergyProvider && ((IEnergyConnection) tileEntity).canConnectEnergy(opposite)) { return true; } return MekanismUtils.useIC2() && IC2Integration.isOutputter(tileEntity, side); @@ -94,12 +103,14 @@ public final class CableUtils { if (CapabilityUtils.hasCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, side.getOpposite())) { return false; } - if (CapabilityUtils.hasCapability(tileEntity, Capabilities.ENERGY_ACCEPTOR_CAPABILITY, side.getOpposite())) { - return CapabilityUtils.getCapability(tileEntity, Capabilities.ENERGY_ACCEPTOR_CAPABILITY, side.getOpposite()).canReceiveEnergy(side.getOpposite()); + IStrictEnergyAcceptor strictEnergyAcceptor; + IEnergyStorage energyStorage; + if ((strictEnergyAcceptor = CapabilityUtils.getCapability(tileEntity, Capabilities.ENERGY_ACCEPTOR_CAPABILITY, side.getOpposite())) != null) { + return strictEnergyAcceptor.canReceiveEnergy(side.getOpposite()); } else if (MekanismUtils.useTesla() && CapabilityUtils.hasCapability(tileEntity, Capabilities.TESLA_CONSUMER_CAPABILITY, side.getOpposite())) { return true; - } else if (MekanismUtils.useForge() && CapabilityUtils.hasCapability(tileEntity, CapabilityEnergy.ENERGY, side.getOpposite())) { - return CapabilityUtils.getCapability(tileEntity, CapabilityEnergy.ENERGY, side.getOpposite()).canReceive(); + } else if (MekanismUtils.useForge() && (energyStorage = CapabilityUtils.getCapability(tileEntity, CapabilityEnergy.ENERGY, side.getOpposite())) != null) { + return energyStorage.canReceive(); } else if (MekanismUtils.useIC2() && IC2Integration.isAcceptor(orig, tileEntity, side)) { return true; } else if (MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver) { diff --git a/src/main/java/mekanism/common/util/CapabilityUtils.java b/src/main/java/mekanism/common/util/CapabilityUtils.java index 2dc726e8b..c86a840b0 100644 --- a/src/main/java/mekanism/common/util/CapabilityUtils.java +++ b/src/main/java/mekanism/common/util/CapabilityUtils.java @@ -1,5 +1,6 @@ package mekanism.common.util; +import java.util.function.Consumer; import net.minecraft.util.EnumFacing; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; @@ -19,4 +20,80 @@ public final class CapabilityUtils { } return provider.getCapability(cap, side); } + + public static OptionalCapability withCapability(ICapabilityProvider provider, Capability cap, EnumFacing side, Consumer consumer) { + return new OptionalCapability(provider).orElseWith(cap, side, consumer); + } + + public static OptionalCapability withCapability(boolean testResult, ICapabilityProvider provider, Capability cap, EnumFacing side, Consumer consumer) { + return new OptionalCapability(provider).orElseWith(testResult, cap, side, consumer); + } + + public static class OptionalCapability { + + private final ICapabilityProvider provider; + + OptionalCapability(ICapabilityProvider provider) { + this.provider = provider; + } + + /** + * If this chain has not yet been satisfied, try to get the capability and consume it. + * + * @param capability the cap to check + * @param side side to give to the provider + * @param consumer function to use the capability + * @param the capability type + * + * @return this instance if unsuccessful, otherwise a no-op OptionalCapability + */ + public OptionalCapability orElseWith(Capability capability, EnumFacing side, Consumer consumer) { + T cap = this.provider.getCapability(capability, side); + if (cap != null) { + consumer.accept(cap); + return NoOpOptionalCapability.INSTANCE; + } + return this; + } + + /** + * Like {@link #orElseWith(Capability, EnumFacing, Consumer)}, but skips if boolean testResult fails. + * + * @param testResult if this param is false, cap is not processed + * @param capability the cap to check + * @param side side to give to the provider + * @param consumer function to use the capability + * @param the capability type + * + * @return this instance if unsuccessful (or testResult is false), otherwise a no-op OptionalCapability + */ + public OptionalCapability orElseWith(boolean testResult, Capability capability, EnumFacing side, Consumer consumer) { + if (!testResult) { + return this; + } + return orElseWith(capability, side, consumer); + } + } + + /** + * All method should be no-op version of super, return this instance when the action succeeded + */ + public static class NoOpOptionalCapability extends OptionalCapability { + + public static final NoOpOptionalCapability INSTANCE = new NoOpOptionalCapability(); + + private NoOpOptionalCapability() { + super(null); + } + + @Override + public OptionalCapability orElseWith(Capability capability, EnumFacing side, Consumer consumer) { + return this; + } + + @Override + public OptionalCapability orElseWith(boolean testResult, Capability capability, EnumFacing side, Consumer consumer) { + return this; + } + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/util/InventoryUtils.java b/src/main/java/mekanism/common/util/InventoryUtils.java index 4bd6c0ac3..ced81c400 100644 --- a/src/main/java/mekanism/common/util/InventoryUtils.java +++ b/src/main/java/mekanism/common/util/InventoryUtils.java @@ -155,7 +155,6 @@ public final class InventoryUtils { return CapabilityUtils.getCapability(tile, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side); } - /* TODO From CCLib -- go back to that version when we're using dependencies again */ public static boolean canStack(ItemStack stack1, ItemStack stack2) { return stack1.isEmpty() || stack2.isEmpty() || stack1.getItem() == stack2.getItem() && (!stack2.getHasSubtypes() || stack2.getItemDamage() == stack1.getItemDamage()) diff --git a/src/main/java/mekanism/common/util/ItemRegistryUtils.java b/src/main/java/mekanism/common/util/ItemRegistryUtils.java index a2967c2d2..191503802 100644 --- a/src/main/java/mekanism/common/util/ItemRegistryUtils.java +++ b/src/main/java/mekanism/common/util/ItemRegistryUtils.java @@ -38,7 +38,6 @@ public final class ItemRegistryUtils { String modId = itemResourceLocation.getNamespace(); String lowercaseModId = modId.toLowerCase(Locale.ENGLISH); - String modName = modIDMap.computeIfAbsent(lowercaseModId, k -> WordUtils.capitalize(modId)); - return modName; + return modIDMap.computeIfAbsent(lowercaseModId, k -> WordUtils.capitalize(modId)); } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/util/MekanismUtils.java b/src/main/java/mekanism/common/util/MekanismUtils.java index e1530b1ef..a1b35ccfa 100644 --- a/src/main/java/mekanism/common/util/MekanismUtils.java +++ b/src/main/java/mekanism/common/util/MekanismUtils.java @@ -640,7 +640,7 @@ public final class MekanismUtils { * @return the corresponding ResourceLocation */ public static ResourceLocation getResource(ResourceType type, String name) { - return new ResourceLocation("mekanism", type.getPrefix() + name); + return new ResourceLocation(Mekanism.MODID, type.getPrefix() + name); } /** @@ -980,6 +980,7 @@ public final class MekanismUtils { return Item.getIdFromItem(itemStack.getItem()); } + @Deprecated//todo remove this public static boolean classExists(String className) { if (classesFound.containsKey(className)) { return classesFound.get(className) != null; @@ -994,6 +995,7 @@ public final class MekanismUtils { return found != null; } + @Deprecated//todo remove this public static boolean existsAndInstance(Object obj, String className) { Class theClass; if (classesFound.containsKey(className)) { diff --git a/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java b/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java index cf7c5b962..3ff49cf8a 100644 --- a/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java +++ b/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java @@ -27,6 +27,7 @@ import mekanism.generators.client.render.item.RenderGeneratorItem; import mekanism.generators.common.GeneratorsBlocks; import mekanism.generators.common.GeneratorsCommonProxy; import mekanism.generators.common.GeneratorsItems; +import mekanism.generators.common.MekanismGenerators; import mekanism.generators.common.block.states.BlockStateGenerator.GeneratorBlockStateMapper; import mekanism.generators.common.block.states.BlockStateGenerator.GeneratorType; import mekanism.generators.common.block.states.BlockStateReactor.ReactorBlockStateMapper; @@ -50,6 +51,7 @@ import net.minecraft.client.renderer.block.statemap.IStateMapper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.IRegistry; import net.minecraft.world.World; @@ -99,16 +101,16 @@ public class GeneratorsClientProxy extends GeneratorsCommonProxy { ModelLoader.setCustomStateMapper(GeneratorsBlocks.ReactorGlass, reactorMapper); for (GeneratorType type : GeneratorType.values()) { - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(type.blockType.getBlock()), type.meta, new ModelResourceLocation("mekanismgenerators:" + type.getName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(type.blockType.getBlock()), type.meta, new ModelResourceLocation(new ResourceLocation(MekanismGenerators.MODID, type.getName()), "inventory")); } for (ReactorBlockType type : ReactorBlockType.values()) { - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(type.blockType.getBlock()), type.meta, new ModelResourceLocation("mekanismgenerators:" + type.getName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(type.blockType.getBlock()), type.meta, new ModelResourceLocation(new ResourceLocation(MekanismGenerators.MODID, type.getName()), "inventory")); } } public void registerItemRender(Item item) { - MekanismRenderer.registerItemRender("mekanismgenerators", item); + MekanismRenderer.registerItemRender(MekanismGenerators.MODID, item); } @SubscribeEvent @@ -123,7 +125,7 @@ public class GeneratorsClientProxy extends GeneratorsCommonProxy { } private void generatorModelBake(IRegistry modelRegistry, GeneratorType type) { - ModelResourceLocation modelResourceLocation = new ModelResourceLocation("mekanismgenerators:" + type.getName(), "inventory"); + ModelResourceLocation modelResourceLocation = new ModelResourceLocation(new ResourceLocation(MekanismGenerators.MODID, type.getName()), "inventory"); ItemLayerWrapper itemLayerWrapper = new ItemLayerWrapper(modelRegistry.getObject(modelResourceLocation)); RenderGeneratorItem.modelMap.put(type, itemLayerWrapper); modelRegistry.putObject(modelResourceLocation, itemLayerWrapper); diff --git a/src/main/java/mekanism/generators/client/gui/GuiGeneratorsConfig.java b/src/main/java/mekanism/generators/client/gui/GuiGeneratorsConfig.java index 03f8eb873..2fecdfaf0 100644 --- a/src/main/java/mekanism/generators/client/gui/GuiGeneratorsConfig.java +++ b/src/main/java/mekanism/generators/client/gui/GuiGeneratorsConfig.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import mekanism.common.Mekanism; import mekanism.common.util.LangUtils; +import mekanism.generators.common.MekanismGenerators; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.common.config.Configuration; @@ -22,7 +23,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class GuiGeneratorsConfig extends GuiConfig { public GuiGeneratorsConfig(GuiScreen parent) { - super(parent, getConfigElements(), "MekanismGenerators", false, false, "MekanismGenerators"); + super(parent, getConfigElements(), MekanismGenerators.MODID, false, false, "MekanismGenerators"); } private static List getConfigElements() { diff --git a/src/main/java/mekanism/generators/client/render/RenderAdvancedSolarGenerator.java b/src/main/java/mekanism/generators/client/render/RenderAdvancedSolarGenerator.java index ed1e97a77..7a96bdeb9 100644 --- a/src/main/java/mekanism/generators/client/render/RenderAdvancedSolarGenerator.java +++ b/src/main/java/mekanism/generators/client/render/RenderAdvancedSolarGenerator.java @@ -1,5 +1,6 @@ package mekanism.generators.client.render; +import mekanism.client.render.MekanismRenderer; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.generators.client.model.ModelAdvancedSolarGenerator; @@ -20,20 +21,7 @@ public class RenderAdvancedSolarGenerator extends TileEntitySpecialRenderer getProperty() { if (generatorTypeProperty == null) { - generatorTypeProperty = PropertyEnum.create("type", GeneratorType.class, new GeneratorBlockPredicate(this)); + generatorTypeProperty = PropertyEnum.create("type", GeneratorType.class, input-> input != null && input.blockType == this); } return generatorTypeProperty; } @@ -71,19 +72,19 @@ public class BlockStateGenerator extends ExtendedBlockState { } public enum GeneratorType implements IStringSerializable, IBlockType { - HEAT_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 0, "HeatGenerator", 0, 160000, TileEntityHeatGenerator.class, true, Plane.HORIZONTAL, false), - SOLAR_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 1, "SolarGenerator", 1, 96000, TileEntitySolarGenerator.class, true, Plane.HORIZONTAL, false), - GAS_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 3, "GasGenerator", 3, -1/*uses config, set after generators config loaded*/, TileEntityGasGenerator.class, true, Plane.HORIZONTAL, false), - BIO_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 4, "BioGenerator", 4, 160000, TileEntityBioGenerator.class, true, Plane.HORIZONTAL, false), - ADVANCED_SOLAR_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 5, "AdvancedSolarGenerator", 1, 200000, TileEntityAdvancedSolarGenerator.class, true, Plane.HORIZONTAL, false), - WIND_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 6, "WindGenerator", 5, 200000, TileEntityWindGenerator.class, true, Plane.HORIZONTAL, false), - TURBINE_ROTOR(GeneratorBlock.GENERATOR_BLOCK_1, 7, "TurbineRotor", -1, -1, TileEntityTurbineRotor.class, false, Predicates.alwaysFalse(), false), - ROTATIONAL_COMPLEX(GeneratorBlock.GENERATOR_BLOCK_1, 8, "RotationalComplex", -1, -1, TileEntityRotationalComplex.class, false, Predicates.alwaysFalse(), false), - ELECTROMAGNETIC_COIL(GeneratorBlock.GENERATOR_BLOCK_1, 9, "ElectromagneticCoil", -1, -1, TileEntityElectromagneticCoil.class, false, Predicates.alwaysFalse(), false), - TURBINE_CASING(GeneratorBlock.GENERATOR_BLOCK_1, 10, "TurbineCasing", -1, -1, TileEntityTurbineCasing.class, false, Predicates.alwaysFalse(), false), - TURBINE_VALVE(GeneratorBlock.GENERATOR_BLOCK_1, 11, "TurbineValve", -1, -1, TileEntityTurbineValve.class, false, Predicates.alwaysFalse(), false), - TURBINE_VENT(GeneratorBlock.GENERATOR_BLOCK_1, 12, "TurbineVent", -1, -1, TileEntityTurbineVent.class, false, Predicates.alwaysFalse(), false), - SATURATING_CONDENSER(GeneratorBlock.GENERATOR_BLOCK_1, 13, "SaturatingCondenser", -1, -1, TileEntitySaturatingCondenser.class, false, Predicates.alwaysFalse(), false); + HEAT_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 0, "HeatGenerator", 0, 160000, TileEntityHeatGenerator::new, true, Plane.HORIZONTAL, false), + SOLAR_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 1, "SolarGenerator", 1, 96000, TileEntitySolarGenerator::new, true, Plane.HORIZONTAL, false), + GAS_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 3, "GasGenerator", 3, -1/*uses config, set after generators config loaded*/, TileEntityGasGenerator::new, true, Plane.HORIZONTAL, false), + BIO_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 4, "BioGenerator", 4, 160000, TileEntityBioGenerator::new, true, Plane.HORIZONTAL, false), + ADVANCED_SOLAR_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 5, "AdvancedSolarGenerator", 1, 200000, TileEntityAdvancedSolarGenerator::new, true, Plane.HORIZONTAL, false), + WIND_GENERATOR(GeneratorBlock.GENERATOR_BLOCK_1, 6, "WindGenerator", 5, 200000, TileEntityWindGenerator::new, true, Plane.HORIZONTAL, false), + TURBINE_ROTOR(GeneratorBlock.GENERATOR_BLOCK_1, 7, "TurbineRotor", -1, -1, TileEntityTurbineRotor::new, false, BlockStateUtils.NO_ROTATION, false), + ROTATIONAL_COMPLEX(GeneratorBlock.GENERATOR_BLOCK_1, 8, "RotationalComplex", -1, -1, TileEntityRotationalComplex::new, false, BlockStateUtils.NO_ROTATION, false), + ELECTROMAGNETIC_COIL(GeneratorBlock.GENERATOR_BLOCK_1, 9, "ElectromagneticCoil", -1, -1, TileEntityElectromagneticCoil::new, false, BlockStateUtils.NO_ROTATION, false), + TURBINE_CASING(GeneratorBlock.GENERATOR_BLOCK_1, 10, "TurbineCasing", -1, -1, TileEntityTurbineCasing::new, false, BlockStateUtils.NO_ROTATION, false), + TURBINE_VALVE(GeneratorBlock.GENERATOR_BLOCK_1, 11, "TurbineValve", -1, -1, TileEntityTurbineValve::new, false, BlockStateUtils.NO_ROTATION, false), + TURBINE_VENT(GeneratorBlock.GENERATOR_BLOCK_1, 12, "TurbineVent", -1, -1, TileEntityTurbineVent::new, false, BlockStateUtils.NO_ROTATION, false), + SATURATING_CONDENSER(GeneratorBlock.GENERATOR_BLOCK_1, 13, "SaturatingCondenser", -1, -1, TileEntitySaturatingCondenser::new, false, BlockStateUtils.NO_ROTATION, false); private static final List GENERATORS_FOR_CONFIG; @@ -102,19 +103,19 @@ public class BlockStateGenerator extends ExtendedBlockState { public String blockName; public int guiId; public double maxEnergy; - public Class tileEntityClass; + public Supplier tileEntitySupplier; public boolean hasModel; public Predicate facingPredicate; public boolean activable; - GeneratorType(GeneratorBlock block, int i, String s, int j, double k, Class tileClass, boolean model, Predicate predicate, + GeneratorType(GeneratorBlock block, int i, String s, int j, double k, Supplier tileClass, boolean model, Predicate predicate, boolean hasActiveTexture) { blockType = block; meta = i; blockName = s; guiId = j; maxEnergy = k; - tileEntityClass = tileClass; + tileEntitySupplier = tileClass; hasModel = model; facingPredicate = predicate; activable = hasActiveTexture; @@ -165,12 +166,7 @@ public class BlockStateGenerator extends ExtendedBlockState { } public TileEntity create() { - try { - return tileEntityClass.newInstance(); - } catch (Exception e) { - Mekanism.logger.error("Unable to indirectly create tile entity.", e); - return null; - } + return this.tileEntitySupplier != null ? this.tileEntitySupplier.get() : null; } @Override @@ -187,11 +183,11 @@ public class BlockStateGenerator extends ExtendedBlockState { } public boolean canRotateTo(EnumFacing side) { - return facingPredicate.apply(side); + return facingPredicate.test(side); } public boolean hasRotations() { - return !facingPredicate.equals(Predicates.alwaysFalse()); + return !facingPredicate.equals(BlockStateUtils.NO_ROTATION); } public boolean hasActiveTexture() { @@ -199,20 +195,6 @@ public class BlockStateGenerator extends ExtendedBlockState { } } - public static class GeneratorBlockPredicate implements Predicate { - - public GeneratorBlock GeneratorBlock; - - public GeneratorBlockPredicate(GeneratorBlock type) { - GeneratorBlock = type; - } - - @Override - public boolean apply(GeneratorType input) { - return input.blockType == GeneratorBlock; - } - } - public static class GeneratorBlockStateMapper extends StateMapperBase { @Nonnull @@ -245,7 +227,7 @@ public class BlockStateGenerator extends ExtendedBlockState { if (builder.length() == 0) { builder.append("normal"); } - ResourceLocation baseLocation = new ResourceLocation("mekanismgenerators", nameOverride != null ? nameOverride : type.getName()); + ResourceLocation baseLocation = new ResourceLocation(MekanismGenerators.MODID, nameOverride != null ? nameOverride : type.getName()); return new ModelResourceLocation(baseLocation, builder.toString()); } diff --git a/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java b/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java index c078d1e99..e124de639 100644 --- a/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java +++ b/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java @@ -2,11 +2,12 @@ package mekanism.generators.common.block.states; import com.google.common.base.Predicate; import java.util.Locale; +import java.util.function.Supplier; import javax.annotation.Nonnull; -import mekanism.common.Mekanism; import mekanism.common.tile.prefab.TileEntityElectricBlock; import mekanism.common.util.LangUtils; import mekanism.generators.common.GeneratorsBlocks; +import mekanism.generators.common.MekanismGenerators; import mekanism.generators.common.block.BlockReactor; import mekanism.generators.common.tile.reactor.TileEntityReactorController; import mekanism.generators.common.tile.reactor.TileEntityReactorFrame; @@ -62,26 +63,26 @@ public class BlockStateReactor extends ExtendedBlockState { } public enum ReactorBlockType implements IStringSerializable { - REACTOR_CONTROLLER(ReactorBlock.REACTOR_BLOCK, 0, "ReactorController", 10, TileEntityReactorController.class, true), - REACTOR_FRAME(ReactorBlock.REACTOR_BLOCK, 1, "ReactorFrame", -1, TileEntityReactorFrame.class, false), - REACTOR_PORT(ReactorBlock.REACTOR_BLOCK, 2, "ReactorPort", -1, TileEntityReactorPort.class, true), - REACTOR_LOGIC_ADAPTER(ReactorBlock.REACTOR_BLOCK, 3, "ReactorLogicAdapter", 15, TileEntityReactorLogicAdapter.class, false), - REACTOR_GLASS(ReactorBlock.REACTOR_GLASS, 0, "ReactorGlass", -1, TileEntityReactorGlass.class, false), - LASER_FOCUS_MATRIX(ReactorBlock.REACTOR_GLASS, 1, "ReactorLaserFocusMatrix", -1, TileEntityReactorLaserFocusMatrix.class, false); + REACTOR_CONTROLLER(ReactorBlock.REACTOR_BLOCK, 0, "ReactorController", 10, TileEntityReactorController::new, true), + REACTOR_FRAME(ReactorBlock.REACTOR_BLOCK, 1, "ReactorFrame", -1, TileEntityReactorFrame::new, false), + REACTOR_PORT(ReactorBlock.REACTOR_BLOCK, 2, "ReactorPort", -1, TileEntityReactorPort::new, true), + REACTOR_LOGIC_ADAPTER(ReactorBlock.REACTOR_BLOCK, 3, "ReactorLogicAdapter", 15, TileEntityReactorLogicAdapter::new, false), + REACTOR_GLASS(ReactorBlock.REACTOR_GLASS, 0, "ReactorGlass", -1, TileEntityReactorGlass::new, false), + LASER_FOCUS_MATRIX(ReactorBlock.REACTOR_GLASS, 1, "ReactorLaserFocusMatrix", -1, TileEntityReactorLaserFocusMatrix::new, false); public ReactorBlock blockType; public int meta; public String name; public int guiId; - public Class tileEntityClass; + public Supplier tileEntitySupplier; public boolean activable; - ReactorBlockType(ReactorBlock b, int i, String s, int j, Class tileClass, boolean activeState) { + ReactorBlockType(ReactorBlock b, int i, String s, int j, Supplier tileClass, boolean activeState) { blockType = b; meta = i; name = s; guiId = j; - tileEntityClass = tileClass; + tileEntitySupplier = tileClass; activable = activeState; } @@ -106,12 +107,7 @@ public class BlockStateReactor extends ExtendedBlockState { } public TileEntity create() { - try { - return tileEntityClass.newInstance(); - } catch (Exception e) { - Mekanism.logger.error("Unable to indirectly create tile entity.", e); - return null; - } + return this.tileEntitySupplier != null ? this.tileEntitySupplier.get() : null; } @Override @@ -164,7 +160,7 @@ public class BlockStateReactor extends ExtendedBlockState { if (builder.length() == 0) { builder.append("normal"); } - ResourceLocation baseLocation = new ResourceLocation("mekanismgenerators", nameOverride != null ? nameOverride : type.getName()); + ResourceLocation baseLocation = new ResourceLocation(MekanismGenerators.MODID, nameOverride != null ? nameOverride : type.getName()); return new ModelResourceLocation(baseLocation, builder.toString()); } } diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java index a03d20f15..28d89e050 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityBioGenerator.java @@ -166,7 +166,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { switch (method) { case 0: return new Object[]{electricityStored}; diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java index 0227de9cb..bb50ed188 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityGasGenerator.java @@ -170,7 +170,7 @@ public class TileEntityGasGenerator extends TileEntityGenerator implements IGasH } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { switch (method) { case 0: return new Object[]{getEnergy()}; diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java index b0a167e17..370d6f9ed 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java @@ -217,7 +217,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { switch (method) { case 0: return new Object[]{electricityStored}; diff --git a/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java index 0bfe280e2..6961a7b75 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java @@ -134,7 +134,7 @@ public class TileEntitySolarGenerator extends TileEntityGenerator { } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { switch (method) { case 0: return new Object[]{electricityStored}; diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityWindGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityWindGenerator.java index 0abc75da8..13b0d508f 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityWindGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityWindGenerator.java @@ -107,7 +107,7 @@ public class TileEntityWindGenerator extends TileEntityGenerator implements IBou } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { switch (method) { case 0: return new Object[]{electricityStored}; diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorController.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorController.java index e8d0577f6..6aaf2999c 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorController.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorController.java @@ -53,7 +53,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen public AxisAlignedBB box; public double clientTemp = 0; public boolean clientBurning = false; - private SoundEvent soundEvent = new SoundEvent(new ResourceLocation("mekanism", "tile.machine.fusionreactor")); + private SoundEvent soundEvent = new SoundEvent(new ResourceLocation(Mekanism.MODID, "tile.machine.fusionreactor")); @SideOnly(Side.CLIENT) private ISound activeSound; private int playSoundCooldown = 0; diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java index 16d007670..137ce4348 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java @@ -114,7 +114,7 @@ public class TileEntityReactorLogicAdapter extends TileEntityReactorBlock implem } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { if (getReactor() == null || !getReactor().isFormed()) { return new Object[]{"Unformed."}; } diff --git a/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java b/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java index 5e09dc20e..299667872 100644 --- a/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java +++ b/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java @@ -352,7 +352,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I } @Override - public Object[] invoke(int method, Object[] arguments) throws Exception { + public Object[] invoke(int method, Object[] arguments) throws NoSuchMethodException { if (method == 0) { return new Object[]{structure != null}; } else { diff --git a/src/main/java/mekanism/tools/client/ToolsClientProxy.java b/src/main/java/mekanism/tools/client/ToolsClientProxy.java index d7d820a47..5428ba449 100644 --- a/src/main/java/mekanism/tools/client/ToolsClientProxy.java +++ b/src/main/java/mekanism/tools/client/ToolsClientProxy.java @@ -1,6 +1,7 @@ package mekanism.tools.client; import mekanism.client.render.MekanismRenderer; +import mekanism.tools.common.MekanismTools; import mekanism.tools.common.ToolsCommonProxy; import mekanism.tools.common.ToolsItems; import net.minecraft.item.Item; @@ -90,6 +91,6 @@ public class ToolsClientProxy extends ToolsCommonProxy { } public void registerItemRender(Item item) { - MekanismRenderer.registerItemRender("mekanismtools", item); + MekanismRenderer.registerItemRender(MekanismTools.MODID, item); } } \ No newline at end of file diff --git a/src/main/java/mekanism/tools/client/gui/GuiToolsConfig.java b/src/main/java/mekanism/tools/client/gui/GuiToolsConfig.java index 19931b8d9..b760a0ee9 100644 --- a/src/main/java/mekanism/tools/client/gui/GuiToolsConfig.java +++ b/src/main/java/mekanism/tools/client/gui/GuiToolsConfig.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import mekanism.common.Mekanism; import mekanism.common.util.LangUtils; +import mekanism.tools.common.MekanismTools; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.common.config.Configuration; @@ -22,7 +23,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class GuiToolsConfig extends GuiConfig { public GuiToolsConfig(GuiScreen parent) { - super(parent, getConfigElements(), "MekanismTools", false, false, "MekanismTools"); + super(parent, getConfigElements(), MekanismTools.MODID, false, false, "MekanismTools"); } private static List getConfigElements() {