mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Add honey comb blocks and improve greenhouse nursery
This commit is contained in:
1 parent
81ef5d536f
commit
ca7d6dbc66
31 files changed
+558
-30
No files matched your search
@@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@API(apiVersion = "2.1.0", owner = "ForestryAPI|core", provides = "ForestryAPI|farming")
|
||||
@API(apiVersion = "2.2.0", owner = "ForestryAPI|core", provides = "ForestryAPI|farming")
|
||||
package forestry.api.farming;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.IIndividualLiving;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -48,6 +51,27 @@ public interface IButterfly extends IIndividualLiving {
|
||||
*/
|
||||
@Nullable
|
||||
IButterfly spawnCaterpillar(World world, IButterflyNursery nursery);
|
||||
|
||||
/**
|
||||
* Determines whether the caterpillar can grow.
|
||||
*
|
||||
* @param cocoon the {@link IButterflyCocoon} the caterpillar resides in.
|
||||
* @param nursery the {@link IButterflyNursery} of the caterpillar.
|
||||
* @return an empty set if the caterpillar can grow, a set of error states if the caterpillar can not grow
|
||||
* @since 5.3.3
|
||||
*/
|
||||
Set<IErrorState> getCanGrow(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon);
|
||||
|
||||
/**
|
||||
* Determines whether the caterpillar can spawn. (Used to auto-spawn butterflies out of a cocoon.)
|
||||
*
|
||||
* @param cocoon the {@link IButterflyCocoon} the caterpillar resides in.
|
||||
* @param nursery the {@link IButterflyNursery} of the caterpillar.
|
||||
* @return an empty set if the caterpillar can spawn, a set of error states if the caterpillar can not spawn
|
||||
* @since 5.3.3
|
||||
*/
|
||||
Set<IErrorState> getCanSpawn(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon);
|
||||
|
||||
|
||||
/**
|
||||
* @param playerKill Whether or not the butterfly was killed by a player.
|
||||
|
||||
@@ -13,7 +13,7 @@ package forestry.api.lepidopterology;
|
||||
import forestry.api.genetics.IHousing;
|
||||
|
||||
public interface IButterflyCocoon extends IHousing {
|
||||
|
||||
|
||||
IButterfly getCaterpillar();
|
||||
|
||||
void setCaterpillar(IButterfly butterfly);
|
||||
|
||||
@@ -10,15 +10,19 @@ import javax.annotation.Nullable;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IHousing;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IButterflyNursery extends IHousing, IClimateProvider {
|
||||
@Nullable
|
||||
IButterfly getCaterpillar();
|
||||
|
||||
@Nullable
|
||||
IIndividual getNanny();
|
||||
|
||||
void setCaterpillar(@Nullable IButterfly caterpillar);
|
||||
|
||||
boolean canNurse(IButterfly caterpillar);
|
||||
|
||||
World getWorldObj();
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@API(apiVersion = "1.3.0", owner = "ForestryAPI|core", provides = "ForestryAPI|lepidopterology")
|
||||
@API(apiVersion = "1.4.0", owner = "ForestryAPI|core", provides = "ForestryAPI|lepidopterology")
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -10,6 +10,7 @@ import forestry.api.climate.IClimateSourceProvider;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.greenhouse.IGreenhouseListener;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
@@ -32,7 +33,7 @@ public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> exte
|
||||
IClimatiserDefinition getDefinition();
|
||||
}
|
||||
|
||||
interface Nursery extends IGreenhouseComponent {
|
||||
interface Nursery extends IGreenhouseComponent, IButterflyNursery {
|
||||
void addCocoonLoot(IButterflyCocoon cocoon, NonNullList<ItemStack> loot);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.greenhouse.IGreenhouseHousing;
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlProvider {
|
||||
|
||||
@@ -21,6 +22,16 @@ public interface IGreenhouseController extends IMultiblockController, IGreenhous
|
||||
*/
|
||||
Set<IInternalBlock> getInternalBlocks();
|
||||
|
||||
/**
|
||||
* spawns a butterfly in a greenhouse
|
||||
* @return true if it has spawned it, and false if it has not
|
||||
*/
|
||||
boolean spawnButterfly(IGreenhouseComponent.Nursery nursery);
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #spawnButterfly(IButterflyCocoon)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean spawnButterfly(IButterfly butterfly);
|
||||
|
||||
IClimateRegion getRegion();
|
||||
|
||||
@@ -38,6 +38,7 @@ import forestry.api.storage.ICrateRegistry;
|
||||
import forestry.api.storage.StorageManager;
|
||||
import forestry.apiculture.blocks.BlockAlvearyType;
|
||||
import forestry.apiculture.blocks.BlockCandle;
|
||||
import forestry.apiculture.blocks.BlockHoneyComb;
|
||||
import forestry.apiculture.blocks.BlockRegistryApiculture;
|
||||
import forestry.apiculture.capabilities.ArmorApiarist;
|
||||
import forestry.apiculture.commands.CommandBee;
|
||||
@@ -487,6 +488,15 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
"C",
|
||||
'B', new ItemStack(blocks.apiary),
|
||||
'C', Items.MINECART);
|
||||
for(int i = 0;i < blocks.beeCombs.length;i++){
|
||||
BlockHoneyComb block = blocks.beeCombs[i];
|
||||
for(int m = 0;m < EnumHoneyComb.VALUES.length - i * 16;m++){
|
||||
RecipeUtil.addRecipe(new ItemStack(block, 1, m),
|
||||
"###",
|
||||
"###",
|
||||
"###", '#', items.beeComb.get(EnumHoneyComb.get(i * 16 + m), 1));
|
||||
}
|
||||
}
|
||||
|
||||
// FOOD STUFF
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FOOD)) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package forestry.apiculture.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public enum BlockBeeProductType implements IStringSerializable {
|
||||
BEE_COMBS,
|
||||
BEESWAX;
|
||||
|
||||
public static final BlockBeeProductType[] VALUES = values();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public int getMeta() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -332,6 +332,7 @@ public class BlockCandle extends BlockTorch implements IItemModelRegister, ITile
|
||||
return new ItemStack(this, amount, 1);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex) {
|
||||
if (worldIn != null && pos != null) {
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package forestry.apiculture.blocks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.apiculture.items.EnumHoneyComb;
|
||||
import forestry.core.blocks.IBlockWithMeta;
|
||||
import forestry.core.blocks.IColoredBlock;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class BlockHoneyComb extends Block implements IItemModelRegister, IBlockWithMeta, IColoredBlock, IStateMapperRegister {
|
||||
public final int minMeta;
|
||||
|
||||
public static final BlockHoneyComb[] create(){
|
||||
BlockHoneyComb[] blocks = new BlockHoneyComb[2];
|
||||
for(int i = 0;i < blocks.length;i++){
|
||||
HoneyCombPredicate filter = new HoneyCombPredicate(i, 16);
|
||||
PropertyEnum<EnumHoneyComb> variant = PropertyEnum.create("type", EnumHoneyComb.class, filter);
|
||||
blocks[i] = new BlockHoneyComb(filter.minMeta) {
|
||||
@Override
|
||||
protected PropertyEnum<EnumHoneyComb> getVariant() {
|
||||
return variant;
|
||||
}
|
||||
};
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public BlockHoneyComb(int minMeta) {
|
||||
super(Material.CLOTH);
|
||||
setHardness(1F);
|
||||
setCreativeTab(Tabs.tabApiculture);
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(getVariant(), getVariant().getAllowedValues().iterator().next()));
|
||||
this.minMeta = minMeta;
|
||||
}
|
||||
|
||||
protected abstract PropertyEnum<EnumHoneyComb> getVariant();
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, getVariant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(getVariant()).ordinal()-minMeta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(getVariant(), EnumHoneyComb.get(minMeta + meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
|
||||
for (EnumHoneyComb honeyComb : getVariant().getAllowedValues()) {
|
||||
if(!honeyComb.isSecret() || Config.isDebug){
|
||||
list.add(get(honeyComb));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return "tile.for.bee_combs";
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public BlockRenderLayer getBlockLayer() {
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
for (EnumHoneyComb comb : getVariant().getAllowedValues()) {
|
||||
manager.registerItemModel(item, comb.ordinal()-minMeta, "block_bee_combs");
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack get(EnumHoneyComb honeyComb) {
|
||||
return new ItemStack(this, 1, honeyComb.ordinal() - minMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameFromMeta(int meta) {
|
||||
EnumHoneyComb honeyComb = EnumHoneyComb.get(minMeta + meta);
|
||||
return honeyComb.name;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) {
|
||||
int meta = getMetaFromState(state);
|
||||
EnumHoneyComb honeyComb = EnumHoneyComb.get(minMeta + meta);
|
||||
if (tintIndex == 1) {
|
||||
return honeyComb.primaryColor;
|
||||
} else {
|
||||
return honeyComb.secondaryColor;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
ModelLoader.setCustomStateMapper(this, new HoneyCombStateMapper());
|
||||
}
|
||||
|
||||
private static class HoneyCombPredicate implements Predicate<EnumHoneyComb> {
|
||||
private final int minMeta;
|
||||
private final int maxMeta;
|
||||
|
||||
public HoneyCombPredicate(int blockNumber, int variantsPerBlock) {
|
||||
this.minMeta = blockNumber * variantsPerBlock;
|
||||
this.maxMeta = minMeta + variantsPerBlock - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(@Nullable EnumHoneyComb honeyComb) {
|
||||
return honeyComb != null && honeyComb.ordinal() >= minMeta && honeyComb.ordinal() <= maxMeta;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static class HoneyCombStateMapper extends StateMapperBase {
|
||||
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
|
||||
return new ModelResourceLocation(Constants.MOD_ID + ":bee_combs", "normal");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ package forestry.apiculture.blocks;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.apiculture.items.ItemBlockHoneyComb;
|
||||
import forestry.apiculture.items.ItemBlockCandle;
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.blocks.BlockRegistry;
|
||||
@@ -27,6 +28,7 @@ public class BlockRegistryApiculture extends BlockRegistry {
|
||||
public final BlockBeeHives beehives;
|
||||
public final BlockCandle candle;
|
||||
public final BlockStump stump;
|
||||
public final BlockHoneyComb[] beeCombs;
|
||||
private final Map<BlockAlvearyType, BlockAlveary> alvearyBlockMap;
|
||||
|
||||
public BlockRegistryApiculture() {
|
||||
@@ -48,6 +50,12 @@ public class BlockRegistryApiculture extends BlockRegistry {
|
||||
registerBlock(candle, new ItemBlockCandle(candle), "candle");
|
||||
stump = new BlockStump();
|
||||
registerBlock(stump, new ItemBlockForestry(stump), "stump");
|
||||
|
||||
beeCombs = BlockHoneyComb.create();
|
||||
for(int i = 0;i < beeCombs.length;i++){
|
||||
BlockHoneyComb block = beeCombs[i];
|
||||
registerBlock(block, new ItemBlockHoneyComb(block), "bee_combs_" + i);
|
||||
}
|
||||
|
||||
alvearyBlockMap = BlockAlveary.create();
|
||||
for (BlockAlveary block : alvearyBlockMap.values()) {
|
||||
|
||||
@@ -13,7 +13,9 @@ package forestry.apiculture.items;
|
||||
import java.awt.Color;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum EnumHoneyComb {
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public enum EnumHoneyComb implements IStringSerializable {
|
||||
HONEY(new Color(0xe8d56a), new Color(0xffa12b)),
|
||||
COCOA(new Color(0x674016), new Color(0xffb62b), true),
|
||||
SIMMERING(new Color(0x981919), new Color(0xffb62b)),
|
||||
@@ -50,6 +52,11 @@ public enum EnumHoneyComb {
|
||||
this.secondaryColor = secondary.getRGB();
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isSecret() {
|
||||
return secret;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package forestry.apiculture.items;
|
||||
|
||||
import forestry.apiculture.blocks.BlockHoneyComb;
|
||||
import forestry.core.items.IColoredItem;
|
||||
import forestry.core.items.ItemBlockForestry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBlockHoneyComb extends ItemBlockForestry<BlockHoneyComb> implements IColoredItem {
|
||||
|
||||
public ItemBlockHoneyComb(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
|
||||
int meta = stack.getMetadata();
|
||||
EnumHoneyComb honeyComb = EnumHoneyComb.get(getBlock().minMeta + meta);
|
||||
if (tintIndex == 1) {
|
||||
return honeyComb.primaryColor;
|
||||
} else {
|
||||
return honeyComb.secondaryColor;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,15 +12,19 @@ package forestry.core.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.climate.IClimateInfo;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.api.genetics.IClimateHelper;
|
||||
import forestry.core.climate.ClimateRegion;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -224,6 +228,27 @@ public class ClimateUtil implements IClimateHelper {
|
||||
return Translator.translateToLocal("for.gui." + humidity.toString().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
public static void addClimateErrorStates(EnumTemperature temperature, EnumHumidity humidity,
|
||||
EnumTemperature baseTemp, EnumTolerance tolTemp,
|
||||
EnumHumidity baseHumid, EnumTolerance tolHumid, Set<IErrorState> errorStates){
|
||||
|
||||
if (!AlleleManager.climateHelper.isWithinLimits(temperature, baseTemp, tolTemp)) {
|
||||
if (baseTemp.ordinal() > temperature.ordinal()) {
|
||||
errorStates.add(EnumErrorCode.TOO_COLD);
|
||||
} else {
|
||||
errorStates.add(EnumErrorCode.TOO_HOT);
|
||||
}
|
||||
}
|
||||
|
||||
if (!AlleleManager.climateHelper.isWithinLimits(humidity, baseHumid, tolHumid)) {
|
||||
if (baseHumid.ordinal() > humidity.ordinal()) {
|
||||
errorStates.add(EnumErrorCode.TOO_ARID);
|
||||
} else {
|
||||
errorStates.add(EnumErrorCode.TOO_HUMID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float getTemperature(World world, BlockPos pos){
|
||||
return ForestryAPI.climateManager.getInfo(world, pos).getTemperature();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent;
|
||||
import forestry.api.greenhouse.GreenhouseEvents.CreateInternalBlockEvent;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.api.greenhouse.IInternalBlockFace;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
@@ -711,6 +712,23 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnButterfly(IButterflyCocoon cocoon) {
|
||||
for(IInternalBlock block : internalBlocks){
|
||||
BlockPos pos = block.getPos();
|
||||
if(world.isAirBlock(pos)){
|
||||
if(ButterflyUtils.spawnButterfly(cocoon, world, pos)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: remove in 5.4 or 5.3.4
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean spawnButterfly(IButterfly butterfly) {
|
||||
for(IInternalBlock block : internalBlocks){
|
||||
BlockPos pos = block.getPos();
|
||||
|
||||
@@ -12,10 +12,15 @@ package forestry.greenhouse.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
@@ -26,6 +31,7 @@ import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAnalyzer;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.utils.ClimateUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.energy.EnergyHelper;
|
||||
import forestry.energy.EnergyManager;
|
||||
@@ -38,8 +44,10 @@ import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -54,6 +62,7 @@ public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouse
|
||||
private int energyPerWorkCycle;
|
||||
@Nullable
|
||||
private IButterfly butterfly;
|
||||
private IButterflyCocoon cocoon;
|
||||
|
||||
private int tickCount = rand.nextInt(256);
|
||||
|
||||
@@ -101,7 +110,7 @@ public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouse
|
||||
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
if(!hasWork()){
|
||||
if(!canWork()){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -137,27 +146,51 @@ public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouse
|
||||
return tickCount % tickInterval == 0;
|
||||
}
|
||||
|
||||
protected boolean hasWork(){
|
||||
protected boolean canWork(){
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
Integer inputSlotIndex = getInputSlotIndex();
|
||||
boolean hasCocoon = inputSlotIndex != null || !getStackInSlot(InventoryGreenhouseNursery.SLOT_WORK).isEmpty();
|
||||
|
||||
getErrorLogic().setCondition(!hasCocoon, EnumErrorCode.NO_RESOURCE_INVENTORY);
|
||||
return hasCocoon;
|
||||
errorLogic.setCondition(!hasCocoon, EnumErrorCode.NO_RESOURCE_INVENTORY);
|
||||
if(butterfly == null && hasCocoon){
|
||||
ItemStack stack = getStackInSlot(InventoryGreenhouseNursery.SLOT_WORK);
|
||||
butterfly = ButterflyManager.butterflyRoot.getMember(stack);
|
||||
if(butterfly == null){
|
||||
setInventorySlotContents(InventoryGreenhouseNursery.SLOT_WORK, ItemStack.EMPTY);
|
||||
errorLogic.setCondition(true, EnumErrorCode.NO_RESOURCE_INVENTORY);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(canSpawnButterfly()){
|
||||
Set<IErrorState> queenErrors = butterfly.getCanSpawn(this, null);
|
||||
for (IErrorState errorState : queenErrors) {
|
||||
errorLogic.setCondition(true, errorState);
|
||||
}
|
||||
}else{
|
||||
Set<IErrorState> queenErrors = butterfly.getCanGrow(this, null);
|
||||
for (IErrorState errorState : queenErrors) {
|
||||
errorLogic.setCondition(true, errorState);
|
||||
}
|
||||
}
|
||||
return !errorLogic.hasErrors();
|
||||
}
|
||||
|
||||
protected boolean workCycle(){
|
||||
moveCocoonToWorkSlot();
|
||||
ItemStack stack = getStackInSlot(InventoryGreenhouseNursery.SLOT_WORK);
|
||||
if(butterfly == null){
|
||||
butterfly = ButterflyManager.butterflyRoot.getMember(stack);
|
||||
if(butterfly == null){
|
||||
setInventorySlotContents(InventoryGreenhouseNursery.SLOT_WORK, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
if(butterfly != null){
|
||||
int age = getAge();
|
||||
if(age >= 0 && age < 2){
|
||||
if(canSpawnButterfly()){
|
||||
IGreenhouseControllerInternal controller = getMultiblockLogic().getController();
|
||||
if(controller.spawnButterfly(this)){
|
||||
setInventorySlotContents(InventoryGreenhouseNursery.SLOT_WORK, ItemStack.EMPTY);
|
||||
setTicksPerWorkCycle(1);
|
||||
setEnergyPerWorkCycle(0);
|
||||
butterfly = null;
|
||||
cocoon = null;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
ItemStack stack = getStackInSlot(InventoryGreenhouseNursery.SLOT_WORK);
|
||||
int age = getAge();
|
||||
IButterflyGenome genome = butterfly.getGenome();
|
||||
float matureTime = genome.getLifespan() / (genome.getFertility() * 2);
|
||||
matureTime*=MATURE_TIME_MULTIPLIER;
|
||||
@@ -168,21 +201,15 @@ public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouse
|
||||
}
|
||||
setTicksPerWorkCycle(caterpillarMatureTime);
|
||||
setEnergyPerWorkCycle(ENERGY_PER_WORK_CYCLE);
|
||||
}else{
|
||||
IGreenhouseControllerInternal controller = getMultiblockLogic().getController();
|
||||
if(controller.spawnButterfly(butterfly)){
|
||||
setInventorySlotContents(InventoryGreenhouseNursery.SLOT_WORK, ItemStack.EMPTY);
|
||||
setTicksPerWorkCycle(1);
|
||||
setEnergyPerWorkCycle(0);
|
||||
butterfly = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean canSpawnButterfly(){
|
||||
int age = getAge();
|
||||
return age > 2 && butterfly != null;
|
||||
}
|
||||
|
||||
private void moveCocoonToWorkSlot() {
|
||||
if (!getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE).isEmpty()) {
|
||||
@@ -250,6 +277,23 @@ public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouse
|
||||
workCounter = data.readVarInt();
|
||||
ticksPerWorkCycle = data.readVarInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setInteger("workCounter", workCounter);
|
||||
data.setInteger("ticksPerWorkCycle", ticksPerWorkCycle);
|
||||
data.setInteger("energyPerWorkCycle", energyPerWorkCycle);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
workCounter = data.getInteger("workCounter");
|
||||
ticksPerWorkCycle = data.getInteger("ticksPerWorkCycle");
|
||||
energyPerWorkCycle = data.getInteger("energyPerWorkCycle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCocoonLoot(IButterflyCocoon cocoon, NonNullList<ItemStack> cocoonDrops) {
|
||||
@@ -280,5 +324,39 @@ public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouse
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IButterfly getCaterpillar() {
|
||||
return butterfly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIndividual getNanny() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaterpillar(IButterfly caterpillar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNurse(IButterfly caterpillar) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome() {
|
||||
return world.getBiome(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.getFromBiome(getBiome(), world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.getFromValue(ClimateUtil.getHumidity(world, pos));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package forestry.lepidopterology;
|
||||
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
@@ -30,6 +31,18 @@ public class ButterflyUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean spawnButterfly(IButterflyCocoon cocoon, World world, BlockPos pos){
|
||||
IButterfly butterfly = cocoon.getCaterpillar();
|
||||
if (world.countEntities(EntityButterfly.class) > PluginLepidopterology.spawnConstraint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.isAirBlock(pos)) {
|
||||
return attemptButterflySpawn(world, butterfly, pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
package forestry.lepidopterology.genetics;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -19,7 +21,9 @@ import java.util.Set;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IChromosome;
|
||||
@@ -35,6 +39,7 @@ import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.lepidopterology.IButterflyMutation;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.api.lepidopterology.IEntityButterfly;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.genetics.Chromosome;
|
||||
import forestry.core.genetics.GenericRatings;
|
||||
import forestry.core.genetics.IndividualLiving;
|
||||
@@ -123,6 +128,53 @@ public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
public IButterflyGenome getMate() {
|
||||
return mate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IErrorState> getCanSpawn(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon) {
|
||||
World world = nursery.getWorldObj();
|
||||
|
||||
Set<IErrorState> errorStates = new HashSet<>();
|
||||
// / Night or darkness requires nocturnal species
|
||||
boolean isDaytime = world.isDaytime();
|
||||
if(!isActiveThisTime(isDaytime)){
|
||||
if(isDaytime){
|
||||
errorStates.add(EnumErrorCode.NOT_NIGHT);
|
||||
}else{
|
||||
errorStates.add(EnumErrorCode.NOT_DAY);
|
||||
}
|
||||
}
|
||||
|
||||
// / And finally climate check
|
||||
IAlleleButterflySpecies species = genome.getPrimary();
|
||||
EnumTemperature actualTemperature = nursery.getTemperature();
|
||||
EnumTemperature baseTemperature = species.getTemperature();
|
||||
EnumTolerance toleranceTemperature = genome.getToleranceTemp();
|
||||
EnumHumidity actualHumidity = nursery.getHumidity();
|
||||
EnumHumidity baseHumidity = species.getHumidity();
|
||||
EnumTolerance toleranceHumidity = genome.getToleranceHumid();
|
||||
ClimateUtil.addClimateErrorStates(actualTemperature, actualHumidity, baseTemperature, toleranceTemperature, baseHumidity, toleranceHumidity, errorStates);
|
||||
|
||||
return errorStates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IErrorState> getCanGrow(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon) {
|
||||
World world = nursery.getWorldObj();
|
||||
|
||||
Set<IErrorState> errorStates = new HashSet<>();
|
||||
|
||||
// / And finally climate check
|
||||
IAlleleButterflySpecies species = genome.getPrimary();
|
||||
EnumTemperature actualTemperature = nursery.getTemperature();
|
||||
EnumTemperature baseTemperature = species.getTemperature();
|
||||
EnumTolerance toleranceTemperature = genome.getToleranceTemp();
|
||||
EnumHumidity actualHumidity = nursery.getHumidity();
|
||||
EnumHumidity baseHumidity = species.getHumidity();
|
||||
EnumTolerance toleranceHumidity = genome.getToleranceHumid();
|
||||
ClimateUtil.addClimateErrorStates(actualTemperature, actualHumidity, baseTemperature, toleranceTemperature, baseHumidity, toleranceHumidity, errorStates);
|
||||
|
||||
return errorStates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSpawn(World world, double x, double y, double z) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.greenhouse.GreenhouseManager;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
|
||||
@@ -4,7 +4,6 @@ import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
Reference in new issue
Block a user