diff --git a/src/main/java/forestry/api/farming/IFarmInstance.java b/src/main/java/forestry/api/farming/IFarmInstance.java index 6903e2711..8cd89c5e9 100644 --- a/src/main/java/forestry/api/farming/IFarmInstance.java +++ b/src/main/java/forestry/api/farming/IFarmInstance.java @@ -14,6 +14,8 @@ public interface IFarmInstance { registerSoil(resource, soilState, false); } + void registerFarmables(String identifier); + void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData); boolean isAcceptedSoil(IBlockState blockState); diff --git a/src/main/java/forestry/api/farming/IFarmable.java b/src/main/java/forestry/api/farming/IFarmable.java index b51eb8ba6..d13f09b47 100644 --- a/src/main/java/forestry/api/farming/IFarmable.java +++ b/src/main/java/forestry/api/farming/IFarmable.java @@ -20,8 +20,19 @@ public interface IFarmable { /** * @return true if the block at the given location is a "sapling" for this type, i.e. a non-harvestable immature version of the crop. + * @deprecated Since Forestry 5.8. Use the version below. TODO Remove this method in 1.13 */ - boolean isSaplingAt(World world, BlockPos pos); + @Deprecated + default boolean isSaplingAt(World world, BlockPos pos){ + return false; + } + + /** + * @return true if the block at the given location is a "sapling" for this type, i.e. a non-harvestable immature version of the crop. + */ + default boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState){ + return isSaplingAt(world, pos); + } /** * @return {@link ICrop} if the block at the given location is a harvestable and mature crop, null otherwise. diff --git a/src/main/java/forestry/core/circuits/Circuits.java b/src/main/java/forestry/core/circuits/Circuits.java index aeee7dd36..81eb7f390 100644 --- a/src/main/java/forestry/core/circuits/Circuits.java +++ b/src/main/java/forestry/core/circuits/Circuits.java @@ -15,11 +15,12 @@ public class Circuits { public static ICircuit farmCropsManaged; public static ICircuit farmPeatManaged; public static ICircuit farmSucculentManaged; - public static ICircuit farmPoaleManaged; + public static ICircuit farmPoalesManaged; public static ICircuit farmInfernalManaged; public static ICircuit farmEnderManaged; public static ICircuit farmOrchidManaged; public static ICircuit farmGourdManaged; + public static ICircuit farmCocoaManaged; public static ICircuit farmArborealManual; diff --git a/src/main/java/forestry/core/render/ParticleRender.java b/src/main/java/forestry/core/render/ParticleRender.java index b79312fd6..05a92a862 100755 --- a/src/main/java/forestry/core/render/ParticleRender.java +++ b/src/main/java/forestry/core/render/ParticleRender.java @@ -1,6 +1,7 @@ package forestry.core.render; import java.util.List; +import java.util.Random; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.Particle; @@ -157,6 +158,26 @@ public class ParticleRender { effectRenderer.addEffect(particle); } } + + public static void addPortalFx(World world, BlockPos pos, Random rand){ + if (!shouldSpawnParticle(world)) { + return; + } + + int j = rand.nextInt(2) * 2 - 1; + int k = rand.nextInt(2) * 2 - 1; + double xPos = (double)pos.getX() + 0.5D + 0.25D * (double)j; + double yPos = (double)((float)pos.getY() + rand.nextFloat()); + double zPos = (double)pos.getZ() + 0.5D + 0.25D * (double)k; + double xSpeed = (double)(rand.nextFloat() * (float)j); + double ySpeed = ((double)rand.nextFloat() - 0.5D) * 0.125D; + double zSpeed = (double)(rand.nextFloat() * (float)k); + ParticleManager effectRenderer = Minecraft.getMinecraft().effectRenderer; + Particle particle = effectRenderer.spawnEffectParticle(EnumParticleTypes.PORTAL.getParticleID(), xPos, yPos, zPos, xSpeed, ySpeed, zSpeed); + if(particle != null){ + effectRenderer.addEffect(particle); + } + } public static void addEntityBiodustFX(World world, double x, double y, double z){ if (!shouldSpawnParticle(world)) { diff --git a/src/main/java/forestry/cultivation/ModuleCultivation.java b/src/main/java/forestry/cultivation/ModuleCultivation.java index 3e33df0c8..a5e8d73f0 100644 --- a/src/main/java/forestry/cultivation/ModuleCultivation.java +++ b/src/main/java/forestry/cultivation/ModuleCultivation.java @@ -6,8 +6,6 @@ import com.google.common.collect.ImmutableSet; import javax.annotation.Nullable; import java.util.Set; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.util.ResourceLocation; import forestry.api.modules.ForestryModule; @@ -53,6 +51,7 @@ public class ModuleCultivation extends BlankForestryModule { blocks.farmMushroom.init(); blocks.farmNether.init(); blocks.farmGourd.init(); + blocks.farmEnder.init(); //blocks.plantation.init(); blocks.peatBog.init(); } @@ -85,39 +84,49 @@ public class ModuleCultivation extends BlankForestryModule { "TCT", "GBG", 'G', OreDictUtil.BLOCK_GLASS, - 'T', coreItems.tubes.get(EnumElectronTube.COPPER, 1), + 'T', coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), 'C', coreItems.sturdyCasing, 'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC)); RecipeUtil.addRecipe("farm_mushroom", blocks.farmMushroom, - "BGR", - "GAG", - "RGB", + "GTG", + "TCT", + "GBG", 'G', OreDictUtil.BLOCK_GLASS, - 'B', Blocks.BROWN_MUSHROOM, - 'R', Blocks.RED_MUSHROOM, - 'A', blocks.arboretum); + 'T', coreItems.tubes.get(EnumElectronTube.APATITE, 1), + 'C', coreItems.sturdyCasing, + 'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC)); RecipeUtil.addRecipe("farm_gourd", blocks.farmGourd, - "MGP", - "GAG", - "PGM", + "GTG", + "TCT", + "GBG", 'G', OreDictUtil.BLOCK_GLASS, - 'M', Blocks.MELON_BLOCK, - 'P', Blocks.PUMPKIN, - 'A', blocks.arboretum); + 'T', coreItems.tubes.get(EnumElectronTube.LAPIS, 1), + 'C', coreItems.sturdyCasing, + 'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC)); RecipeUtil.addRecipe("farm_nether", blocks.farmNether, - "WGW", - "GAG", - "WGW", + "GTG", + "TCT", + "GBG", 'G', OreDictUtil.BLOCK_GLASS, - 'W', Items.NETHER_WART, - 'A', blocks.arboretum); + 'T', coreItems.tubes.get(EnumElectronTube.BLAZE, 1), + 'C', coreItems.sturdyCasing, + 'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC)); + + RecipeUtil.addRecipe("farm_ender", blocks.farmEnder, + "GTG", + "TCT", + "GBG", + 'G', OreDictUtil.BLOCK_GLASS, + 'T', coreItems.tubes.get(EnumElectronTube.ENDER, 1), + 'C', coreItems.sturdyCasing, + 'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC)); for(BlockPlanter planter : getBlocks().getPlanters()){ - RecipeUtil.addRecipe(planter.blockType.getName() + "_manual_managed", planter.get(true), "# ", " ", " ", '#', planter.get(false)); - RecipeUtil.addRecipe(planter.blockType.getName() + "_managed_manual", planter.get(false), "# ", " ", " ", '#', planter.get(true)); + RecipeUtil.addShapelessRecipe(planter.blockType.getName() + "_manual_managed", planter.get(true), planter.get(false)); + RecipeUtil.addShapelessRecipe(planter.blockType.getName() + "_managed_manual", planter.get(false), planter.get(true)); } } } diff --git a/src/main/java/forestry/cultivation/blocks/BlockPlanter.java b/src/main/java/forestry/cultivation/blocks/BlockPlanter.java index 92cdb1623..d596653ae 100644 --- a/src/main/java/forestry/cultivation/blocks/BlockPlanter.java +++ b/src/main/java/forestry/cultivation/blocks/BlockPlanter.java @@ -1,5 +1,7 @@ package forestry.cultivation.blocks; +import java.util.Random; + import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockStateContainer; @@ -7,8 +9,6 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagByte; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; @@ -23,6 +23,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import forestry.core.blocks.BlockBase; +import forestry.core.render.ParticleRender; import forestry.cultivation.tiles.TilePlanter; public class BlockPlanter extends BlockBase { @@ -38,6 +39,16 @@ public class BlockPlanter extends BlockBase { return new BlockStateContainer(this, FACING, MANUAL); } + @SideOnly(Side.CLIENT) + @Override + public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) { + if(blockType == BlockTypePlanter.FARM_ENDER){ + for (int i = 0; i < 3; ++i) { + ParticleRender.addPortalFx(worldIn, pos, rand); + } + } + } + @Override public IBlockState getStateFromMeta(int meta) { int facing = meta & 7; @@ -62,6 +73,11 @@ public class BlockPlanter extends BlockBase { return tile; } + @Override + public int damageDropped(IBlockState state) { + return state.getValue(MANUAL) ? 1 : 0; + } + @Override @SideOnly(Side.CLIENT) public void registerStateMapper() { @@ -87,16 +103,10 @@ public class BlockPlanter extends BlockBase { } public static boolean isManual(ItemStack stack){ - NBTTagCompound tagCompound = stack.getTagCompound(); - if(tagCompound != null){ - return tagCompound.getBoolean("Manual"); - } - return false; + return stack.getMetadata() == 1; } public ItemStack get(boolean isManual){ - ItemStack stack = new ItemStack(this); - stack.setTagInfo("Manual", new NBTTagByte((byte) (isManual ? 1 : 0))); - return stack; + return new ItemStack(this, 1, isManual ? 1 : 0); } } diff --git a/src/main/java/forestry/cultivation/blocks/BlockRegistryCultivation.java b/src/main/java/forestry/cultivation/blocks/BlockRegistryCultivation.java index 3302b5d56..b67c3c048 100644 --- a/src/main/java/forestry/cultivation/blocks/BlockRegistryCultivation.java +++ b/src/main/java/forestry/cultivation/blocks/BlockRegistryCultivation.java @@ -14,6 +14,7 @@ public class BlockRegistryCultivation extends BlockRegistry { public final BlockPlanter farmMushroom; public final BlockPlanter farmGourd; public final BlockPlanter farmNether; + public final BlockPlanter farmEnder; public final BlockPlanter peatBog; /*public final BlockPlanter plantation;*/ @@ -38,6 +39,10 @@ public class BlockRegistryCultivation extends BlockRegistry { registerBlock(farmNether, new ItemBlockPlanter(farmNether), "farm_nether"); planters.add(farmNether); + farmEnder = new BlockPlanter(BlockTypePlanter.FARM_ENDER); + registerBlock(farmEnder, new ItemBlockPlanter(farmEnder), "farm_ender"); + planters.add(farmEnder); + peatBog = new BlockPlanter(BlockTypePlanter.PEAT_POG); registerBlock(peatBog, new ItemBlockPlanter(peatBog), "peat_bog"); planters.add(peatBog); diff --git a/src/main/java/forestry/cultivation/blocks/BlockTypePlanter.java b/src/main/java/forestry/cultivation/blocks/BlockTypePlanter.java index a2871d288..f8542dbf3 100644 --- a/src/main/java/forestry/cultivation/blocks/BlockTypePlanter.java +++ b/src/main/java/forestry/cultivation/blocks/BlockTypePlanter.java @@ -2,14 +2,14 @@ package forestry.cultivation.blocks; import forestry.core.blocks.IBlockTypeCustom; import forestry.core.blocks.IMachineProperties; -import forestry.core.blocks.MachineProperties; -import forestry.core.tiles.TileForestry; import forestry.cultivation.tiles.TileArboretum; import forestry.cultivation.tiles.TileBog; import forestry.cultivation.tiles.TileFarmCrops; +import forestry.cultivation.tiles.TileFarmEnder; import forestry.cultivation.tiles.TileFarmGourd; import forestry.cultivation.tiles.TileFarmMushroom; import forestry.cultivation.tiles.TileFarmNether; +import forestry.cultivation.tiles.TilePlanter; public enum BlockTypePlanter implements IBlockTypeCustom { ARBORETUM(TileArboretum.class, "arboretum"), @@ -17,6 +17,7 @@ public enum BlockTypePlanter implements IBlockTypeCustom { FARM_MUSHROOM(TileFarmMushroom.class, "farm_mushroom"), FARM_GOURD(TileFarmGourd.class, "farm_gourd"), FARM_NETHER(TileFarmNether.class, "farm_nether"), + FARM_ENDER(TileFarmEnder.class, "farm_ender"), PEAT_POG(TileBog.class, "peat_bog"), //TODO Add ic2 integration @@ -24,8 +25,8 @@ public enum BlockTypePlanter implements IBlockTypeCustom { private final IMachineProperties machineProperties; - BlockTypePlanter(Class teClass, String name) { - this.machineProperties = new MachineProperties<>(teClass, name); + BlockTypePlanter(Class teClass, String name) { + this.machineProperties = new PlanterProperties<>(teClass, name); } @Override diff --git a/src/main/java/forestry/cultivation/blocks/PlanterProperties.java b/src/main/java/forestry/cultivation/blocks/PlanterProperties.java new file mode 100644 index 000000000..4a334f702 --- /dev/null +++ b/src/main/java/forestry/cultivation/blocks/PlanterProperties.java @@ -0,0 +1,27 @@ +package forestry.cultivation.blocks; + +import com.google.common.base.Preconditions; + +import net.minecraft.item.Item; +import net.minecraft.util.ResourceLocation; + +import forestry.api.core.IModelManager; +import forestry.core.blocks.MachineProperties; +import forestry.core.utils.ItemStackUtil; +import forestry.cultivation.tiles.TilePlanter; + +public class PlanterProperties extends MachineProperties { + + PlanterProperties(Class teClass, String name) { + super(teClass, name); + } + + @Override + public void registerModel(Item item, IModelManager manager) { + ResourceLocation itemNameFromRegistry = ItemStackUtil.getItemNameFromRegistry(item); + Preconditions.checkNotNull(itemNameFromRegistry, "No registry name for item"); + String identifier = itemNameFromRegistry.getResourcePath(); + manager.registerItemModel(item, 0, identifier); + manager.registerItemModel(item, 1, identifier); + } +} diff --git a/src/main/java/forestry/cultivation/tiles/TileFarmEnder.java b/src/main/java/forestry/cultivation/tiles/TileFarmEnder.java new file mode 100644 index 000000000..60b65f636 --- /dev/null +++ b/src/main/java/forestry/cultivation/tiles/TileFarmEnder.java @@ -0,0 +1,41 @@ +package forestry.cultivation.tiles; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +public class TileFarmEnder extends TilePlanter { + public TileFarmEnder() { + super("farmEnder"); + } + + @Override + public ItemStack[] createGermlingStacks() { + return new ItemStack[]{ + new ItemStack(Blocks.CHORUS_FLOWER), + new ItemStack(Blocks.CHORUS_FLOWER), + new ItemStack(Blocks.CHORUS_FLOWER), + new ItemStack(Blocks.CHORUS_FLOWER) + }; + } + + @Override + public ItemStack[] createResourceStacks() { + return new ItemStack[]{ + new ItemStack(Blocks.END_STONE), + new ItemStack(Blocks.END_STONE), + new ItemStack(Blocks.END_STONE), + new ItemStack(Blocks.END_STONE) + }; + } + + @Override + public ItemStack[] createProductionStacks() { + return new ItemStack[]{ + new ItemStack(Blocks.CHORUS_FLOWER), + new ItemStack(Items.CHORUS_FRUIT), + new ItemStack(Items.CHORUS_FRUIT), + new ItemStack(Blocks.CHORUS_FLOWER) + }; + } +} diff --git a/src/main/java/forestry/farming/FarmRegistry.java b/src/main/java/forestry/farming/FarmRegistry.java index 4c4833212..2de995b58 100644 --- a/src/main/java/forestry/farming/FarmRegistry.java +++ b/src/main/java/forestry/farming/FarmRegistry.java @@ -16,7 +16,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.function.BiFunction; -import java.util.stream.Collectors; import net.minecraft.item.ItemStack; @@ -41,7 +40,6 @@ public final class FarmRegistry implements IFarmRegistry { private static final FarmRegistry INSTANCE = new FarmRegistry(); private final Multimap farmables = HashMultimap.create(); private final Map fertilizers = new LinkedHashMap<>(); - private final Map logics = new HashMap<>(); private final Map farmInstances = new HashMap<>(); public static FarmRegistry getInstance() { @@ -51,7 +49,6 @@ public final class FarmRegistry implements IFarmRegistry { @Override @Deprecated public void registerLogic(String identifier, IFarmLogic logic) { - logics.put(identifier, logic); } @Override @@ -103,8 +100,7 @@ public final class FarmRegistry implements IFarmRegistry { public IFarmInstance registerLogic(String identifier, BiFunction logicFactory, String... farmablesIdentifiers) { Set fIdentifiers = new HashSet<>(Arrays.asList(farmablesIdentifiers)); fIdentifiers.add(identifier); - Collection farmablesSet = fIdentifiers.stream().map(farmables::get).flatMap(Collection::stream).collect(Collectors.toSet()); - IFarmInstance instance = new FarmInstance(identifier, logicFactory, farmablesSet); + IFarmInstance instance = new FarmInstance(identifier, logicFactory, fIdentifiers); farmInstances.put(identifier, instance); return instance; } diff --git a/src/main/java/forestry/farming/ModuleFarming.java b/src/main/java/forestry/farming/ModuleFarming.java index bdd0470a5..fe153ff05 100644 --- a/src/main/java/forestry/farming/ModuleFarming.java +++ b/src/main/java/forestry/farming/ModuleFarming.java @@ -65,6 +65,7 @@ import forestry.farming.circuits.CircuitFarmLogic; import forestry.farming.logic.FarmLogicArboreal; import forestry.farming.logic.FarmLogicCocoa; import forestry.farming.logic.FarmLogicCrops; +import forestry.farming.logic.FarmLogicEnder; import forestry.farming.logic.FarmLogicGourd; import forestry.farming.logic.FarmLogicInfernal; import forestry.farming.logic.FarmLogicMushroom; @@ -73,6 +74,7 @@ import forestry.farming.logic.FarmLogicPeat; import forestry.farming.logic.FarmLogicReeds; import forestry.farming.logic.FarmLogicSucculent; import forestry.farming.logic.farmables.FarmableAgingCrop; +import forestry.farming.logic.farmables.FarmableChorus; import forestry.farming.logic.farmables.FarmableGE; import forestry.farming.logic.farmables.FarmableGourd; import forestry.farming.logic.farmables.FarmableStacked; @@ -153,6 +155,8 @@ public class ModuleFarming extends BlankForestryModule { registry.registerFarmables("farmSucculentes", new FarmableStacked(new ItemStack(Blocks.CACTUS), Blocks.CACTUS, 3)); + registry.registerFarmables("farmEnder", FarmableChorus.INSTANCE); + //Forestry fertilizer registry.registerFertilizer(new ItemStack(coreItems.fertilizerCompound, 1, OreDictionary.WILDCARD_VALUE), 500); @@ -198,6 +202,7 @@ public class ModuleFarming extends BlankForestryModule { IFarmInstance orchardFarm = registry.registerLogic("farmOrchard", FarmLogicOrchard::new); IFarmInstance gourdFarm = registry.registerLogic("farmGourd", FarmLogicGourd::new); IFarmInstance cocoaFarm = registry.registerLogic("farmCocoa", FarmLogicCocoa::new); + IFarmInstance enderFarm = registry.registerLogic("farmEnder", FarmLogicEnder::new); Circuits.farmArborealManaged = new CircuitFarmLogic("managedArboreal", arborealFarm, false); Circuits.farmArborealManual = new CircuitFarmLogic("manualArboreal", arborealFarm, true); @@ -225,16 +230,24 @@ public class ModuleFarming extends BlankForestryModule { Circuits.farmOrchardManaged = new CircuitFarmLogic("managedOrchard", orchardFarm, false); Circuits.farmOrchardManual = new CircuitFarmLogic("manualOrchard", orchardFarm, true); + Circuits.farmSucculentManaged = new CircuitFarmLogic("managedSucculent", succulentFarm, false); Circuits.farmSucculentManual = new CircuitFarmLogic("manualSucculent", succulentFarm, true); succulentFarm.registerSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true); - Circuits.farmPoalesManual = new CircuitFarmLogic("manualPoales", poalesFarm, true).setManual(); + Circuits.farmPoalesManaged = new CircuitFarmLogic("managedPoales", poalesFarm, false); + Circuits.farmPoalesManual = new CircuitFarmLogic("manualPoales", poalesFarm, true); poalesFarm.registerSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true); poalesFarm.registerSoil(new ItemStack(Blocks.DIRT), Blocks.DIRT.getDefaultState(),false); - Circuits.farmGourdManual = new CircuitFarmLogic("manualGourd", gourdFarm, true).setManual(); + Circuits.farmGourdManaged = new CircuitFarmLogic("managedGourd", gourdFarm, false); + Circuits.farmGourdManual = new CircuitFarmLogic("manualGourd", gourdFarm, true); - Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", cocoaFarm, true).setManual(); + Circuits.farmCocoaManaged = new CircuitFarmLogic("managedCocoa", cocoaFarm, false); + Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", cocoaFarm, true); + + Circuits.farmEnderManaged = new CircuitFarmLogic("managedEnder", enderFarm, false); + Circuits.farmEnderManual = new CircuitFarmLogic("manualEnder", enderFarm, false); + enderFarm.registerSoil(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState()); } @Override @@ -302,20 +315,28 @@ public class ModuleFarming extends BlankForestryModule { return; } - ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmArborealManaged); - ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPeatManaged); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.farmArborealManaged); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmSucculentManaged); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.farmPeatManaged); ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCropsManaged); ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BLAZE, 1), Circuits.farmInfernalManaged); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPoalesManual); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.farmGourdManaged); ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.APATITE, 1), Circuits.farmShroomManaged); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.DIAMOND, 1), Circuits.farmCocoaManaged); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.EMERALD, 1), Circuits.farmOrchardManaged); + ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManaged); - ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmOrchardManual); - ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPeatManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.farmArborealManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmSucculentManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.farmPeatManual); ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCropsManual); - ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.farmSucculentManual); - ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.DIAMOND, 1), Circuits.farmPoalesManual); - ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.farmGourdManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPoalesManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.farmGourdManual); ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.APATITE, 1), Circuits.farmShroomManual); - ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.farmCocoaManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.DIAMOND, 1), Circuits.farmCocoaManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.EMERALD, 1), Circuits.farmOrchardManual); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManual); } @Override diff --git a/src/main/java/forestry/farming/logic/FakeFarmInstance.java b/src/main/java/forestry/farming/logic/FakeFarmInstance.java index 864b7de8c..11a7a6bf3 100644 --- a/src/main/java/forestry/farming/logic/FakeFarmInstance.java +++ b/src/main/java/forestry/farming/logic/FakeFarmInstance.java @@ -18,6 +18,10 @@ public class FakeFarmInstance implements IFarmInstance { this.logic = logic; } + @Override + public void registerFarmables(String identifier) { + } + @Override public void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) { } diff --git a/src/main/java/forestry/farming/logic/FarmInstance.java b/src/main/java/forestry/farming/logic/FarmInstance.java index 716862d87..5edf0f916 100644 --- a/src/main/java/forestry/farming/logic/FarmInstance.java +++ b/src/main/java/forestry/farming/logic/FarmInstance.java @@ -1,9 +1,11 @@ package forestry.farming.logic; +import javax.annotation.Nullable; import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.function.BiFunction; +import java.util.stream.Collectors; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -13,23 +15,35 @@ import forestry.api.farming.IFarmInstance; import forestry.api.farming.IFarmLogic; import forestry.api.farming.IFarmable; import forestry.api.farming.ISoil; +import forestry.farming.FarmRegistry; public final class FarmInstance implements IFarmInstance { private final Set soils = new HashSet<>(); - private final Collection farmables; + private final Set farmablesIdentifiers; private final IFarmLogic manualLogic; private final IFarmLogic managedLogic; private final String identifier; - public FarmInstance(String identifier, BiFunction logicFactory, Collection farmables) { + @Nullable + private Collection farmables; + + public FarmInstance(String identifier, BiFunction logicFactory, Set farmablesIdentifiers) { this.identifier = identifier; - this.farmables = farmables; + this.farmablesIdentifiers = farmablesIdentifiers; this.manualLogic = logicFactory.apply(this, true); this.managedLogic = logicFactory.apply(this, false); } + @Override + public void registerFarmables(String identifier) { + farmablesIdentifiers.add(identifier); + } + @Override public Collection getFarmables() { + if(farmables == null){ + farmables = farmablesIdentifiers.stream().map(FarmRegistry.getInstance()::getFarmables).flatMap(Collection::stream).collect(Collectors.toSet()); + } return farmables; } diff --git a/src/main/java/forestry/farming/logic/FarmLogic.java b/src/main/java/forestry/farming/logic/FarmLogic.java index 54810fdbb..6b062f8c1 100755 --- a/src/main/java/forestry/farming/logic/FarmLogic.java +++ b/src/main/java/forestry/farming/logic/FarmLogic.java @@ -65,21 +65,29 @@ public abstract class FarmLogic implements IFarmLogic { Stack crops = new Stack<>(); for (int i = 0; i < extent; i++) { BlockPos position = translateWithOffset(pos.up(), direction, i); - if (world.isAirBlock(position)) { - continue; - } - IBlockState blockState = world.getBlockState(position); - for (IFarmable seed : getFarmables()) { - ICrop crop = seed.getCropAt(world, position, blockState); - if (crop != null) { - crops.push(crop); - break; - } + ICrop crop = getCrop(world, position); + if(crop != null){ + crops.push(crop); } } return crops; } + @Nullable + protected ICrop getCrop(World world, BlockPos position){ + if (world.isAirBlock(position)) { + return null; + } + IBlockState blockState = world.getBlockState(position); + for (IFarmable seed : getFarmables()) { + ICrop crop = seed.getCropAt(world, position, blockState); + if (crop != null) { + return crop; + } + } + return null; + } + public abstract boolean isAcceptedWindfall(ItemStack stack); protected final boolean isWaterSourceBlock(World world, BlockPos position) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java index 116511d75..952528793 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java @@ -36,15 +36,18 @@ import forestry.api.farming.IFarmable; public class FarmLogicArboreal extends FarmLogicHomogeneous { + @Nullable private List farmables; public FarmLogicArboreal(IFarmInstance instance, boolean isManual) { super(instance, isManual); - this.farmables = new ArrayList<>(instance.getFarmables()); } @Override public List getFarmables() { + if(farmables == null){ + this.farmables = new ArrayList<>(instance.getFarmables()); + } return farmables; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicEnder.java b/src/main/java/forestry/farming/logic/FarmLogicEnder.java new file mode 100644 index 000000000..742bcf395 --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmLogicEnder.java @@ -0,0 +1,154 @@ +package forestry.farming.logic; + +import com.google.common.collect.ImmutableSet; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.Stack; + +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.EnumFacing; +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.IFarmInstance; +import forestry.api.farming.IFarmable; +import forestry.core.utils.BlockUtil; +import forestry.farming.logic.crops.CropDestroy; +import forestry.farming.logic.farmables.FarmableChorus; + +public class FarmLogicEnder extends FarmLogicHomogeneous { + private static final Set VALID_DIRECTIONS = ImmutableSet.of(EnumFacing.UP, EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.EAST); + private final IFarmable chorusFarmable; + + public FarmLogicEnder(IFarmInstance instance, boolean isManual) { + super(instance, isManual); + chorusFarmable = FarmableChorus.INSTANCE; + } + + @Override + public String getName() { + return "Manual Ender Farm"; + } + + @Override + public ItemStack getIconItemStack() { + return new ItemStack(Items.ENDER_EYE); + } + + @Override + public int getFertilizerConsumption() { + return 20; + } + + @Override + public int getWaterConsumption(float hydrationModifier) { + return 0; + } + + @Override + public NonNullList collect(World world, IFarmHousing farmHousing) { + NonNullList products = produce; + produce = collectEntityItems(world, farmHousing, true); + return products; + } + + private final Map lastExtentsHarvest = new HashMap<>(); + + @Override + public Collection harvest(World world, BlockPos pos, FarmDirection direction, int extent) { + if (!lastExtentsHarvest.containsKey(pos)) { + lastExtentsHarvest.put(pos, 0); + } + + int lastExtent = lastExtentsHarvest.get(pos); + if (lastExtent > extent) { + lastExtent = 0; + } + + BlockPos position = translateWithOffset(pos.up(), direction, lastExtent); + Collection crops = harvestBlocks(world, position); + lastExtent++; + lastExtentsHarvest.put(pos, lastExtent); + + return crops; + } + + private Collection harvestBlocks(World world, BlockPos position) { + if(world.isAirBlock(position)){ + return Collections.emptySet(); + } + + ICrop crop = getCrop(world, position); + if(crop != null){ + return Collections.singleton(crop); + } + + Stack crops = new Stack<>(); + Stack plants = new Stack<>(); + harvestBlock(world, position, EnumFacing.DOWN, plants, crops); + //Remove all flowers before remove all plants + if(!crops.isEmpty()) { + return crops; + } + return plants; + } + + private boolean harvestBlock(World world, BlockPos pos, EnumFacing from, Stack plants, Stack flowers){ + IBlockState blockState = world.getBlockState(pos); + if(blockState.getBlock() == Blocks.CHORUS_FLOWER){ + ICrop crop = chorusFarmable.getCropAt(world, pos, blockState); + if(crop != null){ + flowers.push(crop); + return false; + } + return false; + }else if(blockState.getBlock() == Blocks.CHORUS_PLANT){ + boolean canHarvest = true; + for(EnumFacing facing : VALID_DIRECTIONS) { + if(facing == from){ + continue; + } + canHarvest &= harvestBlock(world, pos.offset(facing), facing.getOpposite(), plants, flowers); + } + if(canHarvest){ + plants.push(new CropDestroy(world, Blocks.CHORUS_PLANT.getDefaultState(), pos, null)); + } + return canHarvest; + } + return true; + } + + @Override + protected boolean maintainGermlings(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) { + for (int i = 0; i < extent; i++) { + BlockPos position = translateWithOffset(pos, direction, i); + IBlockState state = world.getBlockState(position); + if (!world.isAirBlock(position) && !BlockUtil.isReplaceableBlock(state, world, position)) { + continue; + } + + BlockPos soilPos = position.down(); + IBlockState blockState = world.getBlockState(soilPos); + if (!isAcceptedSoil(blockState)) { + continue; + } + + if(trySetCrop(world, farmHousing, position, direction)){ + return true; + } + } + + return false; + } +} diff --git a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java index ad46f954a..22a133c46 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java +++ b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java @@ -137,7 +137,7 @@ public class FarmLogicOrchard extends FarmLogic { // Determine what type we want to harvest. IBlockState blockState = world.getBlockState(position); Block block = blockState.getBlock(); - if (!block.isWood(world, position) && !isBlockTraversable(blockState, traversalBlocks) && !isFruitBearer(world, position)) { + if (!block.isWood(world, position) && !isBlockTraversable(blockState, traversalBlocks) && !isFruitBearer(world, position, blockState)) { return crops; } @@ -184,11 +184,11 @@ public class FarmLogicOrchard extends FarmLogic { candidates.add(candidate); seen.add(candidate); } - if (isFruitBearer(world, candidate)) { + if (isFruitBearer(world, candidate, blockState)) { candidates.add(candidate); seen.add(candidate); - ICrop crop = getCrop(world, candidate); + ICrop crop = getCropAt(world, candidate); if (crop != null) { crops.push(crop); } @@ -200,14 +200,14 @@ public class FarmLogicOrchard extends FarmLogic { return candidates; } - private boolean isFruitBearer(World world, BlockPos position) { + private boolean isFruitBearer(World world, BlockPos position, IBlockState blockState) { IFruitBearer tile = TileUtil.getTile(world, position, IFruitBearer.class); if (tile != null) { return true; } for (IFarmable farmable : getFarmables()) { - if (farmable.isSaplingAt(world, position)) { + if (farmable.isSaplingAt(world, position, blockState)) { return true; } } @@ -226,7 +226,7 @@ public class FarmLogicOrchard extends FarmLogic { } @Nullable - private ICrop getCrop(World world, BlockPos position) { + private ICrop getCropAt(World world, BlockPos position) { IFruitBearer fruitBearer = TileUtil.getTile(world, position, IFruitBearer.class); if (fruitBearer != null) { @@ -234,13 +234,7 @@ public class FarmLogicOrchard extends FarmLogic { return new CropFruit(world, position); } } else { - IBlockState blockState = world.getBlockState(position); - for (IFarmable seed : getFarmables()) { - ICrop crop = seed.getCropAt(world, position, blockState); - if (crop != null) { - return crop; - } - } + return getCrop(world, position); } return null; } diff --git a/src/main/java/forestry/farming/logic/crops/CropChorusFlower.java b/src/main/java/forestry/farming/logic/crops/CropChorusFlower.java new file mode 100644 index 000000000..11d807393 --- /dev/null +++ b/src/main/java/forestry/farming/logic/crops/CropChorusFlower.java @@ -0,0 +1,42 @@ +package forestry.farming.logic.crops; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.event.ForgeEventFactory; + +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.utils.NetworkUtil; + +public class CropChorusFlower extends Crop { + private static final IBlockState BLOCK_STATE = Blocks.CHORUS_FLOWER.getDefaultState(); + + public CropChorusFlower(World world, BlockPos position) { + super(world, position); + } + + @Override + protected boolean isCrop(World world, BlockPos pos) { + return world.getBlockState(pos).getBlock() == Blocks.CHORUS_FLOWER; + } + + @Override + protected NonNullList harvestBlock(World world, BlockPos pos) { + NonNullList harvested = NonNullList.create(); + harvested.add(new ItemStack(Blocks.CHORUS_FLOWER)); + float chance = ForgeEventFactory.fireBlockHarvesting(harvested, world, pos, BLOCK_STATE, 0, 1.0F, false, null); + + harvested.removeIf(next -> world.rand.nextFloat() > chance); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, BLOCK_STATE); + NetworkUtil.sendNetworkPacket(packet, pos, world); + + world.setBlockToAir(pos); + + return harvested; + } +} diff --git a/src/main/java/forestry/farming/logic/crops/CropDestroy.java b/src/main/java/forestry/farming/logic/crops/CropDestroy.java index 458eb9da4..6ad61af75 100644 --- a/src/main/java/forestry/farming/logic/crops/CropDestroy.java +++ b/src/main/java/forestry/farming/logic/crops/CropDestroy.java @@ -70,6 +70,8 @@ public class CropDestroy extends Crop { } removedSeed = true; } + }else{ + dropIterator.remove(); } } diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableAgingCrop.java b/src/main/java/forestry/farming/logic/farmables/FarmableAgingCrop.java index a9f0b9c72..ab1af6c98 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableAgingCrop.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableAgingCrop.java @@ -45,8 +45,7 @@ public class FarmableAgingCrop implements IFarmable { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - IBlockState blockState = world.getBlockState(pos); + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { return blockState.getBlock() == cropBlock && blockState.getValue(ageProperty) <= minHarvestAge; } diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableBase.java b/src/main/java/forestry/farming/logic/farmables/FarmableBase.java index 5a83ffadd..857a34ac5 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableBase.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableBase.java @@ -25,8 +25,7 @@ public abstract class FarmableBase implements IFarmable { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - IBlockState blockState = world.getBlockState(pos); + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { return blockState.getBlock() == plantedState.getBlock() && blockState != matureState; } diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableChorus.java b/src/main/java/forestry/farming/logic/farmables/FarmableChorus.java new file mode 100644 index 000000000..5821d7838 --- /dev/null +++ b/src/main/java/forestry/farming/logic/farmables/FarmableChorus.java @@ -0,0 +1,80 @@ +package forestry.farming.logic.farmables; + +import javax.annotation.Nullable; + +import net.minecraft.block.BlockChorusFlower; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.utils.BlockUtil; +import forestry.farming.logic.crops.CropChorusFlower; + +public class FarmableChorus implements IFarmable { + public static final IFarmable INSTANCE = new FarmableChorus(); + + private final ItemStack germling; + private final ItemStack fruit; + + private FarmableChorus() { + this.germling = new ItemStack(Blocks.CHORUS_FLOWER); + this.fruit = new ItemStack(Items.CHORUS_FRUIT); + } + + @Override + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { + return blockState.getBlock() == Blocks.CHORUS_FLOWER; + } + + @Nullable + @Override + public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { + if (blockState.getBlock() != Blocks.CHORUS_FLOWER) { + return null; + } + + if (blockState.getValue(BlockChorusFlower.AGE) < 5) { + return null; + } + + return new CropChorusFlower(world, pos); + } + + @Override + public boolean isGermling(ItemStack itemstack) { + return ItemStack.areItemsEqual(germling, itemstack); + } + + @Override + public boolean isWindfall(ItemStack itemstack) { + return ItemStack.areItemsEqual(fruit, itemstack); + } + + @Override + public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { + if(!canPlace(world, pos)){ + return false; + } + return BlockUtil.setBlockWithPlaceSound(world, pos, Blocks.CHORUS_FLOWER.getDefaultState()); + } + + private boolean canPlace(World world, BlockPos position) { + for (int x = -1; x <= 1; x++) { + for (int z = -1; z <= 1; z++) { + BlockPos offsetPosition = position.add(x, 0, z); + IBlockState state = world.getBlockState(offsetPosition); + if (state.getBlock() == Blocks.CHORUS_FLOWER || state.getBlock() == Blocks.CHORUS_PLANT) { + return false; + } + } + } + + return true; + } +} diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableDoubleCrop.java b/src/main/java/forestry/farming/logic/farmables/FarmableDoubleCrop.java index 5e3b62a2e..392070eb5 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableDoubleCrop.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableDoubleCrop.java @@ -17,8 +17,7 @@ public class FarmableDoubleCrop extends FarmableBase { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - IBlockState blockState = world.getBlockState(pos); + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { return blockState.getBlock() == plantedState.getBlock() && blockState != topMatureState; } diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableGE.java b/src/main/java/forestry/farming/logic/farmables/FarmableGE.java index 0ccbf303c..5005beb19 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableGE.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableGE.java @@ -28,14 +28,8 @@ import forestry.farming.logic.crops.CropDestroy; public class FarmableGE implements IFarmable { @Override - public boolean isSaplingAt(World world, BlockPos pos) { - - if (world.isAirBlock(pos)) { - return false; - } - - Block block = world.getBlockState(pos).getBlock(); - return ModuleArboriculture.getBlocks().saplingGE == block; + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { + return ModuleArboriculture.getBlocks().saplingGE == blockState.getBlock(); } @Override diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableGourd.java b/src/main/java/forestry/farming/logic/farmables/FarmableGourd.java index 6cd382579..c77d7a7c9 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableGourd.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableGourd.java @@ -35,8 +35,7 @@ public class FarmableGourd implements IFarmable { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - IBlockState blockState = world.getBlockState(pos); + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { return blockState.getBlock() == stem; } diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableRusticGrape.java b/src/main/java/forestry/farming/logic/farmables/FarmableRusticGrape.java index 4fbde5151..35d6dff14 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableRusticGrape.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableRusticGrape.java @@ -28,8 +28,7 @@ public class FarmableRusticGrape implements IFarmable { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - IBlockState blockState = world.getBlockState(pos); + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { return blockState.getBlock() == cropBlock; } diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java b/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java index 79e321e88..53e3ab2a1 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java @@ -37,8 +37,8 @@ public class FarmableRusticSapling implements IFarmable { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - return world.getBlockState(pos).getBlock() == germlingBlock; + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { + return blockState.getBlock() == germlingBlock; } @Override diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableSapling.java b/src/main/java/forestry/farming/logic/farmables/FarmableSapling.java index 7d1b0111c..fed60f725 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableSapling.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableSapling.java @@ -60,8 +60,8 @@ public class FarmableSapling implements IFarmable { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - return world.getBlockState(pos).getBlock() == this.saplingBlock; + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { + return blockState.getBlock() == this.saplingBlock; } @Override diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableStacked.java b/src/main/java/forestry/farming/logic/farmables/FarmableStacked.java index adc3f3e8d..6b0e6d8f6 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableStacked.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableStacked.java @@ -34,8 +34,7 @@ public class FarmableStacked implements IFarmable { } @Override - public boolean isSaplingAt(World world, BlockPos pos) { - IBlockState blockState = world.getBlockState(pos); + public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) { return blockState.getBlock() == cropBlock; } diff --git a/src/main/java/forestry/plugins/PluginExtraUtilities.java b/src/main/java/forestry/plugins/PluginExtraUtilities.java index 9f5ba2029..af98cd641 100644 --- a/src/main/java/forestry/plugins/PluginExtraUtilities.java +++ b/src/main/java/forestry/plugins/PluginExtraUtilities.java @@ -68,7 +68,7 @@ public class PluginExtraUtilities extends BlankForestryModule { } if (Config.isExUtilEnderLilyEnabled()) { - registerExPlant("Ender", "enderlilly", "Ender Lily", circuit -> Circuits.farmEnderManaged = circuit, Blocks.END_STONE); + registerExPlant("Ender", "enderlilly", "Ender Lily", circuit -> Circuits.farmEnderManaged = circuit); } } @@ -77,10 +77,6 @@ public class PluginExtraUtilities extends BlankForestryModule { if (!ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FARMING))) { return; } - if(Circuits.farmEnderManaged != null) { - ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed"); - ChipsetManager.solderManager.addRecipe(layoutManaged, ModuleCore.getItems().tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManaged); - } if(Circuits.farmOrchidManaged != null) { ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed"); ChipsetManager.solderManager.addRecipe(layoutManaged, ModuleCore.items.tubes.get(EnumElectronTube.ORCHID, 1), Circuits.farmOrchidManaged); @@ -99,16 +95,20 @@ public class PluginExtraUtilities extends BlankForestryModule { if (growthProperty == null) { Log.error("Could not find the growth property of {}.", itemName); } else { + String identifier = "farm" + id; IFarmRegistry registry = FarmRegistry.getInstance(); int harvestAge = Collections.max(growthProperty.getAllowedValues()); int replantAge = plantBlock.getDefaultState().getValue(growthProperty); - registry.registerFarmables(itemName, new FarmableAgingCrop(new ItemStack(plantItem), plantBlock, growthProperty, harvestAge, replantAge)); + registry.registerFarmables(identifier, new FarmableAgingCrop(new ItemStack(plantItem), plantBlock, growthProperty, harvestAge, replantAge)); - IFarmInstance instance = registry.registerLogic("farm" + id, (i, m) -> new FarmLogicExU(i, m, (m ? "Manual " : "Managed ") + itemName + " Farm", plantItem), itemName); - for(Block soil : soils) { - instance.registerSoil(new ItemStack(soil), soil.getDefaultState()); + IFarmInstance instance = registry.getFarm(identifier); + if(instance == null) { + instance = registry.registerLogic(identifier, (i, m) -> new FarmLogicExU(i, m, (m ? "Manual " : "Managed ") + itemName + " Farm", plantItem), itemName); + for (Block soil : soils) { + instance.registerSoil(new ItemStack(soil), soil.getDefaultState()); + } + assignTo.accept(new CircuitFarmLogic("managed" + id, instance, false)); } - assignTo.accept(new CircuitFarmLogic("managed" + id, instance, false)); } } } diff --git a/src/main/resources/assets/forestry/blockstates/farm_ender.json b/src/main/resources/assets/forestry/blockstates/farm_ender.json new file mode 100644 index 000000000..17ac8dddc --- /dev/null +++ b/src/main/resources/assets/forestry/blockstates/farm_ender.json @@ -0,0 +1,8 @@ +{ + "variants": { + "facing=north": { "model": "forestry:farm_ender" }, + "facing=east": { "model": "forestry:farm_ender", "y": 90 }, + "facing=south": { "model": "forestry:farm_ender", "y": 180 }, + "facing=west": { "model": "forestry:farm_ender", "y": -90 } + } +} diff --git a/src/main/resources/assets/forestry/models/block/farm_ender.json b/src/main/resources/assets/forestry/models/block/farm_ender.json new file mode 100644 index 000000000..6b2fd1f90 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/farm_ender.json @@ -0,0 +1,57 @@ +{ + "parent": "block/block", + "textures": { + "particle": "forestry:blocks/farm_ender_particle", + "texture": "forestry:blocks/farm_ender" + }, + "elements": [ + { + "__comment": "base", + "from": [ 0, 0, 0 ], + "to": [ 16, 4, 16 ], + "faces": { + "down": { "uv": [ 4, 4, 8, 8 ], "texture": "#texture", "cullface": "down" }, + "up": { "uv": [ 0, 4, 4, 8 ], "texture": "#texture" }, + "north": { "uv": [ 8, 4, 12, 5 ], "texture": "#texture", "cullface": "north" }, + "south": { "uv": [ 8, 6, 12, 7 ], "texture": "#texture", "cullface": "south" }, + "west": { "uv": [ 8, 7, 12, 8 ], "texture": "#texture", "cullface": "west" }, + "east": { "uv": [ 8, 5, 12, 6 ], "texture": "#texture", "cullface": "east" } + } + }, + { + "__comment": "ceiling", + "from": [ 0, 12, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "uv": [ 4, 0, 8, 4 ], "texture": "#texture" }, + "up": { "uv": [ 0, 0, 4, 4 ], "texture": "#texture", "cullface": "up" }, + "north": { "uv": [ 8, 0, 12, 1 ], "texture": "#texture", "cullface": "north" }, + "south": { "uv": [ 8, 2, 12, 3 ], "texture": "#texture", "cullface": "south" }, + "west": { "uv": [ 8, 3, 12, 4 ], "texture": "#texture", "cullface": "west" }, + "east": { "uv": [ 8, 1, 12, 2 ], "texture": "#texture", "cullface": "east" } + } + }, + { + "__comment": "terrarium", + "from": [ 2, 4, 2 ], + "to": [ 14, 12, 14 ], + "faces": { + "north": { "uv": [ 0, 13.5, 3, 15.5 ], "texture": "#texture" }, + "south": { "uv": [ 6, 13.5, 9, 15.5 ], "texture": "#texture" }, + "west": { "uv": [ 9, 13.5, 12, 15.5 ], "texture": "#texture" }, + "east": { "uv": [ 3, 13.5, 6, 15.5 ], "texture": "#texture" } + } + }, + { + "__comment": "showcase", + "from": [ 4, 4, 4 ], + "to": [ 12, 12, 12 ], + "faces": { + "north": { "uv": [ 6, 10, 8, 12 ], "texture": "#texture" }, + "south": { "uv": [ 10, 10, 12, 12 ], "texture": "#texture" }, + "west": { "uv": [ 12, 10, 14, 12 ], "texture": "#texture" }, + "east": { "uv": [ 8, 10, 10, 12 ], "texture": "#texture" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/item/farm_ender.json b/src/main/resources/assets/forestry/models/item/farm_ender.json new file mode 100644 index 000000000..fd3d60792 --- /dev/null +++ b/src/main/resources/assets/forestry/models/item/farm_ender.json @@ -0,0 +1,3 @@ +{ + "parent": "forestry:block/farm_ender" +} diff --git a/src/main/resources/assets/forestry/textures/blocks/farm_ender.png b/src/main/resources/assets/forestry/textures/blocks/farm_ender.png new file mode 100644 index 000000000..f54084ada Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/farm_ender.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/farm_ender_particle.png b/src/main/resources/assets/forestry/textures/blocks/farm_ender_particle.png new file mode 100644 index 000000000..f99ed652d Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/farm_ender_particle.png differ