Add sprinkler model

This commit is contained in:
Nedelosk committed 2016-03-14 23:30:43 +01:00
1 parent bde92c4afc
commit 3d25bd8626
27 files changed
+478 -69

No files matched your search

@@ -23,6 +23,7 @@ public enum FarmDirection {
return forgeDirection;
}
@SuppressWarnings("incomplete-switch")
public static FarmDirection getFarmDirection(EnumFacing forgeDirection) {
switch (forgeDirection) {
case NORTH:
@@ -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) {
@@ -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<C extends Container, I extends IInventory> extends GuiContainer /*implements INEIGuiHandler*/ {
public abstract class GuiForestry<C extends Container, I extends IInventory> extends GuiContainer {
protected final I inventory;
protected final C container;
@@ -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<String, ITimeValue> parameters){
return null;
}
/* FX */
@@ -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<String, ITimeValue> parameters){
return Animation.INSTANCE.load(location, parameters);
}
private static boolean shouldSpawnParticle(World world) {
if (!Config.enableParticleFX) {
@@ -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());
}
}
}
@@ -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:
@@ -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;
@@ -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
@@ -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<TileGreenhouse> {
public ContainerGreenhouse(InventoryPlayer playerInventory, TileGreenhouse tile) {
super(tile, playerInventory, 8, 84);
addSlotToContainer(new SlotFiltered(tile, 0, 53, 37));
}
@Override
@@ -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;
@@ -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 {
}
@@ -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() {
@@ -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);
}
@@ -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
@@ -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);
}
}
@@ -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(),
@@ -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 MultiblockTileEntityForestry<Multib
}
return EnumCamouflageType.DEFAULT;
}
@Override
public IInventoryAdapter getInternalInventory() {
return getMultiblockLogic().getController().getInternalInventory();
}
}
@@ -116,7 +116,7 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
if (worldObj != null) {
if (worldObj.isRemote) {
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
worldObj.markBlockForUpdate(getPos());
} else {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), worldObj);
}
@@ -10,27 +10,50 @@
******************************************************************************/
package forestry.greenhouse.tiles;
import com.google.common.collect.ImmutableMap;
import forestry.api.core.IClimateControlled;
import forestry.api.greenhouse.IGreenhouseHousing;
import forestry.api.multiblock.IGreenhouseController;
import forestry.core.config.Constants;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.proxy.Proxies;
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.animation.Animation;
import net.minecraftforge.client.model.animation.IAnimationProvider;
import net.minecraftforge.client.model.animation.ITimeValue;
import net.minecraftforge.client.model.animation.TimeValues.VariableValue;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser implements IAnimationProvider {
protected static final int WATER_PER_OPERATION = 75;
private final IAnimationStateMachine asm;
private final VariableValue cycleLength = new VariableValue(4);
private final VariableValue clickTime = new VariableValue(Float.NEGATIVE_INFINITY);
protected static final int WATER_PER_OPERATION = 2;
private static final SprinklerDefinition definition = new SprinklerDefinition();
public TileGreenhouseSprinkler() {
super(definition);
asm = Proxies.render.loadAnimationState(new ResourceLocation(Constants.RESOURCE_ID, "asms/block/sprinkler.json"), ImmutableMap.<String, ITimeValue>of(
"cycle_length", cycleLength,
"click_time", clickTime
));
}
@Override
public boolean hasFastRenderer(){
return true;
}
@Override
public <G extends IGreenhouseController & IGreenhouseHousing & IClimateControlled> 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 {