mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-19 03:49:07 +00:00
Moving gardening helper class to the api
This commit is contained in:
1 parent
beb1ba9ae1
commit
be827a17a7
18 files changed
+342
-205
No files matched your search
@@ -18,7 +18,6 @@ import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
@@ -29,6 +28,8 @@ import binnie.botany.api.EnumAcidity;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.IBlockSoil;
|
||||
import binnie.botany.api.IFlower;
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.ceramic.BlockCeramic;
|
||||
import binnie.botany.ceramic.BlockCeramicPatterned;
|
||||
import binnie.botany.ceramic.BlockStainedGlass;
|
||||
@@ -42,7 +43,6 @@ import binnie.botany.flower.ItemInsulatedTube;
|
||||
import binnie.botany.flower.TileEntityFlower;
|
||||
import binnie.botany.gardening.BlockPlant;
|
||||
import binnie.botany.gardening.BlockSoil;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.botany.gardening.ItemSoilMeter;
|
||||
import binnie.botany.gardening.ItemTrowel;
|
||||
import binnie.botany.gardening.ModuleGardening;
|
||||
@@ -212,20 +212,21 @@ public class Botany extends AbstractMod {
|
||||
if (heldItem.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
Block block = world.getBlockState(event.getPos()).getBlock();
|
||||
if (!Gardening.isSoil(block)) {
|
||||
if (!gardening.isSoil(block)) {
|
||||
pos = pos.down();
|
||||
block = world.getBlockState(pos).getBlock();
|
||||
}
|
||||
|
||||
if (!Gardening.isSoil(block)) {
|
||||
if (!gardening.isSoil(block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
IBlockSoil soil = (IBlockSoil) block;
|
||||
int fertiliserStrength = Gardening.getFertiliserStrength(heldItem);
|
||||
if (Gardening.isNutrientFertiliser(heldItem) && soil.getType(world, pos) != EnumSoilType.FLOWERBED) {
|
||||
int fertiliserStrength = gardening.getFertiliserStrength(heldItem);
|
||||
if (gardening.isNutrientFertiliser(heldItem) && soil.getType(world, pos) != EnumSoilType.FLOWERBED) {
|
||||
EnumSoilType type = soil.getType(world, pos);
|
||||
int next = Math.min(type.ordinal() + fertiliserStrength, 2);
|
||||
if (soil.fertilise(world, pos, EnumSoilType.values()[next]) && !player.capabilities.isCreativeMode) {
|
||||
@@ -234,7 +235,7 @@ public class Botany extends AbstractMod {
|
||||
}
|
||||
}
|
||||
|
||||
if (Gardening.isAcidFertiliser(heldItem) && soil.getPH(world, pos) != EnumAcidity.ACID) {
|
||||
if (gardening.isAcidFertiliser(heldItem) && soil.getPH(world, pos) != EnumAcidity.ACID) {
|
||||
EnumAcidity pH = soil.getPH(world, pos);
|
||||
int next = Math.max(pH.ordinal() - fertiliserStrength, 0);
|
||||
if (soil.setPH(world, pos, EnumAcidity.values()[next]) && !player.capabilities.isCreativeMode) {
|
||||
@@ -243,7 +244,7 @@ public class Botany extends AbstractMod {
|
||||
}
|
||||
}
|
||||
|
||||
if (Gardening.isAlkalineFertiliser(heldItem) && soil.getPH(world, pos) != EnumAcidity.ALKALINE) {
|
||||
if (gardening.isAlkalineFertiliser(heldItem) && soil.getPH(world, pos) != EnumAcidity.ALKALINE) {
|
||||
EnumAcidity pH = soil.getPH(world, pos);
|
||||
int next = Math.min(pH.ordinal() + fertiliserStrength, 2);
|
||||
if (soil.setPH(world, pos, EnumAcidity.values()[next]) && !player.capabilities.isCreativeMode) {
|
||||
@@ -252,7 +253,7 @@ public class Botany extends AbstractMod {
|
||||
}
|
||||
}
|
||||
|
||||
if (Gardening.isWeedkiller(heldItem) && Gardening.addWeedKiller(world, pos) && !player.capabilities.isCreativeMode) {
|
||||
if (gardening.isWeedkiller(heldItem) && gardening.addWeedKiller(world, pos) && !player.capabilities.isCreativeMode) {
|
||||
heldItem.shrink(1);
|
||||
}
|
||||
}
|
||||
@@ -263,14 +264,15 @@ public class Botany extends AbstractMod {
|
||||
BlockPos pos = event.getPos();
|
||||
Block block = world.getBlockState(pos.down()).getBlock();
|
||||
|
||||
if (!Gardening.isSoil(block)) {
|
||||
if (!BotanyCore.getGardening().isSoil(block)) {
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = event.getPlayer();
|
||||
ItemStack heldItem = player.getHeldItem(event.getHand());
|
||||
IFlower flower = BotanyCore.getFlowerRoot().getConversion(heldItem);
|
||||
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
|
||||
IFlower flower = flowerRoot.getConversion(heldItem);
|
||||
if (flower != null) {
|
||||
Gardening.plant(world, pos, flower, player.getGameProfile());
|
||||
flowerRoot.plant(world, pos, flower, player.getGameProfile());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,8 +293,9 @@ public class Botany extends AbstractMod {
|
||||
py = 1;
|
||||
}
|
||||
if (py >= 0) {
|
||||
IFlower flower = BotanyCore.getFlowerRoot().getConversion(heldItem);
|
||||
if (flower != null && Gardening.plant(world, pos.add(0, py, 0), flower, player.getGameProfile()) && !player.capabilities.isCreativeMode) {
|
||||
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
|
||||
IFlower flower = flowerRoot.getConversion(heldItem);
|
||||
if (flower != null && flowerRoot.plant(world, pos.add(0, py, 0), flower, player.getGameProfile()) && !player.capabilities.isCreativeMode) {
|
||||
heldItem.shrink(1);
|
||||
}
|
||||
}
|
||||
@@ -303,7 +306,7 @@ public class Botany extends AbstractMod {
|
||||
public void onBonemeal(final BonemealEvent event) {
|
||||
BlockPos pos = event.getPos();
|
||||
Block block = event.getBlock().getBlock();
|
||||
if (Gardening.isSoil(block)) {
|
||||
if (BotanyCore.getGardening().isSoil(block)) {
|
||||
IBlockSoil soil = (IBlockSoil) block;
|
||||
if (soil.fertilise(event.getWorld(), pos, EnumSoilType.LOAM)) {
|
||||
event.setResult(Event.Result.ALLOW);
|
||||
@@ -315,30 +318,6 @@ public class Botany extends AbstractMod {
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onIMC(final FMLInterModComms.IMCEvent event) {
|
||||
for (FMLInterModComms.IMCMessage message : event.getMessages()) {
|
||||
if (message.key.equals("add-nutrient-fertiliser-1")) {
|
||||
ModuleGardening.queuedNutrientFertilisers.put(message.getItemStackValue(), 1);
|
||||
}
|
||||
if (message.key.equals("add-nutrient-fertiliser-2")) {
|
||||
ModuleGardening.queuedNutrientFertilisers.put(message.getItemStackValue(), 2);
|
||||
}
|
||||
if (message.key.equals("add-acid-fertiliser-1")) {
|
||||
ModuleGardening.queuedAcidFertilisers.put(message.getItemStackValue(), 1);
|
||||
}
|
||||
if (message.key.equals("add-acid-fertiliser-2")) {
|
||||
ModuleGardening.queuedAcidFertilisers.put(message.getItemStackValue(), 2);
|
||||
}
|
||||
if (message.key.equals("add-alkaline-fertiliser-1")) {
|
||||
ModuleGardening.queuedAlkalineFertilisers.put(message.getItemStackValue(), 1);
|
||||
}
|
||||
if (message.key.equals("add-alkaline-fertiliser-2")) {
|
||||
ModuleGardening.queuedAlkalineFertilisers.put(message.getItemStackValue(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketHandler extends BinniePacketHandler {
|
||||
public PacketHandler() {
|
||||
super(Botany.instance);
|
||||
|
||||
@@ -10,4 +10,9 @@ public class FlowerManager {
|
||||
* Used to create new flowers.
|
||||
*/
|
||||
public static IFlowerFactory flowerFactory;
|
||||
|
||||
/**
|
||||
* Used to manager soil.
|
||||
*/
|
||||
public static IGardeningManager gardening;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -49,4 +50,10 @@ public interface IFlowerRoot extends ISpeciesRoot {
|
||||
Collection<IColourMix> getColourMixes(boolean p0);
|
||||
|
||||
void registerColourMix(IColourMix colourMix);
|
||||
|
||||
boolean plant(World world, BlockPos pos, IFlower flower, GameProfile owner);
|
||||
|
||||
void tryGrowSection(World world, BlockPos pos);
|
||||
|
||||
void onGrowFromSeed(World world, BlockPos pos);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package binnie.botany.api;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.EnumTemperature;
|
||||
|
||||
public interface IGardeningManager {
|
||||
default boolean isSoil(final Block block) {
|
||||
return block instanceof IBlockSoil;
|
||||
}
|
||||
|
||||
boolean isSoil(Item item);
|
||||
|
||||
boolean isSoil(ItemStack item);
|
||||
|
||||
EnumMoisture getNaturalMoisture(World world, BlockPos pos);
|
||||
|
||||
EnumAcidity getNaturalPH(World world, BlockPos pos);
|
||||
|
||||
float getBiomeMoisture(World world, BlockPos pos);
|
||||
|
||||
float getBiomePH(World world, BlockPos pos);
|
||||
|
||||
void plantSoil(World world, BlockPos pos, EnumSoilType soil, EnumMoisture moisture, EnumAcidity acidity);
|
||||
|
||||
Collection<ItemStack> getAcidFertilisers();
|
||||
|
||||
Collection<ItemStack> getAlkalineFertilisers();
|
||||
|
||||
Collection<ItemStack> getNutrientFertilisers();
|
||||
|
||||
void registerAcidFertiliser(ItemStack stack, int strength);
|
||||
|
||||
void registerAlkalineFertiliser(ItemStack stack, int strength);
|
||||
|
||||
void registerNutrientFertiliser(ItemStack stack, int strength);
|
||||
|
||||
boolean isAcidFertiliser(ItemStack stack);
|
||||
|
||||
boolean isAlkalineFertiliser(ItemStack stack);
|
||||
|
||||
boolean isNutrientFertiliser(ItemStack stack);
|
||||
|
||||
int getFertiliserStrength(ItemStack stack);
|
||||
|
||||
boolean canTolerate(@Nullable IFlower flower, World world, BlockPos pos);
|
||||
|
||||
EnumSoilType getSoilType(World world, BlockPos pos);
|
||||
|
||||
default Block getSoilBlock(EnumSoilType type) {
|
||||
return getSoilBlock(type, false);
|
||||
}
|
||||
|
||||
Block getSoilBlock(EnumSoilType type, boolean weedkill);
|
||||
|
||||
boolean canTolerate(IFlower flower, EnumAcidity ePH, EnumMoisture eMoisture, EnumTemperature eTemp);
|
||||
|
||||
boolean isWeedkiller(ItemStack heldItem);
|
||||
|
||||
boolean addWeedKiller(World world, BlockPos pos);
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package binnie.botany.core;
|
||||
|
||||
import binnie.botany.api.FlowerManager;
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.botany.genetics.FlowerRoot;
|
||||
|
||||
public class BotanyCore {
|
||||
@@ -13,4 +15,11 @@ public class BotanyCore {
|
||||
}
|
||||
return FlowerManager.flowerRoot;
|
||||
}
|
||||
|
||||
public static IGardeningManager getGardening(){
|
||||
if (FlowerManager.gardening == null) {
|
||||
FlowerManager.gardening = new Gardening();
|
||||
}
|
||||
return FlowerManager.gardening;
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,9 @@ import forestry.api.farming.IFarmable;
|
||||
import binnie.botany.Botany;
|
||||
import binnie.botany.api.EnumFlowerStage;
|
||||
import binnie.botany.api.IFlower;
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.flower.TileEntityFlower;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
|
||||
public class FarmableFlower implements IFarmable {
|
||||
@Override
|
||||
@@ -34,8 +34,9 @@ public class FarmableFlower implements IFarmable {
|
||||
}
|
||||
// Look at TileEntityFlower::onShear logic
|
||||
if (flower != null && flower.getAge() > 1) {
|
||||
ItemStack mature = BotanyCore.getFlowerRoot().getMemberStack(flower, EnumFlowerStage.FLOWER);
|
||||
ItemStack seed = BotanyCore.getFlowerRoot().getMemberStack(flower, EnumFlowerStage.SEED);
|
||||
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
|
||||
ItemStack mature = flowerRoot.getMemberStack(flower, EnumFlowerStage.FLOWER);
|
||||
ItemStack seed = flowerRoot.getMemberStack(flower, EnumFlowerStage.SEED);
|
||||
if (mature != null && seed != null) {
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
|
||||
return new FlowerCrop(pos, mature, seed);
|
||||
@@ -58,8 +59,9 @@ public class FarmableFlower implements IFarmable {
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(final EntityPlayer player, final ItemStack germling, final World world, final BlockPos pos) {
|
||||
final IFlower flower = BotanyCore.getFlowerRoot().getMember(germling);
|
||||
Gardening.plant(world, pos, flower, player.getGameProfile());
|
||||
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
|
||||
IFlower flower = flowerRoot.getMember(germling);
|
||||
flowerRoot.plant(world, pos, flower, player.getGameProfile());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import binnie.botany.api.IFlower;
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
|
||||
public class FarmableVanillaFlower extends FarmableFlower {
|
||||
@Override
|
||||
@@ -17,7 +17,8 @@ public class FarmableVanillaFlower extends FarmableFlower {
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(final EntityPlayer player, final ItemStack germling, final World world, final BlockPos pos) {
|
||||
final IFlower flower = BotanyCore.getFlowerRoot().getConversion(germling);
|
||||
return Gardening.plant(world, pos, flower, player.getGameProfile());
|
||||
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
|
||||
IFlower flower = flowerRoot.getConversion(germling);
|
||||
return flowerRoot.plant(world, pos, flower, player.getGameProfile());
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,9 @@ import binnie.botany.api.EnumAcidity;
|
||||
import binnie.botany.api.EnumMoisture;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.IBlockSoil;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.flower.TileEntityFlower;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.core.liquid.ManagerLiquid;
|
||||
|
||||
public class GardenLogic extends FarmLogic {
|
||||
@@ -73,11 +74,12 @@ public class GardenLogic extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(final ItemStack itemstack) {
|
||||
return Gardening.isSoil(itemstack.getItem()) ||
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
return gardening.isSoil(itemstack.getItem()) ||
|
||||
itemstack.getItem() == Item.getItemFromBlock(Blocks.SAND) ||
|
||||
itemstack.getItem() == Item.getItemFromBlock(Blocks.DIRT) ||
|
||||
Gardening.isAcidFertiliser(itemstack) ||
|
||||
Gardening.isAlkalineFertiliser(itemstack);
|
||||
gardening.isAcidFertiliser(itemstack) ||
|
||||
gardening.isAlkalineFertiliser(itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,9 +101,10 @@ public class GardenLogic extends FarmLogic {
|
||||
}
|
||||
|
||||
private boolean maintainSoil(World world, BlockPos pos, FarmDirection direction, int extent, IFarmHousing housing) {
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
for (int i = 0; i < extent; ++i) {
|
||||
BlockPos position = pos.offset(direction.getFacing(), i);
|
||||
if (this.fertilised && Gardening.isSoil(getBlock(world, position))) {
|
||||
if (this.fertilised && gardening.isSoil(getBlock(world, position))) {
|
||||
IBlockSoil soil = (IBlockSoil) getBlock(world, position);
|
||||
if (soil.fertilise(world, position, EnumSoilType.FLOWERBED)) {
|
||||
continue;
|
||||
@@ -110,7 +113,7 @@ public class GardenLogic extends FarmLogic {
|
||||
if (getBlock(world, position.up()) == Botany.plant) {
|
||||
world.setBlockToAir(position.up());
|
||||
} else {
|
||||
if (this.acidity != null && Gardening.isSoil(getBlock(world, position))) {
|
||||
if (this.acidity != null && gardening.isSoil(getBlock(world, position))) {
|
||||
IBlockSoil soil = (IBlockSoil) getBlock(world, position);
|
||||
EnumAcidity pH = soil.getPH(world, position);
|
||||
if (pH.ordinal() < this.acidity.ordinal()) {
|
||||
@@ -155,7 +158,7 @@ public class GardenLogic extends FarmLogic {
|
||||
}
|
||||
BlockPos previous = position.offset(cclock.getFacing());
|
||||
final ItemStack soil2 = this.getAsItemStack(world, previous);
|
||||
if (!Gardening.isSoil(soil2.getItem())) {
|
||||
if (!gardening.isSoil(soil2.getItem())) {
|
||||
this.trySetSoil(world, position, housing);
|
||||
}
|
||||
}
|
||||
@@ -306,11 +309,12 @@ public class GardenLogic extends FarmLogic {
|
||||
}
|
||||
|
||||
protected boolean maintainCrops(World world, BlockPos pos, FarmDirection direction, int extent, IFarmHousing housing) {
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
for (int i = 0; i < extent; ++i) {
|
||||
BlockPos position = pos.offset(direction.getFacing(), i);
|
||||
if (this.isAirBlock(world, position) || BlockUtil.isReplaceableBlock(getBlockState(world, position), world, position)) {
|
||||
ItemStack below = this.getAsItemStack(world, position.down());
|
||||
if (Gardening.isSoil(below.getItem())) {
|
||||
if (gardening.isSoil(below.getItem())) {
|
||||
return trySetCrop(world, position, housing);
|
||||
}
|
||||
}
|
||||
@@ -337,7 +341,7 @@ public class GardenLogic extends FarmLogic {
|
||||
}
|
||||
|
||||
public ItemStack getAvailableAcid(IFarmHousing housing) {
|
||||
for (final ItemStack stack : Gardening.getAcidFertilisers()) {
|
||||
for (final ItemStack stack : BotanyCore.getGardening().getAcidFertilisers()) {
|
||||
if (!stack.isEmpty()) {
|
||||
final NonNullList<ItemStack> resources = NonNullList.create();
|
||||
resources.add(stack);
|
||||
@@ -350,7 +354,7 @@ public class GardenLogic extends FarmLogic {
|
||||
}
|
||||
|
||||
public ItemStack getAvailableAlkaline(IFarmHousing housing) {
|
||||
for (final ItemStack stack : Gardening.getAlkalineFertilisers()) {
|
||||
for (final ItemStack stack : BotanyCore.getGardening().getAlkalineFertilisers()) {
|
||||
if (!stack.isEmpty()) {
|
||||
final NonNullList<ItemStack> resources = NonNullList.create();
|
||||
resources.add(stack);
|
||||
|
||||
@@ -41,9 +41,9 @@ import forestry.core.blocks.IColoredBlock;
|
||||
import binnie.botany.Botany;
|
||||
import binnie.botany.api.IFlower;
|
||||
import binnie.botany.api.IFlowerGenome;
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.api.IFlowerType;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.botany.genetics.EnumFlowerType;
|
||||
import binnie.botany.genetics.FlowerDefinition;
|
||||
import binnie.botany.network.PacketID;
|
||||
@@ -151,10 +151,11 @@ public class BlockFlower extends BlockContainer implements IColoredBlock, IState
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
||||
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
|
||||
final TileEntity flower = world.getTileEntity(pos);
|
||||
if (!BinnieCore.getBinnieProxy().isSimulating(world)) {
|
||||
if (flower != null && flower instanceof TileEntityFlower) {
|
||||
final IFlower f = BotanyCore.getFlowerRoot().getMember(stack);
|
||||
final IFlower f = flowerRoot.getMember(stack);
|
||||
if (f != null) {
|
||||
((TileEntityFlower) flower).setRender(new TileEntityFlower.RenderInfo(f, (TileEntityFlower) flower));
|
||||
}
|
||||
@@ -170,7 +171,7 @@ public class BlockFlower extends BlockContainer implements IColoredBlock, IState
|
||||
((TileEntityFlower) flower).create(stack, owner);
|
||||
}
|
||||
}
|
||||
Gardening.tryGrowSection(world, pos);
|
||||
flowerRoot.tryGrowSection(world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,7 +208,7 @@ public class BlockFlower extends BlockContainer implements IColoredBlock, IState
|
||||
}
|
||||
|
||||
protected boolean canPlaceBlockOn(final Block block) {
|
||||
return block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.FARMLAND || Gardening.isSoil(block);
|
||||
return block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.FARMLAND || BotanyCore.getGardening().isSoil(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,10 +38,11 @@ import binnie.botany.api.IAlleleFlowerSpecies;
|
||||
import binnie.botany.api.IFlower;
|
||||
import binnie.botany.api.IFlowerColour;
|
||||
import binnie.botany.api.IFlowerGenome;
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.api.IFlowerType;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.gardening.BlockPlant;
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.botany.genetics.EnumFlowerColor;
|
||||
import binnie.botany.genetics.EnumFlowerType;
|
||||
import binnie.botany.genetics.Flower;
|
||||
@@ -165,7 +166,7 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
|
||||
|
||||
public boolean isBreeding() {
|
||||
final Block roots = this.getWorld().getBlockState(getPos().down()).getBlock();
|
||||
return Gardening.isSoil(roots);
|
||||
return BotanyCore.getGardening().isSoil(roots);
|
||||
}
|
||||
|
||||
public void randomUpdate(final Random rand) {
|
||||
@@ -194,8 +195,9 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
|
||||
}
|
||||
}
|
||||
}
|
||||
final boolean canTolerate = Gardening.canTolerate(this.getFlower(), this.world, pos);
|
||||
final EnumSoilType soil = Gardening.getSoilType(this.world, pos.down());
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
final boolean canTolerate = gardening.canTolerate(this.getFlower(), this.world, pos);
|
||||
final EnumSoilType soil = gardening.getSoilType(this.world, pos.down());
|
||||
if (rand.nextFloat() < this.getFlower().getGenome().getAgeChance()) {
|
||||
if (this.flower.getAge() < 1) {
|
||||
if (canTolerate && light > 6.0f) {
|
||||
@@ -239,10 +241,10 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
|
||||
}
|
||||
|
||||
final Block b2 = world.getBlockState(pos.add(dx2, -1, dz)).getBlock();
|
||||
if (world.isAirBlock(pos.add(dx2, 0, dz)) && Gardening.isSoil(b2)) {
|
||||
if (world.isAirBlock(pos.add(dx2, 0, dz)) && BotanyCore.getGardening().isSoil(b2)) {
|
||||
final IFlower offspring = this.flower.getOffspring(world, pos);
|
||||
if (offspring != null) {
|
||||
Gardening.plant(world, pos.add(dx2, 0, dz), offspring, this.getOwner());
|
||||
BotanyCore.getFlowerRoot().plant(world, pos.add(dx2, 0, dz), offspring, this.getOwner());
|
||||
this.flower.removeMate();
|
||||
dispersed = true;
|
||||
}
|
||||
@@ -274,9 +276,10 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
|
||||
private void doFlowerAge() {
|
||||
this.getFlower().age();
|
||||
if (this.getFlower().getAge() == 1) {
|
||||
Gardening.onGrowFromSeed(this.world, pos);
|
||||
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
|
||||
flowerRoot.onGrowFromSeed(this.world, pos);
|
||||
if (this.getOwner() != null && this.getFlower() != null) {
|
||||
BotanyCore.getFlowerRoot().getBreedingTracker(world, this.getOwner()).registerBirth(this.getFlower());
|
||||
flowerRoot.getBreedingTracker(world, this.getOwner()).registerBirth(this.getFlower());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -405,7 +408,7 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
|
||||
if (this.getSection() != 0) {
|
||||
return this.getRoot().checkIfDead(wasCut);
|
||||
}
|
||||
final EnumSoilType soil = Gardening.getSoilType(this.world, pos);
|
||||
final EnumSoilType soil = BotanyCore.getGardening().getSoilType(this.world, pos);
|
||||
final int maxAge = (int) (this.flower.getMaxAge() * (1.0f + soil.ordinal() * 0.25f));
|
||||
if (this.flower.getAge() > maxAge) {
|
||||
if (!wasCut && this.flower.getMate() != null) {
|
||||
@@ -415,7 +418,7 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
|
||||
if (above instanceof TileEntityFlower) {
|
||||
this.world.setBlockToAir(pos.up());
|
||||
}
|
||||
Gardening.plant(this.world, pos, offspring, this.getOwner());
|
||||
BotanyCore.getFlowerRoot().plant(this.world, pos, offspring, this.getOwner());
|
||||
} else {
|
||||
this.kill();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import binnie.botany.Botany;
|
||||
import binnie.botany.CreativeTabBotany;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.IBlockSoil;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
|
||||
public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
public static final PropertyEnum<Type> PLANT_TYPE = PropertyEnum.create("plant_type", Type.class);
|
||||
@@ -81,7 +82,7 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
|
||||
return super.canPlaceBlockAt(worldIn, pos) || Gardening.isSoil(worldIn.getBlockState(pos).getBlock());
|
||||
return super.canPlaceBlockAt(worldIn, pos) || BotanyCore.getGardening().isSoil(worldIn.getBlockState(pos).getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,7 +123,7 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
}
|
||||
}
|
||||
Block below = world.getBlockState(pos.down()).getBlock();
|
||||
if (Gardening.isSoil(below)) {
|
||||
if (BotanyCore.getGardening().isSoil(below)) {
|
||||
IBlockSoil soil = (IBlockSoil) below;
|
||||
if(rand.nextInt(3) != 0){
|
||||
return;
|
||||
|
||||
@@ -36,6 +36,7 @@ import binnie.botany.api.EnumAcidity;
|
||||
import binnie.botany.api.EnumMoisture;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.IBlockSoil;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
|
||||
public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
public static final PropertyEnum<EnumMoisture> MOISTURE = PropertyEnum.create("moisture", EnumMoisture.class);
|
||||
@@ -199,7 +200,7 @@ public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
EnumMoisture moisture = state.getValue(MOISTURE);
|
||||
EnumMoisture desiredMoisture = Gardening.getNaturalMoisture(world, pos);
|
||||
EnumMoisture desiredMoisture = BotanyCore.getGardening().getNaturalMoisture(world, pos);
|
||||
if (desiredMoisture.ordinal() > moisture.ordinal()) {
|
||||
moisture = ((moisture == EnumMoisture.DRY) ? EnumMoisture.NORMAL : EnumMoisture.DAMP);
|
||||
}
|
||||
@@ -253,7 +254,7 @@ public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
return false;
|
||||
}
|
||||
final IBlockState old = world.getBlockState(pos);
|
||||
return world.setBlockState(pos, Gardening.getSoilBlock(maxLevel, this.weedKilled).getDefaultState().withProperty(ACIDITY, old.getValue(ACIDITY)).withProperty(MOISTURE, old.getValue(MOISTURE)), 2);
|
||||
return world.setBlockState(pos, BotanyCore.getGardening().getSoilBlock(maxLevel, this.weedKilled).getDefaultState().withProperty(ACIDITY, old.getValue(ACIDITY)).withProperty(MOISTURE, old.getValue(MOISTURE)), 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -263,7 +264,7 @@ public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
return false;
|
||||
}
|
||||
final IBlockState old = world.getBlockState(pos);
|
||||
return world.setBlockState(pos, Gardening.getSoilBlock(minLevel, this.weedKilled).getDefaultState().withProperty(ACIDITY, old.getValue(ACIDITY)).withProperty(MOISTURE, old.getValue(MOISTURE)), 2);
|
||||
return world.setBlockState(pos, BotanyCore.getGardening().getSoilBlock(minLevel, this.weedKilled).getDefaultState().withProperty(ACIDITY, old.getValue(ACIDITY)).withProperty(MOISTURE, old.getValue(MOISTURE)), 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package binnie.botany.gardening;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -11,13 +12,10 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.climate.IClimateInfo;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
@@ -28,28 +26,34 @@ import binnie.botany.api.EnumMoisture;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.IBlockSoil;
|
||||
import binnie.botany.api.IFlower;
|
||||
import binnie.botany.flower.TileEntityFlower;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.items.BotanyItems;
|
||||
import binnie.core.BinnieCore;
|
||||
|
||||
public class Gardening {
|
||||
public static final Map<ItemStack, Integer> fertiliserAcid = new LinkedHashMap<>();
|
||||
public static final Map<ItemStack, Integer> fertiliserAlkaline = new LinkedHashMap<>();
|
||||
public static final Map<ItemStack, Integer> fertiliserNutrient = new LinkedHashMap<>();
|
||||
|
||||
public static boolean isSoil(final Block block) {
|
||||
public class Gardening implements IGardeningManager {
|
||||
private final Map<ItemStack, Integer> fertiliserAcid = new LinkedHashMap<>();
|
||||
private final Map<ItemStack, Integer> fertiliserAlkaline = new LinkedHashMap<>();
|
||||
private final Map<ItemStack, Integer> fertiliserNutrient = new LinkedHashMap<>();
|
||||
|
||||
public Gardening() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSoil(final Block block) {
|
||||
return block instanceof IBlockSoil;
|
||||
}
|
||||
|
||||
public static boolean isSoil(final Item item) {
|
||||
|
||||
@Override
|
||||
public boolean isSoil(final Item item) {
|
||||
return item instanceof ItemBlock && isSoil(((ItemBlock) item).getBlock());
|
||||
}
|
||||
|
||||
public static boolean isSoil(final ItemStack item) {
|
||||
|
||||
@Override
|
||||
public boolean isSoil(final ItemStack item) {
|
||||
return isSoil(item.getItem());
|
||||
}
|
||||
|
||||
public static EnumMoisture getNaturalMoisture(World world, BlockPos pos) {
|
||||
|
||||
@Override
|
||||
public EnumMoisture getNaturalMoisture(World world, BlockPos pos) {
|
||||
float bias = getBiomeMoisture(world, pos);
|
||||
for (int dx = -1; dx < 2; ++dx) {
|
||||
for (int dz = -1; dz < 2; ++dz) {
|
||||
@@ -76,85 +80,71 @@ public class Gardening {
|
||||
}
|
||||
return (bias <= -1.0f) ? EnumMoisture.DRY : ((bias >= 1.0f) ? EnumMoisture.DAMP : EnumMoisture.NORMAL);
|
||||
}
|
||||
|
||||
public static EnumAcidity getNaturalPH(World world, BlockPos pos) {
|
||||
|
||||
@Override
|
||||
public EnumAcidity getNaturalPH(World world, BlockPos pos) {
|
||||
final float bias = getBiomePH(world, pos);
|
||||
return (bias <= -1.0f) ? EnumAcidity.ACID : ((bias >= 1.0f) ? EnumAcidity.ALKALINE : EnumAcidity.NEUTRAL);
|
||||
}
|
||||
|
||||
public static float getBiomeMoisture(World world, BlockPos pos) {
|
||||
|
||||
@Override
|
||||
public float getBiomeMoisture(World world, BlockPos pos) {
|
||||
IClimateInfo info = ForestryAPI.climateManager.getInfo(world, pos);
|
||||
double humidity = info.getHumidity();
|
||||
double temperature = info.getTemperature();
|
||||
double m = 3.2 * (humidity - 0.5) - 0.4 * (1.0 + temperature + 0.5 * temperature * temperature) + 1.1 - 1.6 * (temperature - 0.9) * (temperature - 0.9) - 0.002 * (pos.getY() - 64);
|
||||
return (float) ((m == 0.0) ? m : ((m < 0.0) ? (-Math.sqrt(m * m)) : Math.sqrt(m * m)));
|
||||
}
|
||||
|
||||
public static float getBiomePH(World world, BlockPos pos) {
|
||||
|
||||
@Override
|
||||
public float getBiomePH(World world, BlockPos pos) {
|
||||
IClimateInfo info = ForestryAPI.climateManager.getInfo(world, pos);
|
||||
double humidity = info.getHumidity();
|
||||
double temperature = info.getTemperature();
|
||||
return (float) (-3.0 * (humidity - 0.5) + 0.5 * (temperature - 0.699999988079071) * (temperature - 0.699999988079071) + 0.02f * (pos.getY() - 64) - 0.15000000596046448);
|
||||
}
|
||||
|
||||
public static void plantSoil(final World world, final BlockPos pos, final EnumSoilType soil, final EnumMoisture moisture, final EnumAcidity acidity) {
|
||||
|
||||
@Override
|
||||
public void plantSoil(final World world, final BlockPos pos, final EnumSoilType soil, final EnumMoisture moisture, final EnumAcidity acidity) {
|
||||
final int meta = moisture.ordinal() + acidity.ordinal() * 3;
|
||||
world.setBlockState(pos, getSoilBlock(soil).getStateFromMeta(meta), 2);
|
||||
}
|
||||
|
||||
public static boolean plant(final World world, final BlockPos pos, final IFlower flower, final GameProfile owner) {
|
||||
final boolean set = world.setBlockState(pos, Botany.flower.getDefaultState());
|
||||
if (!set) {
|
||||
return false;
|
||||
}
|
||||
final TileEntity tileFlower = world.getTileEntity(pos);
|
||||
final TileEntity below = world.getTileEntity(pos.down());
|
||||
if (tileFlower != null && tileFlower instanceof TileEntityFlower) {
|
||||
if (below instanceof TileEntityFlower) {
|
||||
((TileEntityFlower) tileFlower).setSection(((TileEntityFlower) below).getSection());
|
||||
} else {
|
||||
((TileEntityFlower) tileFlower).create(flower, owner);
|
||||
}
|
||||
}
|
||||
tryGrowSection(world, pos);
|
||||
return true;
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getAcidFertilisers() {
|
||||
return Collections.unmodifiableSet(fertiliserAcid.keySet());
|
||||
}
|
||||
|
||||
public static void tryGrowSection(final World world, final BlockPos pos) {
|
||||
if (!BinnieCore.getBinnieProxy().isSimulating(world)) {
|
||||
return;
|
||||
}
|
||||
final TileEntity flower = world.getTileEntity(pos);
|
||||
if (flower != null && flower instanceof TileEntityFlower) {
|
||||
final IFlower iflower = ((TileEntityFlower) flower).getFlower();
|
||||
final int section = ((TileEntityFlower) flower).getSection();
|
||||
if (iflower != null && section < iflower.getGenome().getPrimary().getType().getSections() - 1 && iflower.getAge() > 0) {
|
||||
world.setBlockState(pos.up(), Botany.flower.getDefaultState());
|
||||
final TileEntity tileFlower = world.getTileEntity(pos.up());
|
||||
if (tileFlower != null && tileFlower instanceof TileEntityFlower) {
|
||||
((TileEntityFlower) tileFlower).setSection(section + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getAlkalineFertilisers() {
|
||||
return Collections.unmodifiableSet(fertiliserAlkaline.keySet());
|
||||
}
|
||||
|
||||
public static void onGrowFromSeed(final World world, final BlockPos pos) {
|
||||
tryGrowSection(world, pos);
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getNutrientFertilisers() {
|
||||
return Collections.unmodifiableSet(fertiliserNutrient.keySet());
|
||||
}
|
||||
|
||||
public static Collection<ItemStack> getAcidFertilisers() {
|
||||
return Gardening.fertiliserAcid.keySet();
|
||||
|
||||
@Override
|
||||
public void registerAcidFertiliser(ItemStack stack, int strength) {
|
||||
ModuleGardening.queuedAcidFertilisers.put(stack, strength);
|
||||
fertiliserAcid.put(stack, strength);
|
||||
}
|
||||
|
||||
public static Collection<ItemStack> getAlkalineFertilisers() {
|
||||
return Gardening.fertiliserAlkaline.keySet();
|
||||
|
||||
@Override
|
||||
public void registerAlkalineFertiliser(ItemStack stack, int strength) {
|
||||
ModuleGardening.queuedAlkalineFertilisers.put(stack, strength);
|
||||
fertiliserAlkaline.put(stack, strength);
|
||||
}
|
||||
|
||||
public static Collection<ItemStack> getNutrientFertilisers() {
|
||||
return Gardening.fertiliserNutrient.keySet();
|
||||
|
||||
@Override
|
||||
public void registerNutrientFertiliser(ItemStack stack, int strength) {
|
||||
ModuleGardening.queuedNutrientFertilisers.put(stack, strength);
|
||||
fertiliserNutrient.put(stack, strength);
|
||||
}
|
||||
|
||||
public static boolean isAcidFertiliser(final ItemStack itemstack) {
|
||||
|
||||
@Override
|
||||
public boolean isAcidFertiliser(final ItemStack itemstack) {
|
||||
for (final ItemStack stack : getAcidFertilisers()) {
|
||||
if (!stack.isEmpty() && stack.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
@@ -162,8 +152,9 @@ public class Gardening {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isAlkalineFertiliser(final ItemStack itemstack) {
|
||||
|
||||
@Override
|
||||
public boolean isAlkalineFertiliser(final ItemStack itemstack) {
|
||||
for (final ItemStack stack : getAlkalineFertilisers()) {
|
||||
if (!stack.isEmpty() && stack.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
@@ -171,8 +162,9 @@ public class Gardening {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isNutrientFertiliser(final ItemStack itemstack) {
|
||||
|
||||
@Override
|
||||
public boolean isNutrientFertiliser(final ItemStack itemstack) {
|
||||
for (final ItemStack stack : getNutrientFertilisers()) {
|
||||
if (!stack.isEmpty() && stack.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
@@ -180,27 +172,29 @@ public class Gardening {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getFertiliserStrength(final ItemStack stack) {
|
||||
for (final Map.Entry<ItemStack, Integer> entry : Gardening.fertiliserAcid.entrySet()) {
|
||||
|
||||
@Override
|
||||
public int getFertiliserStrength(final ItemStack stack) {
|
||||
for (final Map.Entry<ItemStack, Integer> entry : fertiliserAcid.entrySet()) {
|
||||
if (entry.getKey().isItemEqual(stack)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
for (final Map.Entry<ItemStack, Integer> entry : Gardening.fertiliserAlkaline.entrySet()) {
|
||||
for (final Map.Entry<ItemStack, Integer> entry : fertiliserAlkaline.entrySet()) {
|
||||
if (entry.getKey().isItemEqual(stack)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
for (final Map.Entry<ItemStack, Integer> entry : Gardening.fertiliserNutrient.entrySet()) {
|
||||
for (final Map.Entry<ItemStack, Integer> entry : fertiliserNutrient.entrySet()) {
|
||||
if (entry.getKey().isItemEqual(stack)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static boolean canTolerate(@Nullable final IFlower flower, final World world, final BlockPos pos) {
|
||||
|
||||
@Override
|
||||
public boolean canTolerate(@Nullable final IFlower flower, final World world, final BlockPos pos) {
|
||||
if (flower == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -211,18 +205,21 @@ public class Gardening {
|
||||
return canTolerate(flower, EnumAcidity.values()[soilMeta / 3 % 3], EnumMoisture.values()[soilMeta % 3], EnumTemperature.getFromValue(biome.getTemperature()));
|
||||
}
|
||||
|
||||
public static EnumSoilType getSoilType(final World world, final BlockPos pos) {
|
||||
@Override
|
||||
public EnumSoilType getSoilType(final World world, final BlockPos pos) {
|
||||
if (world.getBlockState(pos).getBlock() instanceof IBlockSoil) {
|
||||
return ((IBlockSoil) world.getBlockState(pos).getBlock()).getType(world, pos);
|
||||
}
|
||||
return EnumSoilType.SOIL;
|
||||
}
|
||||
|
||||
public static Block getSoilBlock(final EnumSoilType type) {
|
||||
|
||||
@Override
|
||||
public Block getSoilBlock(final EnumSoilType type) {
|
||||
return getSoilBlock(type, false);
|
||||
}
|
||||
|
||||
public static Block getSoilBlock(final EnumSoilType type, final boolean weedkill) {
|
||||
|
||||
@Override
|
||||
public Block getSoilBlock(final EnumSoilType type, final boolean weedkill) {
|
||||
switch (type) {
|
||||
case FLOWERBED: {
|
||||
return weedkill ? Botany.flowerbedNoWeed : Botany.flowerbed;
|
||||
@@ -235,16 +232,19 @@ public class Gardening {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canTolerate(IFlower flower, EnumAcidity ePH, EnumMoisture eMoisture, EnumTemperature eTemp) {
|
||||
|
||||
@Override
|
||||
public boolean canTolerate(IFlower flower, EnumAcidity ePH, EnumMoisture eMoisture, EnumTemperature eTemp) {
|
||||
return flower.getGenome().canTolerate(ePH) && flower.getGenome().canTolerate(eMoisture) && flower.getGenome().canTolerate(eTemp);
|
||||
}
|
||||
|
||||
public static boolean isWeedkiller(ItemStack heldItem) {
|
||||
|
||||
@Override
|
||||
public boolean isWeedkiller(ItemStack heldItem) {
|
||||
return heldItem.isItemEqual(BotanyItems.Weedkiller.get(1));
|
||||
}
|
||||
|
||||
public static boolean addWeedKiller(World world, BlockPos pos) {
|
||||
|
||||
@Override
|
||||
public boolean addWeedKiller(World world, BlockPos pos) {
|
||||
if (!(world.getBlockState(pos).getBlock() instanceof IBlockSoil)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import binnie.botany.CreativeTabBotany;
|
||||
import binnie.botany.api.EnumAcidity;
|
||||
import binnie.botany.api.EnumMoisture;
|
||||
import binnie.botany.api.IBlockSoil;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.core.BinnieCore;
|
||||
|
||||
public class ItemSoilMeter extends Item implements IItemModelRegister {
|
||||
@@ -63,15 +65,16 @@ public class ItemSoilMeter extends Item implements IItemModelRegister {
|
||||
@Override
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
Block block = worldIn.getBlockState(pos).getBlock();
|
||||
if (!Gardening.isSoil(block)) {
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
if (!gardening.isSoil(block)) {
|
||||
pos = pos.down();
|
||||
block = worldIn.getBlockState(pos).getBlock();
|
||||
}
|
||||
if (!Gardening.isSoil(block)) {
|
||||
if (!gardening.isSoil(block)) {
|
||||
pos = pos.down();
|
||||
block = worldIn.getBlockState(pos).getBlock();
|
||||
}
|
||||
if (Gardening.isSoil(block) && !BinnieCore.getBinnieProxy().isSimulating(worldIn)) {
|
||||
if (gardening.isSoil(block) && !BinnieCore.getBinnieProxy().isSimulating(worldIn)) {
|
||||
IBlockSoil soil = (IBlockSoil) block;
|
||||
String info = Binnie.LANGUAGE.localise("botany.soil.type") + ": ";
|
||||
info = info + soil.getType(worldIn, pos).getTranslated(true);
|
||||
|
||||
@@ -34,6 +34,8 @@ import binnie.botany.CreativeTabBotany;
|
||||
import binnie.botany.api.EnumAcidity;
|
||||
import binnie.botany.api.EnumMoisture;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
|
||||
public class ItemTrowel extends Item implements IItemModelRegister {
|
||||
protected final ToolMaterial theToolMaterial;
|
||||
@@ -70,9 +72,10 @@ public class ItemTrowel extends Item implements IItemModelRegister {
|
||||
if (worldIn.isRemote) {
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
EnumMoisture moisture = Gardening.getNaturalMoisture(worldIn, pos);
|
||||
EnumAcidity acidity = Gardening.getNaturalPH(worldIn, pos);
|
||||
Gardening.plantSoil(worldIn, pos, EnumSoilType.SOIL, moisture, acidity);
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
EnumMoisture moisture = gardening.getNaturalMoisture(worldIn, pos);
|
||||
EnumAcidity acidity = gardening.getNaturalPH(worldIn, pos);
|
||||
gardening.plantSoil(worldIn, pos, EnumSoilType.SOIL, moisture, acidity);
|
||||
stack.damageItem(1, player);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import binnie.botany.CreativeTabBotany;
|
||||
import binnie.botany.api.EnumAcidity;
|
||||
import binnie.botany.api.EnumMoisture;
|
||||
import binnie.botany.api.EnumSoilType;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.ceramic.BlockCeramic;
|
||||
import binnie.botany.ceramic.BlockCeramicPatterned;
|
||||
import binnie.botany.ceramic.BlockStainedGlass;
|
||||
@@ -31,6 +32,7 @@ import binnie.botany.ceramic.TileCeramic;
|
||||
import binnie.botany.ceramic.brick.BlockCeramicBrick;
|
||||
import binnie.botany.ceramic.brick.ItemCeramicBrick;
|
||||
import binnie.botany.ceramic.brick.TileCeramicBrick;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.farm.CircuitGarden;
|
||||
import binnie.botany.flower.ItemInsulatedTube;
|
||||
import binnie.botany.genetics.EnumFlowerColor;
|
||||
@@ -140,6 +142,7 @@ public class ModuleGardening implements IInitializable {
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
GameRegistry.addRecipe(new CeramicTileRecipe());
|
||||
for (int mat = 0; mat < 4; ++mat) {
|
||||
for (int insulate = 0; insulate < 6; ++insulate) {
|
||||
@@ -163,28 +166,28 @@ public class ModuleGardening implements IInitializable {
|
||||
GameRegistry.addShapelessRecipe(BotanyItems.PulpPowder.get(4), Mods.Forestry.stack("wood_pulp"));
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(BotanyItems.SulphurPowder.get(4), "dustSulphur"));
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(Botany.pigment, 2, EnumFlowerColor.Black.ordinal()), "pigment", "pigment", "dyeBlack"));
|
||||
ModuleGardening.queuedAcidFertilisers.put(BotanyItems.SulphurPowder.get(1), 1);
|
||||
ModuleGardening.queuedAcidFertilisers.put(BotanyItems.MulchPowder.get(1), 1);
|
||||
ModuleGardening.queuedAcidFertilisers.put(Mods.Forestry.stack("mulch"), 2);
|
||||
gardening.registerAcidFertiliser(BotanyItems.SulphurPowder.get(1), 1);
|
||||
gardening.registerAcidFertiliser(BotanyItems.MulchPowder.get(1), 1);
|
||||
gardening.registerAcidFertiliser(Mods.Forestry.stack("mulch"), 2);
|
||||
for (final ItemStack stack : OreDictionary.getOres("dustSulfur")) {
|
||||
ModuleGardening.queuedAcidFertilisers.put(stack, 2);
|
||||
gardening.registerAcidFertiliser(stack, 2);
|
||||
}
|
||||
ModuleGardening.queuedAlkalineFertilisers.put(BotanyItems.AshPowder.get(1), 1);
|
||||
ModuleGardening.queuedAlkalineFertilisers.put(BotanyItems.PulpPowder.get(1), 1);
|
||||
ModuleGardening.queuedAlkalineFertilisers.put(Mods.Forestry.stack("ash"), 2);
|
||||
ModuleGardening.queuedAlkalineFertilisers.put(Mods.Forestry.stack("wood_pulp"), 2);
|
||||
ModuleGardening.queuedNutrientFertilisers.put(BotanyItems.CompostPowder.get(1), 1);
|
||||
ModuleGardening.queuedNutrientFertilisers.put(BotanyItems.FertiliserPowder.get(1), 1);
|
||||
ModuleGardening.queuedNutrientFertilisers.put(Mods.Forestry.stack("fertilizer_bio"), 2);
|
||||
ModuleGardening.queuedNutrientFertilisers.put(Mods.Forestry.stack("fertilizer_compound"), 2);
|
||||
gardening.registerAlkalineFertiliser(BotanyItems.AshPowder.get(1), 1);
|
||||
gardening.registerAlkalineFertiliser(BotanyItems.PulpPowder.get(1), 1);
|
||||
gardening.registerAlkalineFertiliser(Mods.Forestry.stack("ash"), 2);
|
||||
gardening.registerAlkalineFertiliser(Mods.Forestry.stack("wood_pulp"), 2);
|
||||
gardening.registerNutrientFertiliser(BotanyItems.CompostPowder.get(1), 1);
|
||||
gardening.registerNutrientFertiliser(BotanyItems.FertiliserPowder.get(1), 1);
|
||||
gardening.registerNutrientFertiliser(Mods.Forestry.stack("fertilizer_bio"), 2);
|
||||
gardening.registerNutrientFertiliser(Mods.Forestry.stack("fertilizer_compound"), 2);
|
||||
for (final Map.Entry<ItemStack, Integer> entry : ModuleGardening.queuedAcidFertilisers.entrySet()) {
|
||||
this.addAcidFertiliser(entry.getKey(), entry.getValue());
|
||||
this.addAcidFertiliserRecipe(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (final Map.Entry<ItemStack, Integer> entry : ModuleGardening.queuedAlkalineFertilisers.entrySet()) {
|
||||
this.addAlkalineFertiliser(entry.getKey(), entry.getValue());
|
||||
this.addAlkalineFertiliserRecipe(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (final Map.Entry<ItemStack, Integer> entry : ModuleGardening.queuedNutrientFertilisers.entrySet()) {
|
||||
this.addNutrientFertiliser(entry.getKey(), entry.getValue());
|
||||
this.addNutrientFertiliserRecipe(entry.getKey(), entry.getValue());
|
||||
}
|
||||
GameRegistry.addRecipe(BotanyItems.Mortar.get(6), " c ", "cgc", " c ", 'c', Items.CLAY_BALL, 'g', Blocks.GRAVEL);
|
||||
for (final EnumFlowerColor c : EnumFlowerColor.values()) {
|
||||
@@ -201,13 +204,12 @@ public class ModuleGardening implements IInitializable {
|
||||
|
||||
private ItemStack getStack(final int type, final int pH, final int moisture) {
|
||||
if (type >= 0 && type <= 2 && pH >= 0 && pH <= 2 && moisture >= 0 && moisture <= 2) {
|
||||
return new ItemStack(Gardening.getSoilBlock(EnumSoilType.values()[type]), 1, BlockSoil.getMeta(EnumAcidity.values()[pH], EnumMoisture.values()[moisture]));
|
||||
return new ItemStack(BotanyCore.getGardening().getSoilBlock(EnumSoilType.values()[type]), 1, BlockSoil.getMeta(EnumAcidity.values()[pH], EnumMoisture.values()[moisture]));
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private void addAcidFertiliser(final ItemStack stack, final int strengthMax) {
|
||||
Gardening.fertiliserAcid.put(stack, strengthMax);
|
||||
private void addAcidFertiliserRecipe(final ItemStack stack, final int strengthMax) {
|
||||
for (int moisture = 0; moisture < 3; ++moisture) {
|
||||
for (int pH = 0; pH < 3; ++pH) {
|
||||
for (int type = 0; type < 3; ++type) {
|
||||
@@ -231,8 +233,7 @@ public class ModuleGardening implements IInitializable {
|
||||
}
|
||||
}
|
||||
|
||||
private void addAlkalineFertiliser(final ItemStack stack, final int strengthMax) {
|
||||
Gardening.fertiliserAlkaline.put(stack, strengthMax);
|
||||
private void addAlkalineFertiliserRecipe(final ItemStack stack, final int strengthMax) {
|
||||
for (int moisture = 0; moisture < 3; ++moisture) {
|
||||
for (int pH = 0; pH < 3; ++pH) {
|
||||
for (int type = 0; type < 3; ++type) {
|
||||
@@ -256,8 +257,7 @@ public class ModuleGardening implements IInitializable {
|
||||
}
|
||||
}
|
||||
|
||||
private void addNutrientFertiliser(final ItemStack stack, final int strengthMax) {
|
||||
Gardening.fertiliserNutrient.put(stack, strengthMax);
|
||||
private void addNutrientFertiliserRecipe(final ItemStack stack, final int strengthMax) {
|
||||
for (int moisture = 0; moisture < 3; ++moisture) {
|
||||
for (int pH = 0; pH < 3; ++pH) {
|
||||
for (int type = 0; type < 3; ++type) {
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.util.Random;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -34,6 +36,7 @@ import binnie.botany.api.IFlower;
|
||||
import binnie.botany.api.IFlowerGenome;
|
||||
import binnie.botany.api.IFlowerMutation;
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.flower.TileEntityFlower;
|
||||
|
||||
public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
|
||||
static final String UID = "rootFlowers";
|
||||
@@ -277,4 +280,49 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
|
||||
}
|
||||
return FlowerRoot.colourMixes;
|
||||
}
|
||||
|
||||
public boolean plant(World world, BlockPos pos, IFlower flower, GameProfile owner) {
|
||||
boolean set = world.setBlockState(pos, Botany.flower.getDefaultState());
|
||||
if (!set) {
|
||||
return false;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
TileEntity below = world.getTileEntity(pos.down());
|
||||
if (tile != null && tile instanceof TileEntityFlower) {
|
||||
TileEntityFlower tileFlower = (TileEntityFlower) tile;
|
||||
if (below instanceof TileEntityFlower) {
|
||||
tileFlower.setSection(((TileEntityFlower) below).getSection());
|
||||
} else {
|
||||
tileFlower.create(flower, owner);
|
||||
}
|
||||
}
|
||||
tryGrowSection(world, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tryGrowSection(World world, BlockPos pos) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
TileEntity tileFlower = world.getTileEntity(pos);
|
||||
if(tileFlower == null || !(tileFlower instanceof TileEntityFlower)){
|
||||
return;
|
||||
}
|
||||
IFlower flower = ((TileEntityFlower) tileFlower).getFlower();
|
||||
int section = ((TileEntityFlower) tileFlower).getSection();
|
||||
if(flower == null || section >= flower.getGenome().getPrimary().getType().getSections() - 1 || flower.getAge() <= 0){
|
||||
return;
|
||||
}
|
||||
world.setBlockState(pos.up(), Botany.flower.getDefaultState());
|
||||
TileEntity flowerAbove = world.getTileEntity(pos.up());
|
||||
if (flowerAbove != null && flowerAbove instanceof TileEntityFlower) {
|
||||
((TileEntityFlower) flowerAbove).setSection(section + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGrowFromSeed(World world, BlockPos pos) {
|
||||
tryGrowSection(world, pos);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package binnie.genetics.machine.acclimatiser;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import binnie.botany.gardening.Gardening;
|
||||
import binnie.botany.api.IGardeningManager;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
|
||||
public enum ToleranceType {
|
||||
Temperature,
|
||||
@@ -18,11 +19,12 @@ public enum ToleranceType {
|
||||
return Acclimatiser.getHumidityEffect(stack);
|
||||
}
|
||||
case PH: {
|
||||
if (Gardening.isAcidFertiliser(stack)) {
|
||||
return -0.5f * Gardening.getFertiliserStrength(stack);
|
||||
IGardeningManager gardening = BotanyCore.getGardening();
|
||||
if (gardening.isAcidFertiliser(stack)) {
|
||||
return -0.5f * gardening.getFertiliserStrength(stack);
|
||||
}
|
||||
if (Gardening.isAlkalineFertiliser(stack)) {
|
||||
return 0.5f * Gardening.getFertiliserStrength(stack);
|
||||
if (gardening.isAlkalineFertiliser(stack)) {
|
||||
return 0.5f * gardening.getFertiliserStrength(stack);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user