diff --git a/src/main/java/forestry/api/farming/FarmDirection.java b/src/main/java/forestry/api/farming/FarmDirection.java index 165bce29c..84101c92d 100644 --- a/src/main/java/forestry/api/farming/FarmDirection.java +++ b/src/main/java/forestry/api/farming/FarmDirection.java @@ -23,6 +23,7 @@ public enum FarmDirection { return forgeDirection; } + @SuppressWarnings("incomplete-switch") public static FarmDirection getFarmDirection(EnumFacing forgeDirection) { switch (forgeDirection) { case NORTH: diff --git a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java index 4d7dea66f..f5ea1d000 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java @@ -1005,6 +1005,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe protected abstract void registerMutations(); + @SuppressWarnings("incomplete-switch") @Override public void setLogBlock(ITreeGenome genome, World world, BlockPos pos, EnumFacing facing) { if (woodType == null) { diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index 918c194f4..56ae1daa0 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -49,7 +49,7 @@ import forestry.core.tiles.IClimatised; import forestry.core.tiles.IPowerHandler; @Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems") -public abstract class GuiForestry extends GuiContainer /*implements INEIGuiHandler*/ { +public abstract class GuiForestry extends GuiContainer { protected final I inventory; protected final C container; diff --git a/src/main/java/forestry/core/proxy/ProxyRender.java b/src/main/java/forestry/core/proxy/ProxyRender.java index dfa6458d2..83a71a494 100644 --- a/src/main/java/forestry/core/proxy/ProxyRender.java +++ b/src/main/java/forestry/core/proxy/ProxyRender.java @@ -12,6 +12,8 @@ package forestry.core.proxy; import javax.annotation.Nullable; +import com.google.common.collect.ImmutableMap; + import net.minecraft.block.Block; import net.minecraft.client.renderer.block.statemap.IStateMapper; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; @@ -20,7 +22,8 @@ import net.minecraft.entity.Entity; import net.minecraft.util.BlockPos; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; - +import net.minecraftforge.client.model.animation.ITimeValue; +import net.minecraftforge.common.model.animation.IAnimationStateMachine; import forestry.core.fluids.Fluids; import forestry.core.models.BlockModelIndex; import forestry.core.models.ModelIndex; @@ -93,6 +96,10 @@ public class ProxyRender { public void registerModels() { } + + public IAnimationStateMachine loadAnimationState(ResourceLocation location, ImmutableMap parameters){ + return null; + } /* FX */ diff --git a/src/main/java/forestry/core/proxy/ProxyRenderClient.java b/src/main/java/forestry/core/proxy/ProxyRenderClient.java index 54c31a1d1..c3e40b84f 100644 --- a/src/main/java/forestry/core/proxy/ProxyRenderClient.java +++ b/src/main/java/forestry/core/proxy/ProxyRenderClient.java @@ -12,6 +12,8 @@ package forestry.core.proxy; import javax.annotation.Nonnull; +import com.google.common.collect.ImmutableMap; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -34,7 +36,9 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; - +import net.minecraftforge.client.model.animation.Animation; +import net.minecraftforge.client.model.animation.ITimeValue; +import net.minecraftforge.common.model.animation.IAnimationStateMachine; import forestry.apiculture.entities.EntityFXBee; import forestry.apiculture.render.ParticleRenderer; import forestry.apiculture.render.TextureHabitatLocator; @@ -150,6 +154,11 @@ public class ProxyRenderClient extends ProxyRender { public void registerModels() { ModelManager.registerModels(); } + + @Override + public IAnimationStateMachine loadAnimationState(ResourceLocation location, ImmutableMap parameters){ + return Animation.INSTANCE.load(location, parameters); + } private static boolean shouldSpawnParticle(World world) { if (!Config.enableParticleFX) { diff --git a/src/main/java/forestry/core/utils/CamouflageUtil.java b/src/main/java/forestry/core/utils/CamouflageUtil.java new file mode 100644 index 000000000..e528f59cf --- /dev/null +++ b/src/main/java/forestry/core/utils/CamouflageUtil.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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.core.utils; + +import java.io.IOException; + +import forestry.api.core.EnumCamouflageType; +import forestry.api.core.ICamouflageHandler; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class CamouflageUtil { + + public static void writeCamouflageBlockToNBT(NBTTagCompound data, ICamouflageHandler handler, EnumCamouflageType type){ + ItemStack camouflageBlock = handler.getCamouflageBlock(type); + if(camouflageBlock != null){ + NBTTagCompound nbtTag = new NBTTagCompound(); + camouflageBlock.writeToNBT(nbtTag); + data.setTag("Camouflage" + type.name(), nbtTag); + } + } + + public static void readCamouflageBlockFromNBT(NBTTagCompound data, ICamouflageHandler handler, EnumCamouflageType type){ + if(data.hasKey("Camouflage" + type.name())){ + handler.setCamouflageBlock(type, ItemStack.loadItemStackFromNBT(data.getCompoundTag("Camouflage" + type.name()))); + } + } + + public static void writeCamouflageBlockToData(DataOutputStreamForestry data, ICamouflageHandler handler, EnumCamouflageType type) throws IOException{ + ItemStack camouflageBlock = handler.getCamouflageBlock(type); + if(camouflageBlock != null){ + data.writeShort(1); + data.writeShort(type.ordinal()); + data.writeItemStack(camouflageBlock); + }else{ + data.writeShort(0); + } + } + + public static void readCamouflageBlockFromData(DataInputStreamForestry data, ICamouflageHandler handler) throws IOException{ + if(data.readShort() == 1){ + handler.setCamouflageBlock(EnumCamouflageType.VALUES[data.readShort()], data.readItemStack()); + } + } + +} diff --git a/src/main/java/forestry/energy/EnergyManager.java b/src/main/java/forestry/energy/EnergyManager.java index 55713afc7..691c09253 100644 --- a/src/main/java/forestry/energy/EnergyManager.java +++ b/src/main/java/forestry/energy/EnergyManager.java @@ -42,6 +42,7 @@ public class EnergyManager implements IEnergyHandler, IEnergyReceiver, IEnergyPr mode = EnergyTransferMode.RECEIVE; } + @SuppressWarnings("incomplete-switch") private boolean canExtract() { switch (mode) { case EXTRACT: @@ -51,6 +52,7 @@ public class EnergyManager implements IEnergyHandler, IEnergyReceiver, IEnergyPr return false; } + @SuppressWarnings("incomplete-switch") private boolean canReceive() { switch (mode) { case RECEIVE: diff --git a/src/main/java/forestry/greenhouse/PluginGreenhouse.java b/src/main/java/forestry/greenhouse/PluginGreenhouse.java index 532dcd952..a9fe9e1db 100644 --- a/src/main/java/forestry/greenhouse/PluginGreenhouse.java +++ b/src/main/java/forestry/greenhouse/PluginGreenhouse.java @@ -14,7 +14,6 @@ import forestry.api.core.EnumCamouflageType; import forestry.api.greenhouse.GreenhouseManager; import forestry.api.greenhouse.IGreenhouseItemAccess; import forestry.core.config.Constants; -import forestry.greenhouse.blocks.BlockGreenhouse; import forestry.greenhouse.blocks.BlockGreenhouseType; import forestry.greenhouse.blocks.BlockRegistryGreenhouse; import forestry.greenhouse.proxy.ProxyGreenhouse; diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java index 4269c6dac..b6620645b 100644 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java @@ -27,6 +27,7 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumWorldBlockLayer; @@ -38,10 +39,12 @@ import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; +import net.minecraftforge.common.property.Properties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import forestry.api.core.IModelManager; +import forestry.api.multiblock.IGreenhouseComponent; import forestry.core.CreativeTabForestry; import forestry.core.blocks.BlockStructure; import forestry.core.blocks.propertys.UnlistedBlockAccess; @@ -93,7 +96,7 @@ public abstract class BlockGreenhouse extends BlockStructure { super(Material.rock); BlockGreenhouseType greenhouseType = getGreenhouseType(); IBlockState defaultState = this.blockState.getBaseState(); - if(greenhouseType.activatable){ + if(greenhouseType.activatable && greenhouseType != BlockGreenhouseType.SPRINKLER){ defaultState = defaultState.withProperty(STATE, State.OFF); } setDefaultState(defaultState); @@ -102,6 +105,32 @@ public abstract class BlockGreenhouse extends BlockStructure { setHarvestLevel("pickaxe", 0); setCreativeTab(CreativeTabForestry.tabForestry); } + + @Override + @SideOnly(Side.CLIENT) + public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos){ + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + this.setBlockBoundsBasedOnState(worldIn, pos); + } + return super.getSelectedBoundingBox(worldIn, pos); + } + + @Override + public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state){ + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + this.setBlockBoundsBasedOnState(worldIn, pos); + } + return super.getCollisionBoundingBox(worldIn, pos, state); + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos){ + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + setBlockBounds(0.3125F, 0.25F, 0.3125F, 0.6875F, 1F, 0.6875F); + }else{ + super.setBlockBoundsBasedOnState(worldIn, pos); + } + } @Override public int getMetaFromState(IBlockState state) { @@ -110,18 +139,32 @@ public abstract class BlockGreenhouse extends BlockStructure { @Override public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { - return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos) - .withProperty(UnlistedBlockAccess.BLOCKACCESS, world); + if(getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.DOOR){ + return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos) + . withProperty(UnlistedBlockAccess.BLOCKACCESS, world); + } + return super.getExtendedState(state, world, pos); } @Override protected BlockState createBlockState() { - if(getGreenhouseType().activatable){ + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + return new ExtendedBlockState(this, new IProperty[]{ Properties.StaticProperty }, new IUnlistedProperty[]{ Properties.AnimationProperty }); + }else if(getGreenhouseType().activatable){ return new ExtendedBlockState(this, new IProperty[]{STATE}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); }else{ return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); } } + + @Override + public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + return state.withProperty(Properties.StaticProperty, true); + }else{ + return super.getActualState(state, worldIn, pos); + } + } @Override @SideOnly(Side.CLIENT) @@ -163,7 +206,7 @@ public abstract class BlockGreenhouse extends BlockStructure { @Override @SideOnly(Side.CLIENT) public EnumWorldBlockLayer getBlockLayer() { - if(getGreenhouseType() == BlockGreenhouseType.GLASS){ + if(getGreenhouseType() == BlockGreenhouseType.GLASS || getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ return EnumWorldBlockLayer.TRANSLUCENT; } return EnumWorldBlockLayer.CUTOUT; @@ -176,7 +219,20 @@ public abstract class BlockGreenhouse extends BlockStructure { @Override public boolean isOpaqueCube() { - return getGreenhouseType() != BlockGreenhouseType.GLASS; + return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() != BlockGreenhouseType.SPRINKLER; + } + + @Override + public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + if(worldIn.getBlockState(pos.up()).getBlock() == this){ + return false; + } + if(!(worldIn.getTileEntity(pos.up()) instanceof IGreenhouseComponent)){ + return false; + } + } + return super.canPlaceBlockAt(worldIn, pos); } @Override @@ -207,7 +263,11 @@ public abstract class BlockGreenhouse extends BlockStructure { @SideOnly(Side.CLIENT) @Override public void registerModel(Item item, IModelManager manager) { - ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse", "inventory")); + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.sprinkler", "inventory")); + }else{ + ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse", "inventory")); + } } @Override diff --git a/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java b/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java index 1972bc044..62bb027a6 100644 --- a/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java +++ b/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java @@ -13,6 +13,7 @@ package forestry.greenhouse.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraftforge.fluids.IFluidTank; import forestry.core.gui.ContainerTile; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.packets.PacketGuiUpdate; import forestry.greenhouse.tiles.TileGreenhouse; @@ -20,6 +21,8 @@ public class ContainerGreenhouse extends ContainerTile { public ContainerGreenhouse(InventoryPlayer playerInventory, TileGreenhouse tile) { super(tile, playerInventory, 8, 84); + + addSlotToContainer(new SlotFiltered(tile, 0, 53, 37)); } @Override diff --git a/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java index 1bfdb0fe5..9a46eff1c 100644 --- a/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java @@ -20,13 +20,9 @@ import forestry.core.gui.tooltips.ToolTip; import forestry.core.gui.widgets.Widget; import forestry.core.gui.widgets.WidgetManager; import forestry.core.proxy.Proxies; -import mezz.jei.gui.ingredients.GuiIngredient; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.BlockModelShapes; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/forestry/greenhouse/models/ModelGreenhouseSprinkler.java b/src/main/java/forestry/greenhouse/models/ModelGreenhouseSprinkler.java new file mode 100644 index 000000000..d04c5affc --- /dev/null +++ b/src/main/java/forestry/greenhouse/models/ModelGreenhouseSprinkler.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * 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.models; + +public class ModelGreenhouseSprinkler { + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java index 7aa121099..af5574fc6 100644 --- a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java @@ -13,6 +13,8 @@ package forestry.greenhouse.multiblock; import forestry.api.core.EnumCamouflageType; import forestry.core.fluids.FakeTankManager; import forestry.core.fluids.ITankManager; +import forestry.core.inventory.FakeInventoryAdapter; +import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.FakeMultiblockController; import forestry.energy.EnergyManager; import net.minecraft.item.ItemStack; @@ -24,6 +26,11 @@ public class FakeGreenhouseController extends FakeMultiblockController implement private FakeGreenhouseController() { } + + @Override + public IInventoryAdapter getInternalInventory() { + return FakeInventoryAdapter.instance(); + } @Override public ITankManager getTankManager() { diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index bb8ae8f67..5d2411855 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -29,10 +29,11 @@ import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IMultiblockComponent; import forestry.core.access.EnumAccess; import forestry.core.config.Constants; -import forestry.core.fluids.ITankManager; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.fluids.tanks.StandardTank; +import forestry.core.inventory.FakeInventoryAdapter; +import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.IMultiblockControllerInternal; import forestry.core.multiblock.MultiblockValidationException; import forestry.core.multiblock.RectangularMultiblockControllerBase; @@ -40,9 +41,13 @@ import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.proxy.Proxies; import forestry.core.tiles.ILiquidTankTile; +import forestry.core.utils.CamouflageUtil; import forestry.energy.EnergyManager; +import forestry.greenhouse.blocks.BlockGreenhouse; +import forestry.greenhouse.blocks.BlockGreenhouseType; import forestry.greenhouse.network.packets.PacketCamouflageUpdate; import forestry.greenhouse.tiles.TileGreenhouseSprinkler; +import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -66,6 +71,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im private final TankManager tankManager; private final StandardTank resourceTank; private final EnergyManager energyManager; + private final InventoryGreenhouse inventory; //Camouflage blocks private ItemStack camouflagePlainBlock; @@ -80,8 +86,18 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im this.resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER); this.tankManager = new TankManager(this, resourceTank); this.energyManager = new EnergyManager(2000, 100000); + this.inventory = new InventoryGreenhouse(this); } + @Override + public IInventoryAdapter getInternalInventory() { + if (isAssembled()) { + return inventory; + } else { + return FakeInventoryAdapter.instance(); + } + } + @Override public EnumTemperature getTemperature() { BlockPos coords = getReferenceCoord(); @@ -167,10 +183,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im data.setFloat("Humidity", humidChange); tankManager.writeToNBT(data); energyManager.writeToNBT(data); + inventory.writeToNBT(data); - writeCamouflageBlockToNBT(data, EnumCamouflageType.DEFAULT); - writeCamouflageBlockToNBT(data, EnumCamouflageType.GLASS); - writeCamouflageBlockToNBT(data, EnumCamouflageType.DOOR); + CamouflageUtil.writeCamouflageBlockToNBT(data, this, EnumCamouflageType.DEFAULT); + CamouflageUtil.writeCamouflageBlockToNBT(data, this, EnumCamouflageType.GLASS); + CamouflageUtil.writeCamouflageBlockToNBT(data, this, EnumCamouflageType.DOOR); } @Override @@ -181,25 +198,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im humidChange = data.getFloat("Humidity"); tankManager.readFromNBT(data); energyManager.readFromNBT(data); + inventory.readFromNBT(data); - readCamouflageBlockFromNBT(data, EnumCamouflageType.DEFAULT); - readCamouflageBlockFromNBT(data, EnumCamouflageType.GLASS); - readCamouflageBlockFromNBT(data, EnumCamouflageType.DOOR); - } - - private void writeCamouflageBlockToNBT(NBTTagCompound data, EnumCamouflageType type){ - ItemStack camouflageBlock = getCamouflageBlock(type); - if(camouflageBlock != null){ - NBTTagCompound nbtTag = new NBTTagCompound(); - camouflageBlock.writeToNBT(nbtTag); - data.setTag("Camouflage" + type.name(), nbtTag); - } - } - - private void readCamouflageBlockFromNBT(NBTTagCompound data, EnumCamouflageType type){ - if(data.hasKey("Camouflage" + type.name())){ - setCamouflageBlock(type, ItemStack.loadItemStackFromNBT(data.getCompoundTag("Camouflage" + type.name()))); - } + CamouflageUtil.readCamouflageBlockFromNBT(data, this, EnumCamouflageType.DEFAULT); + CamouflageUtil.readCamouflageBlockFromNBT(data, this, EnumCamouflageType.GLASS); + CamouflageUtil.readCamouflageBlockFromNBT(data, this, EnumCamouflageType.DOOR); } @Override @@ -222,9 +225,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im data.writeVarInt(Math.round(humidChange * 100)); tankManager.writeData(data); energyManager.writeData(data); - writeCamouflageBlockToData(data, EnumCamouflageType.DEFAULT); - writeCamouflageBlockToData(data, EnumCamouflageType.GLASS); - writeCamouflageBlockToData(data, EnumCamouflageType.DOOR); + inventory.writeData(data); + CamouflageUtil.writeCamouflageBlockToData(data, this, EnumCamouflageType.DEFAULT); + CamouflageUtil.writeCamouflageBlockToData(data, this, EnumCamouflageType.GLASS); + CamouflageUtil.writeCamouflageBlockToData(data, this, EnumCamouflageType.DOOR); } @Override @@ -233,26 +237,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im humidChange = data.readVarInt() / 100.0F; tankManager.readData(data); energyManager.readData(data); - readCamouflageBlockFromData(data); - readCamouflageBlockFromData(data); - readCamouflageBlockFromData(data); - } - - private void writeCamouflageBlockToData(DataOutputStreamForestry data, EnumCamouflageType type) throws IOException{ - ItemStack camouflageBlock = getCamouflageBlock(type); - if(camouflageBlock != null){ - data.writeShort(1); - data.writeShort(type.ordinal()); - data.writeItemStack(camouflageBlock); - }else{ - data.writeShort(0); - } - } - - private void readCamouflageBlockFromData(DataInputStreamForestry data) throws IOException{ - if(data.readShort() == 1){ - setCamouflageBlock(EnumCamouflageType.VALUES[data.readShort()], data.readItemStack()); - } + inventory.readData(data); + CamouflageUtil.readCamouflageBlockFromData(data, this); + CamouflageUtil.readCamouflageBlockFromData(data, this); + CamouflageUtil.readCamouflageBlockFromData(data, this); } @Override @@ -305,7 +293,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } @Override - public ITankManager getTankManager() { + public TankManager getTankManager() { return tankManager; } @@ -358,6 +346,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im @Override protected boolean updateServer(int tickCount) { + if (updateOnInterval(20)) { + inventory.drainCan(tankManager); + } + for (IGreenhouseComponent.Active activeComponent : activeComponents) { activeComponent.updateServer(tickCount); } @@ -520,10 +512,12 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } } else { if (part != null) { - if (myClass.equals(part.getMultiblockLogic().getController().getClass())) { + IBlockState state = worldObj.getBlockState(part.getCoordinates()); + if(state.getBlock() instanceof BlockGreenhouse && ((BlockGreenhouse)state.getBlock()).getGreenhouseType() == BlockGreenhouseType.SPRINKLER || !myClass.equals(part.getMultiblockLogic().getController().getClass())){ + isGoodForInterior(part); + }else{ throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.invalid.part", x, y, z, myClass.getSimpleName())); } - isGoodForInterior(part); } else { isBlockGoodForInterior(this.worldObj, pos); } diff --git a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java index e37ad543a..37121ccf9 100644 --- a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java +++ b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java @@ -16,12 +16,15 @@ import forestry.api.core.ICamouflageHandler; import forestry.api.multiblock.IGreenhouseController; import forestry.core.access.IRestrictedAccess; import forestry.core.fluids.ITankManager; +import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.IMultiblockControllerInternal; import forestry.core.network.IStreamableGui; import forestry.energy.EnergyManager; public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IRestrictedAccess, IStreamableGui, ICamouflageHandler { + IInventoryAdapter getInternalInventory(); + ITankManager getTankManager(); @Nullable diff --git a/src/main/java/forestry/greenhouse/multiblock/InventoryGreenhouse.java b/src/main/java/forestry/greenhouse/multiblock/InventoryGreenhouse.java new file mode 100644 index 000000000..ffcdce366 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/InventoryGreenhouse.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.multiblock; + +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.TankManager; +import forestry.core.inventory.InventoryAdapterRestricted; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; + +public class InventoryGreenhouse extends InventoryAdapterRestricted { + + private final GreenhouseController greenhouseController; + + public InventoryGreenhouse(GreenhouseController greenhouseController) { + super(1, "Items", greenhouseController.getAccessHandler()); + this.greenhouseController = greenhouseController; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return greenhouseController.getTankManager().accepts(fluid); + } + + public void drainCan(TankManager tankManager) { + FluidHelper.drainContainers(tankManager, this, 0); + } + +} diff --git a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java index c9aa2da53..09f91f6ed 100644 --- a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java +++ b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java @@ -12,11 +12,14 @@ package forestry.greenhouse.proxy; import net.minecraft.block.Block; import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraftforge.client.model.animation.AnimationTESR; +import net.minecraftforge.fml.client.registry.ClientRegistry; import forestry.core.models.BlockModelIndex; import forestry.core.proxy.Proxies; import forestry.greenhouse.PluginGreenhouse; import forestry.greenhouse.blocks.BlockGreenhouseType; import forestry.greenhouse.models.ModelGreenhouse; +import forestry.greenhouse.tiles.TileGreenhouseSprinkler; public class ProxyGreenhouseClient extends ProxyGreenhouse { @@ -24,7 +27,11 @@ public class ProxyGreenhouseClient extends ProxyGreenhouse { public void initializeModels() { for(BlockGreenhouseType greenhouseType : BlockGreenhouseType.VALUES){ if(greenhouseType == BlockGreenhouseType.DOOR) { - return; + continue; + } + else if(greenhouseType == BlockGreenhouseType.SPRINKLER){ + ClientRegistry.bindTileEntitySpecialRenderer(TileGreenhouseSprinkler.class, new AnimationTESR()); + continue; } Proxies.render.registerBlockModel(new BlockModelIndex(new ModelResourceLocation("forestry:greenhouse." + greenhouseType), new ModelResourceLocation("forestry:greenhouse", "inventory"), new ModelGreenhouse(), diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java index 104253438..f1cd796f8 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java @@ -29,6 +29,7 @@ import forestry.core.access.IAccessHandler; import forestry.core.access.IRestrictedAccess; import forestry.core.config.Config; import forestry.core.gui.IHintSource; +import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.MultiblockTileEntityForestry; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; @@ -196,4 +197,9 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestryof( + "cycle_length", cycleLength, + "click_time", clickTime + )); } + @Override + public boolean hasFastRenderer(){ + return true; + } + @Override public void changeClimate(int tick, G greenhouse) { IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse; if (workingTime < 20 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) { // one tick of work for every 10 RF - workingTime += ENERGY_PER_OPERATION / 10; + workingTime += WATER_PER_OPERATION * 2; } if (workingTime > 0) { @@ -41,9 +64,25 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser { setActive(workingTime > 0); } + @Override + public void setActive(boolean active) { + super.setActive(active); + if (worldObj != null && worldObj.isRemote) { + if(asm.currentState().equals("moving") && !isActive()){ + clickTime.setValue(Animation.getWorldTime(getWorld(), Animation.getPartialTickTime())); + asm.transition("stopping"); + }else if(asm.currentState().equals("default") && isActive()){ + float time = Animation.getWorldTime(getWorld(), Animation.getPartialTickTime()); + clickTime.setValue(time); + + asm.transition("starting"); + } + } + } + public boolean consumeWaterToDoWork(int ticksPerWorkCycle, int fluidPerWorkCycle, StandardTank tank) { int fluidPerCycle = (int) Math.ceil(fluidPerWorkCycle / (float) ticksPerWorkCycle); - if (tank.getFluid().amount < fluidPerCycle) { + if (tank.getFluid() == null || tank.getFluid().amount < fluidPerCycle) { return false; } @@ -61,6 +100,11 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser { tank.getFluid().amount = 0; } } + + @Override + public IAnimationStateMachine asm(){ + return asm; + } private static class SprinklerDefinition implements IClimitiserDefinition { diff --git a/src/main/resources/assets/forestry/armatures/block/greenhouse.sprinkler_iron.json b/src/main/resources/assets/forestry/armatures/block/greenhouse.sprinkler_iron.json new file mode 100644 index 000000000..0237aeeb5 --- /dev/null +++ b/src/main/resources/assets/forestry/armatures/block/greenhouse.sprinkler_iron.json @@ -0,0 +1,40 @@ +{ + "joints": { + "sprinkler_iron": { "0": [ 1.0 ], "1": [ 1.0 ], "2": [ 1.0 ] } + }, + "clips": { + "default": { + "loop": false, + "joint_clips": {}, + "events": {} + }, + "moving": { + "loop": true, + "joint_clips": { + "sprinkler_iron": [ + { + "variable": "axis_y", + "type": "uniform", + "interpolation": "nearest", + "samples": [ 1 ] + }, + { + "variable": "angle", + "type": "uniform", + "interpolation": "linear", + "samples": [ + 0, 120, 240, + 0, 120, 240, + 0, 120, 240, + 0, 120, 240 + ] + } + ] + }, + "events": { + "0.5": "boop" + } + } + } +} + diff --git a/src/main/resources/assets/forestry/asms/block/sprinkler.json b/src/main/resources/assets/forestry/asms/block/sprinkler.json new file mode 100644 index 000000000..f6ccd015d --- /dev/null +++ b/src/main/resources/assets/forestry/asms/block/sprinkler.json @@ -0,0 +1,26 @@ +{ + "parameters": { + "world_to_cycle": [ "/", "#cycle_length" ], + "round_cycle": [ "compose", [ "R", "#cycle_length" ] , "#click_time" ], + "end_cycle": [ "-", "#round_cycle" ] + }, + "clips": { + "default": "forestry:block/greenhouse.sprinkler_iron@default", + "starting": [ "trigger_positive", "#default", "#end_cycle", "!transition:moving" ], + "moving": [ "apply", "forestry:block/greenhouse.sprinkler_iron@moving", "#world_to_cycle" ], + "stopping": [ "trigger_positive", "#moving", "#end_cycle", "!transition:default" ] + }, + "states": [ + "default", + "starting", + "moving", + "stopping" + ], + "transitions": { + "default": "starting", + "starting": "moving", + "moving": "stopping", + "stopping": "default" + }, + "start_state": "default" +} diff --git a/src/main/resources/assets/forestry/blockstates/greenhouse.sprinkler.json b/src/main/resources/assets/forestry/blockstates/greenhouse.sprinkler.json new file mode 100644 index 000000000..7142a1799 --- /dev/null +++ b/src/main/resources/assets/forestry/blockstates/greenhouse.sprinkler.json @@ -0,0 +1,32 @@ +{ + "forge_marker": 1, + "defaults": { + "textures": { + } + }, + "variants": { + "normal": [{}], + "inventory": [{ + "transform": { + "rotation": { "y": 180 }, + "thirdperson": { + "rotation": [ { "z": 170 }, { "y": -45 }, { "z": 20 } ], + "translation": [ 0, 0.09375, -0.171875 ], + "scale": 0.375 + } + }, + "model": "forestry:greenhouse.sprinkler_base", + "submodel": { + "ring": { "model": "forestry:greenhouse.sprinkler_iron" } + } + }], + "static": { + "true": { + "model": "forestry:greenhouse.sprinkler_base" + }, + "false": { + "model": "forestry:greenhouse.sprinkler_iron" + } + } + } +} diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.sprinkler_base.json b/src/main/resources/assets/forestry/models/block/greenhouse.sprinkler_base.json new file mode 100644 index 000000000..70cef0212 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/greenhouse.sprinkler_base.json @@ -0,0 +1,20 @@ +{ +"textures": { + "particle": "blocks/glass_green", + "glass": "blocks/glass_green" +}, +"elements": [ +{ + "from": [ 5, 10, 5 ], + "to": [ 11, 16, 11 ], + "faces": { + "down": { "uv": [ 16, 16, 0, 0 ], "texture": "#glass" }, + "up": { "uv": [ 16, 0, 0, 16 ], "texture": "#glass" }, + "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "east": { "uv": [ 0, 0, 15.5, 16 ], "texture": "#glass" } + } +} +] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.sprinkler_iron.json b/src/main/resources/assets/forestry/models/block/greenhouse.sprinkler_iron.json new file mode 100644 index 000000000..412a673a8 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/greenhouse.sprinkler_iron.json @@ -0,0 +1,43 @@ +{ +"textures": { + "iron_base": "blocks/anvil_base" +}, +"elements": [ +{ + "from": [ 7, 4, 7 ], + "to": [ 9, 10, 9 ], + "faces": { + "down": { "uv": [ 9, 9, 7, 7 ], "texture": "#iron_base" }, + "up": { "uv": [ 7, 7, 9, 9 ], "texture": "#iron_base" }, + "north": { "uv": [ 7, 6, 9, 12 ], "texture": "#iron_base" }, + "south": { "uv": [ 7, 6, 9, 12 ], "texture": "#iron_base" }, + "west": { "uv": [ 7, 6, 9, 12 ], "texture": "#iron_base" }, + "east": { "uv": [ 7, 6, 9, 12 ], "texture": "#iron_base" } + } +}, +{ + "from": [ 7.5, 5, 5.5 ], + "to": [ 8.5, 6, 10.5 ], + "faces": { + "down": { "uv": [ 8.5, 10.5, 7.5, 5.5 ], "texture": "#iron_base" }, + "up": { "uv": [ 7.5, 5.5, 8.5, 10.5 ], "texture": "#iron_base" }, + "north": { "uv": [ 7.5, 10, 8.5, 11 ], "texture": "#iron_base" }, + "south": { "uv": [ 7.5, 10, 8.5, 11 ], "texture": "#iron_base" }, + "west": { "uv": [ 5.5, 10, 10.5, 11 ], "texture": "#iron_base" }, + "east": { "uv": [ 5.5, 10, 10.5, 11 ], "texture": "#iron_base" } + } +}, +{ + "from": [ 5.5, 5, 7.5 ], + "to": [ 10.5, 6, 8.5 ], + "faces": { + "down": { "uv": [ 10.5, 8.5, 5.5, 7.5 ], "texture": "#iron_base" }, + "up": { "uv": [ 5.5, 7.5, 10.5, 8.5 ], "texture": "#iron_base" }, + "north": { "uv": [ 5.5, 10, 10.5, 11 ], "texture": "#iron_base" }, + "south": { "uv": [ 5.5, 10, 10.5, 11 ], "texture": "#iron_base" }, + "west": { "uv": [ 7.5, 10, 8.5, 11 ], "texture": "#iron_base" }, + "east": { "uv": [ 7.5, 10, 8.5, 11 ], "texture": "#iron_base" } + } +} +] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/dryer.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/dryer.png new file mode 100644 index 000000000..659459c7d Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/dryer.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse.png b/src/main/resources/assets/forestry/textures/gui/greenhouse.png index 29387f8fd..98c00a995 100644 Binary files a/src/main/resources/assets/forestry/textures/gui/greenhouse.png and b/src/main/resources/assets/forestry/textures/gui/greenhouse.png differ