From f12c6d2d11dc93913ac13e93a5e91c303f513aa7 Mon Sep 17 00:00:00 2001 From: temp1011 <34900092+temp1011@users.noreply.github.com> Date: Fri, 27 Apr 2018 12:51:04 +0100 Subject: [PATCH] Add IMC for registering flowers (#2027) --- .../forestry/apiculture/ModuleApiculture.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/java/forestry/apiculture/ModuleApiculture.java b/src/main/java/forestry/apiculture/ModuleApiculture.java index 45340bb9f..2ef7f289e 100644 --- a/src/main/java/forestry/apiculture/ModuleApiculture.java +++ b/src/main/java/forestry/apiculture/ModuleApiculture.java @@ -31,6 +31,8 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.init.PotionTypes; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; import net.minecraft.potion.PotionUtils; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; @@ -157,9 +159,9 @@ public class ModuleApiculture extends BlankForestryModule { public static int ticksPerBeeWorkCycle = 550; public static boolean hivesDamageOnPeaceful = false; - + public static boolean doSelfPollination = true; - + public static int maxFlowersSpawnedPerHive = 20; @Nullable public static VillagerRegistry.VillagerProfession villagerApiarist; @@ -282,7 +284,7 @@ public class ModuleApiculture extends BlankForestryModule { ticksPerBeeWorkCycle = config.getIntLocalized("beekeeping", "ticks.work", 550, 250, 850); hivesDamageOnPeaceful = config.getBooleanLocalized("beekeeping", "hivedamage.peaceful", false); - + doSelfPollination = config.getBooleanLocalized("beekeeping", "self.pollination", false); config.save(); @@ -988,11 +990,52 @@ public class ModuleApiculture extends BlankForestryModule { HiveConfig.addBlacklistedDim(dim); } return true; + } else if (message.key.equals("add-plantable-flower")) { + return addPlantableFlower(message); + } else if (message.key.equals("add-acceptable-flower")) { + return addAcceptableFlower(message); } return false; } + private boolean addPlantableFlower(IMCMessage message) { + try { + NBTTagCompound tagCompound = message.getNBTValue(); + IBlockState flowerState = NBTUtil.readBlockState(tagCompound); + double weight = tagCompound.getDouble("weight"); + List flowerTypes = new ArrayList<>(); + for (String key : tagCompound.getKeySet()) { + if (key.contains("flowertype")) { + flowerTypes.add(tagCompound.getString("flowertype")); + } + } + FlowerManager.flowerRegistry.registerPlantableFlower(flowerState, weight, flowerTypes.toArray(new String[flowerTypes.size()])); + return true; + } catch (Exception e) { + IMCUtil.logInvalidIMCMessage(message); + return false; + } + } + + private boolean addAcceptableFlower(IMCMessage message) { + try { + NBTTagCompound tagCompound = message.getNBTValue(); + IBlockState flowerState = NBTUtil.readBlockState(tagCompound); + List flowerTypes = new ArrayList<>(); + for (String key : tagCompound.getKeySet()) { + if (key.contains("flowertype")) { + flowerTypes.add(tagCompound.getString("flowertype")); + } + } + FlowerManager.flowerRegistry.registerAcceptableFlower(flowerState, flowerTypes.toArray(new String[flowerTypes.size()])); + return true; + } catch (Exception e) { + IMCUtil.logInvalidIMCMessage(message); + return false; + } + } + @SubscribeEvent @SideOnly(Side.CLIENT) public void textureHook(TextureStitchEvent.Pre event) {