From 87642c394b2f3928350550cab3d019a41d7074af Mon Sep 17 00:00:00 2001 From: way2muchnoise Date: Mon, 25 Jan 2016 22:55:42 +0100 Subject: [PATCH] rewrites the api and some registries, #22, #23, #24 --- examples/ores.json | 45 ---- gradle.properties | 10 +- src/main/java/jeresources/JEResources.java | 14 +- src/main/java/jeresources/api/IJERAPI.java | 7 + src/main/java/jeresources/api/IJERPlugin.java | 6 + .../java/jeresources/api/IMobRegistry.java | 19 ++ .../jeresources/api/IWorldGenRegistry.java | 16 ++ src/main/java/jeresources/api/JERPlugin.java | 8 + .../{utils => }/conditionals/Conditional.java | 54 ++--- .../conditionals/ExtendedConditional.java | 2 +- .../{utils => conditionals}/LightLevel.java | 41 +--- .../api/distributions/DistributionBase.java | 11 - .../api/distributions/DistributionCustom.java | 2 - .../DistributionHelpers.java | 7 +- .../api/distributions/DistributionSquare.java | 2 - .../distributions/DistributionTriangular.java | 2 - .../distributions/DistributionUnderWater.java | 2 - .../api/distributions/package-info.java | 4 - .../api/{utils => drop}/DropItem.java | 46 +--- .../api/{utils => drop}/PlantDrop.java | 49 +--- .../jeresources/api/messages/Message.java | 51 ---- .../api/messages/ModifyMessage.java | 58 ----- .../api/messages/ModifyMobMessage.java | 191 --------------- .../api/messages/ModifyOreMessage.java | 105 --------- .../api/messages/ModifyPlantMessage.java | 118 ---------- .../api/messages/RegisterDungeonMessage.java | 100 -------- .../api/messages/RegisterMobMessage.java | 78 ------- .../api/messages/RegisterOreMessage.java | 138 ----------- .../api/messages/RegisterPlantMessage.java | 35 --- .../api/messages/RegistryMessage.java | 52 ----- .../api/messages/RemoveMobMessage.java | 85 ------- .../api/messages/RemovePlantMessage.java | 24 -- .../jeresources/api/messages/SendMessage.java | 79 ------- .../api/messages/package-info.java | 4 - .../api/messages/utils/MessageHelper.java | 158 ------------- .../api/messages/utils/MessageKeys.java | 54 ----- .../ColourHelper.java} | 4 +- .../api/render/IMobRenderHook.java | 29 +++ .../TextModifier.java} | 12 +- .../restrictions/BiomeRestriction.java | 29 +-- .../restrictions/BlockRestriction.java | 23 +- .../restrictions/DimensionRegistry.java | 2 +- .../restrictions/DimensionRestriction.java | 26 +-- .../{utils => }/restrictions/Restriction.java | 27 +-- .../api/{utils => }/restrictions/Type.java | 2 +- .../java/jeresources/api/utils/Priority.java | 17 -- .../jeresources/api/utils/package-info.java | 4 - .../jeresources/compatibility/CompatBase.java | 22 +- .../compatibility/Compatibility.java | 19 +- .../jeresources/compatibility/JERAPI.java | 46 ++++ .../compatibility/MobRegistryImpl.java | 91 ++++++++ .../{utils => compatibility}/ModList.java | 7 +- .../compatibility/WorldGenRegistryImpl.java | 62 +++++ .../minecraft/MinecraftCompat.java | 63 +++-- .../compatibility/minecraft/RenderHooks.java | 57 +++++ .../thaumcraft/ThaumcraftCompat.java | 28 ++- .../jeresources/entries/DungeonEntry.java | 9 - .../java/jeresources/entries/MobEntry.java | 22 +- .../jeresources/entries/OreMatchEntry.java | 217 ------------------ .../java/jeresources/entries/PlantEntry.java | 2 +- .../jeresources/entries/WorldGenEntry.java | 170 ++++++++++++++ src/main/java/jeresources/jei/JEIConfig.java | 10 +- .../java/jeresources/jei/mob/MobWrapper.java | 3 +- .../java/jeresources/jei/ore/OreHandler.java | 38 --- .../jeresources/jei/plant/PlantWrapper.java | 2 +- .../WorldGenCategory.java} | 30 +-- .../jei/worldgen/WorldGenHandler.java | 38 +++ .../WorldGenWrapper.java} | 52 ++--- .../jeresources/json/ProfilingAdapter.java | 4 +- .../{OreAdapter.java => WorldGenAdapter.java} | 35 ++- .../java/jeresources/proxy/CommonProxy.java | 6 +- .../java/jeresources/reference/Resources.java | 2 +- .../java/jeresources/reference/Textures.java | 3 +- .../registry/EnchantmentRegistry.java | 2 +- .../jeresources/registry/MessageRegistry.java | 108 --------- .../jeresources/registry/MobRegistry.java | 79 +------ .../jeresources/registry/OreRegistry.java | 129 ----------- .../jeresources/registry/PlantRegistry.java | 2 +- .../registry/WorldGenRegistry.java | 49 ++++ src/main/java/jeresources/utils/MapKeys.java | 11 +- .../java/jeresources/utils/MobHelper.java | 2 +- .../jeresources/utils/ReflectionHelper.java | 22 ++ .../java/jeresources/utils/RenderHelper.java | 34 +-- .../java/jeresources/utils/SeedHelper.java | 2 +- .../jeresources/utils/WorldEventHelper.java | 4 +- .../assets/jeresources/lang/en_US.lang | 12 +- .../assets/jeresources/lang/nl_NL.lang | 10 +- .../assets/jeresources/lang/ru_RU.lang | 10 +- .../assets/jeresources/lang/zh_CN.lang | 10 +- .../gui/{JEIOreGUI.png => JEIWorldGenGUI.png} | Bin 90 files changed, 887 insertions(+), 2489 deletions(-) delete mode 100644 examples/ores.json create mode 100644 src/main/java/jeresources/api/IJERAPI.java create mode 100644 src/main/java/jeresources/api/IJERPlugin.java create mode 100644 src/main/java/jeresources/api/IMobRegistry.java create mode 100644 src/main/java/jeresources/api/IWorldGenRegistry.java create mode 100644 src/main/java/jeresources/api/JERPlugin.java rename src/main/java/jeresources/api/{utils => }/conditionals/Conditional.java (76%) rename src/main/java/jeresources/api/{utils => }/conditionals/ExtendedConditional.java (89%) rename src/main/java/jeresources/api/{utils => conditionals}/LightLevel.java (50%) rename src/main/java/jeresources/api/{utils => distributions}/DistributionHelpers.java (97%) delete mode 100644 src/main/java/jeresources/api/distributions/package-info.java rename src/main/java/jeresources/api/{utils => drop}/DropItem.java (70%) rename src/main/java/jeresources/api/{utils => drop}/PlantDrop.java (53%) delete mode 100644 src/main/java/jeresources/api/messages/Message.java delete mode 100644 src/main/java/jeresources/api/messages/ModifyMessage.java delete mode 100644 src/main/java/jeresources/api/messages/ModifyMobMessage.java delete mode 100644 src/main/java/jeresources/api/messages/ModifyOreMessage.java delete mode 100644 src/main/java/jeresources/api/messages/ModifyPlantMessage.java delete mode 100644 src/main/java/jeresources/api/messages/RegisterDungeonMessage.java delete mode 100644 src/main/java/jeresources/api/messages/RegisterMobMessage.java delete mode 100644 src/main/java/jeresources/api/messages/RegisterOreMessage.java delete mode 100644 src/main/java/jeresources/api/messages/RegisterPlantMessage.java delete mode 100644 src/main/java/jeresources/api/messages/RegistryMessage.java delete mode 100644 src/main/java/jeresources/api/messages/RemoveMobMessage.java delete mode 100644 src/main/java/jeresources/api/messages/RemovePlantMessage.java delete mode 100644 src/main/java/jeresources/api/messages/SendMessage.java delete mode 100644 src/main/java/jeresources/api/messages/package-info.java delete mode 100644 src/main/java/jeresources/api/messages/utils/MessageHelper.java delete mode 100644 src/main/java/jeresources/api/messages/utils/MessageKeys.java rename src/main/java/jeresources/api/{utils/ColorHelper.java => render/ColourHelper.java} (94%) create mode 100644 src/main/java/jeresources/api/render/IMobRenderHook.java rename src/main/java/jeresources/api/{utils/Modifier.java => render/TextModifier.java} (78%) rename src/main/java/jeresources/api/{utils => }/restrictions/BiomeRestriction.java (84%) rename src/main/java/jeresources/api/{utils => }/restrictions/BlockRestriction.java (59%) rename src/main/java/jeresources/api/{utils => }/restrictions/DimensionRegistry.java (98%) rename src/main/java/jeresources/api/{utils => }/restrictions/DimensionRestriction.java (83%) rename src/main/java/jeresources/api/{utils => }/restrictions/Restriction.java (76%) rename src/main/java/jeresources/api/{utils => }/restrictions/Type.java (54%) delete mode 100644 src/main/java/jeresources/api/utils/Priority.java delete mode 100644 src/main/java/jeresources/api/utils/package-info.java create mode 100644 src/main/java/jeresources/compatibility/JERAPI.java create mode 100644 src/main/java/jeresources/compatibility/MobRegistryImpl.java rename src/main/java/jeresources/{utils => compatibility}/ModList.java (93%) create mode 100644 src/main/java/jeresources/compatibility/WorldGenRegistryImpl.java create mode 100644 src/main/java/jeresources/compatibility/minecraft/RenderHooks.java delete mode 100644 src/main/java/jeresources/entries/OreMatchEntry.java create mode 100644 src/main/java/jeresources/entries/WorldGenEntry.java delete mode 100644 src/main/java/jeresources/jei/ore/OreHandler.java rename src/main/java/jeresources/jei/{ore/OreCategory.java => worldgen/WorldGenCategory.java} (58%) create mode 100644 src/main/java/jeresources/jei/worldgen/WorldGenHandler.java rename src/main/java/jeresources/jei/{ore/OreWrapper.java => worldgen/WorldGenWrapper.java} (82%) rename src/main/java/jeresources/json/{OreAdapter.java => WorldGenAdapter.java} (77%) delete mode 100644 src/main/java/jeresources/registry/MessageRegistry.java delete mode 100644 src/main/java/jeresources/registry/OreRegistry.java create mode 100644 src/main/java/jeresources/registry/WorldGenRegistry.java rename src/main/resources/assets/jeresources/textures/gui/{JEIOreGUI.png => JEIWorldGenGUI.png} (100%) diff --git a/examples/ores.json b/examples/ores.json deleted file mode 100644 index f114317a..00000000 --- a/examples/ores.json +++ /dev/null @@ -1,45 +0,0 @@ -[ - { - "ore": "minecraft:coal_ore", - "drops": "minecraft:coal:4", - "silktouch": true, - "distrib": "5,0.01;55,0.01;70,0" - }, - { - "ore": "minecraft:redstone_ore", - "drops": "minecraft:redstone:4", - "silktouch": true, - "distrib": "5,0.008;14,0.008;17,0" - }, - { - "ore": "minecraft:lapis_ore", - "drops": "minecraft:dye:4:4", - "silktouch": true, - "distrib": "14,0.001;30,0" - }, - { - "ore": "minecraft:diamond_ore", - "drops": "minecraft:diamond", - "silktouch": true, - "distrib": "5,0.001;14,0.001;17,0" - }, - { - "ore": "minecraft:gold_ore", - "distrib": "5,0.0012;28,0.0012;30,0" - }, - { - "ore": "minecraft:iron_ore", - "distrib": "5,0.06;50,0.06;60,0" - }, - { - // This entry will only be loaded when mod with modID : randomMod is loaded - "mod": "randomMod", - // optional field - "silktouch": true, - "ore": "randomMod:random_ore", - // optional field item, item, ... - "drops": "randomMod:item1:amount,randomMod:item2:meta:amount", - // distrib is level,chance(1 begin 100%);level,chance... - "distrib": "5,0.06;50,0.06;60,0" - } -] \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 9c69f9b2..c09bce4b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ -version_forge=11.15.0.1707 +version_forge=11.15.1.1722 version_minecraft=1.8.9 version_major=0 -version_minor=2 -version_revis=1 +version_minor=3 +version_revis=0 version_mappings=snapshot_20160101 -version_jei=2.21+ -version_thaumcraft=5.1.0 \ No newline at end of file +version_jei=2.22+ +version_thaumcraft=5.1.4 \ No newline at end of file diff --git a/src/main/java/jeresources/JEResources.java b/src/main/java/jeresources/JEResources.java index f3f6412f..2d9e4b7b 100644 --- a/src/main/java/jeresources/JEResources.java +++ b/src/main/java/jeresources/JEResources.java @@ -1,12 +1,12 @@ package jeresources; +import jeresources.compatibility.JERAPI; import jeresources.config.ConfigHandler; import jeresources.config.Settings; import jeresources.profiling.ProfileCommand; import jeresources.proxy.CommonProxy; import jeresources.reference.MetaData; import jeresources.reference.Reference; -import jeresources.registry.MessageRegistry; import jeresources.utils.LogHelper; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; @@ -42,17 +42,9 @@ public void preInit(FMLPreInitializationEvent event) LogHelper.info("Registering Events..."); PROXY.registerEvents(); - } - @Mod.EventHandler - public void imcCallback(FMLInterModComms.IMCEvent event) - { - for (final FMLInterModComms.IMCMessage imcMessage : event.getMessages()) - { - LogHelper.debug("Message Received - Sender: " + imcMessage.getSender() + " - Message Type: " + imcMessage.key); - if (imcMessage.isNBTMessage()) - MessageRegistry.registerMessage(imcMessage.key, imcMessage.getNBTValue()); - } + LogHelper.info("Init API..."); + JERAPI.init(event.getAsmData()); } @Mod.EventHandler diff --git a/src/main/java/jeresources/api/IJERAPI.java b/src/main/java/jeresources/api/IJERAPI.java new file mode 100644 index 00000000..3078899d --- /dev/null +++ b/src/main/java/jeresources/api/IJERAPI.java @@ -0,0 +1,7 @@ +package jeresources.api; + +public interface IJERAPI +{ + IMobRegistry getMobRegistry(); + IWorldGenRegistry getWorldGenRegistry(); +} diff --git a/src/main/java/jeresources/api/IJERPlugin.java b/src/main/java/jeresources/api/IJERPlugin.java new file mode 100644 index 00000000..db5d07c1 --- /dev/null +++ b/src/main/java/jeresources/api/IJERPlugin.java @@ -0,0 +1,6 @@ +package jeresources.api; + +public interface IJERPlugin +{ + void APIDelivery(IJERAPI ijerapi); +} diff --git a/src/main/java/jeresources/api/IMobRegistry.java b/src/main/java/jeresources/api/IMobRegistry.java new file mode 100644 index 00000000..0924f945 --- /dev/null +++ b/src/main/java/jeresources/api/IMobRegistry.java @@ -0,0 +1,19 @@ +package jeresources.api; + +import jeresources.api.conditionals.LightLevel; +import jeresources.api.drop.DropItem; +import jeresources.api.render.IMobRenderHook; +import net.minecraft.entity.EntityLivingBase; + +public interface IMobRegistry +{ + void registerMob(EntityLivingBase entity, LightLevel lightLevel, int minExp, int maxExp, String[] biomes, DropItem... drops); + void registerMob(EntityLivingBase entity, LightLevel lightLevel, String[] biomes, DropItem... drops); + void registerMob(EntityLivingBase entity, LightLevel lightLevel, int exp, String[] biomes, DropItem... drops); + void registerMob(EntityLivingBase entity, LightLevel lightLevel, int exp, DropItem... drops); + void registerMob(EntityLivingBase entity, LightLevel lightLevel, int minExp, int maxExp, DropItem... drops); + + void registerDrops(Class entity, DropItem... drops); + + void registerRenderHook(Class entity, IMobRenderHook renderHook); +} diff --git a/src/main/java/jeresources/api/IWorldGenRegistry.java b/src/main/java/jeresources/api/IWorldGenRegistry.java new file mode 100644 index 00000000..76bcc0f9 --- /dev/null +++ b/src/main/java/jeresources/api/IWorldGenRegistry.java @@ -0,0 +1,16 @@ +package jeresources.api; + +import jeresources.api.distributions.DistributionBase; +import jeresources.api.drop.DropItem; +import jeresources.api.restrictions.Restriction; +import net.minecraft.item.ItemStack; + +public interface IWorldGenRegistry +{ + void register(ItemStack block, DistributionBase distribution, DropItem... drops); + void register(ItemStack block, DistributionBase distribution, Restriction restriction, DropItem... drops); + void register(ItemStack block, DistributionBase distribution, boolean silktouch, DropItem... drops); + void register(ItemStack block, DistributionBase distribution, Restriction restriction, boolean silktouch, DropItem... drops); + + void registerDrops(ItemStack block, DropItem... drops); +} diff --git a/src/main/java/jeresources/api/JERPlugin.java b/src/main/java/jeresources/api/JERPlugin.java new file mode 100644 index 00000000..b5c3ea0f --- /dev/null +++ b/src/main/java/jeresources/api/JERPlugin.java @@ -0,0 +1,8 @@ +package jeresources.api; + +/** + * Implement {@link IJERPlugin} on a class with this interface + */ +public @interface JERPlugin +{ +} diff --git a/src/main/java/jeresources/api/utils/conditionals/Conditional.java b/src/main/java/jeresources/api/conditionals/Conditional.java similarity index 76% rename from src/main/java/jeresources/api/utils/conditionals/Conditional.java rename to src/main/java/jeresources/api/conditionals/Conditional.java index 47bd091a..d746c0db 100644 --- a/src/main/java/jeresources/api/utils/conditionals/Conditional.java +++ b/src/main/java/jeresources/api/conditionals/Conditional.java @@ -1,6 +1,6 @@ -package jeresources.api.utils.conditionals; +package jeresources.api.conditionals; -import jeresources.api.utils.Modifier; +import jeresources.api.render.TextModifier; import net.minecraft.util.StatCollector; import java.util.LinkedHashMap; @@ -10,49 +10,49 @@ public class Conditional { public static final Map reverse = new LinkedHashMap(); - public static final Conditional magmaCream = new Conditional("jer.magmaCream.text", Modifier.darkRed); - public static final Conditional slimeBall = new Conditional("jer.slimeBall.text", Modifier.lightGreen); - public static final Conditional rareDrop = new Conditional("jer.rareDrop.text", Modifier.purple); - public static final Conditional silkTouch = new Conditional("jer.ore.silkTouch", Modifier.darkCyan); - public static final Conditional equipmentDrop = new Conditional("jer.equipmentDrop.text", Modifier.lightCyan); + public static final Conditional magmaCream = new Conditional("jer.magmaCream.text", TextModifier.darkRed); + public static final Conditional slimeBall = new Conditional("jer.slimeBall.text", TextModifier.lightGreen); + public static final Conditional rareDrop = new Conditional("jer.rareDrop.text", TextModifier.purple); + public static final Conditional silkTouch = new Conditional("jer.worldgen.silkTouch", TextModifier.darkCyan); + public static final Conditional equipmentDrop = new Conditional("jer.equipmentDrop.text", TextModifier.lightCyan); - public static final Conditional burning = new Conditional("jer.burning.text", Modifier.lightRed); + public static final Conditional burning = new Conditional("jer.burning.text", TextModifier.lightRed); public static final Conditional notBurning = new Conditional("jer.notBurning.text", burning); - public static final Conditional wet = new Conditional("jer.wet.text", Modifier.lightCyan); + public static final Conditional wet = new Conditional("jer.wet.text", TextModifier.lightCyan); public static final Conditional notWet = new Conditional("jer.notWet.text", wet); - public static final Conditional hasPotion = new Conditional("jer.hasPotion.text", Modifier.pink); + public static final Conditional hasPotion = new Conditional("jer.hasPotion.text", TextModifier.pink); public static final Conditional hasNoPotion = new Conditional("jer.hasNoPotion.text", hasPotion); - public static final Conditional beyond = new Conditional("jer.beyond.text", Modifier.darkGreen); + public static final Conditional beyond = new Conditional("jer.beyond.text", TextModifier.darkGreen); public static final Conditional nearer = new Conditional("jer.nearer.text", beyond); - public static final Conditional raining = new Conditional("jer.raining.text", Modifier.lightGrey); + public static final Conditional raining = new Conditional("jer.raining.text", TextModifier.lightGrey); public static final Conditional dry = new Conditional("jer.dry.text", raining); - public static final Conditional thundering = new Conditional("jer.thundering.text", Modifier.darkGrey); + public static final Conditional thundering = new Conditional("jer.thundering.text", TextModifier.darkGrey); public static final Conditional notThundering = new Conditional("jer.notThundering.text", thundering); public static final Conditional moonPhase = new Conditional("jer.moonPhase.text"); public static final Conditional notMoonPhase = new Conditional("jer.notMoonPhase.text", moonPhase); - public static final Conditional pastTime = new Conditional("jer.pastTime.text", Modifier.lilac); + public static final Conditional pastTime = new Conditional("jer.pastTime.text", TextModifier.lilac); public static final Conditional beforeTime = new Conditional("jer.beforeTime.text", pastTime); - public static final Conditional pastWorldTime = new Conditional("jer.pastWorldTime.text", Modifier.purple); + public static final Conditional pastWorldTime = new Conditional("jer.pastWorldTime.text", TextModifier.purple); public static final Conditional beforeWorldTime = new Conditional("jer.beforeWorldTime.text", pastWorldTime); - public static final Conditional pastWorldDifficulty = new Conditional("jer.pastWorldDifficulty.text", Modifier.orange); + public static final Conditional pastWorldDifficulty = new Conditional("jer.pastWorldDifficulty.text", TextModifier.orange); public static final Conditional beforeWorldDifficulty = new Conditional("jer.beforeWorldDifficulty.text", pastWorldDifficulty); - public static final Conditional gameDifficulty = new Conditional("jer.gameDifficulty.text", Modifier.orange); + public static final Conditional gameDifficulty = new Conditional("jer.gameDifficulty.text", TextModifier.orange); public static final Conditional notGameDifficulty = new Conditional("jer.notGameDifficulty.text", gameDifficulty); - public static final Conditional inDimension = new Conditional("jer.inDimension.text", Modifier.yellow); + public static final Conditional inDimension = new Conditional("jer.inDimension.text", TextModifier.yellow); public static final Conditional notInDimension = new Conditional("jer.notInDimension.text", inDimension); - public static final Conditional inBiome = new Conditional("jer.inBiome.text", Modifier.orange); + public static final Conditional inBiome = new Conditional("jer.inBiome.text", TextModifier.orange); public static final Conditional notInBiome = new Conditional("jer.notInBiome.text", inBiome); - public static final Conditional onBlock = new Conditional("jer.onBlock.text", Modifier.lightRed); + public static final Conditional onBlock = new Conditional("jer.onBlock.text", TextModifier.lightRed); public static final Conditional notOnBlock = new Conditional("jer.notOnBlock.text", onBlock); - public static final Conditional below = new Conditional("jer.below.text", Modifier.darkGreen); + public static final Conditional below = new Conditional("jer.below.text", TextModifier.darkGreen); public static final Conditional above = new Conditional("jer.above.text", below); - public static final Conditional playerOnline = new Conditional("jer.playerOnline.text", Modifier.bold); + public static final Conditional playerOnline = new Conditional("jer.playerOnline.text", TextModifier.bold); public static final Conditional playerOffline = new Conditional("jer.playerOffline.text", playerOnline); public static final Conditional playerKill = new Conditional("jer.playerKill.text"); public static final Conditional notPlayerKill = new Conditional("jer.notPlayerKill.text", playerKill); - public static final Conditional aboveLooting = new Conditional("jer.aboveLooting.text", Modifier.darkBlue); + public static final Conditional aboveLooting = new Conditional("jer.aboveLooting.text", TextModifier.darkBlue); public static final Conditional belowLooting = new Conditional("jer.belowLooting.text", aboveLooting); - public static final Conditional killedBy = new Conditional("jer.killedBy.text", Modifier.darkRed); + public static final Conditional killedBy = new Conditional("jer.killedBy.text", TextModifier.darkRed); public static final Conditional notKilledBy = new Conditional("jer.notKilledBy.text", killedBy); protected String text; @@ -63,11 +63,11 @@ public Conditional() { } - public Conditional(String text, Modifier... modifiers) + public Conditional(String text, TextModifier... textModifiers) { this.text = text; - for (Modifier modifier : modifiers) - colour += modifier.toString(); + for (TextModifier textModifier : textModifiers) + colour += textModifier.toString(); } public Conditional(String text, Conditional opposite) diff --git a/src/main/java/jeresources/api/utils/conditionals/ExtendedConditional.java b/src/main/java/jeresources/api/conditionals/ExtendedConditional.java similarity index 89% rename from src/main/java/jeresources/api/utils/conditionals/ExtendedConditional.java rename to src/main/java/jeresources/api/conditionals/ExtendedConditional.java index 3280e079..a52bb24e 100644 --- a/src/main/java/jeresources/api/utils/conditionals/ExtendedConditional.java +++ b/src/main/java/jeresources/api/conditionals/ExtendedConditional.java @@ -1,4 +1,4 @@ -package jeresources.api.utils.conditionals; +package jeresources.api.conditionals; public class ExtendedConditional extends Conditional { diff --git a/src/main/java/jeresources/api/utils/LightLevel.java b/src/main/java/jeresources/api/conditionals/LightLevel.java similarity index 50% rename from src/main/java/jeresources/api/utils/LightLevel.java rename to src/main/java/jeresources/api/conditionals/LightLevel.java index 72f44593..c6d5cf20 100644 --- a/src/main/java/jeresources/api/utils/LightLevel.java +++ b/src/main/java/jeresources/api/conditionals/LightLevel.java @@ -1,4 +1,4 @@ -package jeresources.api.utils; +package jeresources.api.conditionals; import net.minecraft.util.StatCollector; @@ -14,7 +14,7 @@ public class LightLevel /** * @param level the level of light - * @param relative an {@link jeresources.api.utils.LightLevel.Relative} + * @param relative an {@link LightLevel.Relative} */ LightLevel(int level, Relative relative) { @@ -22,41 +22,8 @@ public class LightLevel this.relative = relative; } - public static LightLevel decodeLightLevel(String string) - { - if (string == null || string.equals("") || !string.contains(":")) return any; - String[] splitString = string.split(":"); - - if (splitString.length != 2) return any; - int level; - try - { - level = Integer.valueOf(splitString[0]); - } catch (Exception e) - { - return any; - } - if (level < 0 || level > 15) return any; - return new LightLevel(level, splitString[1].equals("a") ? Relative.above : Relative.below); - } - - public String encode() - { - return this.lightLevel + ":" + (relative == Relative.above ? "a" : "b"); - } - - /** - * @param level the level of light - * @param relative the relative positive is above, negative is below. Zero will also be below. - */ - LightLevel(int level, int relative) - { - this.lightLevel = level; - this.relative = relative > 0 ? Relative.above : Relative.below; - } - /** - * @param level the maximum level light the mob can spawn (the {@link jeresources.api.utils.LightLevel.Relative} will be below) + * @param level the maximum level light the mob can spawn (the {@link LightLevel.Relative} will be below) */ LightLevel(int level) { @@ -72,7 +39,7 @@ public String toString() } /** - * The {@link jeresources.api.utils.LightLevel.Relative} enum holding an above and below entry + * The {@link LightLevel.Relative} enum holding an above and below entry */ public enum Relative { diff --git a/src/main/java/jeresources/api/distributions/DistributionBase.java b/src/main/java/jeresources/api/distributions/DistributionBase.java index bd5b3a44..2af52f63 100644 --- a/src/main/java/jeresources/api/distributions/DistributionBase.java +++ b/src/main/java/jeresources/api/distributions/DistributionBase.java @@ -1,9 +1,5 @@ package jeresources.api.distributions; -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import net.minecraft.nbt.NBTTagCompound; - public abstract class DistributionBase { private float[] distribution; @@ -23,11 +19,4 @@ public int getBestHeight() { return bestHeight; } - - public NBTTagCompound writeToNBT(NBTTagCompound result) - { - result.setIntArray(MessageKeys.distribution, MessageHelper.getIntArray(distribution)); - result.setInteger(MessageKeys.bestHeight, bestHeight); - return result; - } } diff --git a/src/main/java/jeresources/api/distributions/DistributionCustom.java b/src/main/java/jeresources/api/distributions/DistributionCustom.java index e7510035..18a920cc 100644 --- a/src/main/java/jeresources/api/distributions/DistributionCustom.java +++ b/src/main/java/jeresources/api/distributions/DistributionCustom.java @@ -1,7 +1,5 @@ package jeresources.api.distributions; -import jeresources.api.utils.DistributionHelpers; - public class DistributionCustom extends DistributionBase { diff --git a/src/main/java/jeresources/api/utils/DistributionHelpers.java b/src/main/java/jeresources/api/distributions/DistributionHelpers.java similarity index 97% rename from src/main/java/jeresources/api/utils/DistributionHelpers.java rename to src/main/java/jeresources/api/distributions/DistributionHelpers.java index 0e67bdb4..1c5e679d 100644 --- a/src/main/java/jeresources/api/utils/DistributionHelpers.java +++ b/src/main/java/jeresources/api/distributions/DistributionHelpers.java @@ -1,4 +1,4 @@ -package jeresources.api.utils; +package jeresources.api.distributions; import java.util.Collections; import java.util.Set; @@ -134,6 +134,11 @@ public static float[] addDistribution(float[] base, float[] add) return addDistribution(base, add, 0); } + public static DistributionBase addDistribution(DistributionBase base, DistributionBase add) + { + return new DistributionCustom(addDistribution(base.getDistribution(), add.getDistribution())); + } + /** * @param base base distribution * @param add the to add distribution diff --git a/src/main/java/jeresources/api/distributions/DistributionSquare.java b/src/main/java/jeresources/api/distributions/DistributionSquare.java index eec6431b..c24ba50d 100644 --- a/src/main/java/jeresources/api/distributions/DistributionSquare.java +++ b/src/main/java/jeresources/api/distributions/DistributionSquare.java @@ -1,7 +1,5 @@ package jeresources.api.distributions; -import jeresources.api.utils.DistributionHelpers; - public class DistributionSquare extends DistributionBase { /** diff --git a/src/main/java/jeresources/api/distributions/DistributionTriangular.java b/src/main/java/jeresources/api/distributions/DistributionTriangular.java index 42b4a946..bd22dfba 100644 --- a/src/main/java/jeresources/api/distributions/DistributionTriangular.java +++ b/src/main/java/jeresources/api/distributions/DistributionTriangular.java @@ -1,7 +1,5 @@ package jeresources.api.distributions; -import jeresources.api.utils.DistributionHelpers; - public class DistributionTriangular extends DistributionBase { /** diff --git a/src/main/java/jeresources/api/distributions/DistributionUnderWater.java b/src/main/java/jeresources/api/distributions/DistributionUnderWater.java index e429daf7..0f5b16d9 100644 --- a/src/main/java/jeresources/api/distributions/DistributionUnderWater.java +++ b/src/main/java/jeresources/api/distributions/DistributionUnderWater.java @@ -1,7 +1,5 @@ package jeresources.api.distributions; -import jeresources.api.utils.DistributionHelpers; - public class DistributionUnderWater extends DistributionBase { diff --git a/src/main/java/jeresources/api/distributions/package-info.java b/src/main/java/jeresources/api/distributions/package-info.java deleted file mode 100644 index e3fb84ca..00000000 --- a/src/main/java/jeresources/api/distributions/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@API(owner = "jeresources", apiVersion = "@MAJOR@.@MINOR@.@REVIS@", provides = "jeresources|API") -package jeresources.api.distributions; - -import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/main/java/jeresources/api/utils/DropItem.java b/src/main/java/jeresources/api/drop/DropItem.java similarity index 70% rename from src/main/java/jeresources/api/utils/DropItem.java rename to src/main/java/jeresources/api/drop/DropItem.java index 2ef0a7f5..9d1f9e5d 100644 --- a/src/main/java/jeresources/api/utils/DropItem.java +++ b/src/main/java/jeresources/api/drop/DropItem.java @@ -1,11 +1,8 @@ -package jeresources.api.utils; +package jeresources.api.drop; -import jeresources.api.utils.conditionals.Conditional; +import jeresources.api.conditionals.Conditional; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import java.util.ArrayList; import java.util.List; @@ -136,45 +133,6 @@ public void addConditionals(List conditionals) this.conditionals.addAll(conditionals); } - public NBTTagCompound writeToNBT() - { - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("stack", item.writeToNBT(new NBTTagCompound())); - compound.setInteger("max", this.maxDrop); - compound.setInteger("min", this.minDrop); - compound.setFloat("chance", this.chance); - NBTTagList conditionals = new NBTTagList(); - for (String condition : this.conditionals) - conditionals.appendTag(new NBTTagString(condition)); - compound.setTag("conditionals", conditionals); - return compound; - } - - public static DropItem readFromNBT(NBTTagCompound tagCompound) - { - NBTTagCompound item = tagCompound.getCompoundTag("stack"); - if (item.hasNoTags()) return null; - ItemStack stack = ItemStack.loadItemStackFromNBT(item); - if (stack == null || stack.getItem() == null) return null; - int max = Math.max(tagCompound.getInteger("max"), 1); - int min = tagCompound.getInteger("min"); - float chance = tagCompound.getFloat("chance"); - if (chance == 0) chance = 1F; - Conditional[] conditionals = decodeConditionals(tagCompound.getTagList("conditionals", 8)); - return new DropItem(stack, min, max, chance, conditionals); - } - - public static Conditional[] decodeConditionals(NBTTagList conditional) - { - List result = new ArrayList(); - for (int i = 0; i < conditional.tagCount(); i++) - { - String condition = conditional.getStringTagAt(i); - if (!condition.equals("")) result.add(new Conditional(condition)); - } - return result.toArray(new Conditional[result.size()]); - } - public float getSortIndex() { return sortIndex; diff --git a/src/main/java/jeresources/api/utils/PlantDrop.java b/src/main/java/jeresources/api/drop/PlantDrop.java similarity index 53% rename from src/main/java/jeresources/api/utils/PlantDrop.java rename to src/main/java/jeresources/api/drop/PlantDrop.java index 60225a00..e27eec17 100644 --- a/src/main/java/jeresources/api/utils/PlantDrop.java +++ b/src/main/java/jeresources/api/drop/PlantDrop.java @@ -1,4 +1,4 @@ -package jeresources.api.utils; +package jeresources.api.drop; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -88,51 +88,4 @@ public DropKind getDropKind() { return dropKind; } - - public NBTTagCompound writeToNBT() - { - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("drop", drop.writeToNBT(new NBTTagCompound())); - compound.setInteger("dropKind", dropKind.ordinal()); - switch (dropKind) - { - case chance: - compound.setFloat("chance", chance); - break; - case weight: - compound.setInteger("weight", itemWeight); - break; - case minMax: - compound.setInteger("min", minDrop); - compound.setInteger("max", maxDrop); - break; - default: - break; - } - return compound; - } - - public static PlantDrop readFromNBT(NBTTagCompound tagCompound) - { - NBTTagCompound drop = tagCompound.getCompoundTag("drop"); - if (drop.hasNoTags()) return null; - ItemStack stack = ItemStack.loadItemStackFromNBT(drop); - if (stack == null || stack.getItem() == null) return null; - DropKind kind = DropKind.values()[tagCompound.getInteger("dropKind")]; - switch (kind) - { - case chance: - float chance = tagCompound.getFloat("chance"); - return new PlantDrop(stack, chance); - case weight: - int weight = tagCompound.getInteger("weight"); - return new PlantDrop(stack, weight); - case minMax: - int min = tagCompound.getInteger("min"); - int max = tagCompound.getInteger("max"); - return new PlantDrop(stack, min, max); - default: - return null; - } - } } diff --git a/src/main/java/jeresources/api/messages/Message.java b/src/main/java/jeresources/api/messages/Message.java deleted file mode 100644 index 0c2700c4..00000000 --- a/src/main/java/jeresources/api/messages/Message.java +++ /dev/null @@ -1,51 +0,0 @@ -package jeresources.api.messages; - -import net.minecraft.nbt.NBTTagCompound; - -public abstract class Message -{ - public NBTTagCompound getMessage() - { - return writeToNBT(new NBTTagCompound()); - } - - public abstract NBTTagCompound writeToNBT(NBTTagCompound tagCompound); - - public abstract boolean isValid(); - - public static class Storage - { - private final String key; - private final Message message; - private final NBTTagCompound messageNBT; - - public Storage(String key, Message message) - { - this.key = key; - this.message = message; - this.messageNBT = message.writeToNBT(new NBTTagCompound()); - } - - public Storage(String key, NBTTagCompound message) - { - this.key = key; - this.message = null; - this.messageNBT = message; - } - - public Message getMessage() - { - return message; - } - - public String getKey() - { - return key; - } - - public NBTTagCompound getMessageNBT() - { - return messageNBT; - } - } -} diff --git a/src/main/java/jeresources/api/messages/ModifyMessage.java b/src/main/java/jeresources/api/messages/ModifyMessage.java deleted file mode 100644 index e78ec794..00000000 --- a/src/main/java/jeresources/api/messages/ModifyMessage.java +++ /dev/null @@ -1,58 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.Priority; -import net.minecraft.nbt.NBTTagCompound; - -public abstract class ModifyMessage extends Message -{ - private final Priority addPriority; - private final Priority removePriority; - - public ModifyMessage(Priority addPriority, Priority removePriority) - { - this.addPriority = addPriority; - this.removePriority = removePriority; - } - - public ModifyMessage(Priority priority, boolean add) - { - if (add) - { - addPriority = priority; - removePriority = Priority.FIRST; - } else - { - addPriority = Priority.FIRST; - removePriority = priority; - } - } - - public Priority getAddPriority() - { - return addPriority; - } - - public Priority getRemovePriority() - { - return removePriority; - } - - public abstract boolean hasAdd(); - - public abstract boolean hasRemove(); - - public ModifyMessage(NBTTagCompound tagCompound) - { - addPriority = Priority.getPriority(tagCompound.getInteger(MessageKeys.addPriority)); - removePriority = Priority.getPriority(tagCompound.getInteger(MessageKeys.removePriority)); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - tagCompound.setInteger(MessageKeys.addPriority, addPriority.ordinal()); - tagCompound.setInteger(MessageKeys.removePriority, removePriority.ordinal()); - return tagCompound; - } -} diff --git a/src/main/java/jeresources/api/messages/ModifyMobMessage.java b/src/main/java/jeresources/api/messages/ModifyMobMessage.java deleted file mode 100644 index fb199306..00000000 --- a/src/main/java/jeresources/api/messages/ModifyMobMessage.java +++ /dev/null @@ -1,191 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.Priority; -import jeresources.utils.ReflectionHelper; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -public class ModifyMobMessage extends ModifyMessage -{ - private Class clazz; - private DropItem[] addDrops = new DropItem[0]; - private ItemStack[] removeDrops = new ItemStack[0]; - private boolean strict; - private boolean witherSkeleton; - - public ModifyMobMessage(Class clazz, DropItem... addDrops) - { - this(clazz, false, false, addDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, DropItem... addDrops) - { - this(clazz, strict, false, addDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, boolean witherSkeleton, DropItem... addDrops) - { - this(clazz, strict, witherSkeleton, Priority.SECOND, addDrops); - } - - public ModifyMobMessage(Class clazz, Priority priority, DropItem... addDrops) - { - this(clazz, false, false, priority, addDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, Priority priority, DropItem... addDrops) - { - this(clazz, strict, false, priority, addDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, boolean witherSkeleton, Priority priority, DropItem... addDrops) - { - this(clazz, strict, witherSkeleton, addDrops, new ItemStack[0], priority); - } - - public ModifyMobMessage(Class clazz, ItemStack... removeDrops) - { - this(clazz, false, false, removeDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, ItemStack... removeDrops) - { - this(clazz, strict, false, removeDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, boolean witherSkeleton, ItemStack... removeDrops) - { - this(clazz, strict, witherSkeleton, Priority.SECOND, removeDrops); - } - - public ModifyMobMessage(Class clazz, Priority priority, ItemStack... removeDrops) - { - this(clazz, false, false, priority, removeDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, Priority priority, ItemStack... removeDrops) - { - this(clazz, strict, false, priority, removeDrops); - } - - public ModifyMobMessage(Class clazz, boolean strict, boolean witherSkeleton, Priority priority, ItemStack... removeDrops) - { - this(clazz, strict, witherSkeleton, new DropItem[0], removeDrops, priority); - } - - public ModifyMobMessage(Class clazz, DropItem[] addDrops, ItemStack[] removeDrops) - { - this(clazz, addDrops, removeDrops, Priority.SECOND); - } - - public ModifyMobMessage(Class clazz, boolean strict, DropItem[] addDrops, ItemStack[] removeDrops) - { - this(clazz, strict, addDrops, removeDrops, Priority.SECOND); - } - - public ModifyMobMessage(Class clazz, boolean strict, boolean witherSkeleton, DropItem[] addDrops, ItemStack[] removeDrops) - { - this(clazz, strict, witherSkeleton, addDrops, removeDrops, Priority.SECOND); - } - - public ModifyMobMessage(Class clazz, DropItem[] addDrops, ItemStack[] removeDrops, Priority priority) - { - this(clazz, false, addDrops, removeDrops, priority); - } - - public ModifyMobMessage(Class clazz, boolean strict, DropItem[] addDrops, ItemStack[] removeDrops, Priority priority) - { - this(clazz, strict, false, addDrops, removeDrops, priority); - } - - public ModifyMobMessage(Class clazz, boolean strict, boolean witherSkeleton, DropItem[] addDrops, ItemStack[] removeDrops, Priority priority) - { - this(clazz, strict, witherSkeleton, addDrops, removeDrops, priority, priority); - } - - public ModifyMobMessage(Class clazz, boolean strict, boolean witherSkeleton, DropItem[] addDrops, ItemStack[] removeDrops, Priority addPriority, Priority removePriority) - { - super(addPriority, removePriority); - initialize(clazz, strict, witherSkeleton, addDrops, removeDrops); - } - - @Override - public boolean hasAdd() - { - return addDrops.length > 0; - } - - @Override - public boolean hasRemove() - { - return removeDrops.length > 0; - } - - public Class getFilterClass() - { - return clazz; - } - - public DropItem[] getAddDrops() - { - return addDrops; - } - - public ItemStack[] getRemoveDrops() - { - return removeDrops; - } - - public boolean isWither() - { - return witherSkeleton; - } - - public boolean isStrict() - { - return strict; - } - - public ModifyMobMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - initialize(ReflectionHelper.findClass(tagCompound.getString(MessageKeys.name)), tagCompound.getBoolean(MessageKeys.strict), tagCompound.getBoolean(MessageKeys.wither), MessageHelper.getDropItems(tagCompound, MessageKeys.addDrops), MessageHelper.getItemStacks(tagCompound, MessageKeys.removeDrops)); - } - - private void initialize(Class clazz, boolean strict, boolean witherSkeleton, DropItem[] addDrops, ItemStack[] removeDrops) - { - this.clazz = clazz; - this.strict = strict; - this.witherSkeleton = witherSkeleton; - this.addDrops = addDrops; - this.removeDrops = removeDrops; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setString(MessageKeys.name, this.clazz.getName()); - tagCompound.setBoolean(MessageKeys.strict, this.strict); - tagCompound.setBoolean(MessageKeys.wither, this.witherSkeleton); - tagCompound.setTag(MessageKeys.addDrops, MessageHelper.getDropItemList(addDrops)); - tagCompound.setTag(MessageKeys.removeDrops, MessageHelper.getItemStackList(removeDrops)); - return tagCompound; - } - - public void setWither(boolean wither) - { - this.witherSkeleton = wither; - } - - @Override - public boolean isValid() - { - return clazz != null && (hasAdd() || hasRemove()); - } - - -} \ No newline at end of file diff --git a/src/main/java/jeresources/api/messages/ModifyOreMessage.java b/src/main/java/jeresources/api/messages/ModifyOreMessage.java deleted file mode 100644 index b0213046..00000000 --- a/src/main/java/jeresources/api/messages/ModifyOreMessage.java +++ /dev/null @@ -1,105 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.Priority; -import jeresources.api.utils.restrictions.Restriction; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -public class ModifyOreMessage extends ModifyMessage -{ - private ItemStack ore; - private DropItem[] addDrops = new DropItem[0]; - private DropItem[] removeDrops = new DropItem[0]; - - public ModifyOreMessage(ItemStack ore, DropItem... drops) - { - this(ore, true, drops); - } - - public ModifyOreMessage(ItemStack ore, Priority priority, DropItem... drops) - { - this(ore, true, priority, drops); - } - - public ModifyOreMessage(ItemStack ore, boolean add, DropItem... drops) - { - this(ore, add, Priority.SECOND, drops); - } - - public ModifyOreMessage(ItemStack ore, boolean add, Priority priority, DropItem... drops) - { - super(priority, add); - this.ore = ore; - if (add) - this.addDrops = drops; - else - this.removeDrops = drops; - } - - public ModifyOreMessage(ItemStack ore, DropItem[] removeDrops, DropItem[] addDrops) - { - this(ore, removeDrops, addDrops, Priority.SECOND, Priority.FIRST); - } - - public ModifyOreMessage(ItemStack ore, DropItem[] removeDrops, DropItem[] addDrops, Priority removePriority, Priority addPriority) - { - super(addPriority, removePriority); - this.ore = ore; - this.removeDrops = removeDrops; - this.addDrops = addDrops; - } - - public ModifyOreMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - this.ore = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag(MessageKeys.stack)); - this.addDrops = MessageHelper.getDropItems(tagCompound, MessageKeys.addDrops); - this.removeDrops = MessageHelper.getDropItems(tagCompound, MessageKeys.removeDrops); - } - - public ItemStack getOre() - { - return ore; - } - - public DropItem[] getRemoveDrops() - { - return removeDrops; - } - - public DropItem[] getAddDrops() - { - return addDrops; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setTag(MessageKeys.stack, ore.writeToNBT(new NBTTagCompound())); - tagCompound.setTag(MessageKeys.addDrops, MessageHelper.getDropItemList(addDrops)); - tagCompound.setTag(MessageKeys.removeDrops, MessageHelper.getDropItemList(removeDrops)); - return tagCompound; - } - - @Override - public boolean hasAdd() - { - return addDrops.length > 0; - } - - @Override - public boolean hasRemove() - { - return removeDrops.length > 0; - } - - @Override - public boolean isValid() - { - return ore != null && (hasAdd() || hasRemove()); - } -} diff --git a/src/main/java/jeresources/api/messages/ModifyPlantMessage.java b/src/main/java/jeresources/api/messages/ModifyPlantMessage.java deleted file mode 100644 index c9626def..00000000 --- a/src/main/java/jeresources/api/messages/ModifyPlantMessage.java +++ /dev/null @@ -1,118 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.PlantDrop; -import jeresources.api.utils.Priority; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -public class ModifyPlantMessage extends ModifyMessage -{ - private ItemStack plant; - private PlantDrop[] addDrops = new PlantDrop[0]; - private ItemStack[] removeDrops = new ItemStack[0]; - - private ModifyPlantMessage(ItemStack plant, Priority priority, boolean add) - { - super(priority, add); - this.plant = plant; - } - - private ModifyPlantMessage(ItemStack plant, Priority addPriority, Priority removePriority) - { - super(addPriority, removePriority); - this.plant = plant; - } - - public ModifyPlantMessage(PlantDrop... addDrops) - { - this(new ItemStack(Blocks.tallgrass), addDrops); - } - - public ModifyPlantMessage(ItemStack plant, PlantDrop... addDrops) - { - this(plant, Priority.SECOND, addDrops); - } - - public ModifyPlantMessage(ItemStack plant, Priority priority, PlantDrop... addDrops) - { - this(plant, priority, true, new ItemStack[0], addDrops); - } - - public ModifyPlantMessage(ItemStack... removeDrops) - { - this(new ItemStack(Blocks.tallgrass), removeDrops); - } - - public ModifyPlantMessage(ItemStack plant, ItemStack... removeDrops) - { - this(plant, Priority.SECOND, removeDrops); - } - - public ModifyPlantMessage(ItemStack plant, Priority priority, ItemStack... removeDrops) - { - this(plant, priority, false, removeDrops, new PlantDrop[0]); - } - - public ModifyPlantMessage(ItemStack plant, Priority priority, boolean add, ItemStack[] removeDrops, PlantDrop[] addDrops) - { - this(plant, priority, add); - this.addDrops = addDrops; - this.removeDrops = removeDrops; - } - - public ModifyPlantMessage(ItemStack plant, ItemStack[] removeDrops, PlantDrop[] addDrops) - { - this(plant, removeDrops, addDrops, Priority.SECOND); - } - - public ModifyPlantMessage(ItemStack plant, ItemStack[] removeDrops, PlantDrop[] addDrops, Priority priority) - { - this(plant, removeDrops, addDrops, priority, priority); - } - - public ModifyPlantMessage(ItemStack plant, ItemStack[] removeDrops, PlantDrop[] addDrops, Priority addPriority, Priority removePriority) - { - this(plant, addPriority, removePriority); - this.addDrops = addDrops; - this.removeDrops = removeDrops; - } - - public ModifyPlantMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - this.plant = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag(MessageKeys.stack)); - this.addDrops = MessageHelper.getPlantDrops(tagCompound, MessageKeys.addDrops); - this.removeDrops = MessageHelper.getItemStacks(tagCompound, MessageKeys.removeDrops); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setTag(MessageKeys.stack, plant.writeToNBT(new NBTTagCompound())); - tagCompound.setTag(MessageKeys.addDrops, MessageHelper.getPlantDropList(addDrops)); - tagCompound.setTag(MessageKeys.removeDrops, MessageHelper.getItemStackList(removeDrops)); - return tagCompound; - } - - @Override - public boolean hasAdd() - { - return addDrops.length > 0; - } - - @Override - public boolean hasRemove() - { - return removeDrops.length > 0; - } - - @Override - public boolean isValid() - { - return plant != null && (hasAdd() || hasRemove()); - } -} diff --git a/src/main/java/jeresources/api/messages/RegisterDungeonMessage.java b/src/main/java/jeresources/api/messages/RegisterDungeonMessage.java deleted file mode 100644 index 0b5f857b..00000000 --- a/src/main/java/jeresources/api/messages/RegisterDungeonMessage.java +++ /dev/null @@ -1,100 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.Priority; -import jeresources.utils.WeightedRandomChestContentHelper; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.WeightedRandomChestContent; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class RegisterDungeonMessage extends RegistryMessage -{ - private Map chestDrops = new LinkedHashMap(); - private String name; - private int maxStacks, minStacks; - - public RegisterDungeonMessage(String name, int maxStacks, List chestDrops) - { - this(name, 0, maxStacks, chestDrops); - } - - public RegisterDungeonMessage(String name, int minStacks, int maxStacks, List chestDrops) - { - this(name, minStacks, maxStacks, Priority.FIRST); - int totalWeight = 0; - for (WeightedRandomChestContent chestItem : chestDrops) - totalWeight += chestItem.itemWeight; - for (WeightedRandomChestContent chestItem : WeightedRandomChestContentHelper.sort(chestDrops.toArray(new WeightedRandomChestContent[chestDrops.size()]))) - this.chestDrops.put(chestItem.theItemId, (float) (chestItem.maxStackSize + chestItem.minStackSize) / 2 * (float) chestItem.itemWeight / totalWeight); - } - - public RegisterDungeonMessage(String name, int maxStacks, Map chestDrops) - { - this(name, 0, maxStacks, chestDrops); - } - - public RegisterDungeonMessage(String name, int minStacks, int maxStacks, Map chestDrops) - { - this(name, minStacks, maxStacks, Priority.FIRST); - this.chestDrops = chestDrops; - } - - private RegisterDungeonMessage(String name, int minStacks, int maxStacks, Priority priority) - { - super(priority, true); - this.name = name; - this.minStacks = minStacks; - this.maxStacks = maxStacks; - } - - public RegisterDungeonMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - this.chestDrops = MessageHelper.nbtTagListToMap(tagCompound.getTagList(MessageKeys.itemList, 10)); - this.name = tagCompound.getString(MessageKeys.name); - this.minStacks = tagCompound.getInteger(MessageKeys.min); - this.maxStacks = tagCompound.getInteger(MessageKeys.max); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setTag(MessageKeys.itemList, MessageHelper.mapToNBTTagList(chestDrops)); - tagCompound.setString(MessageKeys.name, name); - tagCompound.setInteger(MessageKeys.min, minStacks); - tagCompound.setInteger(MessageKeys.max, maxStacks); - return tagCompound; - } - - @Override - public boolean isValid() - { - return !name.equals("") && maxStacks > 0 && chestDrops != null && !chestDrops.isEmpty(); - } - - public Map getChestDrops() - { - return chestDrops; - } - - public String getName() - { - return name; - } - - public int getMinStacks() - { - return minStacks; - } - - public int getMaxStacks() - { - return maxStacks; - } -} diff --git a/src/main/java/jeresources/api/messages/RegisterMobMessage.java b/src/main/java/jeresources/api/messages/RegisterMobMessage.java deleted file mode 100644 index d9af70d5..00000000 --- a/src/main/java/jeresources/api/messages/RegisterMobMessage.java +++ /dev/null @@ -1,78 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.LightLevel; -import jeresources.api.utils.Priority; -import jeresources.utils.ReflectionHelper; -import net.minecraft.nbt.NBTTagCompound; - -public class RegisterMobMessage extends RegistryMessage -{ - private Class mobClass; - private LightLevel lightLevel; - private DropItem[] drops; - - public RegisterMobMessage(Class clazz) - { - this(clazz, LightLevel.any); - } - - public RegisterMobMessage(Class clazz, LightLevel level) - { - this(clazz, level, new DropItem[0]); - } - - public RegisterMobMessage(Class clazz, LightLevel level, DropItem[] drops) - { - this(Priority.FIRST, clazz, level, drops); - } - - public RegisterMobMessage(Priority priority, Class clazz, LightLevel level, DropItem[] drops) - { - super(priority, true); - this.mobClass = clazz; - this.lightLevel = level; - this.drops = drops; - } - - public RegisterMobMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - this.mobClass = ReflectionHelper.findClass(tagCompound.getString(MessageKeys.name)); - this.lightLevel = LightLevel.decodeLightLevel(tagCompound.getString(MessageKeys.lightLevel)); - this.drops = MessageHelper.getDropItems(tagCompound, MessageKeys.addDrops); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setString(MessageKeys.name, mobClass.getName()); - tagCompound.setString(MessageKeys.lightLevel, lightLevel.encode()); - tagCompound.setTag(MessageKeys.addDrops, MessageHelper.getDropItemList(drops)); - return tagCompound; - } - - @Override - public boolean isValid() - { - return mobClass != null; - } - - public Class getMobClass() - { - return mobClass; - } - - public LightLevel getLightLevel() - { - return lightLevel; - } - - public DropItem[] getDrops() - { - return drops; - } -} diff --git a/src/main/java/jeresources/api/messages/RegisterOreMessage.java b/src/main/java/jeresources/api/messages/RegisterOreMessage.java deleted file mode 100644 index 91f8b385..00000000 --- a/src/main/java/jeresources/api/messages/RegisterOreMessage.java +++ /dev/null @@ -1,138 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.distributions.DistributionBase; -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.ColorHelper; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.Priority; -import jeresources.api.utils.restrictions.Restriction; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -public class RegisterOreMessage extends RegistryMessage -{ - private ItemStack ore; - private DropItem[] drops; - private boolean needSilkTouch; - private DistributionBase distribution; - private int colour; - private Restriction restriction; - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, DropItem... drops) - { - this(ore, distribution, ColorHelper.BLACK, Restriction.OVERWORLD_LIKE, false, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, boolean needSilkTouch, DropItem... drops) - { - this(ore, distribution, ColorHelper.BLACK, Restriction.OVERWORLD_LIKE, needSilkTouch, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, int colour, DropItem... drops) - { - this(ore, distribution, colour, Restriction.OVERWORLD_LIKE, false, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, int colour, Restriction restriction, boolean needSilkTouch, DropItem... drops) - { - this(ore, distribution, colour, restriction, needSilkTouch, Priority.FIRST, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, int colour, boolean needSilkTouch, Priority priority, DropItem... drops) - { - this(ore, distribution, colour, Restriction.OVERWORLD_LIKE, needSilkTouch, priority, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, Restriction restriction, DropItem... drops) - { - this(ore, distribution, ColorHelper.BLACK, restriction, false, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, Restriction restriction, boolean needSilkTouch, DropItem... drops) - { - this(ore, distribution, ColorHelper.BLACK, restriction, needSilkTouch, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, Restriction restriction, int colour, DropItem... drops) - { - this(ore, distribution, colour, restriction, false, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, Restriction restriction, int colour, boolean needSilkTouch, Priority priority, DropItem... drops) - { - this(ore, distribution, colour, restriction, needSilkTouch, priority, drops); - } - - public RegisterOreMessage(ItemStack ore, DistributionBase distribution, int colour, Restriction restriction, boolean needSilkTouch, Priority priority, DropItem... drops) - { - super(priority, true); - this.ore = ore; - this.drops = drops; - this.needSilkTouch = needSilkTouch; - this.distribution = distribution; - this.colour = colour; - this.restriction = restriction; - } - - - public RegisterOreMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - this.ore = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag(MessageKeys.stack)); - this.drops = MessageHelper.getDropItems(tagCompound, MessageKeys.addDrops); - this.needSilkTouch = tagCompound.getBoolean(MessageKeys.silkTouch); - this.distribution = MessageHelper.getDistribution(tagCompound); - this.colour = tagCompound.hasKey(MessageKeys.colour) ? tagCompound.getInteger(MessageKeys.colour) : ColorHelper.BLACK; - this.restriction = new Restriction(tagCompound.getCompoundTag(MessageKeys.restriction)); - } - - public ItemStack getOre() - { - return this.ore; - } - - public DistributionBase getDistribution() - { - return distribution; - } - - public boolean needSilkTouch() - { - return this.needSilkTouch; - } - - public int getColour() - { - return colour; - } - - public DropItem[] getDrops() - { - return drops; - } - - public Restriction getRestriction() - { - return restriction; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setTag(MessageKeys.stack, ore.writeToNBT(new NBTTagCompound())); - tagCompound.setTag(MessageKeys.addDrops, MessageHelper.getDropItemList(drops)); - distribution.writeToNBT(tagCompound); - tagCompound.setBoolean(MessageKeys.silkTouch, needSilkTouch); - tagCompound.setInteger(MessageKeys.colour, colour); - tagCompound.setTag(MessageKeys.restriction, restriction.writeToNBT()); - return tagCompound; - } - - @Override - public boolean isValid() - { - return ore != null && distribution.getDistribution().length == 256; - } -} diff --git a/src/main/java/jeresources/api/messages/RegisterPlantMessage.java b/src/main/java/jeresources/api/messages/RegisterPlantMessage.java deleted file mode 100644 index 5c46ef59..00000000 --- a/src/main/java/jeresources/api/messages/RegisterPlantMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageHelper; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.PlantDrop; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -public class RegisterPlantMessage extends RegistryMessage -{ - private ItemStack plant; - private PlantDrop[] addDrops; - - public RegisterPlantMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - this.plant = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag(MessageKeys.stack)); - this.addDrops = MessageHelper.getPlantDrops(tagCompound, MessageKeys.addDrops); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setTag(MessageKeys.stack, plant.writeToNBT(new NBTTagCompound())); - tagCompound.setTag(MessageKeys.addDrops, MessageHelper.getPlantDropList(addDrops)); - return tagCompound; - } - - @Override - public boolean isValid() - { - return plant != null && addDrops.length > 0; - } -} diff --git a/src/main/java/jeresources/api/messages/RegistryMessage.java b/src/main/java/jeresources/api/messages/RegistryMessage.java deleted file mode 100644 index 75dd0249..00000000 --- a/src/main/java/jeresources/api/messages/RegistryMessage.java +++ /dev/null @@ -1,52 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.Priority; -import net.minecraft.nbt.NBTTagCompound; - -public abstract class RegistryMessage extends Message -{ - private final Priority priority; - private final boolean add; - - public RegistryMessage(Priority priority, boolean add) - { - this.priority = priority; - this.add = add; - } - - public RegistryMessage(NBTTagCompound tagCompound) - { - this.priority = Priority.getPriority(tagCompound.getInteger(MessageKeys.priority)); - this.add = tagCompound.getBoolean(MessageKeys.addToRegistry); - } - - public boolean isAdd() - { - return add; - } - - public Priority getAddPriority() - { - return add ? priority : null; - } - - public Priority getRemovePriority() - { - return add ? null : priority; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - tagCompound.setBoolean(MessageKeys.addToRegistry, add); - tagCompound.setInteger(MessageKeys.priority, priority.ordinal()); - return null; - } - - @Override - public boolean isValid() - { - return false; - } -} diff --git a/src/main/java/jeresources/api/messages/RemoveMobMessage.java b/src/main/java/jeresources/api/messages/RemoveMobMessage.java deleted file mode 100644 index 11d3d8d7..00000000 --- a/src/main/java/jeresources/api/messages/RemoveMobMessage.java +++ /dev/null @@ -1,85 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.Priority; -import jeresources.utils.ReflectionHelper; -import net.minecraft.nbt.NBTTagCompound; - -public class RemoveMobMessage extends RegistryMessage -{ - private Class filterClass; - private boolean strict; - private boolean witherSkeleton; - - public RemoveMobMessage(Class clazz) - { - this(clazz, false); - } - - public RemoveMobMessage(Priority priority, Class clazz) - { - this(priority, clazz, false); - } - - public RemoveMobMessage(Class clazz, boolean strict) - { - this(clazz, strict, false); - } - - public RemoveMobMessage(Priority priority, Class clazz, boolean strict) - { - this(priority, clazz, strict, false); - } - - public RemoveMobMessage(Class clazz, boolean strict, boolean witherSkeleton) - { - this(Priority.FIRST, clazz, strict, witherSkeleton); - } - - public RemoveMobMessage(Priority priority, Class clazz, boolean strict, boolean witherSkeleton) - { - super(priority, false); - this.filterClass = clazz; - this.strict = strict; - this.witherSkeleton = witherSkeleton; - } - - public RemoveMobMessage(NBTTagCompound tagCompound) - { - super(tagCompound); - this.filterClass = ReflectionHelper.findClass(tagCompound.getString(MessageKeys.name)); - this.strict = tagCompound.getBoolean(MessageKeys.strict); - this.witherSkeleton = tagCompound.getBoolean(MessageKeys.wither); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - tagCompound.setString(MessageKeys.name, this.filterClass.getName()); - tagCompound.setBoolean(MessageKeys.strict, this.strict); - tagCompound.setBoolean(MessageKeys.wither, this.witherSkeleton); - return tagCompound; - } - - @Override - public boolean isValid() - { - return !this.filterClass.equals(""); - } - - public Class getFilterClass() - { - return filterClass; - } - - public boolean isStrict() - { - return strict; - } - - public boolean isWither() - { - return witherSkeleton; - } -} diff --git a/src/main/java/jeresources/api/messages/RemovePlantMessage.java b/src/main/java/jeresources/api/messages/RemovePlantMessage.java deleted file mode 100644 index 7ac15f2a..00000000 --- a/src/main/java/jeresources/api/messages/RemovePlantMessage.java +++ /dev/null @@ -1,24 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.utils.Priority; -import net.minecraft.nbt.NBTTagCompound; - -public class RemovePlantMessage extends RegistryMessage -{ - public RemovePlantMessage(Priority priority) - { - super(priority, false); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - return tagCompound; - } - - @Override - public boolean isValid() - { - return false; - } -} diff --git a/src/main/java/jeresources/api/messages/SendMessage.java b/src/main/java/jeresources/api/messages/SendMessage.java deleted file mode 100644 index 094054b4..00000000 --- a/src/main/java/jeresources/api/messages/SendMessage.java +++ /dev/null @@ -1,79 +0,0 @@ -package jeresources.api.messages; - -import jeresources.api.messages.utils.MessageKeys; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.event.FMLInterModComms; -import net.minecraftforge.fml.relauncher.Side; - -import java.util.LinkedList; -import java.util.List; - -public class SendMessage -{ - private static List storage = new LinkedList(); - - public static void sendMessage(RegisterDungeonMessage message) - { - sendMessage(message, MessageKeys.registerDungeon); - } - - public static void sendMessage(RegisterOreMessage message) - { - sendMessage(message, MessageKeys.registerOre); - } - - public static void sendMessage(ModifyOreMessage message) - { - sendMessage(message, MessageKeys.modifyOre); - } - - public static void sendMessage(RegisterMobMessage message) - { - sendMessage(message, MessageKeys.registerMob); - } - - public static void sendMessage(ModifyMobMessage message) - { - sendMessage(message, MessageKeys.modifyMob); - } - - public static void sendMessage(RegisterPlantMessage message) - { - sendMessage(message, MessageKeys.registerPlant); - } - - public static void sendMessage(ModifyPlantMessage message) - { - sendMessage(message, MessageKeys.modifyPlant); - } - - public static void sendMessage(RemoveMobMessage message) - { - sendMessage(message, MessageKeys.removeMob); - } - - public static void sendMessage(RemovePlantMessage message) - { - sendMessage(message, MessageKeys.removePlant); - } - - public static void sendMessage(Message message, String key) - { - if (message.isValid()) - { - FMLInterModComms.sendMessage(MessageKeys.notEnoughResources, key, message.getMessage()); - if (FMLCommonHandler.instance().getSide() == Side.SERVER) storage.add(new Message.Storage(key, message)); - } - } - - public static void readFromStorage(List storage) - { - for (Message.Storage stored : storage) - sendMessage(stored.getMessage(), stored.getKey()); - } - - public static List getStorage() - { - return storage; - } -} diff --git a/src/main/java/jeresources/api/messages/package-info.java b/src/main/java/jeresources/api/messages/package-info.java deleted file mode 100644 index 8ea07ab0..00000000 --- a/src/main/java/jeresources/api/messages/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@API(owner = "jeresources", apiVersion = "@MAJOR@.@MINOR@.@REVIS@", provides = "jeresources|API") -package jeresources.api.messages; - -import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/main/java/jeresources/api/messages/utils/MessageHelper.java b/src/main/java/jeresources/api/messages/utils/MessageHelper.java deleted file mode 100644 index 9e1eb947..00000000 --- a/src/main/java/jeresources/api/messages/utils/MessageHelper.java +++ /dev/null @@ -1,158 +0,0 @@ -package jeresources.api.messages.utils; - -import jeresources.api.distributions.DistributionCustom; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.PlantDrop; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class MessageHelper -{ - public static final int NBT_MULTIPLIER = 100000; - - public static NBTTagList getItemStackList(ItemStack... stacks) - { - NBTTagList result = new NBTTagList(); - for (ItemStack stack : stacks) - result.appendTag(stack.writeToNBT(new NBTTagCompound())); - return result; - } - - public static NBTTagList getDropItemList(DropItem... dropItems) - { - NBTTagList result = new NBTTagList(); - for (DropItem dropItem : dropItems) - result.appendTag(dropItem.writeToNBT()); - return result; - } - - public static NBTTagList getPlantDropList(PlantDrop... plantDrops) - { - NBTTagList result = new NBTTagList(); - for (PlantDrop plantDrop : plantDrops) - result.appendTag(plantDrop.writeToNBT()); - return result; - } - - public static ItemStack[] getItemStacks(NBTTagCompound tagCompound, String key) - { - return getItemStacks(tagCompound.getTagList(key, 10)); - } - - public static ItemStack[] getItemStacks(NBTTagList list) - { - List result = new ArrayList(); - if (list != null) - { - for (int i = 0; i < list.tagCount(); i++) - { - ItemStack item = ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(i)); - if (item != null) result.add(item); - } - } - return result.toArray(new ItemStack[result.size()]); - } - - public static DropItem[] getDropItems(NBTTagCompound tagCompound, String key) - { - return getDropItems(tagCompound.getTagList(key, 10)); - } - - public static DropItem[] getDropItems(NBTTagList list) - { - List dropItems = new ArrayList(); - if (list != null) - { - for (int i = 0; i < list.tagCount(); i++) - { - DropItem item = DropItem.readFromNBT(list.getCompoundTagAt(i)); - if (item != null) dropItems.add(item); - } - } - return dropItems.toArray(new DropItem[dropItems.size()]); - } - - public static PlantDrop[] getPlantDrops(NBTTagCompound tagCompound, String key) - { - return getPlantDrops(tagCompound.getTagList(key, 10)); - } - - public static PlantDrop[] getPlantDrops(NBTTagList list) - { - List plantDrops = new ArrayList(); - if (list != null) - { - for (int i = 0; i < list.tagCount(); i++) - { - PlantDrop item = PlantDrop.readFromNBT(list.getCompoundTagAt(i)); - if (item != null) plantDrops.add(item); - } - } - return plantDrops.toArray(new PlantDrop[plantDrops.size()]); - } - - public static int[] getIntArray(float[] distribution) - { - int[] array = new int[distribution.length]; - for (int i = 0; i < array.length; i++) - array[i] = (int) (distribution[i] * NBT_MULTIPLIER); - return array; - } - - public static DistributionCustom getDistribution(NBTTagCompound tagCompound) - { - if (!tagCompound.hasKey(MessageKeys.distribution)) return null; - int[] array = tagCompound.getIntArray(MessageKeys.distribution); - float[] distribution = new float[256]; - for (int i = 0; i < array.length && i < distribution.length; i++) - distribution[i] = (float) array[i] / NBT_MULTIPLIER; - if (tagCompound.hasKey(MessageKeys.bestHeight)) - return new DistributionCustom(distribution, tagCompound.getInteger(MessageKeys.bestHeight)); - else - return new DistributionCustom(distribution); - } - - public static String getClass(Object clazz) - { - if (clazz instanceof String) - return (String) clazz; - if (clazz instanceof Class) - return ((Class) clazz).getName(); - return ""; - } - - public static NBTTagList mapToNBTTagList(Map map) - { - NBTTagList result = new NBTTagList(); - for (Map.Entry entry : map.entrySet()) - result.appendTag(entryToNBTTagCompound(entry)); - return result; - } - - private static NBTTagCompound entryToNBTTagCompound(Map.Entry entry) - { - NBTTagCompound result = new NBTTagCompound(); - entry.getKey().writeToNBT(result); - result.setFloat(MessageKeys.chance, entry.getValue()); - return result; - } - - public static Map nbtTagListToMap(NBTTagList list) - { - Map result = new LinkedHashMap(); - for (int i = 0; i < list.tagCount(); i++) - { - NBTTagCompound entry = list.getCompoundTagAt(i); - ItemStack stack = ItemStack.loadItemStackFromNBT(entry); - float chance = entry.getFloat(MessageKeys.chance); - if (stack != null && !(chance < 0)) result.put(stack, chance); - } - return result; - } -} diff --git a/src/main/java/jeresources/api/messages/utils/MessageKeys.java b/src/main/java/jeresources/api/messages/utils/MessageKeys.java deleted file mode 100644 index c447fb3b..00000000 --- a/src/main/java/jeresources/api/messages/utils/MessageKeys.java +++ /dev/null @@ -1,54 +0,0 @@ -package jeresources.api.messages.utils; - -public class MessageKeys -{ - public static final String notEnoughResources = "jeresources"; - - public static final String registerDungeon = "registerDungeon"; - public static final String registerMob = "registerMob"; - public static final String registerOre = "registerOre"; - public static final String registerPlant = "registerPlant"; - public static final String addToRegistry = "add"; - public static final String modifyMob = "modifyMob"; - public static final String modifyOre = "modifyOre"; - public static final String modifyPlant = "modifyPlant"; - public static final String removeMob = "removeMob"; - public static final String removeOre = "removeOre"; - public static final String removePlant = "removePlant"; - - public static final String distribution = "distribution"; - public static final String bestHeight = "bestHeight"; - public static final String stack = "stack"; - public static final String name = "name"; - public static final String lightLevel = "lightLevel"; - public static final String conditionals = "conditionals"; - public static final String colour = "colour"; - - public static final String itemList = "itemList"; - public static final String chance = "chance"; - public static final String min = "min"; - public static final String max = "max"; - - public static final String priority = "priority"; - public static final String addPriority = "addPriority"; - public static final String removePriority = "removePriority"; - - //Lists - public static final String addDrops = "addDrops"; - public static final String removeDrops = "removeDrops"; - - //Booleans - public static final String silkTouch = "silkTouch"; - public static final String wither = "wither"; - public static final String strict = "strict"; - - - public static final String biomeArray = "biomeArray"; - public static final String type = "type"; - public static final String restriction = "restriction"; - public static final String blockRestriction = "block"; - public static final String dimensionRestriction = "dimension"; - public static final String biomeRestriction = "biome"; - - -} diff --git a/src/main/java/jeresources/api/utils/ColorHelper.java b/src/main/java/jeresources/api/render/ColourHelper.java similarity index 94% rename from src/main/java/jeresources/api/utils/ColorHelper.java rename to src/main/java/jeresources/api/render/ColourHelper.java index b2d7abd9..77b4dd24 100644 --- a/src/main/java/jeresources/api/utils/ColorHelper.java +++ b/src/main/java/jeresources/api/render/ColourHelper.java @@ -1,6 +1,6 @@ -package jeresources.api.utils; +package jeresources.api.render; -public class ColorHelper +public class ColourHelper { public static final int BLACK = -16777216; public static final int BLUE = -16776961; diff --git a/src/main/java/jeresources/api/render/IMobRenderHook.java b/src/main/java/jeresources/api/render/IMobRenderHook.java new file mode 100644 index 00000000..d0e85e5a --- /dev/null +++ b/src/main/java/jeresources/api/render/IMobRenderHook.java @@ -0,0 +1,29 @@ +package jeresources.api.render; + +import net.minecraft.entity.EntityLivingBase; + +public interface IMobRenderHook +{ + class RenderInfo + { + public int x, y; + public float scale, yaw, pitch; + + public RenderInfo(int x, int y, float scale, float yaw, float pitch) + { + this.x = x; + this.y = y; + this.scale = scale; + this.yaw = yaw; + this.pitch = pitch; + } + } + + /** + * + * @param renderInfo contains info about the current render context see {@link RenderInfo} + * @param entity the entity that will be rendered + * @return the given {@link RenderInfo} with possible changes + */ + RenderInfo transform(RenderInfo renderInfo, T entity); +} diff --git a/src/main/java/jeresources/api/utils/Modifier.java b/src/main/java/jeresources/api/render/TextModifier.java similarity index 78% rename from src/main/java/jeresources/api/utils/Modifier.java rename to src/main/java/jeresources/api/render/TextModifier.java index f9f2985f..065f3f03 100644 --- a/src/main/java/jeresources/api/utils/Modifier.java +++ b/src/main/java/jeresources/api/render/TextModifier.java @@ -1,6 +1,6 @@ -package jeresources.api.utils; +package jeresources.api.render; -public enum Modifier +public enum TextModifier { black("\u00A70"), darkBlue("\u00A71"), @@ -25,16 +25,16 @@ public enum Modifier italic("\u00A7o"), reset("\u00A7r"); - private String text; + private String prefix; - Modifier(String text) + TextModifier(String prefix) { - this.text = text; + this.prefix = prefix; } @Override public String toString() { - return text; + return prefix; } } diff --git a/src/main/java/jeresources/api/utils/restrictions/BiomeRestriction.java b/src/main/java/jeresources/api/restrictions/BiomeRestriction.java similarity index 84% rename from src/main/java/jeresources/api/utils/restrictions/BiomeRestriction.java rename to src/main/java/jeresources/api/restrictions/BiomeRestriction.java index 5bfd9c87..252b4c71 100644 --- a/src/main/java/jeresources/api/utils/restrictions/BiomeRestriction.java +++ b/src/main/java/jeresources/api/restrictions/BiomeRestriction.java @@ -1,7 +1,5 @@ -package jeresources.api.utils.restrictions; +package jeresources.api.restrictions; -import jeresources.api.messages.utils.MessageKeys; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.BiomeDictionary; @@ -105,14 +103,6 @@ private ArrayList getBiomes(BiomeDictionary.Type biomeType, BiomeD return biomes; } - public BiomeRestriction(NBTTagCompound tagCompound) - { - int[] ids = tagCompound.getIntArray(MessageKeys.biomeArray); - for (int id : ids) - biomes.add(BiomeGenBase.getBiome(id)); - type = Type.values()[tagCompound.getByte(MessageKeys.type)]; - } - public List toStringList() { List result = new ArrayList(); @@ -121,23 +111,6 @@ public List toStringList() return result; } - public NBTTagCompound writeToNBT() - { - return writeToNBT(new NBTTagCompound()); - } - - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - int[] ids = new int[biomes.size()]; - for (int i = 0; i < ids.length; i++) - { - ids[i] = biomes.get(i).biomeID; - } - tagCompound.setIntArray(MessageKeys.biomeArray, ids); - tagCompound.setByte(MessageKeys.type, (byte) type.ordinal()); - return tagCompound; - } - @Override public boolean equals(Object obj) { diff --git a/src/main/java/jeresources/api/utils/restrictions/BlockRestriction.java b/src/main/java/jeresources/api/restrictions/BlockRestriction.java similarity index 59% rename from src/main/java/jeresources/api/utils/restrictions/BlockRestriction.java rename to src/main/java/jeresources/api/restrictions/BlockRestriction.java index 254fa7bf..b48123ff 100644 --- a/src/main/java/jeresources/api/utils/restrictions/BlockRestriction.java +++ b/src/main/java/jeresources/api/restrictions/BlockRestriction.java @@ -1,10 +1,7 @@ -package jeresources.api.utils.restrictions; +package jeresources.api.restrictions; -import jeresources.api.messages.utils.MessageKeys; import net.minecraft.block.Block; import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; public class BlockRestriction { @@ -26,30 +23,12 @@ public BlockRestriction(Block block, int metadata) this.metadata = metadata; } - public BlockRestriction(NBTTagCompound tagCompound) - { - ItemStack stack = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag(MessageKeys.stack)); - block = Block.getBlockFromItem(stack.getItem()); - metadata = stack.getItemDamage(); - } - @Override public int hashCode() { return block.hashCode() ^ metadata; } - public NBTTagCompound writeToNBT() - { - return writeToNBT(new NBTTagCompound()); - } - - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - tagCompound.setTag(MessageKeys.stack, new ItemStack(block, 1, metadata).writeToNBT(new NBTTagCompound())); - return tagCompound; - } - @Override public boolean equals(Object obj) { diff --git a/src/main/java/jeresources/api/utils/restrictions/DimensionRegistry.java b/src/main/java/jeresources/api/restrictions/DimensionRegistry.java similarity index 98% rename from src/main/java/jeresources/api/utils/restrictions/DimensionRegistry.java rename to src/main/java/jeresources/api/restrictions/DimensionRegistry.java index f564a130..100a7c86 100644 --- a/src/main/java/jeresources/api/utils/restrictions/DimensionRegistry.java +++ b/src/main/java/jeresources/api/restrictions/DimensionRegistry.java @@ -1,4 +1,4 @@ -package jeresources.api.utils.restrictions; +package jeresources.api.restrictions; import net.minecraftforge.common.DimensionManager; diff --git a/src/main/java/jeresources/api/utils/restrictions/DimensionRestriction.java b/src/main/java/jeresources/api/restrictions/DimensionRestriction.java similarity index 83% rename from src/main/java/jeresources/api/utils/restrictions/DimensionRestriction.java rename to src/main/java/jeresources/api/restrictions/DimensionRestriction.java index 622ff522..d652ad8a 100644 --- a/src/main/java/jeresources/api/utils/restrictions/DimensionRestriction.java +++ b/src/main/java/jeresources/api/restrictions/DimensionRestriction.java @@ -1,7 +1,5 @@ -package jeresources.api.utils.restrictions; +package jeresources.api.restrictions; -import jeresources.api.messages.utils.MessageKeys; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import java.util.*; @@ -44,15 +42,6 @@ public DimensionRestriction(Type type, int minDim, int maxDim) this.max = Math.max(maxDim, minDim); } - public DimensionRestriction(NBTTagCompound tagCompound) - { - this.type = Type.values()[tagCompound.getByte(MessageKeys.type)]; - int minDim = tagCompound.getInteger(MessageKeys.min); - int maxDim = tagCompound.getInteger(MessageKeys.max); - this.min = Math.min(minDim, maxDim); - this.max = Math.max(maxDim, minDim); - } - public List getValidDimensions(BlockRestriction blockRestriction) { Set dimensions = DimensionRegistry.getDimensions(blockRestriction); @@ -115,19 +104,6 @@ private List getAltDimensionString(Set dimensions) return result; } - public NBTTagCompound writeToNBT() - { - return writeToNBT(new NBTTagCompound()); - } - - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - tagCompound.setInteger(MessageKeys.max, max); - tagCompound.setInteger(MessageKeys.min, min); - tagCompound.setByte(MessageKeys.type, (byte) type.ordinal()); - return tagCompound; - } - @Override public boolean equals(Object obj) { diff --git a/src/main/java/jeresources/api/utils/restrictions/Restriction.java b/src/main/java/jeresources/api/restrictions/Restriction.java similarity index 76% rename from src/main/java/jeresources/api/utils/restrictions/Restriction.java rename to src/main/java/jeresources/api/restrictions/Restriction.java index 067b1db2..900cf3ae 100644 --- a/src/main/java/jeresources/api/utils/restrictions/Restriction.java +++ b/src/main/java/jeresources/api/restrictions/Restriction.java @@ -1,10 +1,5 @@ -package jeresources.api.utils.restrictions; +package jeresources.api.restrictions; -import jeresources.api.messages.utils.MessageKeys; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.StatCollector; - -import java.util.ArrayList; import java.util.List; public class Restriction @@ -63,13 +58,6 @@ public Restriction(BlockRestriction blockRestriction, BiomeRestriction biomeRest this.dimensionRestriction = dimensionRestriction; } - public Restriction(NBTTagCompound tagCompound) - { - blockRestriction = new BlockRestriction(tagCompound.getCompoundTag(MessageKeys.blockRestriction)); - biomeRestriction = new BiomeRestriction(tagCompound.getCompoundTag(MessageKeys.biomeRestriction)); - dimensionRestriction = new DimensionRestriction(tagCompound.getCompoundTag(MessageKeys.dimensionRestriction)); - } - public List getBiomeRestrictions() { return biomeRestriction.toStringList(); @@ -80,19 +68,6 @@ public List getDimensionRestrictions() return dimensionRestriction.getValidDimensions(blockRestriction); } - public NBTTagCompound writeToNBT() - { - return writeToNBT(new NBTTagCompound()); - } - - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) - { - tagCompound.setTag(MessageKeys.blockRestriction, blockRestriction.writeToNBT()); - tagCompound.setTag(MessageKeys.dimensionRestriction, dimensionRestriction.writeToNBT()); - tagCompound.setTag(MessageKeys.biomeRestriction, biomeRestriction.writeToNBT()); - return tagCompound; - } - @Override public boolean equals(Object obj) { diff --git a/src/main/java/jeresources/api/utils/restrictions/Type.java b/src/main/java/jeresources/api/restrictions/Type.java similarity index 54% rename from src/main/java/jeresources/api/utils/restrictions/Type.java rename to src/main/java/jeresources/api/restrictions/Type.java index 759d59b0..0cd59f9a 100644 --- a/src/main/java/jeresources/api/utils/restrictions/Type.java +++ b/src/main/java/jeresources/api/restrictions/Type.java @@ -1,4 +1,4 @@ -package jeresources.api.utils.restrictions; +package jeresources.api.restrictions; public enum Type { diff --git a/src/main/java/jeresources/api/utils/Priority.java b/src/main/java/jeresources/api/utils/Priority.java deleted file mode 100644 index afc9e6c7..00000000 --- a/src/main/java/jeresources/api/utils/Priority.java +++ /dev/null @@ -1,17 +0,0 @@ -package jeresources.api.utils; - -public enum Priority -{ - FIRST, - SECOND, - THIRD, - FOURTH, - FIFTH; - - public static Priority getPriority(int i) - { - if (i < 0 || i >= values().length) return FIRST; - return values()[i]; - } - -} diff --git a/src/main/java/jeresources/api/utils/package-info.java b/src/main/java/jeresources/api/utils/package-info.java deleted file mode 100644 index 62586730..00000000 --- a/src/main/java/jeresources/api/utils/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@API(owner = "jeresources", apiVersion = "@MAJOR@.@MINOR@.@REVIS@", provides = "jeresources|API") -package jeresources.api.utils; - -import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/main/java/jeresources/compatibility/CompatBase.java b/src/main/java/jeresources/compatibility/CompatBase.java index a52aab3a..716101ae 100644 --- a/src/main/java/jeresources/compatibility/CompatBase.java +++ b/src/main/java/jeresources/compatibility/CompatBase.java @@ -1,14 +1,15 @@ package jeresources.compatibility; -import jeresources.api.messages.RegisterOreMessage; +import jeresources.api.render.IMobRenderHook; import jeresources.entries.MobEntry; import jeresources.entries.PlantEntry; +import jeresources.entries.WorldGenEntry; import jeresources.registry.MobRegistry; -import jeresources.registry.OreRegistry; +import jeresources.registry.WorldGenRegistry; import jeresources.registry.PlantRegistry; import jeresources.utils.LogHelper; -import jeresources.utils.ModList; import jeresources.utils.ReflectionHelper; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; @@ -16,13 +17,13 @@ public abstract class CompatBase { protected static World world = DimensionManager.getWorld(0); - public static boolean load(ModList mod, boolean initOres) + public static boolean load(ModList mod, boolean worldGen) { if (mod.isLoaded()) { LogHelper.info("Loading compatibility for " + mod.getName()); CompatBase compat = (CompatBase) ReflectionHelper.initialize(mod.compatClass()); - compat.init(initOres); + compat.init(worldGen); return true; } else { @@ -31,20 +32,25 @@ public static boolean load(ModList mod, boolean initOres) return false; } - protected abstract void init(boolean initOres); + protected abstract void init(boolean worldGen); public void registerMob(MobEntry entry) { MobRegistry.getInstance().registerMob(entry); } - public void registerOre(RegisterOreMessage message) + public void registerWorldGen(WorldGenEntry entry) { - OreRegistry.registerOre(message); + WorldGenRegistry.getInstance().registerEntry(entry); } public void registerPlant(PlantEntry entry) { PlantRegistry.getInstance().registerPlant(entry); } + + public void registerMobRenderHook(Class clazz, IMobRenderHook renderHook) + { + JERAPI.getInstance().getMobRegistry().registerRenderHook(clazz, renderHook); + } } diff --git a/src/main/java/jeresources/compatibility/Compatibility.java b/src/main/java/jeresources/compatibility/Compatibility.java index 3f85851c..6997ad46 100644 --- a/src/main/java/jeresources/compatibility/Compatibility.java +++ b/src/main/java/jeresources/compatibility/Compatibility.java @@ -1,27 +1,26 @@ package jeresources.compatibility; import jeresources.config.Settings; -import jeresources.json.OreAdapter; -import jeresources.registry.MessageRegistry; -import jeresources.utils.ModList; +import jeresources.json.WorldGenAdapter; public class Compatibility { public static void init() { - boolean initOres = true; + boolean initWorldGen = true; if (Settings.useDIYdata) { - if (OreAdapter.hasOreEntry()) + if (WorldGenAdapter.hasWorldGenDIYData()) { - OreAdapter.readEntrys(); - initOres = false; + WorldGenAdapter.readDIYData(); + initWorldGen = false; } } for (ModList mod : ModList.values()) - mod.initialise(initOres); - - MessageRegistry.processMessages(initOres); + mod.initialise(initWorldGen); + MobRegistryImpl.commit(); + if (initWorldGen) + WorldGenRegistryImpl.commit(); Settings.initedCompat = true; } } diff --git a/src/main/java/jeresources/compatibility/JERAPI.java b/src/main/java/jeresources/compatibility/JERAPI.java new file mode 100644 index 00000000..9fb52596 --- /dev/null +++ b/src/main/java/jeresources/compatibility/JERAPI.java @@ -0,0 +1,46 @@ +package jeresources.compatibility; + +import jeresources.api.*; +import jeresources.utils.ReflectionHelper; +import net.minecraftforge.fml.common.discovery.ASMDataTable; + +import java.util.List; + +public class JERAPI implements IJERAPI +{ + private IWorldGenRegistry worldGenRegistry; + private IMobRegistry mobRegistry; + private static IJERAPI instance; + + public static IJERAPI getInstance() + { + if (instance == null) + instance = new JERAPI(); + return instance; + } + + private JERAPI() + { + worldGenRegistry = new WorldGenRegistryImpl(); + mobRegistry = new MobRegistryImpl(); + } + + public static void init(ASMDataTable asmDataTable) + { + List list = ReflectionHelper.getInstances(asmDataTable, JERPlugin.class, IJERPlugin.class); + for (IJERPlugin plugin : list) + plugin.APIDelivery(getInstance()); + } + + @Override + public IMobRegistry getMobRegistry() + { + return mobRegistry; + } + + @Override + public IWorldGenRegistry getWorldGenRegistry() + { + return worldGenRegistry; + } +} diff --git a/src/main/java/jeresources/compatibility/MobRegistryImpl.java b/src/main/java/jeresources/compatibility/MobRegistryImpl.java new file mode 100644 index 00000000..364e9b0d --- /dev/null +++ b/src/main/java/jeresources/compatibility/MobRegistryImpl.java @@ -0,0 +1,91 @@ +package jeresources.compatibility; + +import jeresources.api.IMobRegistry; +import jeresources.api.conditionals.LightLevel; +import jeresources.api.drop.DropItem; +import jeresources.api.render.IMobRenderHook; +import jeresources.entries.MobEntry; +import jeresources.registry.MobRegistry; +import jeresources.utils.ReflectionHelper; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.Tuple; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MobRegistryImpl implements IMobRegistry +{ + private static List registers = new ArrayList<>(); + private static List, DropItem[]>> addedDrops = new ArrayList<>(); + private static Map, List> renderHooks = new HashMap<>(); + + protected MobRegistryImpl() + { + + } + + @Override + public void registerMob(EntityLivingBase entity, LightLevel lightLevel, int minExp, int maxExp, String[] biomes, DropItem... drops) + { + registers.add(new MobEntry(entity, lightLevel, maxExp, maxExp, biomes, drops)); + } + + @Override + public void registerMob(EntityLivingBase entity, LightLevel lightLevel, String[] biomes, DropItem... drops) + { + registers.add(new MobEntry(entity, lightLevel, biomes, drops)); + } + + @Override + public void registerMob(EntityLivingBase entity, LightLevel lightLevel, int exp, String[] biomes, DropItem... drops) + { + registers.add(new MobEntry(entity, lightLevel, exp, biomes, drops)); + } + + @Override + public void registerMob(EntityLivingBase entity, LightLevel lightLevel, int exp, DropItem... drops) + { + registers.add(new MobEntry(entity, lightLevel, exp, drops)); + } + + @Override + public void registerMob(EntityLivingBase entity, LightLevel lightLevel, int minExp, int maxExp, DropItem... drops) + { + registers.add(new MobEntry(entity, lightLevel, maxExp, maxExp, drops)); + } + + @Override + public void registerDrops(Class entity, DropItem... drops) + { + addedDrops.add(new Tuple, DropItem[]>(entity, drops)); + } + + @Override + public void registerRenderHook(Class entity, IMobRenderHook renderHook) + { + List list = renderHooks.get(entity); + if (list == null) list = new ArrayList<>(); + list.add(renderHook); + renderHooks.put(entity, list); + } + + @SuppressWarnings("unchecked") + public static IMobRenderHook.RenderInfo applyRenderHooks(EntityLivingBase entity, IMobRenderHook.RenderInfo renderInfo) + { + for (Map.Entry, List> entry : renderHooks.entrySet()) + if (ReflectionHelper.isInstanceOf(entity.getClass(), entry.getKey())) + for (IMobRenderHook renderHook : entry.getValue()) + renderInfo = renderHook.transform(renderInfo, entity); + return renderInfo; + } + + protected static void commit() + { + for (MobEntry entry : registers) + MobRegistry.getInstance().registerMob(entry); + for (Tuple, DropItem[]> tuple : addedDrops) + MobRegistry.getInstance().addDrops(tuple.getFirst(), tuple.getSecond()); + } +} diff --git a/src/main/java/jeresources/utils/ModList.java b/src/main/java/jeresources/compatibility/ModList.java similarity index 93% rename from src/main/java/jeresources/utils/ModList.java rename to src/main/java/jeresources/compatibility/ModList.java index dd6d2d5f..a4cc5d23 100644 --- a/src/main/java/jeresources/utils/ModList.java +++ b/src/main/java/jeresources/compatibility/ModList.java @@ -1,6 +1,5 @@ -package jeresources.utils; +package jeresources.compatibility; -import jeresources.compatibility.CompatBase; import jeresources.compatibility.minecraft.MinecraftCompat; import jeresources.compatibility.thaumcraft.ThaumcraftCompat; import net.minecraftforge.fml.common.Loader; @@ -63,9 +62,9 @@ public String getName() return name; } - public boolean initialise(boolean initOres) + public boolean initialise(boolean worldGen) { - return compat != null && CompatBase.load(this, initOres); + return compat != null && CompatBase.load(this, worldGen); } public class Names diff --git a/src/main/java/jeresources/compatibility/WorldGenRegistryImpl.java b/src/main/java/jeresources/compatibility/WorldGenRegistryImpl.java new file mode 100644 index 00000000..b78d0823 --- /dev/null +++ b/src/main/java/jeresources/compatibility/WorldGenRegistryImpl.java @@ -0,0 +1,62 @@ +package jeresources.compatibility; + +import jeresources.api.IWorldGenRegistry; +import jeresources.api.distributions.DistributionBase; +import jeresources.api.drop.DropItem; +import jeresources.api.restrictions.Restriction; +import jeresources.entries.WorldGenEntry; +import jeresources.registry.WorldGenRegistry; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Tuple; + +import java.util.ArrayList; +import java.util.List; + +public class WorldGenRegistryImpl implements IWorldGenRegistry +{ + private static List registers = new ArrayList<>(); + private static List> addedDrops = new ArrayList<>(); + + protected WorldGenRegistryImpl() + { + + } + + @Override + public void register(ItemStack block, DistributionBase distribution, DropItem... drops) + { + registers.add(new WorldGenEntry(block, distribution, drops)); + } + + @Override + public void register(ItemStack block, DistributionBase distribution, Restriction restriction, DropItem... drops) + { + registers.add(new WorldGenEntry(block, distribution, restriction, drops)); + } + + @Override + public void register(ItemStack block, DistributionBase distribution, boolean silktouch, DropItem... drops) + { + registers.add(new WorldGenEntry(block, distribution, silktouch, drops)); + } + + @Override + public void register(ItemStack block, DistributionBase distribution, Restriction restriction, boolean silktouch, DropItem... drops) + { + registers.add(new WorldGenEntry(block, distribution, restriction, silktouch, drops)); + } + + @Override + public void registerDrops(ItemStack block, DropItem... drops) + { + addedDrops.add(new Tuple<>(block, drops)); + } + + protected static void commit() + { + for (WorldGenEntry entry : registers) + WorldGenRegistry.getInstance().registerEntry(entry); + for (Tuple tuple : addedDrops) + WorldGenRegistry.getInstance().addDrops(tuple.getFirst(), tuple.getSecond()); + } +} diff --git a/src/main/java/jeresources/compatibility/minecraft/MinecraftCompat.java b/src/main/java/jeresources/compatibility/minecraft/MinecraftCompat.java index 24233040..d4ac9883 100644 --- a/src/main/java/jeresources/compatibility/minecraft/MinecraftCompat.java +++ b/src/main/java/jeresources/compatibility/minecraft/MinecraftCompat.java @@ -3,24 +3,23 @@ import jeresources.api.distributions.DistributionSquare; import jeresources.api.distributions.DistributionTriangular; import jeresources.api.distributions.DistributionUnderWater; -import jeresources.api.messages.ModifyOreMessage; -import jeresources.api.messages.RegisterOreMessage; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.LightLevel; -import jeresources.api.utils.PlantDrop; -import jeresources.api.utils.Priority; -import jeresources.api.utils.conditionals.Conditional; -import jeresources.api.utils.restrictions.BiomeRestriction; -import jeresources.api.utils.restrictions.BlockRestriction; -import jeresources.api.utils.restrictions.DimensionRestriction; -import jeresources.api.utils.restrictions.Restriction; +import jeresources.api.drop.DropItem; +import jeresources.api.conditionals.LightLevel; +import jeresources.api.drop.PlantDrop; +import jeresources.api.conditionals.Conditional; +import jeresources.api.render.IMobRenderHook; +import jeresources.api.restrictions.BiomeRestriction; +import jeresources.api.restrictions.BlockRestriction; +import jeresources.api.restrictions.DimensionRestriction; +import jeresources.api.restrictions.Restriction; import jeresources.compatibility.CompatBase; import jeresources.entries.MobEntry; import jeresources.entries.PlantEntry; +import jeresources.entries.WorldGenEntry; import jeresources.registry.DungeonRegistry; -import jeresources.registry.MessageRegistry; import jeresources.utils.MobHelper; import jeresources.utils.ReflectionHelper; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.boss.EntityDragon; import net.minecraft.entity.boss.EntityWither; import net.minecraft.entity.monster.*; @@ -36,30 +35,15 @@ public class MinecraftCompat extends CompatBase { @Override - protected void init(boolean initOres) + protected void init(boolean worldGen) { registerVanillaMobs(); registerDungeonLoot(); - if (initOres) - { + if (worldGen) registerOres(); - registerVanillaOreDrops(); - } registerVanillaPlants(); } - private void registerVanillaOreDrops() - { - registerOre(new RegisterOreMessage(new ItemStack(Blocks.clay), new DistributionUnderWater(0.0035F), new DropItem(new ItemStack(Items.clay_ball, 4)))); - MessageRegistry.addMessage(new ModifyOreMessage(new ItemStack(Blocks.clay), Priority.FIRST, new DropItem(new ItemStack(Items.clay_ball, 4)))); - MessageRegistry.addMessage(new ModifyOreMessage(new ItemStack(Blocks.coal_ore), Priority.FIRST, new DropItem(new ItemStack(Items.coal)))); - MessageRegistry.addMessage(new ModifyOreMessage(new ItemStack(Blocks.diamond_ore), Priority.FIRST, new DropItem(new ItemStack(Items.diamond)))); - MessageRegistry.addMessage(new ModifyOreMessage(new ItemStack(Blocks.lapis_ore), Priority.FIRST, new DropItem(new ItemStack(Items.dye, 4, 4)))); - MessageRegistry.addMessage(new ModifyOreMessage(new ItemStack(Blocks.emerald_ore), Priority.FIRST, new DropItem(new ItemStack(Items.emerald)))); - MessageRegistry.addMessage(new ModifyOreMessage(new ItemStack(Blocks.redstone_ore), Priority.FIRST, new DropItem(new ItemStack(Items.redstone, 4)))); - MessageRegistry.addMessage(new ModifyOreMessage(new ItemStack(Blocks.quartz_ore), Priority.FIRST, new DropItem(new ItemStack(Items.quartz, 4)))); - } - private void registerVanillaMobs() { //Iron Golem @@ -102,6 +86,7 @@ private void registerVanillaMobs() //End Dragon DropItem egg = new DropItem(new ItemStack(Blocks.dragon_egg), 1, 1); registerMob(new MobEntry(new EntityDragon(world), LightLevel.any, egg)); + registerMobRenderHook(EntityDragon.class, RenderHooks.ENDER_DRAGON); //Enderman DropItem pearl = new DropItem(Items.ender_pearl, 0, 1); @@ -166,6 +151,7 @@ private void registerVanillaMobs() //Bats registerMob(new MobEntry(new EntityBat(world), LightLevel.hostile)); + registerMobRenderHook(EntityBat.class, RenderHooks.BAT); //Spider DropItem string = new DropItem(Items.string, 0, 2); @@ -178,6 +164,7 @@ private void registerVanillaMobs() //Squid DropItem ink = new DropItem(Items.dye, 0, 1, 3); registerMob(new MobEntry(new EntitySquid(world), LightLevel.any, new String[]{"In water"}, ink)); + registerMobRenderHook(EntitySquid.class, RenderHooks.SQUID); //Rabbit DropItem rabbitHide = new DropItem(Items.rabbit_hide, 0, 1); @@ -199,6 +186,7 @@ private void registerVanillaMobs() elderGuardian.setElder(); registerMob(new MobEntry(new EntityGuardian(world), LightLevel.any, new String[]{"Ocean monument"}, prismarineCrystal, prismarineShard, rawFish, sponge, rareFish, rareSalmon, rarePuffer, rareClown)); registerMob(new MobEntry(elderGuardian, LightLevel.any, new String[]{"Ocean monument"}, prismarineCrystal, prismarineShard, rawFish, sponge, rareFish, rareSalmon, rarePuffer, rareClown)); + registerMobRenderHook(EntityGuardian.class, RenderHooks.ELDER_GUARDIAN); } @@ -215,14 +203,15 @@ private void registerDungeonLoot() private void registerOres() { - registerOre(new RegisterOreMessage(new ItemStack(Blocks.lapis_ore), new DistributionTriangular(15, 15, 0.001F), true)); - registerOre(new RegisterOreMessage(new ItemStack(Blocks.iron_ore), new DistributionSquare(20, 8, 1, 64))); - registerOre(new RegisterOreMessage(new ItemStack(Blocks.redstone_ore), new DistributionSquare(8, 7, 1, 16), true)); - registerOre(new RegisterOreMessage(new ItemStack(Blocks.diamond_ore), new DistributionSquare(1, 7, 1, 16), true)); - registerOre(new RegisterOreMessage(new ItemStack(Blocks.emerald_ore), new DistributionSquare(6, 1, 4, 32), new Restriction(BiomeRestriction.EXTREME_HILLS))); - registerOre(new RegisterOreMessage(new ItemStack(Blocks.gold_ore), new DistributionSquare(2, 8, 1, 32))); - registerOre(new RegisterOreMessage(new ItemStack(Blocks.coal_ore), new DistributionSquare(20, 16, 1, 128), true)); - registerOre(new RegisterOreMessage(new ItemStack(Blocks.quartz_ore), new DistributionSquare(20, 14, 1, 126), new Restriction(BlockRestriction.NETHER, DimensionRestriction.NETHER), true)); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.lapis_ore), new DistributionTriangular(15, 15, 0.001F), true, new DropItem(new ItemStack(Items.dye, 4, 4)))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.iron_ore), new DistributionSquare(20, 8, 1, 64))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.redstone_ore), new DistributionSquare(8, 7, 1, 16), true, new DropItem(new ItemStack(Items.redstone, 4)))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.diamond_ore), new DistributionSquare(1, 7, 1, 16), true, new DropItem(new ItemStack(Items.diamond)))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.emerald_ore), new DistributionSquare(6, 1, 4, 32), new Restriction(BiomeRestriction.EXTREME_HILLS), true, new DropItem(new ItemStack(Items.emerald)))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.gold_ore), new DistributionSquare(2, 8, 1, 32))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.coal_ore), new DistributionSquare(20, 16, 1, 128), true, new DropItem(new ItemStack(Items.coal)))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.quartz_ore), new DistributionSquare(20, 14, 1, 126), new Restriction(BlockRestriction.NETHER, DimensionRestriction.NETHER), true, new DropItem(new ItemStack(Items.quartz, 4)))); + registerWorldGen(new WorldGenEntry(new ItemStack(Blocks.clay), new DistributionUnderWater(0.0035F), new DropItem(new ItemStack(Items.clay_ball, 4)))); } private void registerVanillaPlants() diff --git a/src/main/java/jeresources/compatibility/minecraft/RenderHooks.java b/src/main/java/jeresources/compatibility/minecraft/RenderHooks.java new file mode 100644 index 00000000..7ded824d --- /dev/null +++ b/src/main/java/jeresources/compatibility/minecraft/RenderHooks.java @@ -0,0 +1,57 @@ +package jeresources.compatibility.minecraft; + +import jeresources.api.render.IMobRenderHook; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.boss.EntityDragon; +import net.minecraft.entity.monster.EntityGuardian; +import net.minecraft.entity.passive.EntityBat; +import net.minecraft.entity.passive.EntitySquid; + +public class RenderHooks +{ + public static final IMobRenderHook ENDER_DRAGON = new IMobRenderHook() + { + @Override + public IMobRenderHook.RenderInfo transform(IMobRenderHook.RenderInfo renderInfo, EntityDragon entity) + { + GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); + renderInfo.pitch = -renderInfo.pitch - 80; + GlStateManager.rotate(renderInfo.yaw < 90 ? (renderInfo.yaw < -90 ? 90 : -renderInfo.yaw) : -90, 0.0F, 1.0F, 0.0F); + return renderInfo; + } + }; + + public static final IMobRenderHook BAT = new IMobRenderHook() + { + @Override + public IMobRenderHook.RenderInfo transform(IMobRenderHook.RenderInfo renderInfo, EntityBat entity) + { + GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); + renderInfo.pitch = -renderInfo.pitch; + return renderInfo; + } + }; + + public static final IMobRenderHook ELDER_GUARDIAN = new IMobRenderHook() + { + @Override + public RenderInfo transform(RenderInfo renderInfo, EntityGuardian entity) + { + if (entity.isElder()) + GlStateManager.scale(0.6F, 0.6F, 0.6F); + return renderInfo; + } + }; + + public static final IMobRenderHook SQUID = new IMobRenderHook() + { + @Override + public RenderInfo transform(RenderInfo renderInfo, EntitySquid entity) + { + GlStateManager.rotate(50.0F, 1.0F, 0.0F, 0.0F); + return renderInfo; + } + }; +} diff --git a/src/main/java/jeresources/compatibility/thaumcraft/ThaumcraftCompat.java b/src/main/java/jeresources/compatibility/thaumcraft/ThaumcraftCompat.java index 9d0d497f..71e8c91c 100644 --- a/src/main/java/jeresources/compatibility/thaumcraft/ThaumcraftCompat.java +++ b/src/main/java/jeresources/compatibility/thaumcraft/ThaumcraftCompat.java @@ -1,21 +1,21 @@ package jeresources.compatibility.thaumcraft; +import jeresources.api.drop.DropItem; +import jeresources.api.conditionals.LightLevel; import jeresources.api.distributions.DistributionCustom; +import jeresources.api.distributions.DistributionHelpers; import jeresources.api.distributions.DistributionSquare; -import jeresources.api.messages.ModifyOreMessage; -import jeresources.api.messages.RegisterOreMessage; -import jeresources.api.utils.*; -import jeresources.api.utils.conditionals.Conditional; +import jeresources.api.conditionals.Conditional; +import jeresources.api.render.TextModifier; import jeresources.compatibility.CompatBase; import jeresources.entries.MobEntry; -import jeresources.registry.MessageRegistry; -import jeresources.utils.ModList; +import jeresources.entries.WorldGenEntry; +import jeresources.compatibility.ModList; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.common.registry.GameRegistry; -import thaumcraft.common.Thaumcraft; import thaumcraft.common.config.Config; import thaumcraft.common.entities.monster.EntityBrainyZombie; import thaumcraft.common.entities.monster.EntityMindSpider; @@ -29,9 +29,9 @@ public class ThaumcraftCompat extends CompatBase { @Override - protected void init(boolean initOres) + protected void init(boolean worldGen) { - if (initOres) + if (worldGen) registerThaumcraftOres(); registerThaumcraftMobs(); } @@ -39,9 +39,6 @@ protected void init(boolean initOres) @Optional.Method(modid = ModList.Names.THAUMCRAFT) private void registerThaumcraftOres() { - ItemStack amber = new ItemStack(GameRegistry.findBlock(ModList.Names.THAUMCRAFT, "ore_amber")); - DropItem amberDrop = new DropItem(new ItemStack(GameRegistry.findItem(ModList.Names.THAUMCRAFT, "amber"))); - MessageRegistry.addMessage(new ModifyOreMessage(amber, Priority.FIRST, amberDrop)); if (Config.genCinnibar) genCinnabar(); if (Config.genAmber) genAmber(); } @@ -49,7 +46,7 @@ private void registerThaumcraftOres() @Optional.Method(modid = ModList.Names.THAUMCRAFT) private void registerThaumcraftMobs() { - Conditional randomAspect = new Conditional("jer.randomAspect.text", Modifier.pink); + Conditional randomAspect = new Conditional("jer.randomAspect.text", TextModifier.pink); String[] tainted = new String[]{"Tainted areas"}; DropItem flesh = new DropItem(Items.rotten_flesh, 0, 2); DropItem brain = new DropItem(GameRegistry.findItem(ModList.Names.THAUMCRAFT, "brain"), 0, 1); @@ -107,7 +104,8 @@ private void genAmber() float[] distribution = DistributionHelpers.getSquareDistribution(minY, maxY - (int) maxYRange, chance); DistributionHelpers.addDistribution(distribution, DistributionHelpers.getRampDistribution(maxY, (int) (maxY - maxYRange), chance), maxY - (int) maxYRange); ItemStack amber = new ItemStack(GameRegistry.findBlock(ModList.Names.THAUMCRAFT, "ore_amber")); - registerOre(new RegisterOreMessage(amber, new DistributionCustom(distribution))); + DropItem amberDrop = new DropItem(new ItemStack(GameRegistry.findItem(ModList.Names.THAUMCRAFT, "amber"))); + registerWorldGen(new WorldGenEntry(amber, new DistributionCustom(distribution), amberDrop)); } @Optional.Method(modid = ModList.Names.THAUMCRAFT) @@ -118,6 +116,6 @@ private void genCinnabar() float numVeins = 18F; float chance = numVeins / (maxY * 256); ItemStack ore = new ItemStack(GameRegistry.findBlock(ModList.Names.THAUMCRAFT, "ore_cinnabar")); - registerOre(new RegisterOreMessage(ore, new DistributionSquare(minY, maxY, chance))); + registerWorldGen(new WorldGenEntry(ore, new DistributionSquare(minY, maxY, chance))); } } diff --git a/src/main/java/jeresources/entries/DungeonEntry.java b/src/main/java/jeresources/entries/DungeonEntry.java index 71fbefe3..18bdbc8b 100644 --- a/src/main/java/jeresources/entries/DungeonEntry.java +++ b/src/main/java/jeresources/entries/DungeonEntry.java @@ -1,6 +1,5 @@ package jeresources.entries; -import jeresources.api.messages.RegisterDungeonMessage; import jeresources.utils.ReflectionHelper; import jeresources.utils.WeightedRandomChestContentHelper; import net.minecraft.item.ItemStack; @@ -30,14 +29,6 @@ public DungeonEntry(String name, ChestGenHooks chestGenHooks) this.maxStacks = chestGenHooks.getMax(); } - public DungeonEntry(RegisterDungeonMessage message) - { - chestDrops = message.getChestDrops(); - name = message.getName(); - maxStacks = message.getMaxStacks(); - minStacks = message.getMinStacks(); - } - public boolean containsItem(ItemStack itemStack) { for (ItemStack item : chestDrops.keySet()) diff --git a/src/main/java/jeresources/entries/MobEntry.java b/src/main/java/jeresources/entries/MobEntry.java index e640104e..8878ac31 100644 --- a/src/main/java/jeresources/entries/MobEntry.java +++ b/src/main/java/jeresources/entries/MobEntry.java @@ -1,13 +1,10 @@ package jeresources.entries; -import jeresources.api.messages.RegisterMobMessage; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.LightLevel; +import jeresources.api.drop.DropItem; +import jeresources.api.conditionals.LightLevel; import jeresources.utils.MobHelper; -import jeresources.utils.ReflectionHelper; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import java.util.ArrayList; import java.util.Arrays; @@ -64,15 +61,6 @@ public MobEntry(EntityLivingBase entity, LightLevel lightLevel, DropItem... drop this.maxExp = this.minExp = MobHelper.getExpDrop(this); } - public MobEntry(RegisterMobMessage message) - { - if (!ReflectionHelper.isInstanceOf(message.getMobClass(), EntityLivingBase.class)) return; - entity = (EntityLivingBase) ReflectionHelper.initialize(message.getMobClass(), World.class, null); - this.lightLevel = message.getLightLevel(); - Collections.addAll(drops, message.getDrops()); - Collections.sort(drops); - } - public EntityLivingBase getEntity() { return entity; @@ -110,6 +98,12 @@ public boolean addDrop(DropItem item) return true; } + public void addDrops(DropItem... drops) + { + for (DropItem drop : drops) + addDrop(drop); + } + public LightLevel getLightLevel() { return lightLevel; diff --git a/src/main/java/jeresources/entries/OreMatchEntry.java b/src/main/java/jeresources/entries/OreMatchEntry.java deleted file mode 100644 index ac13584a..00000000 --- a/src/main/java/jeresources/entries/OreMatchEntry.java +++ /dev/null @@ -1,217 +0,0 @@ -package jeresources.entries; - -import jeresources.api.distributions.DistributionBase; -import jeresources.api.messages.RegisterOreMessage; -import jeresources.api.utils.ColorHelper; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.restrictions.Restriction; -import jeresources.config.Settings; -import jeresources.utils.MapKeys; -import net.minecraft.item.ItemStack; - -import java.util.*; - -public class OreMatchEntry -{ - private float[] chances; - Map silkTouchMap = new LinkedHashMap<>(); - List oreSet = new ArrayList<>(); - private int minY; - private int maxY; - private int colour; - private Restriction restriction; - Set drops = new TreeSet<>(); - - public OreMatchEntry(RegisterOreMessage message) - { - restriction = message.getRestriction(); - addMessage(message); - } - - private void addMessage(RegisterOreMessage message) - { - silkTouchMap.put(MapKeys.getKey(message.getOre()), message.needSilkTouch()); - oreSet.add(new OreEntry(message.getOre(), message.getDistribution())); - calcChances(); - if (colour == ColorHelper.BLACK) colour = message.getColour(); - } - - public boolean add(RegisterOreMessage message) - { - if (!restriction.isMergeable(message.getRestriction())) return false; - addMessage(message); - return message.getRestriction().equals(this.restriction); - } - - public void add(OreMatchEntry oreMatchEntry) - { - if (restriction.isMergeable(oreMatchEntry.restriction)) - { - silkTouchMap.putAll(oreMatchEntry.silkTouchMap); - oreSet.addAll(oreMatchEntry.oreSet); - calcChances(); - if (colour == ColorHelper.BLACK) colour = oreMatchEntry.getColour(); - } - } - - private void calcChances() - { - chances = new float[256]; - minY = 256; - maxY = 0; - for (OreEntry entry : oreSet) - { - DistributionBase distribution = entry.getDistribution(); - int i = -1; - for (float chance : distribution.getDistribution()) - { - if (++i == chances.length) break; - chances[i] += chance; - if (chances[i] > 0) - { - if (minY > i) - minY = i; - if (i > maxY) - maxY = i; - } - } - } - if (minY == 256) minY = 0; - if (maxY == 0) maxY = 255; - - if (minY < 128) - minY = 0; - else - minY = 128; - - if (maxY <= 127) - maxY = 127; - else - maxY = 255; - } - - public float[] getChances() - { - return Arrays.copyOfRange(chances, minY , maxY + 1); - } - - public int getMinY() - { - return minY; - } - - public int getMaxY() - { - return maxY; - } - - public boolean isSilkTouchNeeded(ItemStack itemStack) - { - Boolean silkTouch = this.silkTouchMap.get(MapKeys.getKey(itemStack)); - return silkTouch == null ? false : silkTouch; - } - - public int getColour() - { - return colour; - } - - public void addDrop(DropItem nonOre) - { - drops.add(nonOre); - silkTouchMap.put(MapKeys.getKey(nonOre), false); - } - - public void removeDrop(ItemStack removeDrop) - { - for (Iterator itr = drops.iterator(); itr.hasNext(); ) - { - DropItem drop = itr.next(); - if (drop.item.isItemEqual(removeDrop)) - { - silkTouchMap.remove(MapKeys.getKey(drop)); - itr.remove(); - } - } - } - - public List getDrops() - { - return new ArrayList<>(drops); - } - - public List getOresAndDrops() - { - List list = new LinkedList<>(); - for (OreEntry entry : oreSet) - { - ItemStack ore = entry.getOre(); - if (!list.contains(ore)) list.add(ore); - } - - for (DropItem dropItem : drops) - { - ItemStack drop = dropItem.item; - if (!list.contains(drop)) list.add(drop); - } - - return list; - } - - public List getOres() - { - List list = new LinkedList<>(); - for (OreEntry entry : oreSet) - { - ItemStack ore = entry.getOre(); - if (!list.contains(ore)) list.add(ore); - } - return list; - } - - public List getBiomeRestrictions() - { - return this.restriction.getBiomeRestrictions(); - } - - public List getDimensions() - { - return this.restriction.getDimensionRestrictions(); - } - - public DropItem getDropItem(ItemStack itemStack) - { - for (DropItem drop : getDrops()) - if (drop.item.isItemEqual(itemStack)) - return drop; - return null; - } - - @Override - public String toString() - { - return "Match: " + oreSet.get(0).getOre().getDisplayName() + " - " + restriction.toString(); - } - - private class OreEntry - { - private ItemStack ore; - private DistributionBase distribution; - - public OreEntry(ItemStack ore, DistributionBase distribution) - { - this.ore = ore; - this.distribution = distribution; - } - - public ItemStack getOre() - { - return ore; - } - - public DistributionBase getDistribution() - { - return distribution; - } - } -} diff --git a/src/main/java/jeresources/entries/PlantEntry.java b/src/main/java/jeresources/entries/PlantEntry.java index 133a4442..6d0a2587 100644 --- a/src/main/java/jeresources/entries/PlantEntry.java +++ b/src/main/java/jeresources/entries/PlantEntry.java @@ -1,6 +1,6 @@ package jeresources.entries; -import jeresources.api.utils.PlantDrop; +import jeresources.api.drop.PlantDrop; import jeresources.utils.MapKeys; import jeresources.utils.SeedHelper; import net.minecraft.init.Blocks; diff --git a/src/main/java/jeresources/entries/WorldGenEntry.java b/src/main/java/jeresources/entries/WorldGenEntry.java new file mode 100644 index 00000000..7c462c18 --- /dev/null +++ b/src/main/java/jeresources/entries/WorldGenEntry.java @@ -0,0 +1,170 @@ +package jeresources.entries; + +import jeresources.api.distributions.DistributionBase; +import jeresources.api.distributions.DistributionHelpers; +import jeresources.api.render.ColourHelper; +import jeresources.api.drop.DropItem; +import jeresources.api.restrictions.Restriction; +import net.minecraft.item.ItemStack; + +import java.util.*; + +public class WorldGenEntry +{ + private float[] chances; + private boolean silktouch; + private ItemStack block; + private int minY; + private int maxY; + private int colour; + private Restriction restriction; + private DistributionBase distribution; + private Set drops = new TreeSet<>(); + + public WorldGenEntry(ItemStack block, DistributionBase distribution, Restriction restriction, boolean silktouch, DropItem... drops) + { + this.block = block; + this.distribution = distribution; + this.restriction = restriction; + this.colour = ColourHelper.BLACK; + this.silktouch = silktouch; + addDrops(drops); + calcChances(); + } + + public WorldGenEntry(ItemStack block, DistributionBase distribution, DropItem... drops) + { + this(block, distribution, Restriction.OVERWORLD_LIKE, false, drops); + } + + public WorldGenEntry(ItemStack block, DistributionBase distribution, boolean silktouch, DropItem... drops) + { + this(block, distribution, Restriction.OVERWORLD_LIKE, silktouch, drops); + } + + public WorldGenEntry(ItemStack block, DistributionBase distribution, Restriction restriction, DropItem... drops) + { + this(block, distribution, restriction, false, drops); + } + + public void addDrops(DropItem... drops) + { + Collections.addAll(this.drops, drops); + } + + public void addDrops(Collection drops) + { + this.drops.addAll(drops); + } + + private void calcChances() + { + chances = new float[256]; + minY = 256; + maxY = 0; + int i = -1; + for (float chance : this.distribution.getDistribution()) + { + if (++i == chances.length) break; + chances[i] += chance; + if (chances[i] > 0) + { + if (minY > i) + minY = i; + if (i > maxY) + maxY = i; + } + } + if (minY == 256) minY = 0; + if (maxY == 0) maxY = 255; + + if (minY < 128) + minY = 0; + else + minY = 128; + + if (maxY <= 127) + maxY = 127; + else + maxY = 255; + } + + public float[] getChances() + { + return Arrays.copyOfRange(chances, minY , maxY + 1); + } + + public int getMinY() + { + return minY; + } + + public int getMaxY() + { + return maxY; + } + + public boolean isSilkTouchNeeded() + { + return silktouch; + } + + public int getColour() + { + return colour; + } + + public List getDrops() + { + return new ArrayList<>(drops); + } + + public List getBlockAndDrops() + { + List list = new LinkedList<>(); + list.add(this.block); + for (DropItem dropItem: drops) + if (!list.contains(dropItem.item)) list.add(dropItem.item); + return list; + } + + public ItemStack getBlock() + { + return this.block; + } + + public List getBiomeRestrictions() + { + return this.restriction.getBiomeRestrictions(); + } + + public List getDimensions() + { + return this.restriction.getDimensionRestrictions(); + } + + public DropItem getDropItem(ItemStack itemStack) + { + for (DropItem drop : getDrops()) + if (drop.item.isItemEqual(itemStack)) + return drop; + return null; + } + + @Override + public String toString() + { + return "WorldGenEntry: " + block.getDisplayName() + " - " + restriction.toString(); + } + + public Restriction getRestriction() + { + return restriction; + } + + public void merge(WorldGenEntry entry) + { + addDrops(entry.getDrops()); + this.distribution = DistributionHelpers.addDistribution(this.distribution, entry.distribution); + } +} diff --git a/src/main/java/jeresources/jei/JEIConfig.java b/src/main/java/jeresources/jei/JEIConfig.java index 6281191d..e096927b 100644 --- a/src/main/java/jeresources/jei/JEIConfig.java +++ b/src/main/java/jeresources/jei/JEIConfig.java @@ -7,8 +7,8 @@ import jeresources.jei.enchantment.EnchantmentHandler; import jeresources.jei.mob.MobCategory; import jeresources.jei.mob.MobHandler; -import jeresources.jei.ore.OreCategory; -import jeresources.jei.ore.OreHandler; +import jeresources.jei.worldgen.WorldGenCategory; +import jeresources.jei.worldgen.WorldGenHandler; import jeresources.jei.plant.PlantCategory; import jeresources.jei.plant.PlantHandler; import jeresources.reference.Reference; @@ -19,7 +19,7 @@ public class JEIConfig implements IModPlugin { public static final String MOB = Reference.ID + ".mob"; public static final String DUNGEON = Reference.ID + ".dungeon"; - public static final String ORE = Reference.ID + ".ore"; + public static final String WORLDGEN = Reference.ID + ".worldgen"; public static final String PLANT = Reference.ID + ".plant"; public static final String ENCHANTMENT = Reference.ID + ".enchantment"; @@ -38,8 +38,8 @@ public void onItemRegistryAvailable(IItemRegistry itemRegistry) @Override public void register(IModRegistry registry) { - registry.addRecipeHandlers(new PlantHandler(), new OreHandler(), new MobHandler(), new EnchantmentHandler(), new DungeonHandler()); - registry.addRecipeCategories(new PlantCategory(), new OreCategory(), new MobCategory(), new EnchantmentCategory(), new DungeonCategory()); + registry.addRecipeHandlers(new PlantHandler(), new WorldGenHandler(), new MobHandler(), new EnchantmentHandler(), new DungeonHandler()); + registry.addRecipeCategories(new PlantCategory(), new WorldGenCategory(), new MobCategory(), new EnchantmentCategory(), new DungeonCategory()); } @Override diff --git a/src/main/java/jeresources/jei/mob/MobWrapper.java b/src/main/java/jeresources/jei/mob/MobWrapper.java index 57b0457a..ed6afb09 100644 --- a/src/main/java/jeresources/jei/mob/MobWrapper.java +++ b/src/main/java/jeresources/jei/mob/MobWrapper.java @@ -1,6 +1,7 @@ package jeresources.jei.mob; -import jeresources.api.utils.DropItem; +import jeresources.api.drop.DropItem; +import jeresources.compatibility.ModList; import jeresources.entries.MobEntry; import jeresources.utils.*; import mezz.jei.api.gui.ITooltipCallback; diff --git a/src/main/java/jeresources/jei/ore/OreHandler.java b/src/main/java/jeresources/jei/ore/OreHandler.java deleted file mode 100644 index 318cea77..00000000 --- a/src/main/java/jeresources/jei/ore/OreHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -package jeresources.jei.ore; - -import jeresources.entries.OreMatchEntry; -import jeresources.jei.JEIConfig; -import mezz.jei.api.recipe.IRecipeHandler; -import mezz.jei.api.recipe.IRecipeWrapper; - -import javax.annotation.Nonnull; - -public class OreHandler implements IRecipeHandler -{ - @Nonnull - @Override - public Class getRecipeClass() - { - return OreMatchEntry.class; - } - - @Nonnull - @Override - public String getRecipeCategoryUid() - { - return JEIConfig.ORE; - } - - @Nonnull - @Override - public IRecipeWrapper getRecipeWrapper(@Nonnull OreMatchEntry recipe) - { - return new OreWrapper(recipe); - } - - @Override - public boolean isRecipeValid(@Nonnull OreMatchEntry recipe) - { - return true; - } -} diff --git a/src/main/java/jeresources/jei/plant/PlantWrapper.java b/src/main/java/jeresources/jei/plant/PlantWrapper.java index fef10eb7..de2344ee 100644 --- a/src/main/java/jeresources/jei/plant/PlantWrapper.java +++ b/src/main/java/jeresources/jei/plant/PlantWrapper.java @@ -1,6 +1,6 @@ package jeresources.jei.plant; -import jeresources.api.utils.PlantDrop; +import jeresources.api.drop.PlantDrop; import jeresources.entries.PlantEntry; import jeresources.utils.CollectionHelper; import jeresources.utils.RenderHelper; diff --git a/src/main/java/jeresources/jei/ore/OreCategory.java b/src/main/java/jeresources/jei/worldgen/WorldGenCategory.java similarity index 58% rename from src/main/java/jeresources/jei/ore/OreCategory.java rename to src/main/java/jeresources/jei/worldgen/WorldGenCategory.java index 7b80ef8a..717e6025 100644 --- a/src/main/java/jeresources/jei/ore/OreCategory.java +++ b/src/main/java/jeresources/jei/worldgen/WorldGenCategory.java @@ -1,7 +1,7 @@ -package jeresources.jei.ore; +package jeresources.jei.worldgen; -import jeresources.api.utils.ColorHelper; -import jeresources.api.utils.DropItem; +import jeresources.api.render.ColourHelper; +import jeresources.api.drop.DropItem; import jeresources.jei.JEIConfig; import jeresources.reference.Resources; import jeresources.utils.RenderHelper; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; -public class OreCategory implements IRecipeCategory +public class WorldGenCategory implements IRecipeCategory { protected static final int X_ITEM = 5; protected static final int Y_ITEM = 21; @@ -27,28 +27,28 @@ public class OreCategory implements IRecipeCategory @Override public String getUid() { - return JEIConfig.ORE; + return JEIConfig.WORLDGEN; } @Nonnull @Override public String getTitle() { - return TranslationHelper.translateToLocal("jer.ore.title"); + return TranslationHelper.translateToLocal("jer.worldgen.title"); } @Nonnull @Override public IDrawable getBackground() { - return Resources.Gui.Jei.ORE; + return Resources.Gui.Jei.WORLD_GEN; } @Override public void drawExtras(Minecraft minecraft) { - RenderHelper.drawLine(OreWrapper.X_OFFSET, OreWrapper.Y_OFFSET, OreWrapper.X_OFFSET + OreWrapper.X_AXIS_SIZE, OreWrapper.Y_OFFSET, ColorHelper.GRAY); - RenderHelper.drawLine(OreWrapper.X_OFFSET, OreWrapper.Y_OFFSET, OreWrapper.X_OFFSET, OreWrapper.Y_OFFSET - OreWrapper.Y_AXIS_SIZE, ColorHelper.GRAY); + RenderHelper.drawLine(WorldGenWrapper.X_OFFSET, WorldGenWrapper.Y_OFFSET, WorldGenWrapper.X_OFFSET + WorldGenWrapper.X_AXIS_SIZE, WorldGenWrapper.Y_OFFSET, ColourHelper.GRAY); + RenderHelper.drawLine(WorldGenWrapper.X_OFFSET, WorldGenWrapper.Y_OFFSET, WorldGenWrapper.X_OFFSET, WorldGenWrapper.Y_OFFSET - WorldGenWrapper.Y_AXIS_SIZE, ColourHelper.GRAY); } @Override @@ -65,14 +65,14 @@ public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapp for (int i = 0; i < DROP_ITEM_COUNT; i++) recipeLayout.getItemStacks().init(i + 1, false, X_DROP_ITEM + i * 18, Y_DROP_ITEM); - if (recipeWrapper instanceof OreWrapper) + if (recipeWrapper instanceof WorldGenWrapper) { - OreWrapper oreWrapper = (OreWrapper) recipeWrapper; - recipeLayout.getItemStacks().addTooltipCallback(oreWrapper); - recipeLayout.getItemStacks().setFromRecipe(0, oreWrapper.getOres()); - for (int i = 0 ; i < Math.min(DROP_ITEM_COUNT, oreWrapper.getDrops().size()); i++) + WorldGenWrapper worldGenWrapper = (WorldGenWrapper) recipeWrapper; + recipeLayout.getItemStacks().addTooltipCallback(worldGenWrapper); + recipeLayout.getItemStacks().set(0, worldGenWrapper.getBlock()); + for (int i = 0; i < Math.min(DROP_ITEM_COUNT, worldGenWrapper.getDrops().size()); i++) { - DropItem drop = oreWrapper.getDrops().get(i); + DropItem drop = worldGenWrapper.getDrops().get(i); ItemStack itemStack = drop.item.copy(); itemStack.stackSize = Math.max(1, (int)Math.floor(drop.chance)); recipeLayout.getItemStacks().set(i + 1, itemStack); diff --git a/src/main/java/jeresources/jei/worldgen/WorldGenHandler.java b/src/main/java/jeresources/jei/worldgen/WorldGenHandler.java new file mode 100644 index 00000000..b7e1c625 --- /dev/null +++ b/src/main/java/jeresources/jei/worldgen/WorldGenHandler.java @@ -0,0 +1,38 @@ +package jeresources.jei.worldgen; + +import jeresources.entries.WorldGenEntry; +import jeresources.jei.JEIConfig; +import mezz.jei.api.recipe.IRecipeHandler; +import mezz.jei.api.recipe.IRecipeWrapper; + +import javax.annotation.Nonnull; + +public class WorldGenHandler implements IRecipeHandler +{ + @Nonnull + @Override + public Class getRecipeClass() + { + return WorldGenEntry.class; + } + + @Nonnull + @Override + public String getRecipeCategoryUid() + { + return JEIConfig.WORLDGEN; + } + + @Nonnull + @Override + public IRecipeWrapper getRecipeWrapper(@Nonnull WorldGenEntry recipe) + { + return new WorldGenWrapper(recipe); + } + + @Override + public boolean isRecipeValid(@Nonnull WorldGenEntry recipe) + { + return true; + } +} diff --git a/src/main/java/jeresources/jei/ore/OreWrapper.java b/src/main/java/jeresources/jei/worldgen/WorldGenWrapper.java similarity index 82% rename from src/main/java/jeresources/jei/ore/OreWrapper.java rename to src/main/java/jeresources/jei/worldgen/WorldGenWrapper.java index d21c0721..2a6874d4 100644 --- a/src/main/java/jeresources/jei/ore/OreWrapper.java +++ b/src/main/java/jeresources/jei/worldgen/WorldGenWrapper.java @@ -1,8 +1,8 @@ -package jeresources.jei.ore; +package jeresources.jei.worldgen; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.conditionals.Conditional; -import jeresources.entries.OreMatchEntry; +import jeresources.api.drop.DropItem; +import jeresources.api.conditionals.Conditional; +import jeresources.entries.WorldGenEntry; import jeresources.utils.Font; import jeresources.utils.RenderHelper; import jeresources.utils.TranslationHelper; @@ -22,23 +22,23 @@ import org.lwjgl.input.Mouse; -public class OreWrapper implements IRecipeWrapper, ITooltipCallback +public class WorldGenWrapper implements IRecipeWrapper, ITooltipCallback { protected static final int X_OFFSET = 49-20; protected static final int Y_OFFSET = 52; protected static final int X_AXIS_SIZE = 100+20+8; protected static final int Y_AXIS_SIZE = 40; - private final OreMatchEntry oreMatchEntry; + private final WorldGenEntry worldGenEntry; - public OreWrapper(OreMatchEntry oreMatchEntry) + public WorldGenWrapper(WorldGenEntry worldGenEntry) { - this.oreMatchEntry = oreMatchEntry; + this.worldGenEntry = worldGenEntry; } public int getLineColor() { - return this.oreMatchEntry.getColour(); + return this.worldGenEntry.getColour(); } @Override @@ -50,17 +50,17 @@ public List getInputs() @Override public List getOutputs() { - return this.oreMatchEntry.getOresAndDrops(); + return this.worldGenEntry.getBlockAndDrops(); } - public List getOres() + public ItemStack getBlock() { - return this.oreMatchEntry.getOres(); + return this.worldGenEntry.getBlock(); } public List getDrops() { - return this.oreMatchEntry.getDrops(); + return this.worldGenEntry.getDrops(); } @Override @@ -79,7 +79,7 @@ public List getFluidOutputs() @Deprecated public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight) { - float[] array = this.oreMatchEntry.getChances(); + float[] array = this.worldGenEntry.getChances(); double max = 0; for (double d : array) if (d > max) max = d; @@ -112,12 +112,12 @@ public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHe final int yLabels = Y_OFFSET; final int xLabels = X_OFFSET; - final int minLabel = this.oreMatchEntry.getMinY(); + final int minLabel = this.worldGenEntry.getMinY(); final int minLabelWidth = Font.small.getStringWidth(String.valueOf(minLabel)); final int minLabelOffset = xLabels - (minLabelWidth / 2); Font.small.print(minLabel, minLabelOffset, yLabels); - final int maxLabel = this.oreMatchEntry.getMaxY(); + final int maxLabel = this.worldGenEntry.getMaxY(); final int maxLabelWidth = Font.small.getStringWidth(String.valueOf(maxLabel)); final int maxLabelOffset = xLabels + X_AXIS_SIZE - (maxLabelWidth / 2); Font.small.print(maxLabel, maxLabelOffset, yLabels); @@ -127,9 +127,9 @@ public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHe final int midLabelOffset = xLabels + (X_AXIS_SIZE / 2) - (midLabelWidth / 2); Font.small.print(midLabel, midLabelOffset, yLabels); - Font.small.print(TranslationHelper.translateToLocal("jer.ore.drops"), OreCategory.X_DROP_ITEM, OreCategory.Y_DROP_ITEM - 8); + Font.small.print(TranslationHelper.translateToLocal("jer.worldgen.drops"), WorldGenCategory.X_DROP_ITEM, WorldGenCategory.Y_DROP_ITEM - 8); - List dimensions = oreMatchEntry.getDimensions(); + List dimensions = worldGenEntry.getDimensions(); if (dimensions.size() == 1) { String dimension = dimensions.get(0); @@ -177,36 +177,36 @@ private List getItemStackTooltip(int slot, ItemStack itemStack) List tooltip = new LinkedList<>(); if (itemStack != null && slot == 0) { - if (this.oreMatchEntry.isSilkTouchNeeded(itemStack)) + if (this.worldGenEntry.isSilkTouchNeeded()) tooltip.add(Conditional.silkTouch.toString()); - List biomes = oreMatchEntry.getBiomeRestrictions(); + List biomes = worldGenEntry.getBiomeRestrictions(); if (biomes.size() > 0) { - tooltip.add(StatCollector.translateToLocal("jer.ore.biomes") + ":"); + tooltip.add(StatCollector.translateToLocal("jer.worldgen.biomes") + ":"); tooltip.addAll(biomes); } - List dimensions = oreMatchEntry.getDimensions(); + List dimensions = worldGenEntry.getDimensions(); if (dimensions.size() > 1) { - tooltip.add(StatCollector.translateToLocal("jer.ore.dimensions") + ":"); + tooltip.add(StatCollector.translateToLocal("jer.worldgen.dimensions") + ":"); tooltip.addAll(dimensions); } } else - tooltip.add(TranslationHelper.translateToLocal("jer.ore.average") + " " + this.oreMatchEntry.getDropItem(itemStack).chanceString()); + tooltip.add(TranslationHelper.translateToLocal("jer.worldgen.average") + " " + this.worldGenEntry.getDropItem(itemStack).chanceString()); return tooltip; } private List getLineTooltip(int mouseX, List tooltip) { final double exactMouseX = getExactMouseX(mouseX); - final float[] chances = this.oreMatchEntry.getChances(); + final float[] chances = this.worldGenEntry.getChances(); final double space = X_AXIS_SIZE / (chances.length * 1D); // Calculate the hovered over y value final int index = (int) ((exactMouseX - X_OFFSET + 1) / space); - final int yValue = index + this.oreMatchEntry.getMinY(); + final int yValue = index + this.worldGenEntry.getMinY(); if (index >= 0 && index < chances.length) { float chance = chances[index] * 100; diff --git a/src/main/java/jeresources/json/ProfilingAdapter.java b/src/main/java/jeresources/json/ProfilingAdapter.java index 4f2d3981..3babd6fe 100644 --- a/src/main/java/jeresources/json/ProfilingAdapter.java +++ b/src/main/java/jeresources/json/ProfilingAdapter.java @@ -27,7 +27,7 @@ public static void write(final Map allDimensionData) { try { - JsonWriter writer = new JsonWriter(new FileWriter(new File(ConfigHandler.getConfigDir(), "blocks.json"))); + JsonWriter writer = new JsonWriter(new FileWriter(new File(ConfigHandler.getConfigDir(), "world-gen-scan.json"))); writer.setIndent("\t"); writer.beginArray(); @@ -40,7 +40,7 @@ public static void write(final Map allDimensionData) for (String blockKey : blockKeys) { writer.beginObject(); - writer.name("ore").value(blockKey); + writer.name("block").value(blockKey); Float[] distribution = dimensionData.distribution.get(blockKey); if (distribution != null && distribution.length > 0) diff --git a/src/main/java/jeresources/json/OreAdapter.java b/src/main/java/jeresources/json/WorldGenAdapter.java similarity index 77% rename from src/main/java/jeresources/json/OreAdapter.java rename to src/main/java/jeresources/json/WorldGenAdapter.java index 5fbff5db..98888133 100644 --- a/src/main/java/jeresources/json/OreAdapter.java +++ b/src/main/java/jeresources/json/WorldGenAdapter.java @@ -6,13 +6,12 @@ import com.google.gson.JsonParser; import jeresources.api.distributions.DistributionBase; import jeresources.api.distributions.DistributionCustom; -import jeresources.api.messages.RegisterOreMessage; -import jeresources.api.utils.DistributionHelpers; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.restrictions.DimensionRestriction; -import jeresources.api.utils.restrictions.Restriction; +import jeresources.api.distributions.DistributionHelpers; +import jeresources.api.drop.DropItem; +import jeresources.api.restrictions.Restriction; import jeresources.config.ConfigHandler; -import jeresources.registry.OreRegistry; +import jeresources.entries.WorldGenEntry; +import jeresources.registry.WorldGenRegistry; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -25,19 +24,19 @@ import java.util.ArrayList; import java.util.List; -public class OreAdapter +public class WorldGenAdapter { - public static boolean hasOreEntry() + public static boolean hasWorldGenDIYData() { - return new File(ConfigHandler.getConfigDir(), "ores.json").exists(); + return new File(ConfigHandler.getConfigDir(), "world-gen.json").exists(); } - public static boolean readEntrys() + public static boolean readDIYData() { JsonParser parser = new JsonParser(); try { - JsonElement base = parser.parse(new FileReader(new File(ConfigHandler.getConfigDir(), "ores.json"))); + JsonElement base = parser.parse(new FileReader(new File(ConfigHandler.getConfigDir(), "world-gen.json"))); if (!base.isJsonArray() || base.getAsJsonArray().size() == 0) return false; JsonArray array = base.getAsJsonArray(); for (int i = 0; i < array.size(); i++) @@ -49,7 +48,7 @@ public static boolean readEntrys() if (!Loader.isModLoaded(element.getAsString())) // when modID is not loaded skip item continue; - String ore = obj.get("ore").getAsString(); + String block = obj.get("block").getAsString(); JsonElement distribElement = obj.get("distrib"); if (distribElement == null) continue; @@ -63,12 +62,12 @@ public static boolean readEntrys() JsonElement dimElement = obj.get("dim"); String dim = dimElement != null ? dimElement.getAsString() : ""; - String[] oreParts = ore.split(":"); + String[] blockParts = block.split(":"); - Block oreBlock = GameRegistry.findBlock(oreParts[0], oreParts[1]); - if (oreBlock == null || Item.getItemFromBlock(oreBlock) == null) continue; - int oreMeta = oreParts.length == 3 ? Integer.parseInt(oreParts[2]) : 0; - ItemStack oreStack = new ItemStack(oreBlock, 1, oreMeta); + Block blockBlock = GameRegistry.findBlock(blockParts[0], blockParts[1]); + if (blockBlock == null || Item.getItemFromBlock(blockBlock) == null) continue; + int oreMeta = blockParts.length == 3 ? Integer.parseInt(blockParts[2]) : 0; + ItemStack blockStack = new ItemStack(blockBlock, 1, oreMeta); List points = new ArrayList<>(); for (String point : distrib.split(";")) { @@ -99,7 +98,7 @@ public static boolean readEntrys() } } - OreRegistry.registerOre(new RegisterOreMessage(oreStack, distribution, getRestriction(dim), silktouch, dropList.toArray(new DropItem[dropList.size()]))); + WorldGenRegistry.getInstance().registerEntry(new WorldGenEntry(blockStack, distribution, getRestriction(dim), silktouch, dropList.toArray(new DropItem[dropList.size()]))); } } catch (FileNotFoundException e) { diff --git a/src/main/java/jeresources/proxy/CommonProxy.java b/src/main/java/jeresources/proxy/CommonProxy.java index 393cdbb2..8880ce2f 100644 --- a/src/main/java/jeresources/proxy/CommonProxy.java +++ b/src/main/java/jeresources/proxy/CommonProxy.java @@ -4,11 +4,11 @@ import jeresources.config.Settings; import jeresources.entries.DungeonEntry; import jeresources.entries.MobEntry; -import jeresources.entries.OreMatchEntry; +import jeresources.entries.WorldGenEntry; import jeresources.entries.PlantEntry; import jeresources.jei.JEIConfig; import jeresources.registry.*; -import jeresources.utils.ModList; +import jeresources.compatibility.ModList; import jeresources.utils.WorldEventHelper; import mezz.jei.api.IRecipeRegistry; import net.minecraft.item.ItemStack; @@ -25,7 +25,7 @@ public void initCompatibility() if (Loader.isModLoaded(ModList.Names.JEI)) { IRecipeRegistry recipeRegistry = JEIConfig.getRecipeRegistry(); - for (OreMatchEntry entry : OreRegistry.getOres()) + for (WorldGenEntry entry : WorldGenRegistry.getInstance().getWorldGen()) recipeRegistry.addRecipe(entry); for (PlantEntry entry : PlantRegistry.getInstance().getAllPlants()) recipeRegistry.addRecipe(entry); diff --git a/src/main/java/jeresources/reference/Resources.java b/src/main/java/jeresources/reference/Resources.java index 4b74f480..c00c9b1d 100644 --- a/src/main/java/jeresources/reference/Resources.java +++ b/src/main/java/jeresources/reference/Resources.java @@ -10,7 +10,7 @@ public static final class Gui public static final class Jei { public static final BackgroundDrawable MOB = new BackgroundDrawable(Textures.Gui.Jei.MOB, 163, 120); - public static final BackgroundDrawable ORE = new BackgroundDrawable(Textures.Gui.Jei.ORE, 156, 80); + public static final BackgroundDrawable WORLD_GEN = new BackgroundDrawable(Textures.Gui.Jei.WORLD_GEN, 156, 80); public static final BackgroundDrawable DUNGEON = new BackgroundDrawable(Textures.Gui.Jei.DUNGEON, 163, 120); public static final BackgroundDrawable PLANT = new BackgroundDrawable(Textures.Gui.Jei.PLANT, 165, 120); public static final BackgroundDrawable ENCHANTMENT = new BackgroundDrawable(Textures.Gui.Jei.ENCHANTMENT, 163, 120); diff --git a/src/main/java/jeresources/reference/Textures.java b/src/main/java/jeresources/reference/Textures.java index 349f1506..c4eb235d 100644 --- a/src/main/java/jeresources/reference/Textures.java +++ b/src/main/java/jeresources/reference/Textures.java @@ -9,8 +9,7 @@ public static final class Gui public static final class Jei { public static final String MOB = GUI_DIR + "JEIMobGUI.png"; - public static final String ORE = GUI_DIR + "JEIOreGUI.png"; - public static final String DROPS = GUI_DIR + "JEIDropsGUI.png"; + public static final String WORLD_GEN = GUI_DIR + "JEIWorldGenGUI.png"; public static final String DUNGEON = GUI_DIR + "JEIDungeonGUI.png"; public static final String PLANT = GUI_DIR + "JEIPlantGUI.png"; public static final String ENCHANTMENT = GUI_DIR + "JEIEnchantmentGUI.png"; diff --git a/src/main/java/jeresources/registry/EnchantmentRegistry.java b/src/main/java/jeresources/registry/EnchantmentRegistry.java index 2c50a6b3..6972c976 100644 --- a/src/main/java/jeresources/registry/EnchantmentRegistry.java +++ b/src/main/java/jeresources/registry/EnchantmentRegistry.java @@ -12,7 +12,7 @@ public class EnchantmentRegistry { - private static Set enchantments = new HashSet(); + private Set enchantments = new HashSet(); private static EnchantmentRegistry instance = null; public static EnchantmentRegistry getInstance() diff --git a/src/main/java/jeresources/registry/MessageRegistry.java b/src/main/java/jeresources/registry/MessageRegistry.java deleted file mode 100644 index 59a98381..00000000 --- a/src/main/java/jeresources/registry/MessageRegistry.java +++ /dev/null @@ -1,108 +0,0 @@ -package jeresources.registry; - -import jeresources.api.messages.*; -import jeresources.api.messages.utils.MessageKeys; -import jeresources.api.utils.Priority; -import jeresources.entries.DungeonEntry; -import jeresources.entries.MobEntry; -import net.minecraft.nbt.NBTTagCompound; - -import java.util.LinkedHashSet; -import java.util.Set; - -public class MessageRegistry -{ - private static Set registerMessages = new LinkedHashSet(); - private static Set modifyMessages = new LinkedHashSet(); - private static Set registryMessages = new LinkedHashSet(); - - public static void clear() - { - registerMessages = new LinkedHashSet(); - modifyMessages = new LinkedHashSet(); - registryMessages = new LinkedHashSet(); - } - - private static void getModifyMessages(Priority priority, Set add, Set remove) - { - for (ModifyMessage message : modifyMessages) - { - if (message.hasAdd() && message.getAddPriority() == priority) add.add(message); - if (message.hasRemove() && message.getRemovePriority() == priority) remove.add(message); - } - } - - private static void getRegistryMessages(Priority priority, Set add, Set remove) - { - for (RegistryMessage message : registryMessages) - { - if (message.getAddPriority() == priority) add.add(message); - if (message.getRemovePriority() == priority) remove.add(message); - } - } - - public static void addMessage(Message message) - { - if (message == null || !message.isValid()) return; - if (message instanceof ModifyMessage) modifyMessages.add((ModifyMessage) message); - else if (message instanceof RegistryMessage) registryMessages.add((RegistryMessage) message); - } - - public static void registerMessage(String key, NBTTagCompound tagCompound) - { - Message message = null; - if (key.equals(MessageKeys.registerMob)) message = new RegisterMobMessage(tagCompound); - else if (key.equals(MessageKeys.registerOre)) message = new RegisterOreMessage(tagCompound); - else if (key.equals(MessageKeys.registerDungeon)) message = new RegisterDungeonMessage(tagCompound); - else if (key.equals(MessageKeys.modifyMob)) message = new ModifyMobMessage(tagCompound); - else if (key.equals(MessageKeys.modifyOre)) message = new ModifyOreMessage(tagCompound); - else if (key.equals(MessageKeys.modifyPlant)) message = new ModifyPlantMessage(tagCompound); - else if (key.equals(MessageKeys.removeMob)) message = new RemoveMobMessage(tagCompound); - addMessage(message); - } - - public static void processMessages(boolean initOres) - { - for (Priority priority : Priority.values()) - { - Set addMessages = new LinkedHashSet(); - Set removeMessages = new LinkedHashSet(); - getRegistryMessages(priority, addMessages, removeMessages); - for (RegistryMessage message : addMessages) - { - if (initOres && message instanceof RegisterOreMessage) - OreRegistry.registerOre((RegisterOreMessage) message); - else if (message instanceof RegisterMobMessage) - MobRegistry.getInstance().registerMob(new MobEntry((RegisterMobMessage) message)); - else if (message instanceof RegisterDungeonMessage) - DungeonRegistry.getInstance().registerDungeonEntry(new DungeonEntry((RegisterDungeonMessage) message)); - } - for (RegistryMessage message : removeMessages) - { - if (message instanceof RemoveMobMessage) - MobRegistry.getInstance().removeMob((RemoveMobMessage) message); - } - } - - for (Priority priority : Priority.values()) - { - Set addMessages = new LinkedHashSet(); - Set removeMessages = new LinkedHashSet(); - getModifyMessages(priority, addMessages, removeMessages); - for (ModifyMessage addMessage : addMessages) - { - if (addMessage instanceof ModifyMobMessage) - MobRegistry.getInstance().addMobDrops((ModifyMobMessage) addMessage); - else if (initOres && addMessage instanceof ModifyOreMessage) - OreRegistry.addDrops((ModifyOreMessage) addMessage); - } - for (ModifyMessage removeMessage : removeMessages) - { - if (removeMessage instanceof ModifyMobMessage) - MobRegistry.getInstance().removeMobDrops((ModifyMobMessage) removeMessage); - else if (initOres && removeMessage instanceof ModifyOreMessage) - OreRegistry.removeDrops((ModifyOreMessage) removeMessage); - } - } - } -} diff --git a/src/main/java/jeresources/registry/MobRegistry.java b/src/main/java/jeresources/registry/MobRegistry.java index feee0db6..5e5a9e22 100644 --- a/src/main/java/jeresources/registry/MobRegistry.java +++ b/src/main/java/jeresources/registry/MobRegistry.java @@ -1,22 +1,17 @@ package jeresources.registry; -import jeresources.api.messages.ModifyMobMessage; -import jeresources.api.messages.RemoveMobMessage; -import jeresources.api.utils.DropItem; +import jeresources.api.drop.DropItem; import jeresources.entries.MobEntry; -import jeresources.utils.ClassScraper; import jeresources.utils.MobHelper; -import net.minecraft.entity.monster.EntitySkeleton; +import jeresources.utils.ReflectionHelper; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class MobRegistry { - private Set registry = new LinkedHashSet(); + private Set registry = new LinkedHashSet<>(); private static MobRegistry instance = null; @@ -29,22 +24,7 @@ public static MobRegistry getInstance() public boolean registerMob(MobEntry entry) { - return registerMob(entry.getMobName(), entry); - } - - public boolean registerMob(String key, MobEntry entry) - { - if (!registry.contains(entry)) - { - registry.add(entry); - return true; - } - return false; - } - - public MobEntry getMobEntry(String key) - { - return null;//registry.get(key); + return registry.add(entry); } public List getMobsThatDropItem(ItemStack item) @@ -60,49 +40,10 @@ public List getMobs() return new ArrayList(registry); } - public void removeMobDrops(ModifyMobMessage entry) + public void addDrops(Class entity, DropItem... drops) { - for (MobEntry regEntry : getRegistryMatches(entry.getFilterClass(), entry.isStrict(), entry.isWither())) - for (ItemStack item : entry.getRemoveDrops()) - regEntry.removeDrop(item); - } - - public void addMobDrops(ModifyMobMessage entry) - { - for (MobEntry regEntry : getRegistryMatches(entry.getFilterClass(), entry.isStrict(), entry.isWither())) - for (DropItem item : entry.getAddDrops()) - regEntry.addDrop(item); - } - - public void removeMob(RemoveMobMessage message) - { - registry.removeAll(getRegistryMatches(message.getFilterClass(), message.isStrict(), message.isWither())); - } - - public Set getRegistryMatches(Class clazz, boolean exactMatch, boolean witherSkeleton) - { - Set result = new LinkedHashSet(); - int wither = witherSkeleton ? 1 : 0; - for (MobEntry regEntry : registry) - { - Set classes = new LinkedHashSet(); - if (exactMatch) classes.add(regEntry.getEntity().getClass()); - else classes = ClassScraper.getGeneralizations(regEntry.getEntity().getClass()); - for (Object generalClass : classes) - { - if (generalClass == clazz) - { - if (exactMatch && clazz == EntitySkeleton.class) - if (((EntitySkeleton) regEntry.getEntity()).getSkeletonType() != wither) break; - result.add(regEntry); - } - } - } - return result; - } - - public void clear() - { - instance = new MobRegistry(); + for (MobEntry entry : registry) + if (ReflectionHelper.isInstanceOf(entry.getClass(), entity)) + entry.addDrops(drops); } } diff --git a/src/main/java/jeresources/registry/OreRegistry.java b/src/main/java/jeresources/registry/OreRegistry.java deleted file mode 100644 index c7a4ac01..00000000 --- a/src/main/java/jeresources/registry/OreRegistry.java +++ /dev/null @@ -1,129 +0,0 @@ -package jeresources.registry; - -import jeresources.api.messages.ModifyOreMessage; -import jeresources.api.messages.RegisterOreMessage; -import jeresources.api.utils.DropItem; -import jeresources.api.utils.Priority; -import jeresources.entries.OreMatchEntry; -import jeresources.utils.MapKeys; - -import java.util.*; - -public class OreRegistry -{ - private static Map matchEntryMap = new LinkedHashMap(); - private static Map> dropMap = new LinkedHashMap>(); - - public static void registerOre(RegisterOreMessage message) - { - String key = MapKeys.getKey(message.getOre(), message.getRestriction()); - if (key == null) return; - - if (dropMap.containsKey(key)) - { - Set hashCodes = dropMap.get(key); - boolean matched = false; - for (int hashCode : hashCodes) - { - if (matchEntryMap.get(hashCode).add(message)) - { - matched = true; - break; - } - } - if (!matched) - { - int newHash = addNewOre(key, message); - for (int hashCode : hashCodes) - { - if (hashCode != newHash) - matchEntryMap.get(newHash).add(matchEntryMap.get(hashCode)); - } - } - } else - { - addNewOre(key, message); - } - DropItem[] drops = message.getDrops(); - if (drops == null || drops.length == 0) return; - addDrops(new ModifyOreMessage(message.getOre(), Priority.FIRST, drops)); - } - - private static int addNewOre(String key, RegisterOreMessage message) - { - OreMatchEntry newMatch = new OreMatchEntry(message); - int hashCode = newMatch.hashCode(); - Set hashSet = dropMap.containsKey(key) ? dropMap.get(key) : new LinkedHashSet(); - hashSet.add(hashCode); - dropMap.put(key, hashSet); - matchEntryMap.put(hashCode, newMatch); - return hashCode; - } - - public static List getOres() - { - List result = new ArrayList(); - Set addedCodes = new TreeSet(); - for (Set hashCodes : dropMap.values()) - { - for (int hashCode : hashCodes) - { - if (!addedCodes.contains(hashCode)) - { - addedCodes.add(hashCode); - result.add(matchEntryMap.get(hashCode)); - } - } - } - return result; - } - - public static boolean removeDrops(ModifyOreMessage oreMod) - { - if (oreMod.getRemoveDrops() == null) return true; - String oreKey = MapKeys.getKey(oreMod.getOre()); - if (oreKey == null || !dropMap.containsKey(oreKey) || dropMap.get(oreKey).isEmpty()) return false; - for (DropItem drop : oreMod.getRemoveDrops()) - { - String dropKey = MapKeys.getKey(drop); - if (dropKey == null || !dropMap.containsKey(dropKey)) continue; - Set hashSet = dropMap.get(oreKey); - dropMap.get(dropKey).removeAll(hashSet); - for (int hashCode : hashSet) - matchEntryMap.get(hashCode).removeDrop(drop.item); - } - return true; - } - - public static boolean addDrops(ModifyOreMessage oreMod) - { - if (oreMod.getAddDrops() == null) return true; - String oreKeyPrefix = MapKeys.getKey(oreMod.getOre()); - if (oreKeyPrefix == null) return false; - Set oreKeys = new TreeSet<>(); - boolean found = false; - for (String key : dropMap.keySet()) - { - if (key.startsWith(oreKeyPrefix)) - { - found = true; - oreKeys.add(key); - } - } - if (!found) return false; - for (DropItem drop : oreMod.getAddDrops()) - { - String dropKey = MapKeys.getKey(drop); - if (dropKey == null) continue; - Set hashSet = dropMap.containsKey(dropKey) ? dropMap.get(dropKey) : new LinkedHashSet(); - for (String oreKey : oreKeys) - { - for (int hashCode : dropMap.get(oreKey)) - matchEntryMap.get(hashCode).addDrop(drop); - hashSet.addAll(dropMap.get(oreKey)); - } - dropMap.put(dropKey, hashSet); - } - return true; - } -} diff --git a/src/main/java/jeresources/registry/PlantRegistry.java b/src/main/java/jeresources/registry/PlantRegistry.java index 7f265d91..ee157be5 100644 --- a/src/main/java/jeresources/registry/PlantRegistry.java +++ b/src/main/java/jeresources/registry/PlantRegistry.java @@ -1,6 +1,6 @@ package jeresources.registry; -import jeresources.api.utils.PlantDrop; +import jeresources.api.drop.PlantDrop; import jeresources.entries.PlantEntry; import jeresources.utils.MapKeys; import net.minecraft.item.ItemStack; diff --git a/src/main/java/jeresources/registry/WorldGenRegistry.java b/src/main/java/jeresources/registry/WorldGenRegistry.java new file mode 100644 index 00000000..d1134217 --- /dev/null +++ b/src/main/java/jeresources/registry/WorldGenRegistry.java @@ -0,0 +1,49 @@ +package jeresources.registry; + +import jeresources.api.drop.DropItem; +import jeresources.entries.WorldGenEntry; +import jeresources.utils.MapKeys; +import net.minecraft.item.ItemStack; + +import java.util.*; + +public class WorldGenRegistry +{ + private Map worldGenMap; + private static WorldGenRegistry instance; + + public static WorldGenRegistry getInstance() + { + if (instance == null) + instance = new WorldGenRegistry(); + return instance; + } + + private WorldGenRegistry() + { + worldGenMap = new HashMap<>(); + } + + + public void registerEntry(WorldGenEntry entry) + { + if (worldGenMap.containsKey(MapKeys.getKey(entry))) + { + WorldGenEntry existing = worldGenMap.get(MapKeys.getKey(entry)); + existing.merge(entry); + } else + worldGenMap.put(MapKeys.getKey(entry), entry); + } + + public void addDrops(ItemStack block, DropItem... drops) + { + for (Map.Entry entry : worldGenMap.entrySet()) + if (entry.getKey().startsWith(MapKeys.getKey(block))) + entry.getValue().addDrops(drops); + } + + public List getWorldGen() + { + return new ArrayList<>(worldGenMap.values()); + } +} diff --git a/src/main/java/jeresources/utils/MapKeys.java b/src/main/java/jeresources/utils/MapKeys.java index ddb74f29..d177dea2 100644 --- a/src/main/java/jeresources/utils/MapKeys.java +++ b/src/main/java/jeresources/utils/MapKeys.java @@ -1,12 +1,12 @@ package jeresources.utils; -import jeresources.api.utils.DropItem; +import jeresources.api.drop.DropItem; -import jeresources.api.utils.restrictions.Restriction; +import jeresources.api.restrictions.Restriction; +import jeresources.entries.WorldGenEntry; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.IPlantable; -import net.minecraftforge.oredict.OreDictionary; public class MapKeys { @@ -34,4 +34,9 @@ public static String getKey(ItemStack drop, Restriction restriction) { return getKey(drop) + ":" + restriction.toString(); } + + public static String getKey(WorldGenEntry entry) + { + return getKey(entry.getBlock(), entry.getRestriction()); + } } diff --git a/src/main/java/jeresources/utils/MobHelper.java b/src/main/java/jeresources/utils/MobHelper.java index 6278b0b8..69628b1d 100644 --- a/src/main/java/jeresources/utils/MobHelper.java +++ b/src/main/java/jeresources/utils/MobHelper.java @@ -1,6 +1,6 @@ package jeresources.utils; -import jeresources.api.utils.DropItem; +import jeresources.api.drop.DropItem; import jeresources.entries.MobEntry; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.monster.EntitySlime; diff --git a/src/main/java/jeresources/utils/ReflectionHelper.java b/src/main/java/jeresources/utils/ReflectionHelper.java index 1303f95d..5b1b0874 100644 --- a/src/main/java/jeresources/utils/ReflectionHelper.java +++ b/src/main/java/jeresources/utils/ReflectionHelper.java @@ -1,6 +1,11 @@ package jeresources.utils; +import net.minecraftforge.fml.common.discovery.ASMDataTable; + import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; public class ReflectionHelper extends net.minecraftforge.fml.relauncher.ReflectionHelper { @@ -51,4 +56,21 @@ public static boolean isInstanceOf(Class clazz, Class checkClass) if (instanceOf == checkClass) return true; return false; } + + public static List getInstances(ASMDataTable asmDataTable, Class annotationClass, Class instanceClass) { + String annotationClassName = annotationClass.getCanonicalName(); + Set asmDatas = asmDataTable.getAll(annotationClassName); + List instances = new ArrayList<>(); + for (ASMDataTable.ASMData asmData : asmDatas) { + try { + Class asmClass = Class.forName(asmData.getClassName()); + Class asmInstanceClass = asmClass.asSubclass(instanceClass); + T instance = asmInstanceClass.newInstance(); + instances.add(instance); + } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { + LogHelper.warn("Failed to load: {}" + asmData.getClassName()); + } + } + return instances; + } } diff --git a/src/main/java/jeresources/utils/RenderHelper.java b/src/main/java/jeresources/utils/RenderHelper.java index 9b10cb9e..84875322 100644 --- a/src/main/java/jeresources/utils/RenderHelper.java +++ b/src/main/java/jeresources/utils/RenderHelper.java @@ -1,6 +1,8 @@ package jeresources.utils; -import jeresources.api.utils.ColorHelper; +import jeresources.api.render.ColourHelper; +import jeresources.api.render.IMobRenderHook; +import jeresources.compatibility.MobRegistryImpl; import jeresources.reference.Resources; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -27,7 +29,7 @@ public static void drawArrow(double xBegin, double yBegin, double xEnd, double y { Minecraft mc = Minecraft.getMinecraft(); int scale = new ScaledResolution(mc).getScaleFactor(); - GlStateManager.color(ColorHelper.getRed(color), ColorHelper.getGreen(color), ColorHelper.getBlue(color)); + GlStateManager.color(ColourHelper.getRed(color), ColourHelper.getGreen(color), ColourHelper.getBlue(color)); GL11.glLineWidth(scale * 1.3F); GL11.glBegin(GL11.GL_LINES); GL11.glVertex2d(xBegin, yBegin); @@ -50,7 +52,7 @@ public static void drawLine(double xBegin, double yBegin, double xEnd, double yE { Minecraft mc = Minecraft.getMinecraft(); int scale = new ScaledResolution(mc).getScaleFactor(); - GlStateManager.color(ColorHelper.getRed(color), ColorHelper.getGreen(color), ColorHelper.getBlue(color)); + GlStateManager.color(ColourHelper.getRed(color), ColourHelper.getGreen(color), ColourHelper.getBlue(color)); GL11.glLineWidth(scale * 1.3F); GL11.glBegin(GL11.GL_LINES); GL11.glVertex2d(xBegin, yBegin); @@ -62,7 +64,7 @@ public static void drawPoint(double x, double y, int color) { Minecraft mc = Minecraft.getMinecraft(); int scale = new ScaledResolution(mc).getScaleFactor(); - GlStateManager.color(ColorHelper.getRed(color), ColorHelper.getGreen(color), ColorHelper.getBlue(color)); + GlStateManager.color(ColourHelper.getRed(color), ColourHelper.getGreen(color), ColourHelper.getBlue(color)); GL11.glPointSize(scale * 1.3F); GL11.glBegin(GL11.GL_POINTS); GL11.glVertex2d(x, y); @@ -83,24 +85,12 @@ public static void renderEntity(int x, int y, float scale, float yaw, float pitc float prevRotationYawHead = entityLivingBase.prevRotationYawHead; float rotationYawHead = entityLivingBase.rotationYawHead; net.minecraft.client.renderer.RenderHelper.enableStandardItemLighting(); - if (entityLivingBase instanceof EntityDragon || entityLivingBase instanceof EntityBat) - { - GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F); - GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); - if (entityLivingBase instanceof EntityDragon) - { - pitch = -pitch - 80; - GlStateManager.rotate(yaw < 90 ? (yaw < -90 ? 90 : -yaw) : -90, 0.0F, 1.0F, 0.0F); - } else pitch = -pitch; - } - if (entityLivingBase instanceof EntityGuardian && ((EntityGuardian) entityLivingBase).isElder()) - { - GlStateManager.scale(0.6F, 0.6F, 0.6F); - } - if (entityLivingBase instanceof EntitySquid) - { - GlStateManager.rotate(50.0F, 1.0F, 0.0F, 0.0F); - } + IMobRenderHook.RenderInfo renderInfo = MobRegistryImpl.applyRenderHooks(entityLivingBase, new IMobRenderHook.RenderInfo(x, y, scale, yaw, pitch)); + x = renderInfo.x; + y = renderInfo.y; + scale = renderInfo.scale; + yaw = renderInfo.yaw; + pitch = renderInfo.pitch; GlStateManager.rotate(-((float) Math.atan((double) (pitch / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); entityLivingBase.renderYawOffset = (float) Math.atan((double) (yaw / 40.0F)) * 20.0F; entityLivingBase.rotationYaw = (float) Math.atan((double) (yaw / 40.0F)) * 40.0F; diff --git a/src/main/java/jeresources/utils/SeedHelper.java b/src/main/java/jeresources/utils/SeedHelper.java index c27f1344..1cffe792 100644 --- a/src/main/java/jeresources/utils/SeedHelper.java +++ b/src/main/java/jeresources/utils/SeedHelper.java @@ -1,6 +1,6 @@ package jeresources.utils; -import jeresources.api.utils.PlantDrop; +import jeresources.api.drop.PlantDrop; import net.minecraft.item.ItemStack; import net.minecraft.util.WeightedRandom; import net.minecraftforge.common.ForgeHooks; diff --git a/src/main/java/jeresources/utils/WorldEventHelper.java b/src/main/java/jeresources/utils/WorldEventHelper.java index e4f6aa04..bbf8f50d 100644 --- a/src/main/java/jeresources/utils/WorldEventHelper.java +++ b/src/main/java/jeresources/utils/WorldEventHelper.java @@ -1,7 +1,7 @@ package jeresources.utils; -import jeresources.api.utils.restrictions.BlockRestriction; -import jeresources.api.utils.restrictions.DimensionRegistry; +import jeresources.api.restrictions.BlockRestriction; +import jeresources.api.restrictions.DimensionRegistry; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; diff --git a/src/main/resources/assets/jeresources/lang/en_US.lang b/src/main/resources/assets/jeresources/lang/en_US.lang index 46c14fc8..60e36264 100644 --- a/src/main/resources/assets/jeresources/lang/en_US.lang +++ b/src/main/resources/assets/jeresources/lang/en_US.lang @@ -40,12 +40,12 @@ jer.enchantments.title=Enchantments jer.plant.title=Plant Drops #Ore View -jer.ore.title=World Gen -jer.ore.silkTouch=Silk Touch Needed -jer.ore.biomes=Spawn Biomes -jer.ore.dimensions=Valid Dimensions -jer.ore.drops=Drops -jer.ore.average=Avg. Drop: +jer.worldgen.title=World Gen +jer.worldgen.silkTouch=Silk Touch Needed +jer.worldgen.biomes=Spawn Biomes +jer.worldgen.dimensions=Valid Dimensions +jer.worldgen.drops=Drops +jer.worldgen.average=Avg. Drop: #Mob View jer.mob.title=Mob Drops diff --git a/src/main/resources/assets/jeresources/lang/nl_NL.lang b/src/main/resources/assets/jeresources/lang/nl_NL.lang index b667abf8..2a9116c8 100644 --- a/src/main/resources/assets/jeresources/lang/nl_NL.lang +++ b/src/main/resources/assets/jeresources/lang/nl_NL.lang @@ -29,11 +29,11 @@ jer.enchantments.title=Enchantments jer.plant.title=Plant Drops #Ore View -jer.ore.title=Ore Gen -jer.ore.bestY=bestY -jer.ore.silkTouch=Silk Touch Nodig -jer.ore.biomes=Spawn Biomes -jer.ore.dimensions=Spawn Dimensions +jer.worldgen.title=Ore Gen +jer.worldgen.bestY=bestY +jer.worldgen.silkTouch=Silk Touch Nodig +jer.worldgen.biomes=Spawn Biomes +jer.worldgen.dimensions=Spawn Dimensions #Mob View jer.mob.title=Mob Drops diff --git a/src/main/resources/assets/jeresources/lang/ru_RU.lang b/src/main/resources/assets/jeresources/lang/ru_RU.lang index 4c6071ab..82bc5e4e 100644 --- a/src/main/resources/assets/jeresources/lang/ru_RU.lang +++ b/src/main/resources/assets/jeresources/lang/ru_RU.lang @@ -38,11 +38,11 @@ jer.enchantments.title=Зачарования jer.plant.title=Плоды растений #Ore View -jer.ore.title=Генерация руд -jer.ore.bestY=Лучшее значение по Y -jer.ore.silkTouch=Необходимо шёлковое касание -jer.ore.biomes=Появляется в биомах -jer.ore.dimensions=Допустимые измерения +jer.worldgen.title=Генерация руд +jer.worldgen.bestY=Лучшее значение по Y +jer.worldgen.silkTouch=Необходимо шёлковое касание +jer.worldgen.biomes=Появляется в биомах +jer.worldgen.dimensions=Допустимые измерения #Mob View jer.mob.title=Добыча мобов diff --git a/src/main/resources/assets/jeresources/lang/zh_CN.lang b/src/main/resources/assets/jeresources/lang/zh_CN.lang index 1ff8f2a0..78a956db 100644 --- a/src/main/resources/assets/jeresources/lang/zh_CN.lang +++ b/src/main/resources/assets/jeresources/lang/zh_CN.lang @@ -38,11 +38,11 @@ jer.enchantments.title=可用附魔属性 jer.plant.title=植物掉落信息 #Ore View -jer.ore.title=矿物生成 -jer.ore.bestY=常见层数 -jer.ore.silkTouch=需要精准采集 -jer.ore.biomes=生物群系 -jer.ore.dimensions=有效生物群系 +jer.worldgen.title=矿物生成 +jer.worldgen.bestY=常见层数 +jer.worldgen.silkTouch=需要精准采集 +jer.worldgen.biomes=生物群系 +jer.worldgen.dimensions=有效生物群系 #Mob View jer.mob.title=生物资源 diff --git a/src/main/resources/assets/jeresources/textures/gui/JEIOreGUI.png b/src/main/resources/assets/jeresources/textures/gui/JEIWorldGenGUI.png similarity index 100% rename from src/main/resources/assets/jeresources/textures/gui/JEIOreGUI.png rename to src/main/resources/assets/jeresources/textures/gui/JEIWorldGenGUI.png