Clean up and greenhouse door logic

This commit is contained in:
Nedelosk committed 2016-03-19 01:40:52 +01:00
1 parent 252a08f416
commit 0f3e63ed20
13 files changed
+201 -115

No files matched your search

@@ -10,6 +10,9 @@ import net.minecraft.world.World;
public interface IGreenhouseHelper {
/**
* @return A {@link IGreenhouseState} of a greenhouse, when the pos is a greenhouse
*/
IGreenhouseState getGreenhouseState(World world, BlockPos pos);
}
@@ -21,8 +21,15 @@ public interface IGreenhouseHousing extends IErrorLogicSource {
float getExactHumidity();
/**
* @return The world in that the housing is
*/
World getWorld();
/**
* @return Is the position in the greenhouse
*/
boolean isInGreenhouse(BlockPos pos);
}
@@ -19,6 +19,9 @@ public interface IGreenhouseState {
float getExactHumidity();
/**
* @return The world in that the greenhouse standing
*/
World getWorld();
}
@@ -0,0 +1,9 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@API(apiVersion = "5.0.0", owner = "ForestryAPI|greenhouse", provides = "ForestryAPI|greenhouse")
package forestry.api.greenhouse;
import net.minecraftforge.fml.common.API;
@@ -15,8 +15,14 @@ import forestry.api.greenhouse.IGreenhouseLogic;
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlled {
/**
* Handle change events
*/
void onChange(EnumGreenhouseChangeType type, Object event);
/**
* @return The logics of the greenhouse
*/
List<IGreenhouseLogic> getLogics();
}
@@ -15,7 +15,8 @@ import forestry.api.greenhouse.IGreenhouseAccess;
import forestry.core.config.Constants;
import forestry.core.network.IPacketRegistry;
import forestry.greenhouse.blocks.BlockRegistryGreenhouse;
import forestry.greenhouse.logics.GreenhouseEffect;
import forestry.greenhouse.logics.GreenhouseLogicGreenhouseDoor;
import forestry.greenhouse.logics.GreenhouseLogicGreenhouseEffect;
import forestry.greenhouse.network.PacketRegistryGreenhouse;
import forestry.greenhouse.proxy.ProxyGreenhouse;
import forestry.greenhouse.tiles.TileGreenhouseControl;
@@ -98,7 +99,8 @@ public class PluginGreenhouse extends BlankForestryPlugin {
proxy.initializeModels();
GreenhouseManager.greenhouseLogics.add(GreenhouseEffect.class);
GreenhouseManager.greenhouseLogics.add(GreenhouseLogicGreenhouseEffect.class);
GreenhouseManager.greenhouseLogics.add(GreenhouseLogicGreenhouseDoor.class);
}
@Override
@@ -0,0 +1,50 @@
/*******************************************************************************
* 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.logics;
import forestry.api.greenhouse.DefaultGreenhouseLogic;
import forestry.api.greenhouse.IGreenhouseClimaLogic;
import forestry.api.multiblock.IGreenhouseController;
import net.minecraft.nbt.NBTTagCompound;
public class GreenhouseLogicGreenhouseDoor extends DefaultGreenhouseLogic implements IGreenhouseClimaLogic{
private int workTimer;
public GreenhouseLogicGreenhouseDoor(IGreenhouseController controller) {
super(controller, "GreenhouseDoor");
}
@Override
public void work() {
if(controller == null || !controller.isAssembled()){
return;
}
if(controller.getWorld().isDaytime()){
if(workTimer++>20){
controller.addTemperatureChange(-0.0001F, 0.05F, 2.5F);
controller.addHumidityChange(-0.0001F, 0.05F, 2.5F);
workTimer = 0;
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("workTimer", workTimer);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
workTimer = nbt.getInteger("workTimer");
}
}
@@ -23,12 +23,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class GreenhouseEffect extends DefaultGreenhouseLogic implements IGreenhouseClimaLogic {
public class GreenhouseLogicGreenhouseEffect extends DefaultGreenhouseLogic implements IGreenhouseClimaLogic {
private float lightTransmittance;
private int workTimer;
public GreenhouseEffect(IGreenhouseController controller) {
public GreenhouseLogicGreenhouseEffect(IGreenhouseController controller) {
super(controller, "GreenhouseEffect");
}
@@ -39,7 +39,10 @@ public class GreenhouseEffect extends DefaultGreenhouseLogic implements IGreenho
return;
}
if(controller.getWorld().isDaytime()){
controller.addTemperatureChange(lightTransmittance / 100, 0F, 2.5F);
if(workTimer++>20){
controller.addTemperatureChange(lightTransmittance / 100, 0F, 2.5F);
workTimer = 0;
}
}
}
@@ -74,7 +77,7 @@ public class GreenhouseEffect extends DefaultGreenhouseLogic implements IGreenho
float camouflageLightTransmittance = GreenhouseManager.greenhouseAccess.getGreenhouseGlassLightTransmittance(camouflageStack);
if(camouflageLightTransmittance < 1 && camouflageLightTransmittance > 0){
lightTransmittance=+ camouflageLightTransmittance;
lightTransmittance= lightTransmittance + camouflageLightTransmittance;
i++;
}
}
@@ -17,7 +17,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
@@ -26,14 +25,11 @@ import net.minecraftforge.common.property.IExtendedBlockState;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import forestry.api.core.ICamouflageHandler;
import forestry.api.core.ICamouflagedBlock;
import forestry.api.core.IModelBaker;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.core.models.ModelBlockOverlay;
import forestry.core.utils.CamouflageUtil;
public class ModelGreenhouse<G extends TileEntity & IGreenhouseComponent & ICamouflageHandler & ICamouflagedBlock> extends ModelBlockOverlay<BlockGreenhouse> {
public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
public ModelGreenhouse() {
super(BlockGreenhouse.class);
@@ -81,10 +81,6 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
public void onChange(EnumGreenhouseChangeType type, Object event) {
}
@Override
public void createLogics() {
}
@Override
public void addTemperatureChange(float change, float boundaryDown, float boundaryUp) {
}
@@ -92,8 +92,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
public GreenhouseController(World world) {
super(world, GreenhouseMultiblockSizeLimits.instance);
tempChange = 0;
humidChange = 0;
this.tempChange = 0;
this.humidChange = 0;
this.resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
this.tankManager = new TankManager(this, resourceTank);
@@ -101,32 +101,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
this.inventory = new InventoryGreenhouse(this);
}
@Override
public void createLogics() {
logics.clear();
for(Class<? extends IGreenhouseLogic> logicClass : GreenhouseManager.greenhouseLogics){
try{
logics.add(createLogic(logicClass));
}catch(Exception e){
Log.error("Fail to create a greenhouse logic with the class: " + logicClass);
e.printStackTrace();
}
}
}
private IGreenhouseLogic createLogic(Class<? extends IGreenhouseLogic> logicClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException{
return logicClass.getConstructor(IGreenhouseController.class).newInstance(this);
}
@Override
public IInventoryAdapter getInternalInventory() {
if (isAssembled()) {
return inventory;
} else {
return FakeInventoryAdapter.instance();
}
}
/* CLIMATE */
@Override
public EnumTemperature getTemperature() {
BlockPos coords = getReferenceCoord();
@@ -189,21 +164,19 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
return change;
}
/* LOCATION */
@Override
public World getWorld() {
return worldObj;
}
@Override
public void formatDescriptionPacket(NBTTagCompound data) {
writeToNBT(data);
}
@Override
public void decodeDescriptionPacket(NBTTagCompound data) {
readFromNBT(data);
public BlockPos getCoordinates() {
BlockPos coord = getReferenceCoord();
return new BlockPos(coord);
}
/* SAVING & LOADING */
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
@@ -243,6 +216,21 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
logic.readFromNBT(data.getCompoundTag("logic" + logic.getName()));
}
}
@Override
public void formatDescriptionPacket(NBTTagCompound data) {
writeToNBT(data);
}
@Override
public void decodeDescriptionPacket(NBTTagCompound data) {
readFromNBT(data);
}
@Override
protected void onAttachedPartWithMultiblockData(IMultiblockComponent part, NBTTagCompound data) {
readFromNBT(data);
}
@Override
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
@@ -257,7 +245,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
markDirty();
}
}
/* GUI DATA */
@Override
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
data.writeVarInt(Math.round(tempChange * 100));
@@ -282,6 +271,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
CamouflageUtil.readCamouflageBlockFromData(data, this);
}
/* CAMOUFLAGE */
@Override
public void setCamouflageBlock(EnumCamouflageType type, ItemStack camouflageBlock) {
switch (type) {
@@ -342,13 +332,53 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
return null;
}
}
/* GREENHOUSE */
@Override
public BlockPos getCoordinates() {
BlockPos coord = getReferenceCoord();
return new BlockPos(coord);
public boolean isInGreenhouse(BlockPos pos) {
for(InternalBlock inerBlock : internalBlocks){
if(inerBlock.pos.equals(pos)){
return true;
}
}
return false;
}
@Override
public IGreenhouseState createState() {
return new GreenhouseState(worldObj, getBiome().rainfall + humidChange, getBiome().temperature + tempChange);
}
@Override
public void onChange(EnumGreenhouseChangeType type, Object event) {
for(IGreenhouseLogic logic : logics){
logic.onChange(type, event);
}
}
/* GREENHOUSE LOGICS */
private void createLogics() {
logics.clear();
for(Class<? extends IGreenhouseLogic> logicClass : GreenhouseManager.greenhouseLogics){
try{
logics.add(createLogic(logicClass));
}catch(Exception e){
Log.error("Fail to create a greenhouse logic with the class: " + logicClass);
e.printStackTrace();
}
}
}
private IGreenhouseLogic createLogic(Class<? extends IGreenhouseLogic> logicClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException{
return logicClass.getConstructor(IGreenhouseController.class).newInstance(this);
}
@Override
public List<IGreenhouseLogic> getLogics() {
return logics;
}
/* MANAGERS */
@Override
public TankManager getTankManager() {
return tankManager;
@@ -358,12 +388,17 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
public EnergyManager getEnergyManager() {
return energyManager;
}
@Override
protected void onAttachedPartWithMultiblockData(IMultiblockComponent part, NBTTagCompound data) {
readFromNBT(data);
public IInventoryAdapter getInternalInventory() {
if (isAssembled()) {
return inventory;
} else {
return FakeInventoryAdapter.instance();
}
}
/* CONTROLLER */
@Override
protected void onMachineAssembled() {
super.onMachineAssembled();
@@ -463,34 +498,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
return canWork;
}
}
@Override
protected void updateClient(int tickCount) {
}
@Override
protected void isGoodForExteriorLevel(IMultiblockComponent part, int level) throws MultiblockValidationException {
}
@Override
protected void isGoodForInterior(IMultiblockComponent part) throws MultiblockValidationException {
}
@Override
protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException {
}
@Override
public boolean isInGreenhouse(BlockPos pos) {
for(InternalBlock inerBlock : internalBlocks){
if(inerBlock.pos.equals(pos)){
return true;
}
}
return false;
}
@Override
protected void isMachineWhole() throws MultiblockValidationException {
@@ -626,6 +633,24 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
}
this.internalBlocks.addAll(internalBlocks);
}
@Override
protected void updateClient(int tickCount) {
}
@Override
protected void isGoodForExteriorLevel(IMultiblockComponent part, int level) throws MultiblockValidationException {
}
@Override
protected void isGoodForInterior(IMultiblockComponent part) throws MultiblockValidationException {
}
@Override
protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException {
}
private void addInternalBlock(InternalBlock internalBlock, List<InternalBlock> internalBlocks) throws MultiblockValidationException{
isBlockGoodForInterior(worldObj, internalBlock.pos);
@@ -659,7 +684,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
}
}
}
private static class InternalBlock{
public BlockPos pos;
public EnumMap<EnumFacing, Boolean> testetFaces = Maps.newEnumMap(EnumFacing.class);
@@ -690,21 +715,4 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
}
}
@Override
public void onChange(EnumGreenhouseChangeType type, Object event) {
for(IGreenhouseLogic logic : logics){
logic.onChange(type, event);
}
}
@Override
public List<IGreenhouseLogic> getLogics() {
return logics;
}
@Override
public IGreenhouseState createState() {
return new GreenhouseState(worldObj, getBiome().rainfall + humidChange, getBiome().temperature + tempChange);
}
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.greenhouse.multiblock;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import forestry.api.greenhouse.IGreenhouseState;
@@ -30,8 +31,7 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM
@Nullable
EnergyManager getEnergyManager();
@Nonnull
IGreenhouseState createState();
void createLogics();
}
@@ -27,7 +27,7 @@ import forestry.core.network.packets.PacketCoordinates;
public class PacketCamouflageUpdate extends PacketCoordinates implements IForestryPacketServer {
private ItemStack camouflageBlock;
private ItemStack camouflageStack;
private EnumCamouflageType type;
private boolean isMultiblock;
@@ -36,14 +36,14 @@ public class PacketCamouflageUpdate extends PacketCoordinates implements IForest
public PacketCamouflageUpdate(ICamouflageHandler tile, EnumCamouflageType type, boolean isMultiblock) {
super(tile.getCoordinates());
this.camouflageBlock = tile.getCamouflageBlock(type);
this.camouflageStack = tile.getCamouflageBlock(type);
this.isMultiblock = isMultiblock;
this.type = type;
}
public PacketCamouflageUpdate(ICamouflageHandler tile, EnumCamouflageType type) {
super(tile.getCoordinates());
this.camouflageBlock = tile.getCamouflageBlock(type);
this.camouflageStack = tile.getCamouflageBlock(type);
this.isMultiblock = false;
this.type = type;
}
@@ -58,7 +58,7 @@ public class PacketCamouflageUpdate extends PacketCoordinates implements IForest
super.writeData(data);
data.writeBoolean(isMultiblock);
data.writeShort(type.ordinal());
data.writeItemStack(camouflageBlock);
data.writeItemStack(camouflageStack);
}
@Override
@@ -66,24 +66,27 @@ public class PacketCamouflageUpdate extends PacketCoordinates implements IForest
super.readData(data);
isMultiblock = data.readBoolean();
type = EnumCamouflageType.VALUES[data.readShort()];
camouflageBlock = data.readItemStack();
camouflageStack = data.readItemStack();
}
@Override
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) {
TileEntity tile = getTarget(player.worldObj);
ICamouflageHandler handler = null;
if(isMultiblock && tile instanceof IMultiblockComponent){
IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController();
if(controller instanceof ICamouflageHandler){
handler = (ICamouflageHandler) controller;
}
}
else if (tile instanceof ICamouflageHandler) {
}else if (tile instanceof ICamouflageHandler) {
handler = (ICamouflageHandler) tile;
}
if(handler != null){
handler.setCamouflageBlock(type, camouflageBlock);
handler.setCamouflageBlock(type, camouflageStack);
}
}
}