From 3084b058dad8e21dc172ff412db442c92853ff92 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sat, 5 Mar 2016 22:02:22 -0600 Subject: [PATCH] Cleanups in API --- MC18_notes.txt | 29 --------- .../java/vazkii/botania/api/BotaniaAPI.java | 20 ++++-- .../botania/api/mana/TileSignature.java | 12 ++++ .../api/mana/spark/ISparkAttachable.java | 10 +-- .../botania/api/mana/spark/ISparkEntity.java | 14 +--- .../api/mana/spark/SparkUpgradeType.java | 9 +++ .../java/vazkii/botania/api/package-info.java | 2 +- .../api/recipe/ElvenPortalUpdateEvent.java | 2 +- .../vazkii/botania/api/recipe/RecipeBrew.java | 21 ++++-- .../botania/api/recipe/RecipeElvenTrade.java | 11 ++-- .../api/recipe/RecipeManaInfusion.java | 6 +- .../botania/api/recipe/RecipeMiniFlower.java | 2 +- .../botania/api/recipe/RecipePetals.java | 11 ++-- .../botania/api/recipe/RecipeRuneAltar.java | 2 +- .../botania/api/state/BotaniaStateProps.java | 2 +- .../botania/api/subtile/RadiusDescriptor.java | 2 +- .../api/subtile/signature/BasicSignature.java | 2 +- .../botania/api/wiki/SimpleWikiProvider.java | 4 +- .../client/render/entity/RenderSpark.java | 2 +- .../common/block/tile/TileSparkChanger.java | 11 ++-- .../botania/common/entity/EntitySpark.java | 65 ++++++++++--------- 21 files changed, 120 insertions(+), 119 deletions(-) delete mode 100644 MC18_notes.txt create mode 100644 src/main/java/vazkii/botania/api/mana/spark/SparkUpgradeType.java diff --git a/MC18_notes.txt b/MC18_notes.txt deleted file mode 100644 index ff7736d96..000000000 --- a/MC18_notes.txt +++ /dev/null @@ -1,29 +0,0 @@ --- API -- -* Updated to BlockPos and EnumFacing everywhere where it made sense -* Registering repainting blocks will need to also receive a PropertyEnum with EnumDyeColor as the component type -so Botania knows what property to set the color on -* ICorporeaSpark.getInventory had to be changed to ICorporeaSpark.getSparkInventory because the signature clashed (IInventory vs ItemStack[], respectively) -This can be changed to match vanilla signature, but either would break backward compat. -* SubTileEntity.getComparatorInputOverride parameter removed (it was actually incorrect also. Not side, but the meta of the block). -Anyways, vanilla removed it from their method so we follow suit. -* SubTileEntity's methods that are copied from block (onBlockadded, etc.) updated to match vanilla counterparts -* Multiblock system reworked to use states and blockposes -* Magnet blacklist still uses metas instead of states because they need to support the short maxvalue wildcard. -* Now includes a way for addons to pass the Botania loader the models they want to use to render their subtile with -* Removed icon methods from SubTileSignature - --- Other -- -* Lang entries to be updated in non-english: Corporea funnel new numbers. Moving of prismarine entry. -* Most things left untouched to make patches from upstream easier -* Most uses of chunkcoordinates directly convert blockpos (THANK YOU VAZKII FOR USING THEM). Remove creation of extra instances -since BlockPos'es are immutable and thus can be reused everywhere. -* Some really needed fields in EntityItem are private now. Reflection time :( -* Alfglass now just uses the vanilla random model selection system to choose a pattern. Some of your builds may look different. -Unless someone figures out a way to use the old one -* The alt textures will probably be a resource pack now to decrease complexity... -sorry :/ The systems needed to dynamically switch out the textures like that is not worth just throwing them into a resource pack -* Slabs are kinda janky if you look at them - Mojang made some extremely silly assumptions and we're going to have to go with them -* Quartz stair textures may be assigned incorrectly - resource pack authors check me -* Glass pane inner faces are not getting culled (vanilla bug?) -* Some item forms of technical/non-user blocks are removed - * Full list: [all double slab items, all solid vine items] diff --git a/src/main/java/vazkii/botania/api/BotaniaAPI.java b/src/main/java/vazkii/botania/api/BotaniaAPI.java index 0ba3e4fe2..a86313d1e 100644 --- a/src/main/java/vazkii/botania/api/BotaniaAPI.java +++ b/src/main/java/vazkii/botania/api/BotaniaAPI.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.google.common.base.Preconditions; import net.minecraft.block.BlockCarpet; import net.minecraft.block.BlockColored; import net.minecraft.block.BlockStainedGlass; @@ -38,6 +39,7 @@ import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.EnumHelper; +import net.minecraftforge.fml.common.LoaderState; import net.minecraftforge.oredict.OreDictionary; import vazkii.botania.api.brew.Brew; import vazkii.botania.api.internal.DummyMethodHandler; @@ -299,14 +301,14 @@ public final class BotaniaAPI { return fallbackBrew; } - /* + /** * Registers a Block as disposable using its Ore Dictionary Name. */ public static void registerDisposableBlock(String oreDictName) { disposableBlocks.add(oreDictName); } - /* + /** * Registers a Block as semi disposable using its Ore Dictionary Name. * This means it will not be trashed when sneaking. */ @@ -317,14 +319,13 @@ public final class BotaniaAPI { /** * Registers a paintableBlock and returns it. * You must also provide the PropertyEnum that this block uses to express its color - * The component type of the property must be EnumDyeColor */ public static Block registerPaintableBlock(Block paintable, PropertyEnum colorProp){ paintableBlocks.put(paintable, colorProp); return paintable; } - /* + /** * Blacklists an Entity from being affected by the Rod of the Shaded Mesa. * Pass in the class for the Entity, e.g. EntityCow.class */ @@ -332,7 +333,7 @@ public final class BotaniaAPI { gravityRodBlacklist.add(entity); } - /* + /** * Checks if the provided Entity is contained in the Blacklist. * Pass in the class for the Entity, e.g. entity.getClass() */ @@ -407,6 +408,7 @@ public final class BotaniaAPI { * @return The recipe created. */ public static RecipePetals registerPetalRecipe(ItemStack output, Object... inputs) { + Preconditions.checkArgument(inputs.length <= 16); RecipePetals recipe = new RecipePetals(output, inputs); petalRecipes.add(recipe); return recipe; @@ -445,6 +447,7 @@ public final class BotaniaAPI { * @return The recipe created. */ public static RecipeRuneAltar registerRuneAltarRecipe(ItemStack output, int mana, Object... inputs) { + Preconditions.checkArgument(inputs.length <= 16); RecipeRuneAltar recipe = new RecipeRuneAltar(output, mana, inputs); runeAltarRecipes.add(recipe); return recipe; @@ -458,6 +461,7 @@ public final class BotaniaAPI { * @return The recipe created. */ public static RecipeManaInfusion registerManaInfusionRecipe(ItemStack output, Object input, int mana) { + Preconditions.checkArgument(mana <= 1000000); RecipeManaInfusion recipe = new RecipeManaInfusion(output, input, mana); manaInfusionRecipes.add(recipe); return recipe; @@ -503,6 +507,7 @@ public final class BotaniaAPI { * @inputs The items used in the recipe, no more than 6. */ public static RecipeBrew registerBrewRecipe(Brew brew, Object... inputs) { + Preconditions.checkArgument(inputs.length <= 6); RecipeBrew recipe = new RecipeBrew(brew, inputs); brewRecipes.add(recipe); return recipe; @@ -510,9 +515,10 @@ public final class BotaniaAPI { /** * Registers a SubTileEntity, a new special flower. Look in the subtile package of the API. - * If you call this after PostInit you're a failiure and we are very disappointed in you. + * Call this in preInit, and don't forget to register a model in BotaniaAPIClient. */ public static void registerSubTile(String key, Class subtileClass) { + Preconditions.checkArgument(Loader.instance().isInState(LoaderState.PREINITIALIZATION)); subTiles.put(key, subtileClass); subTileMods.put(key, Loader.instance().activeModContainer().getModId()); } @@ -667,7 +673,7 @@ public final class BotaniaAPI { /** * Registers a Wiki provider for a mod so it uses that instead of the fallback - * FTB wiki. Make sure to call this on PostInit only! + * FTB wiki. */ public static void registerModWiki(String mod, IWikiProvider provider) { WikiHooks.registerModWiki(mod, provider); diff --git a/src/main/java/vazkii/botania/api/mana/TileSignature.java b/src/main/java/vazkii/botania/api/mana/TileSignature.java index 5573670da..8f5b98759 100644 --- a/src/main/java/vazkii/botania/api/mana/TileSignature.java +++ b/src/main/java/vazkii/botania/api/mana/TileSignature.java @@ -12,4 +12,16 @@ public class TileSignature { this.remoteWorld = remoteWorld; } + @Override + public int hashCode() { + return Boolean.hashCode(remoteWorld) ^ tile.hashCode(); + } + + @Override + public boolean equals(Object o) { + return o instanceof TileSignature + && tile == ((TileSignature) o).tile + && remoteWorld == ((TileSignature) o).remoteWorld; + } + } diff --git a/src/main/java/vazkii/botania/api/mana/spark/ISparkAttachable.java b/src/main/java/vazkii/botania/api/mana/spark/ISparkAttachable.java index d7708f6f0..6a924671c 100644 --- a/src/main/java/vazkii/botania/api/mana/spark/ISparkAttachable.java +++ b/src/main/java/vazkii/botania/api/mana/spark/ISparkAttachable.java @@ -38,15 +38,7 @@ public interface ISparkAttachable extends IManaReceiver { /** * Gets the Spark that is attached to this block. A common implementation is - * to check for Spark entities above: - * - List sparks = worldObj.getEntitiesWithinAABB(ISparkEntity.class, new AxisAlignedBB(xCoord, yCoord + 1, zCoord, xCoord + 1, yCoord + 2, zCoord + 1)); - if(sparks.size() == 1) { - Entity e = (Entity) sparks.get(0); - return (ISparkEntity) e; - } - - return null; + * to check for Spark entities above using world.getEntitiesWithinAABB() */ public ISparkEntity getAttachedSpark(); diff --git a/src/main/java/vazkii/botania/api/mana/spark/ISparkEntity.java b/src/main/java/vazkii/botania/api/mana/spark/ISparkEntity.java index e35076ceb..81f6d14ca 100644 --- a/src/main/java/vazkii/botania/api/mana/spark/ISparkEntity.java +++ b/src/main/java/vazkii/botania/api/mana/spark/ISparkEntity.java @@ -19,15 +19,7 @@ public interface ISparkEntity { /** * Which TileEntity is this Spark attached to? A common implementation is checking the block below. - * - int x = MathHelper.floor_double(posX); - int y = MathHelper.floor_double(posY) - 1; - int z = MathHelper.floor_double(posZ); - TileEntity tile = worldObj.getTileEntity(x, y, z); - if(tile != null && tile instanceof ISparkAttachable) - return (ISparkAttachable) tile; - - return null; + * using world.getTileEntity(new BlockPos(this).down()) */ public ISparkAttachable getAttachedTile(); @@ -49,12 +41,12 @@ public interface ISparkEntity { * 3: Recessive
* 4: Isolated */ - public int getUpgrade(); + public SparkUpgradeType getUpgrade(); /** * Sets the upgrade on this Spark. See {@link ISparkEntity#getUpgrade} */ - public void setUpgrade(int upgrade); + public void setUpgrade(SparkUpgradeType upgrade); /** * See {@link ISparkAttachable#areIncomingTranfersDone()} diff --git a/src/main/java/vazkii/botania/api/mana/spark/SparkUpgradeType.java b/src/main/java/vazkii/botania/api/mana/spark/SparkUpgradeType.java new file mode 100644 index 000000000..cdfc48a40 --- /dev/null +++ b/src/main/java/vazkii/botania/api/mana/spark/SparkUpgradeType.java @@ -0,0 +1,9 @@ +package vazkii.botania.api.mana.spark; + +public enum SparkUpgradeType { + NONE, + DISPERSIVE, + DOMINANT, + RECESSIVE, + ISOLATED +} diff --git a/src/main/java/vazkii/botania/api/package-info.java b/src/main/java/vazkii/botania/api/package-info.java index 37d0091e4..f82edd722 100644 --- a/src/main/java/vazkii/botania/api/package-info.java +++ b/src/main/java/vazkii/botania/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Botania", apiVersion = "76", provides = "BotaniaAPI") +@API(owner = "Botania", apiVersion = "77", provides = "BotaniaAPI") package vazkii.botania.api; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/vazkii/botania/api/recipe/ElvenPortalUpdateEvent.java b/src/main/java/vazkii/botania/api/recipe/ElvenPortalUpdateEvent.java index df0235646..b0933a2cb 100644 --- a/src/main/java/vazkii/botania/api/recipe/ElvenPortalUpdateEvent.java +++ b/src/main/java/vazkii/botania/api/recipe/ElvenPortalUpdateEvent.java @@ -29,7 +29,7 @@ public class ElvenPortalUpdateEvent extends Event { */ public final TileEntity portalTile; public final AxisAlignedBB aabb; - public boolean open; + public final boolean open; public final List stacksInside; public ElvenPortalUpdateEvent(TileEntity te, AxisAlignedBB aabb, boolean open, List stacks) { diff --git a/src/main/java/vazkii/botania/api/recipe/RecipeBrew.java b/src/main/java/vazkii/botania/api/recipe/RecipeBrew.java index 40ab346a1..bedf6f061 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipeBrew.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipeBrew.java @@ -13,6 +13,7 @@ package vazkii.botania.api.recipe; import java.util.ArrayList; import java.util.List; +import com.google.common.collect.ImmutableList; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -23,20 +24,20 @@ import vazkii.botania.api.brew.IBrewContainer; public class RecipeBrew { - Brew brew; - List inputs; + private final Brew brew; + private final ImmutableList inputs; public RecipeBrew(Brew brew, Object... inputs) { this.brew = brew; - List inputsToSet = new ArrayList<>(); + ImmutableList.Builder inputsToSet = ImmutableList.builder(); for(Object obj : inputs) { if(obj instanceof String || obj instanceof ItemStack) inputsToSet.add(obj); else throw new IllegalArgumentException("Invalid input"); } - this.inputs = inputsToSet; + this.inputs = inputsToSet.build(); } public boolean matches(IItemHandler inv) { @@ -112,4 +113,16 @@ public class RecipeBrew { return container.getItemForBrew(brew, stack); } + @Override + public int hashCode() { + return 31 * brew.hashCode() ^ inputs.hashCode(); + } + + @Override + public boolean equals(Object o) { + return o instanceof RecipeBrew + && brew == ((RecipeBrew) o).brew + && inputs.equals(((RecipeBrew) o).inputs); + } + } diff --git a/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java b/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java index ed701973e..b1dbc324c 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java @@ -3,25 +3,26 @@ package vazkii.botania.api.recipe; import java.util.ArrayList; import java.util.List; +import com.google.common.collect.ImmutableList; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; public class RecipeElvenTrade { - ItemStack output; - List inputs; + private final ItemStack output; + private final ImmutableList inputs; public RecipeElvenTrade(ItemStack output, Object... inputs) { this.output = output; - List inputsToSet = new ArrayList<>(); + ImmutableList.Builder inputsToSet = ImmutableList.builder(); for(Object obj : inputs) { if(obj instanceof String || obj instanceof ItemStack) inputsToSet.add(obj); else throw new IllegalArgumentException("Invalid input"); } - this.inputs = inputsToSet; + this.inputs = inputsToSet.build(); } public boolean matches(List stacks, boolean remove) { @@ -84,7 +85,7 @@ public class RecipeElvenTrade { } public List getInputs() { - return new ArrayList<>(inputs); + return inputs; } public ItemStack getOutput() { diff --git a/src/main/java/vazkii/botania/api/recipe/RecipeManaInfusion.java b/src/main/java/vazkii/botania/api/recipe/RecipeManaInfusion.java index 368c8d4c4..b782f43e2 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipeManaInfusion.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipeManaInfusion.java @@ -17,9 +17,9 @@ import net.minecraftforge.oredict.OreDictionary; public class RecipeManaInfusion { - ItemStack output; - Object input; - int mana; + private final ItemStack output; + private final Object input; + private final int mana; boolean isAlchemy = false; boolean isConjuration = false; diff --git a/src/main/java/vazkii/botania/api/recipe/RecipeMiniFlower.java b/src/main/java/vazkii/botania/api/recipe/RecipeMiniFlower.java index 92908c0a7..e4f165ae4 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipeMiniFlower.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipeMiniFlower.java @@ -23,7 +23,7 @@ public class RecipeMiniFlower extends RecipeManaInfusion { @Override public boolean matches(ItemStack stack) { String key = BotaniaAPI.internalHandler.getStackSubTileKey(stack); - String input = this.input instanceof String ? (String) this.input : BotaniaAPI.internalHandler.getStackSubTileKey((ItemStack) this.input); + String input = this.getInput() instanceof String ? (String) this.getInput() : BotaniaAPI.internalHandler.getStackSubTileKey((ItemStack) this.getInput()); return key != null && key.equals(input); } diff --git a/src/main/java/vazkii/botania/api/recipe/RecipePetals.java b/src/main/java/vazkii/botania/api/recipe/RecipePetals.java index f2df5cc57..9f1848a9b 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipePetals.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipePetals.java @@ -13,6 +13,7 @@ package vazkii.botania.api.recipe; import java.util.ArrayList; import java.util.List; +import com.google.common.collect.ImmutableList; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; @@ -20,20 +21,20 @@ import net.minecraftforge.oredict.OreDictionary; public class RecipePetals { - ItemStack output; - List inputs; + private final ItemStack output; + private final ImmutableList inputs; public RecipePetals(ItemStack output, Object... inputs) { this.output = output; - List inputsToSet = new ArrayList<>(); + ImmutableList.Builder inputsToSet = ImmutableList.builder(); for(Object obj : inputs) { if(obj instanceof String || obj instanceof ItemStack) inputsToSet.add(obj); else throw new IllegalArgumentException("Invalid input"); } - this.inputs = inputsToSet; + this.inputs = inputsToSet.build(); } public boolean matches(IItemHandler inv) { @@ -87,7 +88,7 @@ public class RecipePetals { } public List getInputs() { - return new ArrayList<>(inputs); + return inputs; } public ItemStack getOutput() { diff --git a/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java b/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java index f8bb211c1..22c6dcf37 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipeRuneAltar.java @@ -14,7 +14,7 @@ import net.minecraft.item.ItemStack; public class RecipeRuneAltar extends RecipePetals { - int mana; + private final int mana; public RecipeRuneAltar(ItemStack output, int mana, Object... inputs) { super(output, inputs); diff --git a/src/main/java/vazkii/botania/api/state/BotaniaStateProps.java b/src/main/java/vazkii/botania/api/state/BotaniaStateProps.java index f9771a7f9..fbf159d3c 100644 --- a/src/main/java/vazkii/botania/api/state/BotaniaStateProps.java +++ b/src/main/java/vazkii/botania/api/state/BotaniaStateProps.java @@ -28,7 +28,7 @@ import javax.annotation.Nullable; /** * Holds all Botania block state properties. Use these to set botania blockstates */ -public class BotaniaStateProps { +public final class BotaniaStateProps { /** Unlisted properties **/ diff --git a/src/main/java/vazkii/botania/api/subtile/RadiusDescriptor.java b/src/main/java/vazkii/botania/api/subtile/RadiusDescriptor.java index 5ff9a45cb..2d8fa4266 100644 --- a/src/main/java/vazkii/botania/api/subtile/RadiusDescriptor.java +++ b/src/main/java/vazkii/botania/api/subtile/RadiusDescriptor.java @@ -19,7 +19,7 @@ import net.minecraft.util.BlockPos; */ public class RadiusDescriptor { - final BlockPos subtileCoords; + private final BlockPos subtileCoords; public RadiusDescriptor(BlockPos subtileCoords) { this.subtileCoords = subtileCoords; diff --git a/src/main/java/vazkii/botania/api/subtile/signature/BasicSignature.java b/src/main/java/vazkii/botania/api/subtile/signature/BasicSignature.java index 66b710147..511fa7d1c 100644 --- a/src/main/java/vazkii/botania/api/subtile/signature/BasicSignature.java +++ b/src/main/java/vazkii/botania/api/subtile/signature/BasicSignature.java @@ -28,7 +28,7 @@ import vazkii.botania.api.subtile.SubTileGenerating; */ public class BasicSignature extends SubTileSignature { - final String name; + private final String name; public BasicSignature(String name) { this.name = name; diff --git a/src/main/java/vazkii/botania/api/wiki/SimpleWikiProvider.java b/src/main/java/vazkii/botania/api/wiki/SimpleWikiProvider.java index 132182269..05eb15e7b 100644 --- a/src/main/java/vazkii/botania/api/wiki/SimpleWikiProvider.java +++ b/src/main/java/vazkii/botania/api/wiki/SimpleWikiProvider.java @@ -21,8 +21,8 @@ import org.apache.commons.lang3.text.WordUtils; public class SimpleWikiProvider implements IWikiProvider { - final String name, urlBase, replacement; - final boolean lowercase; + private final String name, urlBase, replacement; + private final boolean lowercase; public SimpleWikiProvider(String name, String urlBase) { this(name, urlBase, "%20"); diff --git a/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java b/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java index cbda1c6a2..b3018ff48 100644 --- a/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java +++ b/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java @@ -23,7 +23,7 @@ public class RenderSpark extends RenderSparkBase { @Override public TextureAtlasSprite getSpinningIcon(EntitySpark entity) { - int upgrade = entity.getUpgrade() - 1; + int upgrade = entity.getUpgrade().ordinal() - 1; return upgrade >= 0 && upgrade < MiscellaneousIcons.INSTANCE.sparkUpgradeIcons.length ? MiscellaneousIcons.INSTANCE.sparkUpgradeIcons[upgrade] : null; } diff --git a/src/main/java/vazkii/botania/common/block/tile/TileSparkChanger.java b/src/main/java/vazkii/botania/common/block/tile/TileSparkChanger.java index 2e237e997..f53bdf9e9 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileSparkChanger.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileSparkChanger.java @@ -20,6 +20,7 @@ import net.minecraft.util.EnumFacing; import vazkii.botania.api.internal.VanillaPacketDispatcher; import vazkii.botania.api.mana.spark.ISparkAttachable; import vazkii.botania.api.mana.spark.ISparkEntity; +import vazkii.botania.api.mana.spark.SparkUpgradeType; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.lib.LibMisc; @@ -37,8 +38,8 @@ public class TileSparkChanger extends TileSimpleInventory { ISparkAttachable attach = (ISparkAttachable) tile; ISparkEntity spark = attach.getAttachedSpark(); if(spark != null) { - int upg = spark.getUpgrade(); - int newUpg = changeStack == null ? 0 : changeStack.getItemDamage() + 1; + SparkUpgradeType upg = spark.getUpgrade(); + SparkUpgradeType newUpg = changeStack == null ? SparkUpgradeType.NONE : SparkUpgradeType.values()[changeStack.getItemDamage() + 1]; if(upg != newUpg) attachables.add(attach); } @@ -48,9 +49,9 @@ public class TileSparkChanger extends TileSimpleInventory { if(attachables.size() > 0) { ISparkAttachable attach = attachables.get(worldObj.rand.nextInt(attachables.size())); ISparkEntity spark = attach.getAttachedSpark(); - int upg = spark.getUpgrade(); - ItemStack sparkStack = upg == 0 ? null : new ItemStack(ModItems.sparkUpgrade, 1, upg - 1); - int newUpg = changeStack == null ? 0 : changeStack.getItemDamage() + 1; + SparkUpgradeType upg = spark.getUpgrade(); + ItemStack sparkStack = upg == SparkUpgradeType.NONE ? null : new ItemStack(ModItems.sparkUpgrade, 1, upg.ordinal() - 1); + SparkUpgradeType newUpg = changeStack == null ? SparkUpgradeType.NONE : SparkUpgradeType.values()[changeStack.getItemDamage() + 1]; spark.setUpgrade(newUpg); Collection transfers = spark.getTransfers(); if(transfers != null) diff --git a/src/main/java/vazkii/botania/common/entity/EntitySpark.java b/src/main/java/vazkii/botania/common/entity/EntitySpark.java index d81c5892c..f349b0cbc 100644 --- a/src/main/java/vazkii/botania/common/entity/EntitySpark.java +++ b/src/main/java/vazkii/botania/common/entity/EntitySpark.java @@ -34,6 +34,7 @@ import vazkii.botania.api.mana.IManaPool; import vazkii.botania.api.mana.spark.ISparkAttachable; import vazkii.botania.api.mana.spark.ISparkEntity; import vazkii.botania.api.mana.spark.SparkHelper; +import vazkii.botania.api.mana.spark.SparkUpgradeType; import vazkii.botania.common.Botania; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.item.ModItems; @@ -77,9 +78,9 @@ public class EntitySpark extends Entity implements ISparkEntity { } boolean first = worldObj.isRemote && !firstTick; - int upgrade = getUpgrade(); + SparkUpgradeType upgrade = getUpgrade(); List allSparks = null; - if(first || upgrade == 2 || upgrade == 3) + if(first || upgrade == SparkUpgradeType.DOMINANT || upgrade == SparkUpgradeType.RECESSIVE) allSparks = SparkHelper.getSparksAround(worldObj, posX, posY, posZ); if(first) @@ -88,9 +89,9 @@ public class EntitySpark extends Entity implements ISparkEntity { Collection transfers = getTransfers(); - if(upgrade != 0) { + if(upgrade != SparkUpgradeType.NONE) { switch(upgrade) { - case 1 : { // Dispersive + case DISPERSIVE : { List players = SparkHelper.getEntitiesAround(EntityPlayer.class, worldObj, posX, posY, posZ); Map> receivingPlayers = new HashMap<>(); @@ -141,14 +142,14 @@ public class EntitySpark extends Entity implements ISparkEntity { break; } - case 2 : { // Dominant + case DOMINANT : { List validSparks = new ArrayList<>(); for(ISparkEntity spark : allSparks) { if(spark == this) continue; - int upgrade_ = spark.getUpgrade(); - if(upgrade_ == 0 && spark.getAttachedTile() instanceof IManaPool) + SparkUpgradeType upgrade_ = spark.getUpgrade(); + if(upgrade_ == SparkUpgradeType.NONE && spark.getAttachedTile() instanceof IManaPool) validSparks.add(spark); } if(validSparks.size() > 0) @@ -156,13 +157,13 @@ public class EntitySpark extends Entity implements ISparkEntity { break; } - case 3 : { // Recessive + case RECESSIVE : { // Recessive for(ISparkEntity spark : allSparks) { if(spark == this) continue; - int upgrade_ = spark.getUpgrade(); - if(upgrade_ != 2 && upgrade_ != 3 && upgrade_ != 4) + SparkUpgradeType upgrade_ = spark.getUpgrade(); + if(upgrade_ != SparkUpgradeType.DOMINANT && upgrade_ != SparkUpgradeType.RECESSIVE && upgrade_ != SparkUpgradeType.ISOLATED) transfers.add(spark); } break; @@ -252,13 +253,13 @@ public class EntitySpark extends Entity implements ISparkEntity { public boolean interactFirst(EntityPlayer player) { ItemStack stack = player.getCurrentEquippedItem(); if(stack != null) { - int upgrade = getUpgrade(); + SparkUpgradeType upgrade = getUpgrade(); if(stack.getItem() == ModItems.twigWand) { if(player.isSneaking()) { - if(upgrade > 0) { + if(upgrade != SparkUpgradeType.NONE) { if(!worldObj.isRemote) - entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade - 1), 0F); - setUpgrade(0); + entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade.ordinal() - 1), 0F); + setUpgrade(SparkUpgradeType.NONE); transfers.clear(); removeTransferants = 2; @@ -272,9 +273,9 @@ public class EntitySpark extends Entity implements ISparkEntity { particleBeam(this, (Entity) spark); return true; } - } else if(stack.getItem() == ModItems.sparkUpgrade && upgrade == 0) { + } else if(stack.getItem() == ModItems.sparkUpgrade && upgrade == SparkUpgradeType.NONE) { int newUpgrade = stack.getItemDamage() + 1; - setUpgrade(newUpgrade); + setUpgrade(SparkUpgradeType.values()[newUpgrade]); stack.stackSize--; if(player.worldObj.isRemote) player.swingItem(); @@ -297,13 +298,13 @@ public class EntitySpark extends Entity implements ISparkEntity { @Override protected void readEntityFromNBT(NBTTagCompound cmp) { - setUpgrade(cmp.getInteger(TAG_UPGRADE)); + setUpgrade(SparkUpgradeType.values()[cmp.getInteger(TAG_UPGRADE)]); dataWatcher.updateObject(INVISIBILITY_DATA_WATCHER_KEY, cmp.getInteger(TAG_INVIS)); } @Override protected void writeEntityToNBT(NBTTagCompound cmp) { - cmp.setInteger(TAG_UPGRADE, getUpgrade()); + cmp.setInteger(TAG_UPGRADE, getUpgrade().ordinal()); cmp.setInteger(TAG_INVIS, dataWatcher.getWatchableObjectInt(INVISIBILITY_DATA_WATCHER_KEY)); } @@ -311,10 +312,10 @@ public class EntitySpark extends Entity implements ISparkEntity { public void setDead() { super.setDead(); if(!worldObj.isRemote) { - int upgrade = getUpgrade(); + SparkUpgradeType upgrade = getUpgrade(); entityDropItem(new ItemStack(ModItems.spark), 0F); - if(upgrade > 0) - entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade - 1), 0F); + if(upgrade != SparkUpgradeType.NONE) + entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade.ordinal() - 1), 0F); } } @@ -335,14 +336,16 @@ public class EntitySpark extends Entity implements ISparkEntity { public Collection getTransfers() { Collection removals = new ArrayList<>(); - for(ISparkEntity e : transfers) { - ISparkEntity spark = e; - int upgr = getUpgrade(); - int supgr = spark.getUpgrade(); + for(ISparkEntity spark : transfers) { + SparkUpgradeType upgr = getUpgrade(); + SparkUpgradeType supgr = spark.getUpgrade(); ISparkAttachable atile = spark.getAttachedTile(); - if(!(spark != this && !spark.areIncomingTransfersDone() && atile != null && !atile.isFull() && (upgr == 0 && supgr == 2 || upgr == 3 && (supgr == 0 || supgr == 1) || !(atile instanceof IManaPool)))) - removals.add(e); + if(!(spark != this + && !spark.areIncomingTransfersDone() + && atile != null && !atile.isFull() + && (upgr == SparkUpgradeType.NONE && supgr == SparkUpgradeType.DOMINANT || upgr == SparkUpgradeType.RECESSIVE && (supgr == SparkUpgradeType.NONE || supgr == SparkUpgradeType.DISPERSIVE) || !(atile instanceof IManaPool)))) + removals.add(spark); } if(!removals.isEmpty()) @@ -363,13 +366,13 @@ public class EntitySpark extends Entity implements ISparkEntity { } @Override - public int getUpgrade() { - return dataWatcher.getWatchableObjectInt(28); + public SparkUpgradeType getUpgrade() { + return SparkUpgradeType.values()[dataWatcher.getWatchableObjectInt(28)]; } @Override - public void setUpgrade(int upgrade) { - dataWatcher.updateObject(28, upgrade); + public void setUpgrade(SparkUpgradeType upgrade) { + dataWatcher.updateObject(28, upgrade.ordinal()); } @Override