mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 20:42:35 +00:00
Remove butterfly hatch and add butterfly nursery
This commit is contained in:
1 parent
66bdedd65b
commit
4da5e86813
61 files changed
+804
-428
No files matched your search
@@ -32,8 +32,8 @@ public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> exte
|
||||
IClimatiserDefinition getDefinition();
|
||||
}
|
||||
|
||||
interface ButterflyHatch extends IGreenhouseComponent {
|
||||
NonNullList<ItemStack> addCocoonLoot(IButterflyCocoon cocoon);
|
||||
interface Nursery extends IGreenhouseComponent {
|
||||
void addCocoonLoot(IButterflyCocoon cocoon, NonNullList<ItemStack> loot);
|
||||
}
|
||||
|
||||
interface Active extends IGreenhouseComponent {
|
||||
|
||||
@@ -12,6 +12,7 @@ import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.greenhouse.IGreenhouseHousing;
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlProvider {
|
||||
|
||||
@@ -20,6 +21,8 @@ public interface IGreenhouseController extends IMultiblockController, IGreenhous
|
||||
*/
|
||||
Set<IInternalBlock> getInternalBlocks();
|
||||
|
||||
boolean spawnButterfly(IButterfly butterfly);
|
||||
|
||||
IClimateRegion getRegion();
|
||||
|
||||
}
|
||||
@@ -59,7 +59,6 @@ import forestry.core.utils.VectUtil;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
@@ -13,7 +13,6 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
@@ -20,7 +20,6 @@ import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -22,7 +22,6 @@ import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -20,7 +20,6 @@ import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -25,7 +25,6 @@ import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
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;
|
||||
|
||||
@@ -492,7 +492,7 @@ public class PluginArboriculture extends BlankForestryPlugin {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
TreeManager.treeRoot.registerTranslator(Blocks.LEAVES, new IBlockTranslator<ITree>() {
|
||||
TreeManager.treeRoot.registerTranslator(Blocks.LEAVES2, new IBlockTranslator<ITree>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ITree getIndividualFromObject(IBlockState blockState) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -25,7 +25,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -13,7 +13,6 @@ package forestry.core.blocks;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.api.multiblock.MultiblockTileEntityBase;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.multiblock.MultiblockTileEntityForestry;
|
||||
import forestry.core.multiblock.MultiblockUtil;
|
||||
@@ -25,7 +24,6 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -165,6 +165,7 @@ public class LedgerManager {
|
||||
errorLedger.draw(-errorLedger.getWidth(), yPos);
|
||||
yPos += errorLedger.getHeight();
|
||||
}
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
public void drawTooltips(int mouseX, int mouseY) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
@@ -14,7 +14,6 @@ import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.List;
|
||||
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -21,7 +21,6 @@ import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -22,7 +22,6 @@ import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -22,7 +22,6 @@ import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
@@ -40,7 +40,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import forestry.greenhouse.tiles.TileGreenhouseNursery;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -22,6 +23,8 @@ public class MigrationHelper {
|
||||
|
||||
itemRemappings.put("greenhouse.dryer", "greenhouse.dehumidifier");
|
||||
blockRemappings.put("greenhouse.dryer", "greenhouse.dehumidifier");
|
||||
itemRemappings.put("greenhouse.butterfly_hatch", "greenhouse.nursery");
|
||||
blockRemappings.put("greenhouse.butterfly_hatch", "greenhouse.nursery");
|
||||
itemRemappings.put("pile_dirt", "loam");
|
||||
blockRemappings.put("pile_dirt", "loam");
|
||||
itemRemappings.put("pile_wood", "wood_pile");
|
||||
|
||||
@@ -21,7 +21,6 @@ import forestry.core.tiles.TileUtil;
|
||||
import forestry.factory.recipes.RecipeMemory;
|
||||
import forestry.factory.tiles.TileWorktable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -23,7 +23,6 @@ import forestry.factory.gui.ContainerWorktable;
|
||||
import forestry.factory.recipes.MemorizedRecipe;
|
||||
import forestry.factory.tiles.TileWorktable;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,6 @@ import forestry.core.tiles.TileUtil;
|
||||
import forestry.factory.recipes.MemorizedRecipe;
|
||||
import forestry.factory.tiles.TileWorktable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -16,7 +16,6 @@ import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -31,7 +31,6 @@ import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -24,7 +24,7 @@ import forestry.core.utils.OreDictUtil;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.blocks.BlockRegistryGreenhouse;
|
||||
import forestry.greenhouse.proxy.ProxyGreenhouse;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseNursery;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseClimateControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
@@ -93,7 +93,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
GameRegistry.registerTileEntity(TileGreenhouseClimateControl.class, "forestry.GreenhouseClimateControl");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseWindow.class, "forestry.GreenhouseWindow");
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
|
||||
GameRegistry.registerTileEntity(TileGreenhouseButterflyHatch.class, "forestry.GreenhouseButterflyHatch");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseNursery.class, "forestry.GreenhouseButterflyHatch");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
'E', coreItems.tubes.get(EnumElectronTube.BLAZE, 1));
|
||||
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
|
||||
Block greenhouseButterflyHatchBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.BUTTERFLY_HATCH);
|
||||
Block greenhouseButterflyHatchBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.NURSERY);
|
||||
RecipeUtil.addRecipe(greenhouseButterflyHatchBlock,
|
||||
true,
|
||||
"IRG",
|
||||
|
||||
@@ -36,7 +36,7 @@ import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseNursery;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseClimateControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
@@ -105,7 +105,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
public static Map<BlockGreenhouseType, BlockGreenhouse> create() {
|
||||
Map<BlockGreenhouseType, BlockGreenhouse> blockMap = new EnumMap<>(BlockGreenhouseType.class);
|
||||
for (final BlockGreenhouseType type : BlockGreenhouseType.VALUES) {
|
||||
if (type == BlockGreenhouseType.BUTTERFLY_HATCH) {
|
||||
if (type == BlockGreenhouseType.NURSERY) {
|
||||
if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
|
||||
continue;
|
||||
}
|
||||
@@ -322,8 +322,8 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
case HATCH_INPUT:
|
||||
case HATCH_OUTPUT:
|
||||
return new TileGreenhouseHatch();
|
||||
case BUTTERFLY_HATCH:
|
||||
return new TileGreenhouseButterflyHatch();
|
||||
case NURSERY:
|
||||
return new TileGreenhouseNursery();
|
||||
default:
|
||||
return new TileGreenhousePlain();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
||||
@@ -42,7 +42,7 @@ public enum BlockGreenhouseType {
|
||||
CONTROL(true),
|
||||
DOOR,
|
||||
CLIMATE_CONTROL(true),
|
||||
BUTTERFLY_HATCH(true);
|
||||
NURSERY(true);
|
||||
|
||||
public static final BlockGreenhouseType[] VALUES = values();
|
||||
|
||||
@@ -177,7 +177,7 @@ public enum BlockGreenhouseType {
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().missingImage;
|
||||
}
|
||||
return sprites.get(BlockGreenhouseSprites.CLIMATE_CONTROL);
|
||||
case BUTTERFLY_HATCH:
|
||||
case NURSERY:
|
||||
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().missingImage;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package forestry.greenhouse.gui;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.primitives.Floats;
|
||||
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.climate.IClimateInfo;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.core.climate.ClimateInfo;
|
||||
import forestry.core.gui.TextLayoutHelper;
|
||||
import forestry.core.network.packets.PacketUpdateClimateControl;
|
||||
import forestry.core.render.ColourProperties;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
public class ClimateTextFields {
|
||||
|
||||
private final GuiTextField humidityField;
|
||||
private final GuiTextField temperatureField;
|
||||
private final IClimateControlProvider provider;
|
||||
|
||||
public ClimateTextFields(IGreenhouseController controller, FontRenderer fontRenderer, int guiLeft, int guiTop) {
|
||||
this.provider = controller;
|
||||
IClimateInfo info = controller.getControlClimate();
|
||||
|
||||
temperatureField = new GuiTextField(0, fontRenderer, guiLeft + 64, guiTop + 31, 50, 10);
|
||||
temperatureField.setValidator(NUMBER_FILTER);
|
||||
temperatureField.setEnableBackgroundDrawing(false);
|
||||
temperatureField.setText(Float.toString(info.getTemperature()));
|
||||
|
||||
humidityField = new GuiTextField(1, fontRenderer, guiLeft + 64, guiTop + 61, 50, 10);
|
||||
humidityField.setValidator(NUMBER_FILTER);
|
||||
humidityField.setEnableBackgroundDrawing(false);
|
||||
humidityField.setText(Float.toString(info.getHumidity()));
|
||||
|
||||
}
|
||||
|
||||
protected boolean keyTyped(char typedChar, int keyCode) {
|
||||
return humidityField.textboxKeyTyped(typedChar, keyCode) || temperatureField.textboxKeyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton){
|
||||
boolean temperatureWasFocused = temperatureField.isFocused();
|
||||
boolean humidityWasFocused = humidityField.isFocused();
|
||||
|
||||
temperatureField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
humidityField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
if (temperatureWasFocused && !temperatureField.isFocused() || humidityWasFocused && !humidityField.isFocused()) {
|
||||
float temp = parseField(temperatureField);
|
||||
float hum = parseField(humidityField);
|
||||
setClimate(provider, temp, hum);
|
||||
}
|
||||
NetworkUtil.sendToServer(new PacketUpdateClimateControl(provider));
|
||||
}
|
||||
|
||||
public void draw(GuiGreenhouse gui, int guiLeft, int guiTop){
|
||||
TextLayoutHelper textLayout = gui.getTextLayout();
|
||||
|
||||
gui.drawTexturedModalRect(guiLeft + 62, guiTop + 29, 204, 115, 52, 12);
|
||||
gui.drawTexturedModalRect(guiLeft + 62, guiTop + 59, 204, 127, 52, 12);
|
||||
|
||||
textLayout.line = 20;
|
||||
textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.temperature"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.temperature.text"));
|
||||
temperatureField.drawTextBox();
|
||||
|
||||
textLayout.line = 50;
|
||||
textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.humidity"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.humidity.text"));
|
||||
humidityField.drawTextBox();
|
||||
}
|
||||
|
||||
public void setClimate(float temp){
|
||||
IClimateInfo info = provider.getControlClimate();
|
||||
setClimate(provider, temp, info.getHumidity());
|
||||
}
|
||||
|
||||
public void setClimate(IClimateControlProvider provider, float temp, float hum){
|
||||
temperatureField.setText(Float.toString(temp));
|
||||
humidityField.setText(Float.toString(hum));
|
||||
provider.setControlClimate(new ClimateInfo(temp, hum));
|
||||
}
|
||||
|
||||
private static float parseField(GuiTextField field) {
|
||||
String text = field.getText();
|
||||
if (text.isEmpty()) {
|
||||
return 2.0F;
|
||||
}
|
||||
try {
|
||||
float f = Float.parseFloat(text);
|
||||
if (f >= 2) {
|
||||
f = 2.0F;
|
||||
}
|
||||
return f;
|
||||
} catch (NumberFormatException var5) {
|
||||
return 2.0F;
|
||||
}
|
||||
}
|
||||
|
||||
protected static final Predicate<String> NUMBER_FILTER = text -> {
|
||||
if (text == null) {
|
||||
return false;
|
||||
}
|
||||
if (!text.isEmpty() && text.length() > 1) {
|
||||
if (!text.contains(".")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (text.length() > 7) {
|
||||
return false;
|
||||
}
|
||||
Float f = Floats.tryParse(text);
|
||||
return text.isEmpty() || f != null && Floats.isFinite(f) && f >= 0.0F;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.gui;
|
||||
|
||||
import forestry.core.gui.ContainerTile;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
public class ContainerGreenhouseButterflyHatch extends ContainerTile<TileGreenhouseButterflyHatch> {
|
||||
|
||||
public ContainerGreenhouseButterflyHatch(InventoryPlayer playerInventory, TileGreenhouseButterflyHatch tile) {
|
||||
super(tile, playerInventory, 8, 84);
|
||||
|
||||
addSlotToContainer(new SlotOutput(tile, 0, 60, 40));
|
||||
addSlotToContainer(new SlotOutput(tile, 1, 80, 27));
|
||||
addSlotToContainer(new SlotOutput(tile, 2, 101, 40));
|
||||
addSlotToContainer(new SlotOutput(tile, 3, 80, 53));
|
||||
}
|
||||
|
||||
public IFluidTank getTank(int slot) {
|
||||
return tile.getMultiblockLogic().getController().getTankManager().getTank(slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.gui;
|
||||
|
||||
import forestry.core.gui.ContainerTile;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.gui.slots.SlotWorking;
|
||||
import forestry.core.network.packets.PacketGuiUpdate;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouseNursery;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseNursery;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class ContainerGreenhouseNursery extends ContainerTile<TileGreenhouseNursery> {
|
||||
|
||||
public ContainerGreenhouseNursery(InventoryPlayer playerInventory, TileGreenhouseNursery tile) {
|
||||
super(tile, playerInventory, 8, 94);
|
||||
|
||||
// Input buffer
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int k = 0; k < 2; k++) {
|
||||
addSlotToContainer(new SlotFiltered(tile, InventoryGreenhouseNursery.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Analyze slot
|
||||
addSlotToContainer(new SlotWorking(tile, InventoryGreenhouseNursery.SLOT_WORK, 84, 45));
|
||||
|
||||
// Output buffer
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int k = 0; k < 2; k++) {
|
||||
addSlotToContainer(new SlotOutput(tile, InventoryGreenhouseNursery.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 28 + i * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
PacketGuiUpdate packet = new PacketGuiUpdate(tile);
|
||||
sendPacketToListeners(packet);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package forestry.greenhouse.gui;
|
||||
|
||||
import forestry.core.gui.ledgers.Ledger;
|
||||
import forestry.core.gui.ledgers.LedgerManager;
|
||||
import forestry.core.render.TextureManagerForestry;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
|
||||
public class GreenhouseEnergyLedger extends Ledger {
|
||||
|
||||
final IGreenhouseControllerInternal controller;
|
||||
|
||||
public GreenhouseEnergyLedger(LedgerManager ledgerManager, IGreenhouseControllerInternal controller) {
|
||||
super(ledgerManager, "power");
|
||||
maxHeight = 48;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
// Draw background
|
||||
drawBackground(x, y);
|
||||
|
||||
// Draw icon
|
||||
drawSprite(TextureManagerForestry.getInstance().getDefault("misc/energy"), x + 3, y + 4);
|
||||
|
||||
if (!isFullyOpened()) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawHeader(Translator.translateToLocal("for.gui.energy"), x + 22, y + 8);
|
||||
|
||||
drawSubheader(Translator.translateToLocal("for.gui.stored") + ':', x + 22, y + 20);
|
||||
drawText(controller.getEnergyManager().getEnergyStored() + " RF", x + 22, y + 32);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return Translator.translateToLocal("for.gui.energy") + ": " + controller.getEnergyManager().getEnergyStored() + " RF/t";
|
||||
}
|
||||
}
|
||||
@@ -12,52 +12,26 @@ package forestry.greenhouse.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.primitives.Floats;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.climate.IClimateInfo;
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.core.climate.ClimateInfo;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.ledgers.Ledger;
|
||||
import forestry.core.gui.TextLayoutHelper;
|
||||
import forestry.core.gui.widgets.TankWidget;
|
||||
import forestry.core.network.packets.PacketUpdateClimateControl;
|
||||
import forestry.core.render.ColourProperties;
|
||||
import forestry.core.render.TextureManagerForestry;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouse;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
|
||||
private static final Predicate<String> numberFilter = text -> {
|
||||
if (text == null) {
|
||||
return false;
|
||||
}
|
||||
if (!text.isEmpty() && text.length() > 1) {
|
||||
if (!text.contains(".")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (text.length() > 7) {
|
||||
return false;
|
||||
}
|
||||
Float f = Floats.tryParse(text);
|
||||
return text.isEmpty() || f != null && Floats.isFinite(f) && f >= 0.0F;
|
||||
};
|
||||
|
||||
private final TileGreenhouse tile;
|
||||
private GuiTextField humidityField;
|
||||
private GuiTextField temperatureField;
|
||||
private boolean fieldsEnabeled;
|
||||
private final IGreenhouseControllerInternal controller;
|
||||
private final IOwnedTile tile;
|
||||
private ClimateTextFields fields;
|
||||
|
||||
public GuiGreenhouse(EntityPlayer player, TileGreenhouse tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/greenhouse.png", new ContainerGreenhouse(player.inventory, tile), tile);
|
||||
this.controller = tile.getMultiblockLogic().getController();
|
||||
this.tile = tile;
|
||||
|
||||
//Add the water tank
|
||||
@@ -65,51 +39,39 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
//Add the multiblock camouflage tabs
|
||||
WidgetCamouflageTab previous;
|
||||
int x = 3;
|
||||
widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, tile.getMultiblockLogic().getController(), tile, CamouflageManager.BLOCK));
|
||||
widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.BLOCK));
|
||||
x+=50 + (previous.getHandlerSlot() != null ? 20 : 0);
|
||||
widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, tile.getMultiblockLogic().getController(), tile, CamouflageManager.GLASS));
|
||||
widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.GLASS));
|
||||
x+=50 + (previous.getHandlerSlot() != null ? 20 : 0);
|
||||
widgetManager.add(new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, tile.getMultiblockLogic().getController(), tile, CamouflageManager.DOOR));
|
||||
widgetManager.add(new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.DOOR));
|
||||
|
||||
widgetManager.add(new WidgetClimatePillar(widgetManager, guiLeft- 23, guiTop + 5));
|
||||
|
||||
fieldsEnabeled = true;
|
||||
if(hasFields()){
|
||||
widgetManager.add(new WidgetClimatePillar(widgetManager, guiLeft- 23, guiTop + 5));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFields(){
|
||||
return controller != null && controller.getControlClimate() != ClimateInfo.MAX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
temperatureField = new GuiTextField(0, fontRendererObj, guiLeft + 64, guiTop + 31, 50, 10);
|
||||
humidityField = new GuiTextField(1, fontRendererObj, guiLeft + 64, guiTop + 61, 50, 10);
|
||||
|
||||
temperatureField.setValidator(numberFilter);
|
||||
humidityField.setValidator(numberFilter);
|
||||
|
||||
temperatureField.setEnableBackgroundDrawing(false);
|
||||
humidityField.setEnableBackgroundDrawing(false);
|
||||
|
||||
IGreenhouseController controller = tile.getMultiblockLogic().getController();
|
||||
if (controller == null || controller.getControlClimate() == ClimateInfo.MAX) {
|
||||
temperatureField.setEnabled(false);
|
||||
temperatureField.setVisible(false);
|
||||
humidityField.setEnabled(false);
|
||||
humidityField.setVisible(false);
|
||||
fieldsEnabeled = false;
|
||||
} else {
|
||||
IClimateInfo info = controller.getControlClimate();
|
||||
temperatureField.setText(Float.toString(info.getTemperature()));
|
||||
humidityField.setText(Float.toString(info.getHumidity()));
|
||||
if(hasFields()){
|
||||
fields = new ClimateTextFields(controller, fontRendererObj, guiLeft, guiTop);
|
||||
}else{
|
||||
fields = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ClimateTextFields getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if (fieldsEnabeled) {
|
||||
if (!humidityField.textboxKeyTyped(typedChar, keyCode) && !temperatureField.textboxKeyTyped(typedChar, keyCode)) {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
} else {
|
||||
if (fields == null || !fields.keyTyped(typedChar, keyCode)) {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
@@ -117,49 +79,8 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
if (fieldsEnabeled) {
|
||||
boolean temperatureWasFocused = temperatureField.isFocused();
|
||||
boolean humidityWasFocused = humidityField.isFocused();
|
||||
temperatureField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
humidityField.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
IClimateControlProvider provider = tile.getMultiblockLogic().getController();
|
||||
if (temperatureWasFocused && !temperatureField.isFocused() || humidityWasFocused && !humidityField.isFocused()) {
|
||||
float temp = parseField(temperatureField);
|
||||
float hum = parseField(humidityField);
|
||||
setClimate(provider, temp, hum);
|
||||
}
|
||||
NetworkUtil.sendToServer(new PacketUpdateClimateControl(provider));
|
||||
}
|
||||
}
|
||||
|
||||
public void setClimate(float temp){
|
||||
setClimate(tile.getMultiblockLogic().getController(), temp);
|
||||
}
|
||||
|
||||
public void setClimate(IClimateControlProvider provider, float temp){
|
||||
IClimateInfo info = provider.getControlClimate();
|
||||
setClimate(provider, temp, info.getHumidity());
|
||||
}
|
||||
|
||||
public void setClimate(IClimateControlProvider provider, float temp, float hum){
|
||||
temperatureField.setText(Float.toString(temp));
|
||||
humidityField.setText(Float.toString(hum));
|
||||
provider.setControlClimate(new ClimateInfo(temp, hum));
|
||||
}
|
||||
|
||||
private float parseField(GuiTextField field) {
|
||||
String text = field.getText();
|
||||
if (text.isEmpty()) {
|
||||
return 2.0F;
|
||||
}
|
||||
try {
|
||||
float f = Float.parseFloat(text);
|
||||
if (f >= 2) {
|
||||
f = 2.0F;
|
||||
}
|
||||
return f;
|
||||
} catch (NumberFormatException var5) {
|
||||
return 2.0F;
|
||||
if (fields != null) {
|
||||
fields.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,61 +88,21 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
|
||||
|
||||
if (fieldsEnabeled) {
|
||||
drawTexturedModalRect(guiLeft + 62, guiTop + 29, 204, 115, 52, 12);
|
||||
drawTexturedModalRect(guiLeft + 62, guiTop + 59, 204, 127, 52, 12);
|
||||
|
||||
textLayout.line = 20;
|
||||
textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.temperature"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.temperature.text"));
|
||||
temperatureField.drawTextBox();
|
||||
textLayout.line = 50;
|
||||
textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.humidity"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.humidity.text"));
|
||||
|
||||
humidityField.drawTextBox();
|
||||
if (fields != null) {
|
||||
fields.draw(this, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TextLayoutHelper getTextLayout() {
|
||||
return textLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLedgers() {
|
||||
IGreenhouseControllerInternal greenhouseController = tile.getMultiblockLogic().getController();
|
||||
|
||||
addErrorLedger(greenhouseController);
|
||||
ledgerManager.add(new EnergyLedger());
|
||||
addClimateLedger(greenhouseController);
|
||||
addErrorLedger(controller);
|
||||
ledgerManager.add(new GreenhouseEnergyLedger(ledgerManager, controller));
|
||||
addClimateLedger(controller);
|
||||
addHintLedger("greenhouse");
|
||||
addOwnerLedger(tile);
|
||||
}
|
||||
|
||||
protected class EnergyLedger extends Ledger {
|
||||
|
||||
public EnergyLedger() {
|
||||
super(ledgerManager, "power");
|
||||
maxHeight = 48;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
|
||||
// Draw background
|
||||
drawBackground(x, y);
|
||||
|
||||
// Draw icon
|
||||
drawSprite(TextureManagerForestry.getInstance().getDefault("misc/energy"), x + 3, y + 4);
|
||||
|
||||
if (!isFullyOpened()) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawHeader(Translator.translateToLocal("for.gui.energy"), x + 22, y + 8);
|
||||
|
||||
drawSubheader(Translator.translateToLocal("for.gui.stored") + ':', x + 22, y + 20);
|
||||
drawText(tile.getMultiblockLogic().getController().getEnergyManager().getEnergyStored() + " RF", x + 22, y + 32);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return Translator.translateToLocal("for.gui.energy") + ": " + tile.getMultiblockLogic().getController().getEnergyManager().getEnergyStored() + " RF/t";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.gui;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class GuiGreenhouseButterflyHatch extends GuiForestryTitled<ContainerGreenhouseButterflyHatch> {
|
||||
private final TileGreenhouseButterflyHatch tile;
|
||||
|
||||
public GuiGreenhouseButterflyHatch(EntityPlayer player, TileGreenhouseButterflyHatch tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/greenhouse_butterfly_hatch.png", new ContainerGreenhouseButterflyHatch(player.inventory, tile), tile);
|
||||
|
||||
this.tile = tile;
|
||||
|
||||
//Add the tile camouflage slots
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 17, tile, tile.getCamouflageType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLedgers() {
|
||||
IGreenhouseControllerInternal greenhouseController = tile.getMultiblockLogic().getController();
|
||||
|
||||
addErrorLedger(greenhouseController);
|
||||
addClimateLedger(greenhouseController);
|
||||
addOwnerLedger(greenhouseController);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.gui;
|
||||
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.render.EnumTankLevel;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseNursery;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class GuiGreenhouseNursery extends GuiForestryTitled<ContainerGreenhouseNursery> {
|
||||
private final TileGreenhouseNursery tile;
|
||||
|
||||
public GuiGreenhouseNursery(EntityPlayer player, TileGreenhouseNursery tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/greenhouse_nursery.png", new ContainerGreenhouseNursery(player.inventory, tile), tile);
|
||||
|
||||
this.tile = tile;
|
||||
this.ySize = 176;
|
||||
|
||||
IGreenhouseControllerInternal controller = tile.getMultiblockLogic().getController();
|
||||
WidgetCamouflageTab previous;
|
||||
int x = 3;
|
||||
widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.BLOCK));
|
||||
x+=50 + (previous.getHandlerSlot() != null ? 20 : 0);
|
||||
widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.GLASS));
|
||||
x+=50 + (previous.getHandlerSlot() != null ? 20 : 0);
|
||||
widgetManager.add(new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.DOOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
drawMeter(guiLeft + 75, guiTop + 30, tile.getProgressScaled(46), EnumTankLevel.rateTankLevel(tile.getProgressScaled(100)));
|
||||
}
|
||||
|
||||
private void drawMeter(int x, int y, int height, EnumTankLevel rated) {
|
||||
int i = 176 + rated.getLevelScaled(16);
|
||||
|
||||
drawTexturedModalRect(x, y + 46 - height, i, 46 - height, 4, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLedgers() {
|
||||
IGreenhouseControllerInternal controller = tile.getMultiblockLogic().getController();
|
||||
|
||||
addErrorLedger(controller);
|
||||
addClimateLedger(controller);
|
||||
ledgerManager.add(new GreenhouseEnergyLedger(ledgerManager, controller));
|
||||
addHintLedger("greenhouse");
|
||||
addOwnerLedger(tile);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
@@ -53,6 +54,7 @@ public class WidgetCamouflageTab extends Widget {
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
TextureManager textureManager = minecraft.getTextureManager();
|
||||
textureManager.bindTexture(manager.gui.textureFile);
|
||||
|
||||
@@ -84,7 +84,7 @@ public class WidgetClimatePillar extends Widget {
|
||||
mouseY-=manager.gui.getGuiTop();
|
||||
for(ClimateButton button : buttons){
|
||||
if(button.isMouseOver(mouseX, mouseY)){
|
||||
((GuiGreenhouse)manager.gui).setClimate(button.value);
|
||||
((GuiGreenhouse)manager.gui).getFields().setClimate(button.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.inventory;
|
||||
|
||||
import forestry.core.inventory.InventoryAdapterTile;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
|
||||
public class InventoryGreenhouseButterflyHatch extends InventoryAdapterTile<TileGreenhouseButterflyHatch> {
|
||||
|
||||
public static final int SLOTS = 4;
|
||||
|
||||
public InventoryGreenhouseButterflyHatch(TileGreenhouseButterflyHatch tile) {
|
||||
super(tile, SLOTS, "Items");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.inventory;
|
||||
|
||||
import forestry.core.inventory.InventoryAdapterTile;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseNursery;
|
||||
import forestry.lepidopterology.PluginLepidopterology;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class InventoryGreenhouseNursery extends InventoryAdapterTile<TileGreenhouseNursery> {
|
||||
|
||||
public static final short SLOT_WORK = 0;
|
||||
public static final short SLOT_OUTPUT_1 = 1;
|
||||
public static final short SLOT_OUTPUT_COUNT = 6;
|
||||
public static final short SLOT_INPUT_1 = 7;
|
||||
public static final short SLOT_INPUT_COUNT = 6;
|
||||
public static final short SLOTS = 13;
|
||||
|
||||
public InventoryGreenhouseNursery(TileGreenhouseNursery tile) {
|
||||
super(tile, SLOTS, "Items", 64);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if(SlotUtil.isSlotInRange(slotIndex, SLOT_INPUT_1, SLOT_INPUT_COUNT)){
|
||||
return itemStack.getItem() == PluginLepidopterology.getItems().cocoonGE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slotIndex, ItemStack stack, EnumFacing side) {
|
||||
return SlotUtil.isSlotInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,14 +10,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.multiblock;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.climate.IClimateInfo;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.Nursery;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.Listener;
|
||||
import forestry.core.climate.ClimateInfo;
|
||||
import forestry.core.fluids.FakeTankManager;
|
||||
@@ -94,6 +94,11 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
|
||||
public Set<Listener> getListenerComponents() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Nursery> getButterflyNurserys() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork() {
|
||||
@@ -111,8 +116,7 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ButterflyHatch getButterflyHatch() {
|
||||
return null;
|
||||
public boolean spawnButterfly(IButterfly butterfly) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,11 @@ import forestry.api.core.ForestryAPI;
|
||||
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.greenhouse.IInternalBlock;
|
||||
import forestry.api.greenhouse.IInternalBlockFace;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.Nursery;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.ClimateControl;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.Climatiser;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
@@ -61,6 +62,7 @@ import forestry.core.utils.Translator;
|
||||
import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouse;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHumidifier;
|
||||
import forestry.lepidopterology.ButterflyUtils;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -78,10 +80,9 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
private final Set<IGreenhouseComponent.Listener> listenerComponents = new HashSet<>();
|
||||
private final Set<IGreenhouseComponent.Active> activeComponents = new HashSet<>();
|
||||
private final Set<IGreenhouseComponent.Climatiser> climatiserComponents = new HashSet<>();
|
||||
private final Set<IGreenhouseComponent.Nursery> butterflyNurserys = new HashSet<>();
|
||||
@Nullable
|
||||
protected ClimateControl climateControl;
|
||||
@Nullable
|
||||
protected ButterflyHatch butterflyHatch;
|
||||
|
||||
private final TankManager tankManager;
|
||||
private final EnergyManager energyManager;
|
||||
@@ -383,6 +384,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
climatiserComponents.add((Climatiser) newPart);
|
||||
} else if (newPart instanceof IGreenhouseComponent.Active) {
|
||||
activeComponents.add((IGreenhouseComponent.Active) newPart);
|
||||
} else if (newPart instanceof IGreenhouseComponent.Nursery) {
|
||||
butterflyNurserys.add((IGreenhouseComponent.Nursery) newPart);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,6 +398,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
ForestryAPI.climateManager.removeSource((IClimateSourceProvider) oldPart);
|
||||
} else if (oldPart instanceof IGreenhouseComponent.Active) {
|
||||
activeComponents.remove(oldPart);
|
||||
} else if (oldPart instanceof IGreenhouseComponent.Nursery) {
|
||||
butterflyNurserys.remove(oldPart);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,24 +563,15 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.space.closed"));
|
||||
}
|
||||
|
||||
Set<ButterflyHatch> hatches = new HashSet<>();
|
||||
Set<ClimateControl> controls = new HashSet<>();
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
if (comp instanceof ButterflyHatch) {
|
||||
hatches.add((ButterflyHatch) comp);
|
||||
} else if (comp instanceof ClimateControl) {
|
||||
if (comp instanceof ClimateControl) {
|
||||
controls.add((ClimateControl) comp);
|
||||
}
|
||||
}
|
||||
if (hatches.size() > 1) {
|
||||
throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.butterflyhatch.toomany"));
|
||||
}
|
||||
if (controls.size() > 1) {
|
||||
throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.climatecontrol.toomany"));
|
||||
}
|
||||
if (hatches.iterator().hasNext()) {
|
||||
butterflyHatch = hatches.iterator().next();
|
||||
}
|
||||
if (controls.iterator().hasNext()) {
|
||||
climateControl = controls.iterator().next();
|
||||
}
|
||||
@@ -675,11 +671,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
this.climateControl.setControlClimate(climateControl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ButterflyHatch getButterflyHatch() {
|
||||
return butterflyHatch;
|
||||
public Set<Nursery> getButterflyNurserys() {
|
||||
return butterflyNurserys;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -714,5 +709,18 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
}
|
||||
return canWork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnButterfly(IButterfly butterfly) {
|
||||
for(IInternalBlock block : internalBlocks){
|
||||
BlockPos pos = block.getPos();
|
||||
if(world.isAirBlock(pos)){
|
||||
if(ButterflyUtils.spawnButterfly(butterfly, world, pos)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,8 +50,8 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM
|
||||
Set<IGreenhouseComponent.Listener> getListenerComponents();
|
||||
|
||||
/**
|
||||
* @return A butterfly hatch, if one exists.
|
||||
* @return A Set of butterfly nurserys.
|
||||
*/
|
||||
@Nullable
|
||||
IGreenhouseComponent.ButterflyHatch getButterflyHatch();
|
||||
Set<IGreenhouseComponent.Nursery> getButterflyNurserys();
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class ProxyGreenhouseClient extends ProxyGreenhouse {
|
||||
null, new ModelGreenhouse(),
|
||||
greenhouseBlock, false));
|
||||
continue;
|
||||
} else if (greenhouseType == BlockGreenhouseType.BUTTERFLY_HATCH) {
|
||||
} else if (greenhouseType == BlockGreenhouseType.NURSERY) {
|
||||
if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
|
||||
return data;
|
||||
}
|
||||
|
||||
/* ICamouflageHandler */
|
||||
@Override
|
||||
public boolean setCamouflageBlock(String type, ItemStack camouflageBlock, boolean sendClientUpdate) {
|
||||
if (!ItemStackUtil.isIdenticalItem(camouflageBlock, this.camouflageBlock)) {
|
||||
@@ -151,6 +152,7 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
|
||||
return getMultiblockLogic().getController().getErrorLogic();
|
||||
}
|
||||
|
||||
/* IOwnedTile */
|
||||
@Override
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return getMultiblockLogic().getController().getOwnerHandler();
|
||||
@@ -174,6 +176,7 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
|
||||
getMultiblockLogic().getController().readGuiData(data);
|
||||
}
|
||||
|
||||
/* IGuiHandlerTile */
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public GuiContainer getGui(EntityPlayer player, int data) {
|
||||
@@ -184,7 +187,8 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
|
||||
public Container getContainer(EntityPlayer player, int data) {
|
||||
return new ContainerGreenhouse(player.inventory, this);
|
||||
}
|
||||
|
||||
|
||||
/* ICamouflagedTile */
|
||||
@Override
|
||||
public String getCamouflageType() {
|
||||
if (getBlockType() instanceof BlockGreenhouse && ((BlockGreenhouse) getBlockType()).getGreenhouseType() == BlockGreenhouseType.GLASS) {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.greenhouse.gui.ContainerGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.gui.GuiGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouseButterflyHatch;
|
||||
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.util.NonNullList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileGreenhouseButterflyHatch extends TileGreenhouse implements IGreenhouseComponent.ButterflyHatch {
|
||||
|
||||
private final InventoryGreenhouseButterflyHatch inventory;
|
||||
|
||||
public TileGreenhouseButterflyHatch() {
|
||||
this.inventory = new InventoryGreenhouseButterflyHatch(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> addCocoonLoot(IButterflyCocoon cocoon) {
|
||||
NonNullList<ItemStack> loots = NonNullList.create();
|
||||
for (ItemStack loot : cocoon.getCaterpillar().getCocoonDrop(cocoon)) {
|
||||
if (!InventoryUtil.tryAddStack(this, loot, 0, InventoryGreenhouseButterflyHatch.SLOTS, true)) {
|
||||
loots.add(loot);
|
||||
}
|
||||
}
|
||||
return loots;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public GuiContainer getGui(EntityPlayer player, int data) {
|
||||
return new GuiGreenhouseButterflyHatch(player, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getContainer(EntityPlayer player, int data) {
|
||||
return new ContainerGreenhouseButterflyHatch(player.inventory, this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAnalyzer;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.energy.EnergyHelper;
|
||||
import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.gui.ContainerGreenhouseNursery;
|
||||
import forestry.greenhouse.gui.GuiGreenhouseNursery;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouseNursery;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.lepidopterology.items.ItemButterflyGE;
|
||||
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.util.ITickable;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouseComponent.Nursery, IStreamableGui, ITickable {
|
||||
private static final int WORK_TICK_INTERVAL = 5; // one Forestry work tick happens every WORK_TICK_INTERVAL game ticks
|
||||
private static final Random rand = new Random();
|
||||
private static final int ENERGY_PER_WORK_CYCLE = 3200;
|
||||
private static final int MATURE_TIME_MULTIPLIER = 250;
|
||||
|
||||
private int workCounter;
|
||||
private int ticksPerWorkCycle;
|
||||
private int energyPerWorkCycle;
|
||||
@Nullable
|
||||
private IButterfly butterfly;
|
||||
|
||||
private int tickCount = rand.nextInt(256);
|
||||
|
||||
// the number of work ticks that this tile has had no power
|
||||
private int noPowerTime = 0;
|
||||
|
||||
private final InventoryGreenhouseNursery inventory;
|
||||
|
||||
public TileGreenhouseNursery() {
|
||||
this.inventory = new InventoryGreenhouseNursery(this);
|
||||
this.ticksPerWorkCycle = 4;
|
||||
}
|
||||
|
||||
public int getWorkCounter() {
|
||||
return workCounter;
|
||||
}
|
||||
|
||||
public void setTicksPerWorkCycle(int ticksPerWorkCycle) {
|
||||
this.ticksPerWorkCycle = ticksPerWorkCycle;
|
||||
this.workCounter = 0;
|
||||
}
|
||||
|
||||
public int getTicksPerWorkCycle() {
|
||||
return ticksPerWorkCycle;
|
||||
}
|
||||
|
||||
public void setEnergyPerWorkCycle(int energyPerWorkCycle) {
|
||||
this.energyPerWorkCycle = EnergyHelper.scaleForDifficulty(energyPerWorkCycle);
|
||||
}
|
||||
|
||||
public int getEnergyPerWorkCycle() {
|
||||
return energyPerWorkCycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if(world.isRemote){
|
||||
return;
|
||||
}
|
||||
tickCount++;
|
||||
|
||||
if (!updateOnInterval(WORK_TICK_INTERVAL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
if(!hasWork()){
|
||||
return;
|
||||
}
|
||||
|
||||
EnergyManager energyManager = getMultiblockLogic().getController().getEnergyManager();
|
||||
if(energyManager == null){
|
||||
return;
|
||||
}
|
||||
int ticksPerWorkCycle = getTicksPerWorkCycle();
|
||||
|
||||
if (workCounter < ticksPerWorkCycle) {
|
||||
int energyPerWorkCycle = getEnergyPerWorkCycle();
|
||||
boolean consumedEnergy = EnergyHelper.consumeEnergyToDoWork(energyManager, ticksPerWorkCycle, energyPerWorkCycle);
|
||||
if (consumedEnergy) {
|
||||
errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
|
||||
workCounter++;
|
||||
noPowerTime = 0;
|
||||
} else {
|
||||
noPowerTime++;
|
||||
if (noPowerTime > 4) {
|
||||
errorLogic.setCondition(true, EnumErrorCode.NO_POWER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (workCounter >= ticksPerWorkCycle) {
|
||||
if (workCycle()) {
|
||||
workCounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final boolean updateOnInterval(int tickInterval) {
|
||||
return tickCount % tickInterval == 0;
|
||||
}
|
||||
|
||||
protected boolean hasWork(){
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
Integer inputSlotIndex = getInputSlotIndex();
|
||||
boolean hasCocoon = inputSlotIndex != null || !getStackInSlot(InventoryGreenhouseNursery.SLOT_WORK).isEmpty();
|
||||
|
||||
getErrorLogic().setCondition(!hasCocoon, EnumErrorCode.NO_RESOURCE_INVENTORY);
|
||||
return hasCocoon;
|
||||
}
|
||||
|
||||
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){
|
||||
IButterflyGenome genome = butterfly.getGenome();
|
||||
float matureTime = genome.getLifespan() / (genome.getFertility() * 2);
|
||||
matureTime*=MATURE_TIME_MULTIPLIER;
|
||||
int caterpillarMatureTime = Math.round(matureTime);
|
||||
if(workCounter > 4){
|
||||
age++;
|
||||
ItemButterflyGE.setAge(stack, age);
|
||||
}
|
||||
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 void moveCocoonToWorkSlot() {
|
||||
if (!getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Integer slotIndex = getInputSlotIndex();
|
||||
if (slotIndex == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack inputStack = inventory.getStackInSlot(slotIndex);
|
||||
if (inputStack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = inputStack.copy();
|
||||
stack.setCount(1);
|
||||
inputStack.shrink(1);
|
||||
setInventorySlotContents(InventoryGreenhouseNursery.SLOT_WORK, stack);
|
||||
if(inputStack.isEmpty()){
|
||||
inventory.setInventorySlotContents(slotIndex, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Integer getInputSlotIndex() {
|
||||
for (int slotIndex = 0; slotIndex < InventoryGreenhouseNursery.SLOT_INPUT_COUNT; slotIndex++) {
|
||||
ItemStack inputStack = inventory.getStackInSlot(InventoryGreenhouseNursery.SLOT_INPUT_1 + slotIndex);
|
||||
if (!inputStack.isEmpty()) {
|
||||
return InventoryGreenhouseNursery.SLOT_INPUT_1 + slotIndex;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getAge(){
|
||||
ItemStack cocoon = getStackInSlot(InventoryGreenhouseNursery.SLOT_WORK);
|
||||
if(cocoon.isEmpty() || !cocoon.hasTagCompound()){
|
||||
return -1;
|
||||
}
|
||||
return cocoon.getTagCompound().getInteger(ItemButterflyGE.NBT_AGE);
|
||||
}
|
||||
|
||||
public int getProgressScaled(int i) {
|
||||
int ticksPerWorkCycle = getTicksPerWorkCycle();
|
||||
if (ticksPerWorkCycle == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return workCounter * i / ticksPerWorkCycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(PacketBufferForestry data) {
|
||||
super.writeGuiData(data);
|
||||
data.writeVarInt(workCounter);
|
||||
data.writeVarInt(getTicksPerWorkCycle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void readGuiData(PacketBufferForestry data) throws IOException {
|
||||
super.readGuiData(data);
|
||||
workCounter = data.readVarInt();
|
||||
ticksPerWorkCycle = data.readVarInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCocoonLoot(IButterflyCocoon cocoon, NonNullList<ItemStack> cocoonDrops) {
|
||||
for (ItemStack drop : cocoonDrops) {
|
||||
InventoryUtil.tryAddStack(this, drop, InventoryGreenhouseNursery.SLOT_OUTPUT_1, InventoryGreenhouseNursery.SLOT_OUTPUT_COUNT, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* IGuiHandlerTile */
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public GuiContainer getGui(EntityPlayer player, int data) {
|
||||
return new GuiGreenhouseNursery(player, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getContainer(EntityPlayer player, int data) {
|
||||
return new ContainerGreenhouseNursery(player.inventory, this);
|
||||
}
|
||||
|
||||
/* ITitled */
|
||||
@Override
|
||||
public String getUnlocalizedTitle() {
|
||||
return "for.gui.greenhouse.nursery.title";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package forestry.lepidopterology;
|
||||
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ButterflyUtils {
|
||||
|
||||
private static boolean attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
EntityLiving entityLiving = ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ());
|
||||
Log.trace("Spawned a butterfly '%s' at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ());
|
||||
return entityLiving != null;
|
||||
}
|
||||
|
||||
public static boolean spawnButterfly(IButterfly butterfly, World world, BlockPos pos){
|
||||
if (world.countEntities(EntityButterfly.class) > PluginLepidopterology.spawnConstraint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!butterfly.canSpawn(world, pos.getX(), pos.getY(), pos.getZ())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.isAirBlock(pos)) {
|
||||
return attemptButterflySpawn(world, butterfly, pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -107,9 +107,6 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
return;
|
||||
}
|
||||
|
||||
// if (rand.nextFloat() > 0.25) {
|
||||
// return;
|
||||
// }
|
||||
tileCocoon.onBlockTick();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ package forestry.lepidopterology.entities;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.lepidopterology.PluginLepidopterology;
|
||||
|
||||
@@ -50,7 +50,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
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;
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import forestry.core.config.Config;
|
||||
import forestry.core.genetics.ItemGE;
|
||||
import forestry.core.items.IColoredItem;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.EntityUtil;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
@@ -51,7 +50,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
@@ -100,9 +98,7 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
|
||||
ItemStack butterfly = ButterflyManager.butterflyRoot.getMemberStack(individual, type);
|
||||
|
||||
if (butterfly.getTagCompound() != null) {
|
||||
butterfly.getTagCompound().setInteger(NBT_AGE, age);
|
||||
}
|
||||
ItemButterflyGE.setAge(butterfly, age);
|
||||
|
||||
subItems.add(butterfly);
|
||||
}
|
||||
@@ -210,22 +206,7 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (type == EnumFlutterType.COCOON) {
|
||||
NBTTagCompound tagCompound = stack.getTagCompound();
|
||||
int age = tagCompound.getInteger(NBT_AGE);
|
||||
|
||||
// x, y, z are the coordinates of the block "hit", can thus either
|
||||
// be the soil or tall grass, etc.
|
||||
int yShift;
|
||||
if (!BlockUtil.isReplaceableBlock(blockState, world, pos)) {
|
||||
if (!world.isAirBlock(pos.down())) {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
yShift = 1;
|
||||
} else {
|
||||
yShift = 0;
|
||||
}
|
||||
|
||||
pos = ButterflyManager.butterflyRoot.plantCocoon(world, pos, flutter, player.getGameProfile(), age, true);
|
||||
pos = ButterflyManager.butterflyRoot.plantCocoon(world, pos, flutter, player.getGameProfile(), getAge(stack), true);
|
||||
if (pos != BlockPos.ORIGIN) {
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos,
|
||||
world.getBlockState(pos));
|
||||
@@ -261,6 +242,34 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAge(ItemStack cocoon, int age){
|
||||
if(cocoon.isEmpty()){
|
||||
return;
|
||||
}
|
||||
if (ButterflyManager.butterflyRoot.getType(cocoon) != EnumFlutterType.COCOON) {
|
||||
return;
|
||||
}
|
||||
NBTTagCompound tagCompound = cocoon.getTagCompound();
|
||||
if(tagCompound == null){
|
||||
cocoon.setTagCompound(tagCompound = new NBTTagCompound());
|
||||
}
|
||||
tagCompound.setInteger(NBT_AGE, age);
|
||||
}
|
||||
|
||||
public static int getAge(ItemStack cocoon){
|
||||
if(cocoon.isEmpty()){
|
||||
return 0;
|
||||
}
|
||||
if (ButterflyManager.butterflyRoot.getType(cocoon) != EnumFlutterType.COCOON) {
|
||||
return 0;
|
||||
}
|
||||
NBTTagCompound tagCompound = cocoon.getTagCompound();
|
||||
if(tagCompound == null){
|
||||
return 0;
|
||||
}
|
||||
return tagCompound.getInteger(NBT_AGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register butterfly item sprites
|
||||
|
||||
@@ -12,6 +12,9 @@ package forestry.lepidopterology.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.genetics.IAllele;
|
||||
@@ -21,7 +24,7 @@ import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.Nursery;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.network.IStreamable;
|
||||
@@ -176,12 +179,12 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
world.notifyBlockUpdate(pos, blockState, blockState, 0);
|
||||
} else if (caterpillar.canTakeFlight(world, getPos().getX(), getPos().getY(), getPos().getZ())) {
|
||||
IGreenhouseComponent.ButterflyHatch hatch = getButterflyHatch(world, pos);
|
||||
NonNullList<ItemStack> cocoonDrops;
|
||||
if (hatch != null) {
|
||||
cocoonDrops = hatch.addCocoonLoot(this);
|
||||
} else {
|
||||
cocoonDrops = caterpillar.getCocoonDrop(this);
|
||||
NonNullList<ItemStack> cocoonDrops = caterpillar.getCocoonDrop(this);
|
||||
for(IGreenhouseComponent.Nursery nursery : getNursery(world, pos)){
|
||||
nursery.addCocoonLoot(this, cocoonDrops);
|
||||
if(isListEmpty(cocoonDrops)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (ItemStack drop : cocoonDrops) {
|
||||
ItemStackUtil.dropItemStackAsEntity(drop, world, pos);
|
||||
@@ -192,25 +195,38 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ButterflyHatch getButterflyHatch(World world, BlockPos pos) {
|
||||
if (GreenhouseManager.greenhouseHelper == null
|
||||
|| GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos) == null) {
|
||||
return null;
|
||||
private Set<Nursery> getNursery(World world, BlockPos pos) {
|
||||
if (GreenhouseManager.greenhouseHelper == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
IGreenhouseController controller = GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos);
|
||||
if (controller != null) {
|
||||
Set<Nursery> nurserys;
|
||||
if (controller instanceof IGreenhouseControllerInternal) {
|
||||
return ((IGreenhouseControllerInternal) controller).getButterflyHatch();
|
||||
}
|
||||
|
||||
for (IMultiblockComponent greenhouse : controller.getComponents()) {
|
||||
if (greenhouse instanceof ButterflyHatch) {
|
||||
return (ButterflyHatch) greenhouse;
|
||||
nurserys = ((IGreenhouseControllerInternal) controller).getButterflyNurserys();
|
||||
}else{
|
||||
nurserys = new HashSet<>();
|
||||
for (IMultiblockComponent greenhouseComponent : controller.getComponents()) {
|
||||
if (greenhouseComponent instanceof Nursery) {
|
||||
nurserys.add((Nursery) greenhouseComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nurserys;
|
||||
}
|
||||
return null;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
private boolean isListEmpty(NonNullList<ItemStack> cocoonDrops){
|
||||
if(cocoonDrops.isEmpty()){
|
||||
return true;
|
||||
}
|
||||
for(ItemStack stack : cocoonDrops){
|
||||
if(!stack.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import forestry.lepidopterology.PluginLepidopterology;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
@@ -20,7 +20,6 @@ import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.mail.tiles.TileTrader;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class PacketTraderAddressRequest extends ForestryPacket implements IForestryPacketServer {
|
||||
|
||||
@@ -20,7 +20,6 @@ import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.mail.tiles.TileTrader;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
Reference in new issue
Block a user