From fd724d147ae4b1236b7697bd4c3732a5ea0c2581 Mon Sep 17 00:00:00 2001 From: Robert Obermeier Date: Sat, 12 Aug 2017 05:56:12 +0200 Subject: [PATCH 1/7] Fix #1789 The End has no hives. (#1795) --- src/main/java/forestry/apiculture/PluginApiculture.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/forestry/apiculture/PluginApiculture.java b/src/main/java/forestry/apiculture/PluginApiculture.java index 5afd16d08..ac3ce479c 100755 --- a/src/main/java/forestry/apiculture/PluginApiculture.java +++ b/src/main/java/forestry/apiculture/PluginApiculture.java @@ -33,6 +33,7 @@ import net.minecraft.potion.PotionUtils; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.DimensionType; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.IChunkGenerator; @@ -897,6 +898,14 @@ public class PluginApiculture extends BlankForestryPlugin { return new SaveEventHandlerApiculture(); } + @Override + public void populateChunk(IChunkGenerator chunkGenerator, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) { + if(!world.provider.getDimensionType().equals(DimensionType.THE_END)) return; + if (Config.getBeehivesAmount() > 0.0) { + HiveDecorator.decorateHives(world, rand, chunkX, chunkZ); + } + } + @Override public void decorateBiome(World world, Random rand, BlockPos pos) { if (Config.getBeehivesAmount() > 0.0) { From 6593118f3dae25b872c0174e03f4dfb19836196f Mon Sep 17 00:00:00 2001 From: mezz Date: Sat, 12 Aug 2017 12:36:47 -0700 Subject: [PATCH 2/7] Fix #1787 Wood logs drop the wrong item when harvested with silk touch --- .../forestry/arboriculture/blocks/BlockForestryLog.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/forestry/arboriculture/blocks/BlockForestryLog.java b/src/main/java/forestry/arboriculture/blocks/BlockForestryLog.java index a40cf354f..603d54e69 100755 --- a/src/main/java/forestry/arboriculture/blocks/BlockForestryLog.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockForestryLog.java @@ -142,6 +142,14 @@ public abstract class BlockForestryLog & IWoodType> extends Bl return woodType.getHardness(); } + @Override + protected ItemStack getSilkTouchDrop(IBlockState state) { + ItemStack silkTouchDrop = super.getSilkTouchDrop(state); + int damage = this.damageDropped(state); + silkTouchDrop.setItemDamage(damage); + return silkTouchDrop; + } + /* PROPERTIES */ @Override public final int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) { From edcc47a6b3abac8fcf8a672f3decf2eb6a5efb26 Mon Sep 17 00:00:00 2001 From: Robert Obermeier Date: Sat, 12 Aug 2017 23:44:16 +0200 Subject: [PATCH 3/7] Fix #1753 Add generalized sapling support (#1798) --- .../farming/logic/FarmableSapling.java | 108 ++++++++++++++++++ .../farming/logic/FarmableVanillaSapling.java | 60 +--------- 2 files changed, 111 insertions(+), 57 deletions(-) create mode 100644 src/main/java/forestry/farming/logic/FarmableSapling.java diff --git a/src/main/java/forestry/farming/logic/FarmableSapling.java b/src/main/java/forestry/farming/logic/FarmableSapling.java new file mode 100644 index 000000000..48819d57b --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmableSapling.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.farming.logic; + +import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.TreeManager; +import forestry.api.core.ForestryAPI; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.api.genetics.IIndividual; +import forestry.core.blocks.BlockRegistry; +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.utils.GeneticsUtil; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.NetworkUtil; +import forestry.plugins.ForestryPluginUids; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.EnumAction; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.registry.GameRegistry; + +public class FarmableSapling implements IFarmable { + protected final ItemStack germling; + protected final boolean ignoreMetadata; + protected final Block saplingBlock; + protected final ItemStack[] windfall; + + public FarmableSapling(final ItemStack germling, final ItemStack[] windfall) { + this(germling, windfall, true); + } + + public FarmableSapling(final ItemStack germling, final ItemStack[] windfall, boolean addSubItems) { + this.germling = germling; + this.windfall = windfall; + this.saplingBlock = ItemStackUtil.getBlock(germling); + this.ignoreMetadata = addSubItems; + } + + @Override + public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { + if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) { + IIndividual tree = GeneticsUtil.getGeneticEquivalent(germling); + if (tree instanceof ITree) { + return TreeManager.treeRoot.plantSapling(world, (ITree) tree, player.getGameProfile(), pos); + } + } + ItemStack copy = germling.copy(); + player.setHeldItem(EnumHand.MAIN_HAND, copy); + EnumActionResult actionResult = copy.onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); + player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY); + if (actionResult == EnumActionResult.SUCCESS) { + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState()); + NetworkUtil.sendNetworkPacket(packet, pos, world); + return true; + } + return false; + } + + @Override + public boolean isSaplingAt(World world, BlockPos pos) { + return world.getBlockState(pos).getBlock() == this.saplingBlock; + } + + @Override + public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { + Block block = blockState.getBlock(); + if (!block.isWood(world, pos)) { + return null; + } + + return new CropDestroy(world, blockState, pos, null); + } + + @Override + public boolean isGermling(ItemStack itemstack) { + if (ignoreMetadata) { + return ItemStack.areItemsEqual(germling, new ItemStack((itemstack.getItem()))); + } + return ItemStack.areItemsEqual(germling, itemstack); + } + + @Override + public boolean isWindfall(ItemStack itemstack) { + for (ItemStack drop : windfall) { + if (drop.isItemEqual(itemstack)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java b/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java index 74fbedf35..d72a58306 100755 --- a/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java +++ b/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java @@ -29,67 +29,13 @@ import forestry.api.farming.ICrop; import forestry.api.farming.IFarmable; import forestry.api.genetics.IIndividual; import forestry.core.network.packets.PacketFXSignal; +import forestry.core.proxy.Proxies; import forestry.core.utils.GeneticsUtil; -import forestry.core.utils.NetworkUtil; import forestry.plugins.ForestryPluginUids; -public class FarmableVanillaSapling implements IFarmable { - - protected final ItemStack germling; - private final ItemStack[] windfall; +public class FarmableVanillaSapling extends FarmableSapling { public FarmableVanillaSapling() { - this.germling = new ItemStack(Blocks.SAPLING); - this.windfall = new ItemStack[]{new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META)}; - } - - @Override - public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { - if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) { - IIndividual tree = GeneticsUtil.getGeneticEquivalent(germling); - if (!(tree instanceof ITree)) { - return false; - } - - return TreeManager.treeRoot.plantSapling(world, (ITree) tree, player.getGameProfile(), pos); - } else { - EnumActionResult actionResult = germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); - if (actionResult == EnumActionResult.SUCCESS) { - PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState()); - NetworkUtil.sendNetworkPacket(packet, pos, world); - return true; - } - return false; - } - } - - @Override - public boolean isSaplingAt(World world, BlockPos pos) { - return world.getBlockState(pos).getBlock() == Blocks.SAPLING; - } - - @Override - public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { - Block block = blockState.getBlock(); - if (!block.isWood(world, pos)) { - return null; - } - - return new CropDestroy(world, blockState, pos, null); - } - - @Override - public boolean isGermling(ItemStack itemstack) { - return ItemStack.areItemsEqual(germling, itemstack); - } - - @Override - public boolean isWindfall(ItemStack itemstack) { - for (ItemStack drop : windfall) { - if (drop.isItemEqual(itemstack)) { - return true; - } - } - return false; + super(new ItemStack(Blocks.SAPLING), new ItemStack[]{new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META)}); } } From cfd513ea8073f362c82c2bd70595a0f5662b4c24 Mon Sep 17 00:00:00 2001 From: Robert Obermeier Date: Sun, 13 Aug 2017 00:50:31 +0200 Subject: [PATCH 4/7] Fix Natura support (#1794) --- src/main/java/forestry/Forestry.java | 13 +- .../java/forestry/plugins/PluginManager.java | 13 +- .../forestry/plugins/compat/PluginNatura.java | 386 ++++++++---------- 3 files changed, 182 insertions(+), 230 deletions(-) diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 4ce2dafa5..353e66976 100755 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -15,7 +15,10 @@ import com.google.common.base.Preconditions; import javax.annotation.Nullable; import java.io.File; +import forestry.plugins.compat.PluginNatura; +import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fml.common.Mod; @@ -26,6 +29,7 @@ import net.minecraftforge.fml.common.event.FMLInterModComms.IMCEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; @@ -58,7 +62,8 @@ import forestry.plugins.compat.PluginIC2; acceptedMinecraftVersions = "[1.12]", dependencies = "required-after:forge@[14.21.1.2395,);" + "after:jei@[4.7.0,);" - + "after:" + PluginIC2.modId + ";") + + "after:" + PluginIC2.modId + ";" + + "after:" + PluginNatura.modId + ";") public class Forestry { @SuppressWarnings("NullableProblems") @@ -73,6 +78,7 @@ public class Forestry { ForestryAPI.errorStateRegistry = new ErrorStateRegistry(); EnumErrorCode.init(); FluidRegistry.enableUniversalBucket(); + MinecraftForge.EVENT_BUS.register(this); } @Nullable @@ -105,6 +111,11 @@ public class Forestry { PluginManager.runPreInit(event.getSide()); + } + + @SubscribeEvent + public void registerModels(ModelRegistryEvent event) { + PluginManager.runRegisterBackpacksAndCrates(); Proxies.render.registerModels(); } diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index 2aca860fb..88b8809fd 100755 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -66,7 +66,8 @@ public class PluginManager { SETUP, // setup API to make it functional. GameMode Configs are not yet accessible SETUP_DISABLED, // setup fallback API to avoid crashes REGISTER, // register basic blocks and items - PRE_INIT, // register handlers, triggers, definitions, backpacks, crates, and anything that depends on basic items + PRE_INIT, // register handlers, triggers, definitions, and anything that depends on basic items + BACKPACKS_CRATES, // backpacks, crates INIT, // anything that depends on PreInit stages, recipe registration POST_INIT, // stubborn mod integration, dungeon loot, and finalization of things that take input from mods FINISHED @@ -228,11 +229,19 @@ public class PluginManager { if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.BUILDCRAFT_STATEMENTS)) { plugin.registerTriggers(); } + Log.debug("Pre-Init Complete: {}", plugin); + } + } + + public static void runRegisterBackpacksAndCrates() { + stage = Stage.BACKPACKS_CRATES; + for (IForestryPlugin plugin : loadedPlugins) { if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.STORAGE)) { + Log.debug("BackpacksAndCrates Start: {}", plugin); plugin.registerBackpackItems(); plugin.registerCrates(); + Log.debug("BackpacksAndCrates Complete: {}", plugin); } - Log.debug("Pre-Init Complete: {}", plugin); } } diff --git a/src/main/java/forestry/plugins/compat/PluginNatura.java b/src/main/java/forestry/plugins/compat/PluginNatura.java index 75efdfc27..66931716f 100644 --- a/src/main/java/forestry/plugins/compat/PluginNatura.java +++ b/src/main/java/forestry/plugins/compat/PluginNatura.java @@ -10,11 +10,9 @@ ******************************************************************************/ package forestry.plugins.compat; -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - +import com.google.common.collect.Iterables; import forestry.api.core.ForestryAPI; +import forestry.api.farming.Farmables; import forestry.api.fuels.FuelManager; import forestry.api.fuels.MoistenerFuel; import forestry.api.recipes.RecipeManagers; @@ -25,48 +23,57 @@ import forestry.core.config.Constants; import forestry.core.fluids.Fluids; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.Log; import forestry.core.utils.ModUtil; +import forestry.farming.FarmRegistry; +import forestry.farming.logic.FarmableAgingCrop; +import forestry.farming.logic.FarmableSapling; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; import forestry.plugins.ForestryPluginUids; import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.event.FMLInterModComms; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.oredict.OreDictionary; +import java.util.ArrayList; +import java.util.Collection; +import java.util.function.Consumer; + @ForestryPlugin(pluginID = ForestryPluginUids.NATURA, name = "Natura", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.natura.description") public class PluginNatura extends BlankForestryPlugin { - private static final String NATURA = "Natura"; + public static final String modId = "natura"; - @Nullable - private static Block logNatura; - @Nullable - private static Block logWillow; - @Nullable - private static Block leavesNatura; - @Nullable - private static Block saplingNatura; - @Nullable - private static Block saplingNaturaRare; + private static ArrayList fruits = new ArrayList<>(); + private static ArrayList soups = new ArrayList<>(); + private static ArrayList berries = new ArrayList<>(); + private static ArrayList edibles = new ArrayList<>(); + private static ArrayList seeds = new ArrayList<>(); + private static ArrayList logs = new ArrayList<>(); + private static ArrayList saplings = new ArrayList<>(); + private static ArrayList shrooms = new ArrayList<>(); + private static ArrayList materials = new ArrayList<>(); + private static ArrayList crops = new ArrayList<>(); + private static ArrayList cropBlocks = new ArrayList<>(); - private static ItemStack berryBlight = ItemStack.EMPTY; - private static ItemStack berryDusk = ItemStack.EMPTY; - private static ItemStack berrySky = ItemStack.EMPTY; - private static ItemStack berrySting = ItemStack.EMPTY; - private static ItemStack berryRasp = ItemStack.EMPTY; - private static ItemStack berryBlue = ItemStack.EMPTY; - private static ItemStack berryBlack = ItemStack.EMPTY; - private static ItemStack berryMalo = ItemStack.EMPTY; - private static ItemStack itemBarley = ItemStack.EMPTY; + public PluginNatura() { + super(); + MinecraftForge.EVENT_BUS.register(this); + } @Override public boolean isAvailable() { - return ModUtil.isModLoaded(NATURA); + return ModUtil.isModLoaded(modId); } @Override @@ -74,44 +81,94 @@ public class PluginNatura extends BlankForestryPlugin { return "Natura not found"; } - @Override - public void preInit() { - super.preInit(); + @SubscribeEvent + public void registerItems(RegistryEvent itemRegistryEvent) { + ForgeRegistries.ITEMS.forEach(item -> { + final ResourceLocation registryName = item.getRegistryName(); + if(!registryName.getResourceDomain().equals(modId)) return; - logNatura = getBlock("tree"); - logWillow = getBlock("willow"); - leavesNatura = getBlock("floraleaves"); - saplingNatura = getBlock("florasapling"); - saplingNaturaRare = getBlock("Rare Sapling"); + final String itemName = registryName.getResourcePath(); - ArrayList saplingItemKeys = new ArrayList<>(); + if(itemName.matches("^.*_sapling\\d?$")) { + consumeSubItems(item, "saplings", saplings); - if (saplingNatura != null) { - saplingItemKeys.add("florasapling"); - } - if (saplingNaturaRare != null) { - saplingItemKeys.add("Rare Sapling"); - } + RecipeUtil.addFermenterRecipes( + new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE), + ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), + Fluids.BIOMASS + ); - for (String key : saplingItemKeys) { - ItemStack saplingWild = getItemStack(key, OreDictionary.WILDCARD_VALUE); - if (!saplingWild.isEmpty()) { - RecipeUtil.addFermenterRecipes(saplingWild, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); - - String saplingName = ItemStackUtil.getItemNameFromRegistryAsString(saplingWild.getItem()); - FMLInterModComms.sendMessage(Constants.MOD_ID, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingName)); + FarmRegistry.getInstance().registerFarmables("farmArboreal", new FarmableSapling( + new ItemStack(item), + new ItemStack[] {} + )); + return; } - } - berryBlight = getItemStack("berry.nether", 0); - berryDusk = getItemStack("berry.nether", 1); - berrySky = getItemStack("berry.nether", 2); - berrySting = getItemStack("berry.nether", 3); - berryRasp = getItemStack("berry", 0); - berryBlue = getItemStack("berry", 1); - berryBlack = getItemStack("berry", 2); - berryMalo = getItemStack("berry", 3); - itemBarley = getItemStack("barleyFood", 0); + if(itemName.matches("^edibles|.*fruit_item|soups$")) { + complexConsumeSubItems(item, "edibles", subitem -> { + final String subItemName = subitem.getUnlocalizedName(); + if(subItemName.matches("^.*berry$")) { + berries.add(subitem); + return; + } + + if(subItemName.matches("^.*(fruit_item|apple)$")) { + fruits.add(subitem); + return; + } + + if(subItemName.matches("^.*stew$")) { + soups.add(subitem); + return; + } + + edibles.add(subitem); + }); + } + + if(itemName.matches("^.*_seeds$")) { + consumeSubItems(item, "seeds", seeds); + return; + } + + if(itemName.matches("^.*_logs\\d?$")) { + consumeSubItems(item, "logs", logs); + return; + } + + if(itemName.matches("^.*_crop\\d?$")) { + consumeSubItems(item, "cropBlocks", cropBlocks); + return; + } + + if(itemName.matches("^materials$")) { + complexConsumeSubItems(item, "materials", subitem -> { + final String subItemName = subitem.getUnlocalizedName(); + + if (subItemName.matches("^.*(barley|cotton)$")) { + crops.add(subitem); + return; + } + materials.add(subitem); + }); + } + }); + } + + private void consumeSubItems(Item item, String groupName, Collection consumer) { + complexConsumeSubItems(item, groupName, subItem -> consumer.add(subItem)); + } + + private void complexConsumeSubItems(Item item, String groupName, Consumer consumer) { + final NonNullList subItems = NonNullList.create(); + item.getSubItems(CreativeTabs.SEARCH, subItems); + + subItems.forEach(itemStack -> { + final String subItemName = itemStack.getUnlocalizedName(); + Log.info("[PluginNatura] Adding '{}' to list of {}", subItemName, groupName); + consumer.accept(itemStack); + }); } @Override @@ -120,196 +177,71 @@ public class PluginNatura extends BlankForestryPlugin { ICrateRegistry crateRegistry = StorageManager.crateRegistry; - if (!berryBlight.isEmpty()) { - crateRegistry.registerCrate(berryBlight); - } - if (!berryDusk.isEmpty()) { - crateRegistry.registerCrate(berryDusk); - } - if (!berrySky.isEmpty()) { - crateRegistry.registerCrate(berrySky); - } - if (!berrySting.isEmpty()) { - crateRegistry.registerCrate(berrySting); - } - if (!berryRasp.isEmpty()) { - crateRegistry.registerCrate(berryRasp); - } - if (!berryBlue.isEmpty()) { - crateRegistry.registerCrate(berryBlue); - } - if (!berryBlack.isEmpty()) { - crateRegistry.registerCrate(berryBlack); - } - if (!berryMalo.isEmpty()) { - crateRegistry.registerCrate(berryMalo); - } - if (!itemBarley.isEmpty()) { - crateRegistry.registerCrate(itemBarley); - } - if (saplingNatura != null) { - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 0)); - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 1)); - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 2)); - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 3)); - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 4)); - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 5)); - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 6)); - crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 7)); - } - - if (saplingNaturaRare != null) { - crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 0)); - crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 1)); - crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 2)); - crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 3)); - crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 4)); - } - ItemStack potashApple = getItemStack("Natura.netherfood", 0); - if (!potashApple.isEmpty()) { - crateRegistry.registerCrate(potashApple); - } - Item glowShroom = getItem("Glowshroom"); - if (glowShroom != null) { - crateRegistry.registerCrate(new ItemStack(glowShroom, 1, 0)); - crateRegistry.registerCrate(new ItemStack(glowShroom, 1, 1)); - crateRegistry.registerCrate(new ItemStack(glowShroom, 1, 2)); - } - if (logNatura != null) { - crateRegistry.registerCrate(new ItemStack(logNatura, 1, 0)); - crateRegistry.registerCrate(new ItemStack(logNatura, 1, 1)); - crateRegistry.registerCrate(new ItemStack(logNatura, 1, 2)); - crateRegistry.registerCrate(new ItemStack(logNatura, 1, 3)); - } - if (logWillow != null) { - crateRegistry.registerCrate(new ItemStack(logWillow, 1, 0)); - } - - Item bloodWood = getItem("bloodwood"); - if (bloodWood != null) { - crateRegistry.registerCrate(new ItemStack(bloodWood, 1, 0)); - } - Item darkTree = getItem("Dark Tree"); - if (darkTree != null) { - crateRegistry.registerCrate(new ItemStack(darkTree, 1, 0)); - crateRegistry.registerCrate(new ItemStack(darkTree, 1, 1)); - } - Item heatSand = getItem("heatsand"); - if (heatSand != null) { - crateRegistry.registerCrate(new ItemStack(heatSand, 1, 0)); - } - Item taintedSoil = getItem("soil.tainted"); - if (taintedSoil != null) { - crateRegistry.registerCrate(new ItemStack(taintedSoil, 1, 0)); - } + Iterables.concat( + edibles, logs, saplings, shrooms, + materials, seeds, berries, fruits, + crops + ).forEach(item -> crateRegistry.registerCrate(item)); } @Override public void registerRecipes() { int amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); - - Item seed = getItem("barley.seed"); - if (seed != null) { - ItemStack seedBarley = new ItemStack(seed, 1, 0); - ItemStack seedCotton = new ItemStack(seed, 1, 1); - - ArrayList seedList = new ArrayList<>(); - if (!seedBarley.isEmpty()) { - seedList.add(seedBarley); - RecipeManagers.moistenerManager.addRecipe(seedBarley, new ItemStack(Blocks.MYCELIUM), 5000); - } - if (!seedCotton.isEmpty()) { - seedList.add(seedCotton); - } - - for (ItemStack aSeedList : seedList) { - RecipeManagers.squeezerManager.addRecipe(10, aSeedList, Fluids.SEED_OIL.getFluid(amount)); - } + for (ItemStack seed : seeds) { + RecipeManagers.squeezerManager.addRecipe(10, NonNullList.from(seed, seed), Fluids.SEED_OIL.getFluid(amount)); + RecipeManagers.moistenerManager.addRecipe(seed, new ItemStack(Blocks.MYCELIUM), 5000); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) { - Block cropBlock = getBlock("N Crops"); - //TODO: Natura for 1.9 - // Farmables.farmables.get("farmWheat").add(new FarmableHandPlanted(seedBarley, cropBlock, 3)); - // Farmables.farmables.get("farmWheat").add(new FarmableHandPlanted(seedCotton, cropBlock, 8)); - } + cropBlocks.forEach(itemStack -> { + Block block = ItemStackUtil.getBlock(itemStack); + ItemStack seedItem; + int maxAge; + try { + maxAge = (int)block.getClass().getDeclaredMethod("getMaxAge").invoke(block); + seedItem = block.getPickBlock(block.getBlockState().getBaseState(), null, null, null, null); + } catch (Exception _) {return;} // if this fails just ignore the error. + Log.info("[PluginNatura] Addding crop '{}'", itemStack); + if(seedItem == null) return; - List berries = new ArrayList<>(); - if (!berryBlight.isEmpty()) { - berries.add(berryBlight); + Farmables.farmables.get("farmWheat").add( + new FarmableAgingCrop( + seedItem, + block, + (IProperty)block.getBlockState().getProperty("age"), + maxAge + ) + ); + }); } - if (!berryDusk.isEmpty()) { - berries.add(berryDusk); - } - if (!berrySky.isEmpty()) { - berries.add(berrySky); - } - if (!berrySting.isEmpty()) { - berries.add(berrySting); - } - if (!berryRasp.isEmpty()) { - berries.add(berryRasp); - } - if (!berryBlue.isEmpty()) { - berries.add(berryBlue); - } - if (!berryBlack.isEmpty()) { - berries.add(berryBlack); - } - if (!berryMalo.isEmpty()) { - berries.add(berryMalo); - } - + amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 2; - amount = Math.max(amount, 1); // Produce at least 1 mb of juice. - ItemStack netherFood = getItemStack("Natura.netherfood", 0); - ItemStack mulch = PluginCore.getItems().mulch.getItemStack(); - RecipeManagers.squeezerManager.addRecipe(10, netherFood, Fluids.JUICE.getFluid(amount), mulch, ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple")); + final int juiceAmount = Math.max(amount, 1); // Produce at least 1 mb of juice. + ItemStack mulch = PluginCore.items.mulch.getItemStack(); + fruits.forEach(fruit -> RecipeManagers.squeezerManager.addRecipe( + 10, NonNullList.from(fruit, fruit), + Fluids.JUICE.getFluid(juiceAmount), mulch, + ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple")) + ); amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 25; amount = Math.max(amount, 1); // Produce at least 1 mb of juice. for (ItemStack berry : berries) { - RecipeManagers.squeezerManager.addRecipe(3, berry, Fluids.JUICE.getFluid(amount)); + RecipeManagers.squeezerManager.addRecipe(3, NonNullList.from(berry, berry), Fluids.JUICE.getFluid(amount)); } - if (!itemBarley.isEmpty()) { - RecipeUtil.addFermenterRecipes(itemBarley, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + crops.forEach(crop -> { + RecipeUtil.addFermenterRecipes(crop, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + if (crop.getUnlocalizedName().matches("^.*cotton$")) return; + int compostWheatAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.compost.wheat"); if (compostWheatAmount > 0) { - ItemStack compostWheat = PluginCore.getItems().compost.getItemStack(compostWheatAmount); - RecipeUtil.addRecipe("natura_compost_wheat", compostWheat, " X ", "X#X", " X ", '#', Blocks.DIRT, 'X', itemBarley); + ItemStack compostWheat = PluginCore.items.fertilizerCompound.getItemStack(compostWheatAmount); + RecipeUtil.addRecipe(compostWheat.getUnlocalizedName(), compostWheat, " X ", "X#X", " X ", '#', Blocks.DIRT, 'X', crop); } - FuelManager.moistenerResource.put(itemBarley, new MoistenerFuel(itemBarley, PluginCore.getItems().mouldyWheat.getItemStack(), 0, 300)); - } + FuelManager.moistenerResource.put(crop, new MoistenerFuel(crop, PluginCore.items.mouldyWheat.getItemStack(), 0, 300)); + }); } - @Nullable - private static Block getBlock(String blockName) { - ResourceLocation key = new ResourceLocation(NATURA, blockName); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - return ForgeRegistries.BLOCKS.getValue(key); - } else { - return null; - } - } - - @Nullable - private static Item getItem(String itemName) { - ResourceLocation key = new ResourceLocation(NATURA, itemName); - if (ForgeRegistries.ITEMS.containsKey(key)) { - return ForgeRegistries.ITEMS.getValue(key); - } else { - return null; - } - } - - private static ItemStack getItemStack(String itemName, int meta) { - ResourceLocation key = new ResourceLocation(NATURA, itemName); - if (ForgeRegistries.ITEMS.containsKey(key)) { - return new ItemStack(ForgeRegistries.ITEMS.getValue(key), 1, meta); - } else { - return ItemStack.EMPTY; - } - } } From 6a75347b059b51487c65f81340b717c4a1b2347c Mon Sep 17 00:00:00 2001 From: Robert Obermeier Date: Sun, 13 Aug 2017 02:09:00 +0200 Subject: [PATCH 5/7] Add Red Orchid support to farm (#1800) --- lang | 2 +- .../java/forestry/core/circuits/Circuits.java | 1 + .../java/forestry/core/config/Config.java | 4 ++ .../forestry/core/items/EnumElectronTube.java | 3 +- .../java/forestry/factory/PluginFactory.java | 6 +++ ...{FarmLogicEnder.java => FarmLogicExU.java} | 36 ++++++++----- .../plugins/compat/PluginExtraUtilities.java | 54 ++++++++++++------- .../forestry/plugins/compat/PluginNatura.java | 11 +++- 8 files changed, 81 insertions(+), 36 deletions(-) rename src/main/java/forestry/farming/logic/{FarmLogicEnder.java => FarmLogicExU.java} (82%) diff --git a/lang b/lang index f5300f059..192d6f858 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit f5300f059b2a0e55ecea645536acde0406152559 +Subproject commit 192d6f85845f6702e93fb234b56b72d945f5e2ab diff --git a/src/main/java/forestry/core/circuits/Circuits.java b/src/main/java/forestry/core/circuits/Circuits.java index 707f33859..f8bcc6469 100644 --- a/src/main/java/forestry/core/circuits/Circuits.java +++ b/src/main/java/forestry/core/circuits/Circuits.java @@ -29,6 +29,7 @@ public class Circuits { public static ICircuit farmOrchardManual; public static ICircuit farmRubberManual; public static ICircuit farmEnderManaged; + public static ICircuit farmOrchidManaged; public static ICircuit machineSpeedUpgrade1; public static ICircuit machineSpeedUpgrade2; public static ICircuit machineEfficiencyUpgrade1; diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index 4ce247750..e4f10cebb 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -92,6 +92,7 @@ public class Config { public static int farmSize = 2; public static boolean squareFarms = false; private static boolean enableExUtilEnderLily = true; + private static boolean enableExUtilRedOrchid = true; private static boolean enableMagicalCropsSupport = true; // Mail @@ -131,6 +132,8 @@ public class Config { return enableExUtilEnderLily; } + public static boolean isExUtilRedOrchidEnabled() { return enableExUtilRedOrchid; } + public static boolean isMagicalCropsSupportEnabled() { return enableMagicalCropsSupport; } @@ -241,6 +244,7 @@ public class Config { farmSize = configCommon.getIntLocalized("tweaks.farms", "size", farmSize, 1, 3); squareFarms = configCommon.getBooleanLocalized("tweaks.farms", "square", squareFarms); enableExUtilEnderLily = configCommon.getBooleanLocalized("tweaks.farms", "enderlily", enableExUtilEnderLily); + enableExUtilRedOrchid = configCommon.getBooleanLocalized("tweaks.farms", "redorchid", enableExUtilRedOrchid); enableMagicalCropsSupport = configCommon.getBooleanLocalized("tweaks.farms", "magicalcrops", enableMagicalCropsSupport); String[] availableStructures = new String[]{"alveary3x3", "farm3x3", "farm3x4", "farm3x5", "farm4x4", "farm5x5"}; diff --git a/src/main/java/forestry/core/items/EnumElectronTube.java b/src/main/java/forestry/core/items/EnumElectronTube.java index e77bc1a97..0d571071b 100644 --- a/src/main/java/forestry/core/items/EnumElectronTube.java +++ b/src/main/java/forestry/core/items/EnumElectronTube.java @@ -26,7 +26,8 @@ public enum EnumElectronTube implements ItemOverlay.IOverlayInfo { EMERALD(new Color(0x00CC41)), APATITE(new Color(0x579CD9)), LAPIS(new Color(0x1c57c6)), - ENDER(new Color(0x33adad), new Color(0x255661)); + ENDER(new Color(0x33adad), new Color(0x255661)), + ORCHID(new Color(0x820208), new Color(0xc64f3f)); public static final EnumElectronTube[] VALUES = values(); diff --git a/src/main/java/forestry/factory/PluginFactory.java b/src/main/java/forestry/factory/PluginFactory.java index 4ef722ee3..0cb8a433c 100755 --- a/src/main/java/forestry/factory/PluginFactory.java +++ b/src/main/java/forestry/factory/PluginFactory.java @@ -325,6 +325,12 @@ public class PluginFactory extends BlankForestryPlugin { "XXX", '#', new ItemStack(Items.ENDER_EYE, 1, 0), 'X', new ItemStack(Blocks.END_STONE, 1, 0)}); + RecipeManagers.fabricatorManager.addRecipe(ItemStack.EMPTY, Fluids.GLASS.getFluid(500), electronTube.get(EnumElectronTube.ORCHID, 4), new Object[]{ + " X ", + "#X#", + "XXX", + '#', new ItemStack(Items.REPEATER, 1, 0), + 'X', new ItemStack(Blocks.REDSTONE_ORE, 1, 0)}); String[] dyes = {"dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray", "dyePink", "dyeLime", "dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite"}; diff --git a/src/main/java/forestry/farming/logic/FarmLogicEnder.java b/src/main/java/forestry/farming/logic/FarmLogicExU.java similarity index 82% rename from src/main/java/forestry/farming/logic/FarmLogicEnder.java rename to src/main/java/forestry/farming/logic/FarmLogicExU.java index eb082e021..92cac7a94 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicEnder.java +++ b/src/main/java/forestry/farming/logic/FarmLogicExU.java @@ -13,34 +13,44 @@ package forestry.farming.logic; import java.util.Collection; import java.util.Stack; +import forestry.farming.FarmRegistry; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import forestry.api.farming.FarmDirection; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.core.utils.BlockUtil; -import forestry.farming.FarmRegistry; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -public class FarmLogicEnder extends FarmLogicHomogeneous { +public class FarmLogicExU extends FarmLogicHomogeneous { - public FarmLogicEnder() { - super(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmEnder")); + private final String name; + private final Item iconItem; + + public FarmLogicExU(String name, Item iconItem, Block soil, String farmablesKey) { + super(new ItemStack(soil), soil.getDefaultState(), FarmRegistry.getInstance().getFarmables(farmablesKey)); + if (soil.equals(Blocks.REDSTONE_ORE)) { + super.addSoil(new ItemStack(Blocks.LIT_REDSTONE_ORE), Blocks.LIT_REDSTONE_ORE.getDefaultState(), false); + } + this.name = name; + this.iconItem = iconItem; } @Override public String getName() { - return "Managed Ender Farm"; + return name; } @Override public ItemStack getIconItemStack() { - return new ItemStack(Items.ENDER_EYE); + return new ItemStack(iconItem); } @Override diff --git a/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java b/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java index 83407b81a..01fbc0932 100644 --- a/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java +++ b/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java @@ -11,8 +11,10 @@ package forestry.plugins.compat; import java.util.Collections; +import java.util.function.Consumer; import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.ICircuit; import forestry.api.circuits.ICircuitLayout; import forestry.api.core.ForestryAPI; import forestry.core.PluginCore; @@ -25,7 +27,7 @@ import forestry.core.utils.Log; import forestry.core.utils.ModUtil; import forestry.farming.FarmRegistry; import forestry.farming.circuits.CircuitFarmLogic; -import forestry.farming.logic.FarmLogicEnder; +import forestry.farming.logic.FarmLogicExU; import forestry.farming.logic.FarmableAgingCrop; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; @@ -33,7 +35,6 @@ import forestry.plugins.ForestryPluginUids; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -58,33 +59,46 @@ public class PluginExtraUtilities extends BlankForestryPlugin { public void doInit() { super.doInit(); + if (Config.isExUtilRedOrchidEnabled()) { + registerExPlant("Orchid", "redorchid", "Red Orchid", Blocks.REDSTONE_ORE, circuit -> Circuits.farmOrchidManaged = circuit); + } + if (Config.isExUtilEnderLilyEnabled()) { - Block enderLillyBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ExU, "enderlilly")); - Item enderLillyItem = Item.getItemFromBlock(enderLillyBlock); - if (enderLillyBlock == Blocks.AIR) { - Log.error("Could not find ender lilly block."); - } else if (enderLillyItem == Items.AIR) { - Log.error("Could not find ender lilly item."); - } else { - IProperty growthProperty = BlockUtil.getProperty(enderLillyBlock, "growth", Integer.class); - if (growthProperty == null) { - Log.error("Could not find the growth property of ender lily."); - } else { - int harvestAge = Collections.max(growthProperty.getAllowedValues()); - int replantAge = enderLillyBlock.getDefaultState().getValue(growthProperty); - FarmRegistry.getInstance().registerFarmables("farmEnder", new FarmableAgingCrop(new ItemStack(enderLillyItem), enderLillyBlock, growthProperty, harvestAge, replantAge)); - Circuits.farmEnderManaged = new CircuitFarmLogic("managedEnder", new FarmLogicEnder()); - } - } + registerExPlant("Ender", "enderlilly", "Ender Lily", Blocks.END_STONE, circuit -> Circuits.farmEnderManaged = circuit); } } @Override public void registerRecipes() { super.registerRecipes(); - if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && Circuits.farmEnderManaged != null) { + if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) return; + if(Circuits.farmEnderManaged != null) { ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed"); ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.getItems().tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManaged); } + if(Circuits.farmOrchidManaged != null) { + ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed"); + ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.ORCHID, 1), Circuits.farmOrchidManaged); + } + } + + private void registerExPlant(String id, String itemResourceName, String itemName, Block soil, Consumer assignTo) { + Block plantBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ExU, itemResourceName)); + Item plantItem = Item.getItemFromBlock(plantBlock); + if(plantBlock == Blocks.AIR) { + Log.error("Could not find {} block.", itemName); + } else if (plantItem == null) { + Log.error("Could not find {} item.", itemName); + } else { + IProperty growthProperty = BlockUtil.getProperty(plantBlock, "growth", Integer.class); + if (growthProperty == null) { + Log.error("Could not find the growth property of {}.", itemName); + } else { + int harvestAge = Collections.max(growthProperty.getAllowedValues()); + int replantAge = plantBlock.getDefaultState().getValue(growthProperty); + FarmRegistry.getInstance().registerFarmables(itemName, new FarmableAgingCrop(new ItemStack(plantItem), plantBlock, growthProperty, harvestAge, replantAge)); + assignTo.accept(new CircuitFarmLogic("managed" + id, new FarmLogicExU("Managed " + itemName + " Farm", plantItem, soil, itemName))); + } + } } } diff --git a/src/main/java/forestry/plugins/compat/PluginNatura.java b/src/main/java/forestry/plugins/compat/PluginNatura.java index 66931716f..8d12417a4 100644 --- a/src/main/java/forestry/plugins/compat/PluginNatura.java +++ b/src/main/java/forestry/plugins/compat/PluginNatura.java @@ -164,6 +164,15 @@ public class PluginNatura extends BlankForestryPlugin { final NonNullList subItems = NonNullList.create(); item.getSubItems(CreativeTabs.SEARCH, subItems); + // Fallback if item is not returned in sub items + if(subItems.isEmpty()) { + final ItemStack itemStack = new ItemStack(item, 1); + final String subItemName = itemStack.getUnlocalizedName(); + Log.info("[PluginNatura] Adding '{}' to list of {}", subItemName, groupName); + consumer.accept(itemStack); + return; + } + subItems.forEach(itemStack -> { final String subItemName = itemStack.getUnlocalizedName(); Log.info("[PluginNatura] Adding '{}' to list of {}", subItemName, groupName); @@ -204,7 +213,7 @@ public class PluginNatura extends BlankForestryPlugin { Log.info("[PluginNatura] Addding crop '{}'", itemStack); if(seedItem == null) return; - Farmables.farmables.get("farmWheat").add( + FarmRegistry.getInstance().registerFarmables("farmWheat", new FarmableAgingCrop( seedItem, block, From e1df424bfd3b67831cee1d6ee95ec7845c1867aa Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Sun, 13 Aug 2017 16:35:26 +0200 Subject: [PATCH 6/7] reduce SimpleModel memory usage --- .../arboriculture/models/SimpleModel.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/forestry/arboriculture/models/SimpleModel.java b/src/main/java/forestry/arboriculture/models/SimpleModel.java index 9e66996a9..b499fcbfc 100755 --- a/src/main/java/forestry/arboriculture/models/SimpleModel.java +++ b/src/main/java/forestry/arboriculture/models/SimpleModel.java @@ -47,28 +47,35 @@ public class SimpleModel implements IModel { private static final ModelResourceLocation MISSING = new ModelResourceLocation("builtin/missing", "missing"); private final List variants; - private final List locations = new ArrayList<>(); - private final Set textures = Sets.newHashSet(); - private final List models = new ArrayList<>(); + private final ImmutableList locations; + private final ImmutableSet textures; + private final ImmutableList models; private final IModelState defaultState; public SimpleModel(List locations, List models, List variants, IModelState defaultState) { - this.locations.addAll(locations); - this.models.addAll(models); this.variants = variants; + this.locations = ImmutableList.copyOf(locations); + this.models = ImmutableList.copyOf(models); this.defaultState = defaultState; + + ImmutableSet.Builder texturesBuilder = ImmutableSet.builder(); for (IModel model : models) { - textures.addAll(model.getTextures()); + texturesBuilder.addAll(model.getTextures()); } + textures = texturesBuilder.build(); } public SimpleModel(ResourceLocation parent, VariantList variants) throws Exception { this.variants = variants.getVariantList(); ImmutableList.Builder> builder = ImmutableList.builder(); + ImmutableList.Builder modelsBuilder = ImmutableList.builder(); + ImmutableList.Builder locationsBuilder = ImmutableList.builder(); + ImmutableSet.Builder texturesBuilder = ImmutableSet.builder(); + for (Variant variant : this.variants) { ResourceLocation loc = variant.getModelLocation(); - locations.add(loc); + locationsBuilder.add(loc); IModel model; if (loc.equals(MISSING)) { @@ -81,19 +88,23 @@ public class SimpleModel implements IModel { for (ResourceLocation location : model.getDependencies()) { ModelLoaderRegistry.getModelOrMissing(location); } - textures.addAll(model.getTextures()); + texturesBuilder.addAll(model.getTextures()); - models.add(model); + modelsBuilder.add(model); builder.add(Pair.of(model, variant.getState())); } - if (models.size() == 0) { + if (this.variants.size() == 0) { IModel missing = ModelLoaderRegistry.getMissingModel(); - models.add(missing); + modelsBuilder.add(missing); builder.add(Pair.of(missing, TRSRTransformation.identity())); } defaultState = new MultiModelState(builder.build()); + + locations = locationsBuilder.build(); + models = modelsBuilder.build(); + textures = texturesBuilder.build(); } @Override @@ -129,6 +140,7 @@ public class SimpleModel implements IModel { @Override public IModel retexture(ImmutableMap textures) { + List locations = new ArrayList<>(); List models = new ArrayList<>(); ImmutableList.Builder> builder = ImmutableList.builder(); for (Variant variant : this.variants) { From 307580aed8fefe28383a77555f2e0f0521d1b33b Mon Sep 17 00:00:00 2001 From: mezz Date: Sun, 13 Aug 2017 22:06:46 -0700 Subject: [PATCH 7/7] Mark as working on 1.12.1 on CurseForge --- build.gradle | 1 + src/main/java/forestry/Forestry.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 727a9ac70..f8bdaad65 100755 --- a/build.gradle +++ b/build.gradle @@ -162,6 +162,7 @@ curseforge { changelogType = 'html' releaseType = 'beta' } + addGameVersion '1.12.1' } afterEvaluate { diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 353e66976..e095373f0 100755 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -59,7 +59,7 @@ import forestry.plugins.compat.PluginIC2; name = Constants.MOD_NAME, version = Constants.VERSION, guiFactory = "forestry.core.config.ForestryGuiConfigFactory", - acceptedMinecraftVersions = "[1.12]", + acceptedMinecraftVersions = "[1.12, 1.12.1]", dependencies = "required-after:forge@[14.21.1.2395,);" + "after:jei@[4.7.0,);" + "after:" + PluginIC2.modId + ";"