mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
Adding Greenhouse windows and climate control and improve recipes
This commit is contained in:
1 parent
27d932ee34
commit
a20fbbe60f
121 files changed
+3088
-802
No files matched your search
@@ -7,11 +7,11 @@ package forestry.api.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.genetics.IHousing;
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package forestry.api.climate;
|
||||
|
||||
public enum EnumClimatiserModes {
|
||||
|
||||
POSITIVE, NEGATIVE, NONE
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package forestry.api.climate;
|
||||
|
||||
public enum EnumClimatiserTypes {
|
||||
|
||||
TEMPERATURE, HUMIDITY, NONE
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
public interface IClimateControl {
|
||||
|
||||
float getControlTemperature();
|
||||
|
||||
float getControlHumidity();
|
||||
|
||||
void setControlTemperature(float temperature);
|
||||
|
||||
void setControlHumidity(float humidity);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IClimateControlProvider {
|
||||
|
||||
IClimateControl getClimateControl();
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getCoordinates();
|
||||
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
public interface IClimateControlled {
|
||||
/**
|
||||
+3
-7
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -11,7 +11,6 @@ import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -27,9 +26,9 @@ public interface IClimateManager {
|
||||
|
||||
void removeRegion(IClimateRegion region);
|
||||
|
||||
void addSource(IClimateSource source);
|
||||
void addSource(IClimateSourceProvider source);
|
||||
|
||||
void removeSource(IClimateSource source);
|
||||
void removeSource(IClimateSourceProvider source);
|
||||
|
||||
@Nullable
|
||||
IClimateRegion getRegionForPos(World world, BlockPos pos);
|
||||
@@ -37,7 +36,4 @@ public interface IClimateManager {
|
||||
@Nonnull
|
||||
Map<Integer, List<IClimateRegion>> getRegions();
|
||||
|
||||
@Nonnull
|
||||
Map<Integer, Map<BlockPos, IClimateSource>> getSources();
|
||||
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public interface IClimateProvider {
|
||||
Biome getBiome();
|
||||
|
||||
EnumTemperature getTemperature();
|
||||
|
||||
EnumHumidity getHumidity();
|
||||
}
|
||||
+16
-6
@@ -3,9 +3,9 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -21,15 +21,25 @@ public interface IClimateRegion extends INbtReadable, INbtWritable {
|
||||
World getWorld();
|
||||
|
||||
/**
|
||||
* Update the climate in a region, all 20 world ticks.
|
||||
* Update the climate in a region.
|
||||
*/
|
||||
void updateClimate();
|
||||
void updateClimate(int ticks);
|
||||
|
||||
int getTicksPerUpdate();
|
||||
|
||||
@Nonnull
|
||||
Map<BlockPos, IClimatePosition> getPositions();
|
||||
|
||||
int getTicksPerUpdate();
|
||||
void addSource(IClimateSource source);
|
||||
|
||||
List<BlockPos> getOtherPositions();
|
||||
void removeSource(IClimateSource source);
|
||||
|
||||
Collection<IClimateSource> getSources();
|
||||
|
||||
Collection<BlockPos> getOtherPositions();
|
||||
|
||||
float getTemperature();
|
||||
|
||||
float getHumidity();
|
||||
|
||||
}
|
||||
+2
-7
@@ -3,10 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
package forestry.api.climate;
|
||||
|
||||
/**
|
||||
* A climate source is used to change the climate in a region.
|
||||
@@ -24,8 +21,6 @@ public interface IClimateSource {
|
||||
*/
|
||||
int getTicksForChange(IClimateRegion region);
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getPos();
|
||||
IClimateSourceProvider getProvider();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IClimateSourceProvider {
|
||||
|
||||
IClimateSource getClimateSource();
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getCoordinates();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
public interface IClimatiserDefinition {
|
||||
|
||||
float getChange();
|
||||
|
||||
double getRange();
|
||||
|
||||
EnumClimatiserModes getMode();
|
||||
|
||||
EnumClimatiserTypes getType();
|
||||
|
||||
}
|
||||
@@ -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 = "2.1.0", owner = "Forestry", provides = "ForestryAPI|climate")
|
||||
package forestry.api.climate;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -7,7 +7,7 @@ package forestry.api.core;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.core.climate.IClimateManager;
|
||||
import forestry.api.climate.IClimateManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
@@ -30,4 +30,6 @@ public interface ICamouflageAccess {
|
||||
|
||||
boolean isItemBlackListed(@Nonnull String type, @Nonnull ItemStack camouflageBlock);
|
||||
|
||||
ICamouflageItemHandler getHandlerFromItem(ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public interface ICamouflageItemHandler {
|
||||
|
||||
boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler);
|
||||
boolean canHandle(ItemStack stack);
|
||||
|
||||
String getType();
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package forestry.api.core;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public interface IClimateProvider {
|
||||
Biome getBiome();
|
||||
|
||||
EnumTemperature getTemperature();
|
||||
|
||||
EnumHumidity getHumidity();
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
@API(apiVersion = "5.0.0", owner = "ForestryAPI|core", provides = "ForestryAPI|greenhouse")
|
||||
@API(apiVersion = "5.2.0", owner = "ForestryAPI|core", provides = "ForestryAPI|greenhouse")
|
||||
package forestry.api.greenhouse;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IHousing;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ package forestry.api.multiblock;
|
||||
|
||||
import forestry.api.apiculture.IBeeListener;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
|
||||
/**
|
||||
* Needs to be implemented by TileEntities that want to be part of an alveary.
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.multiblock;
|
||||
|
||||
import forestry.api.core.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.climate.IClimateSourceProvider;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.greenhouse.IGreenhouseListener;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -18,10 +21,17 @@ public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> exte
|
||||
IGreenhouseListener getGreenhouseListener();
|
||||
}
|
||||
|
||||
interface ClimateControl extends IGreenhouseComponent, IClimateControlProvider {
|
||||
|
||||
@Override
|
||||
IClimateControl getClimateControl();
|
||||
}
|
||||
|
||||
interface Door extends IGreenhouseComponent {
|
||||
}
|
||||
|
||||
interface Climatiser extends IGreenhouseComponent, IClimateSource {
|
||||
interface Climatiser extends IGreenhouseComponent, IClimateSourceProvider {
|
||||
IClimatiserDefinition getDefinition();
|
||||
}
|
||||
|
||||
interface ButterflyHatch extends IGreenhouseComponent {
|
||||
|
||||
@@ -7,15 +7,18 @@ package forestry.api.multiblock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.IGreenhouseHousing;
|
||||
import forestry.api.greenhouse.IGreenhouseLogic;
|
||||
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler {
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlProvider {
|
||||
|
||||
/**
|
||||
* Handle change events.
|
||||
@@ -29,5 +32,9 @@ public interface IGreenhouseController extends IMultiblockController, IGreenhous
|
||||
|
||||
@Nullable
|
||||
IClimateRegion getRegion();
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
IClimateControl getClimateControl();
|
||||
|
||||
}
|
||||
@@ -21,11 +21,11 @@ import forestry.api.apiculture.IBeeHousingInventory;
|
||||
import forestry.api.apiculture.IBeeListener;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.apiculture.IBeekeepingLogic;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
import forestry.api.core.BiomeHelper;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.multiblock.IAlvearyComponent;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.apiculture.AlvearyBeeModifier;
|
||||
|
||||
@@ -15,7 +15,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
import forestry.api.multiblock.IAlvearyComponent;
|
||||
import forestry.apiculture.network.packets.PacketActiveUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
@@ -22,7 +22,7 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
import forestry.api.multiblock.IAlvearyComponent;
|
||||
import forestry.apiculture.blocks.BlockAlvearyType;
|
||||
import forestry.apiculture.gui.ContainerAlvearyHygroregulator;
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
public class CamouflageHandlerArbDoor implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
return false;
|
||||
}
|
||||
if(stack.getItem() instanceof ItemBlockWoodDoor){
|
||||
|
||||
@@ -419,7 +419,7 @@ public class PluginArboriculture extends BlankForestryPlugin {
|
||||
}
|
||||
|
||||
//Dirt Pile Block
|
||||
RecipeUtil.addShapelessRecipe(new ItemStack(PluginArboriculture.blocks.piles.get(EnumPileType.DIRT)), OreDictUtil.DUST_ASH, Items.CLAY_BALL, OreDictUtil.DUST_ASH, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.TREE_LEAVES, Items.CLAY_BALL, OreDictUtil.TREE_LEAVES);
|
||||
RecipeUtil.addShapelessRecipe(new ItemStack(PluginArboriculture.blocks.piles.get(EnumPileType.DIRT)), PluginCore.items.fertilizerBio, Items.CLAY_BALL, PluginCore.items.fertilizerBio, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.DIRT, PluginCore.items.fertilizerBio, Items.CLAY_BALL, PluginCore.items.fertilizerBio);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ import com.google.gson.stream.JsonReader;
|
||||
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.core.render.FontColour;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -20,7 +20,6 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import forestry.api.core.ICamouflageAccess;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
@@ -48,6 +47,13 @@ public class CamouflageAccess implements ICamouflageAccess {
|
||||
|
||||
@Override
|
||||
public List<ICamouflageItemHandler> getCamouflageItemHandler(String type) {
|
||||
if(type == null){
|
||||
List<ICamouflageItemHandler> handlers = new ArrayList<>();
|
||||
for(List<ICamouflageItemHandler> handler : camouflageItemHandlers.values()){
|
||||
handlers.addAll(handler);
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
if(!camouflageItemHandlers.containsKey(type)){
|
||||
return null;
|
||||
}
|
||||
@@ -76,21 +82,31 @@ public class CamouflageAccess implements ICamouflageAccess {
|
||||
|
||||
@Override
|
||||
public boolean isItemBlackListed(String type, ItemStack camouflageBlock) {
|
||||
if (camouflageBlock == null || camouflageBlock.getItem() == null || Block.getBlockFromItem(camouflageBlock.getItem()) == null || !camouflageItemBlacklist.containsKey(type)) {
|
||||
if (camouflageBlock == null || camouflageBlock.getItem() == null || Block.getBlockFromItem(camouflageBlock.getItem()) == null || type != null && !camouflageItemBlacklist.containsKey(type)) {
|
||||
return false;
|
||||
}
|
||||
for (ItemStack camouflageBlacklisted : camouflageItemBlacklist.get(type)) {
|
||||
List<ItemStack> camouflageItemBlacklisted;
|
||||
if(type == null){
|
||||
camouflageItemBlacklisted = new ArrayList<>();
|
||||
for(List<ItemStack> stacks : camouflageItemBlacklist.values()){
|
||||
camouflageItemBlacklisted.addAll(stacks);
|
||||
}
|
||||
}else{
|
||||
camouflageItemBlacklisted = camouflageItemBlacklist.get(type);
|
||||
}
|
||||
for (ItemStack camouflageBlacklisted : camouflageItemBlacklisted) {
|
||||
if (camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ICamouflageItemHandler getHandlerFromItem(@Nonnull ItemStack camouflageItem, ICamouflageHandler camouflageHandler){
|
||||
|
||||
@Override
|
||||
public ICamouflageItemHandler getHandlerFromItem(ItemStack stack) {
|
||||
for(List<ICamouflageItemHandler> handlers : camouflageItemHandlers.values()){
|
||||
for(ICamouflageItemHandler handler : handlers){
|
||||
if(handler.canHandle(camouflageItem, camouflageHandler)){
|
||||
if(handler.canHandle(stack)){
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public class CamouflageHandlerDefault implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
return false;
|
||||
}
|
||||
Block block = Block.getBlockFromItem(stack.getItem());
|
||||
IBlockState stateFromMeta = block.getStateFromMeta(stack.getItemDamage());
|
||||
|
||||
return stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && block.isNormalCube(stateFromMeta, camouflageHandler.getWorld(), camouflageHandler.getCoordinates());
|
||||
return stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && block.isNormalCube(stateFromMeta) && block.isFullCube(stateFromMeta) && block.isBlockNormalCube(stateFromMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,8 +33,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public class CamouflageHandlerDoor implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
return false;
|
||||
}
|
||||
if(stack.getItem() instanceof ItemDoor){
|
||||
|
||||
@@ -28,14 +28,14 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public class CamouflageHandlerGlass implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
return false;
|
||||
}
|
||||
Block block = Block.getBlockFromItem(stack.getItem());
|
||||
IBlockState stateFromMeta = block.getStateFromMeta(stack.getItemDamage());
|
||||
|
||||
return !stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta);
|
||||
return !stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && !block.isBlockNormalCube(stateFromMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.core.owner.GameProfileDataSerializer;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -60,6 +61,8 @@ import forestry.core.genetics.alleles.AlleleRegistry;
|
||||
import forestry.core.items.EnumContainerType;
|
||||
import forestry.core.items.ItemRegistryCore;
|
||||
import forestry.core.loot.functions.SetSpeciesNBT;
|
||||
import forestry.core.models.ModelCamouflageSprayCan;
|
||||
import forestry.core.models.ModelEntry;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.multiblock.MultiblockLogicFactory;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
@@ -449,6 +452,9 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void onBakeModel(ModelBakeEvent event) {
|
||||
ModelResourceLocation modelLocation = new ModelResourceLocation("forestry:camouflageSprayCan", "inventory");
|
||||
ModelEntry blockModelIndex = new ModelEntry(modelLocation, new ModelCamouflageSprayCan());
|
||||
Proxies.render.registerModel(blockModelIndex);
|
||||
ModelManager.getInstance().registerCustomModels(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, ISpriteRegister, IStateMapperRegister {
|
||||
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, ISpriteRegister, IStateMapperRegister, IBlockRotatable {
|
||||
/** use this instead of {@link BlockHorizontal#FACING} so the blocks rotate in a circle instead of NSWE order. */
|
||||
public static final PropertyEnum<EnumFacing> FACING = PropertyEnum.create("facing", EnumFacing.class, EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.DOWN, EnumFacing.UP);
|
||||
|
||||
@@ -170,6 +170,7 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class BlockStructure extends BlockForestry {
|
||||
return false;
|
||||
}
|
||||
|
||||
private long previousMessageTick = 0;
|
||||
protected long previousMessageTick = 0;
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package forestry.core.blocks;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IBlockRotatable {
|
||||
|
||||
void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package forestry.core.climate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.greenhouse.multiblock.DefaultClimateControl;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class BiomeClimateControl extends DefaultClimateControl {
|
||||
|
||||
private static final Map<Biome, BiomeClimateControl> climateControls = new HashMap<>();
|
||||
|
||||
public static BiomeClimateControl getControl(Biome biome){
|
||||
if(!climateControls.containsKey(biome)){
|
||||
climateControls.put(biome, new BiomeClimateControl(biome));
|
||||
}
|
||||
return climateControls.get(biome);
|
||||
}
|
||||
|
||||
private final Biome biome;
|
||||
|
||||
private BiomeClimateControl(Biome biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlTemperature() {
|
||||
return biome.getTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlHumidity() {
|
||||
return biome.getRainfall();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
|
||||
public class ClimateControl implements IClimateControl, INbtWritable, INbtReadable, IStreamable {
|
||||
|
||||
private float temperature;
|
||||
private float humidity;
|
||||
|
||||
public ClimateControl() {
|
||||
temperature = 2.0F;
|
||||
humidity = 2.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlTemperature(float temperature) {
|
||||
if(temperature > 2.0F){
|
||||
temperature = 2.0F;
|
||||
}else{
|
||||
this.temperature = temperature;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlHumidity(float humidity) {
|
||||
if(humidity > 2.0F){
|
||||
humidity = 2.0F;
|
||||
}else{
|
||||
this.humidity = humidity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
data.writeFloat(temperature);
|
||||
data.writeFloat(humidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
temperature = data.readFloat();
|
||||
humidity = data.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
temperature = nbt.getFloat("Temperature");
|
||||
humidity = nbt.getFloat("Humidity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setFloat("Temperature", temperature);
|
||||
nbt.setFloat("Humidity", humidity);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,21 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.climate.IClimateManager;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimateSource;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
@@ -33,20 +38,7 @@ public class ClimateEventHandler {
|
||||
Map<Integer, List<IClimateRegion>> regions = ForestryAPI.climateManager.getRegions();
|
||||
if(regions != null && regions.containsKey(dim)){
|
||||
for(IClimateRegion region : regions.get(dim)){
|
||||
if(ticks % region.getTicksPerUpdate() == 0){
|
||||
region.updateClimate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<Integer, Map<BlockPos, IClimateSource>> sources = ForestryAPI.climateManager.getSources();
|
||||
if(sources != null && sources.containsKey(dim)){
|
||||
for(IClimateSource source : sources.get(dim).values()){
|
||||
IClimateRegion region = ForestryAPI.climateManager.getRegionForPos(event.world, source.getPos());
|
||||
if(region != null){
|
||||
if(ticks % source.getTicksForChange(region) == 0){
|
||||
source.changeClimate(ticks, region);
|
||||
}
|
||||
}
|
||||
region.updateClimate(ticks);
|
||||
}
|
||||
}
|
||||
serverTicks.put(dim, ticks+1);
|
||||
|
||||
@@ -19,23 +19,21 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.core.climate.IClimateManager;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimateManager;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSourceProvider;
|
||||
import forestry.core.DefaultClimateProvider;
|
||||
|
||||
public class ClimateManager implements IClimateManager{
|
||||
|
||||
protected Map<Integer, List<IClimateRegion>> regions;
|
||||
protected Map<Integer, Map<BlockPos, IClimateSource>> sources;
|
||||
|
||||
private final Object regionsMutex;
|
||||
|
||||
public ClimateManager() {
|
||||
regions = new HashMap<>();
|
||||
sources = new HashMap<>();
|
||||
regionsMutex = new Object();
|
||||
}
|
||||
|
||||
@@ -79,24 +77,40 @@ public class ClimateManager implements IClimateManager{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSource(IClimateSource source) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorld().provider.getDimension());
|
||||
if(!sources.containsKey(dimensionID)){
|
||||
sources.put(dimensionID, new HashMap<>());
|
||||
public void removeSource(IClimateSourceProvider source) {
|
||||
if(source == null){
|
||||
return;
|
||||
}
|
||||
if(sources.get(dimensionID).keySet().contains(source.getPos())){
|
||||
sources.get(dimensionID).remove(source.getPos(), source);
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorld().provider.getDimension());
|
||||
if(!regions.containsKey(dimensionID)){
|
||||
regions.put(dimensionID, new ArrayList<>());
|
||||
}
|
||||
IClimateRegion region = getRegionForPos(source.getWorld(), source.getCoordinates());
|
||||
if(region != null){
|
||||
if(!region.getSources().contains(source.getClimateSource())){
|
||||
region.removeSource(source.getClimateSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSource(IClimateSource source) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorld().provider.getDimension());
|
||||
if(!sources.containsKey(dimensionID)){
|
||||
sources.put(dimensionID, new HashMap<>());
|
||||
public void addSource(IClimateSourceProvider source) {
|
||||
if(source == null){
|
||||
return;
|
||||
}
|
||||
if(sources.get(dimensionID).get(source.getPos()) == null){
|
||||
sources.get(dimensionID).put(source.getPos(), source);
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorld().provider.getDimension());
|
||||
if(!regions.containsKey(dimensionID)){
|
||||
regions.put(dimensionID, new ArrayList<>());
|
||||
}
|
||||
IClimateRegion region = getRegionForPos(source.getWorld(), source.getCoordinates());
|
||||
if(region != null){
|
||||
if(!region.getSources().contains(source.getClimateSource())){
|
||||
region.addSource(source.getClimateSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,11 +164,6 @@ public class ClimateManager implements IClimateManager{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Map<BlockPos, IClimateSource>> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateProvider getDefaultClimate(World world, BlockPos pos) {
|
||||
return new DefaultClimateProvider(world, pos);
|
||||
|
||||
@@ -12,8 +12,8 @@ package forestry.core.climate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
@@ -27,6 +27,12 @@ public class ClimatePosition implements IClimatePosition {
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos, NBTTagCompound nbtTag) {
|
||||
this.climateRegion = climateRegion;
|
||||
this.pos = pos;
|
||||
readFromNBT(nbtTag);
|
||||
}
|
||||
|
||||
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos) {
|
||||
Biome biome = climateRegion.getWorld().getBiome(pos);
|
||||
this.climateRegion = climateRegion;
|
||||
|
||||
@@ -1,87 +1,148 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
|
||||
protected World world;
|
||||
protected IGreenhouseController controller;
|
||||
protected Map<BlockPos, IClimatePosition> positions;
|
||||
protected List<BlockPos> wallPositions;
|
||||
protected final World world;
|
||||
protected final IGreenhouseControllerInternal controller;
|
||||
protected final Map<BlockPos, IClimatePosition> positions;
|
||||
protected final List<BlockPos> wallPositions;
|
||||
protected final List<IClimateSource> sources;
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
public ClimateRoom(ClimateRoom oldRoom, Map<BlockPos, IClimatePosition> innerPositions, List<BlockPos> wallPositions) {
|
||||
public ClimateRoom(ClimateRoom oldRoom, Map<BlockPos, IClimatePosition> newPositions, List<BlockPos> newWallPositions) {
|
||||
this.world = oldRoom.getWorld();
|
||||
this.controller = oldRoom.controller;
|
||||
Map<BlockPos, IClimatePosition> newPositions = new HashMap<>();
|
||||
for(Entry<BlockPos, IClimatePosition> positionEntry : innerPositions.entrySet()){
|
||||
IClimatePosition position = oldRoom.getPositions().get(positionEntry.getKey());
|
||||
if(position == null){
|
||||
newPositions.put(positionEntry.getKey(), positionEntry.getValue());
|
||||
}else{
|
||||
newPositions.put(positionEntry.getKey(), position);
|
||||
this.positions = new HashMap<>();
|
||||
this.wallPositions = newWallPositions;
|
||||
this.sources = new ArrayList<>();
|
||||
for(Entry<BlockPos, IClimatePosition> positionEntry : newPositions.entrySet()){
|
||||
BlockPos pos = positionEntry.getKey();
|
||||
IClimatePosition position = positionEntry.getValue();
|
||||
IClimatePosition oldPosition = oldRoom.getPositions().get(pos);
|
||||
float temperature = position.getTemperature();
|
||||
float humidity = position.getHumidity();
|
||||
if(oldPosition != null){
|
||||
temperature = oldPosition.getTemperature();
|
||||
humidity = oldPosition.getHumidity();
|
||||
}
|
||||
addPosition(pos, temperature, humidity);
|
||||
}
|
||||
this.positions = newPositions;
|
||||
this.wallPositions = wallPositions;
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseController controller, Map<BlockPos, IClimatePosition> innerPositions, List<BlockPos> wallPositions) {
|
||||
public ClimateRoom(IGreenhouseControllerInternal controller, Map<BlockPos, IClimatePosition> innerPositions, List<BlockPos> wallPositions) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = innerPositions;
|
||||
this.wallPositions = wallPositions;
|
||||
this.sources = new ArrayList<>();
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseController controller, NBTTagCompound nbtTag) {
|
||||
public ClimateRoom(IGreenhouseControllerInternal controller, List<BlockPos> wallPositions, NBTTagCompound nbtTag) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = new HashMap<>();
|
||||
this.wallPositions = new ArrayList<>();
|
||||
this.sources = new ArrayList<>();
|
||||
readFromNBT(nbtTag);
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
private float getExactTemperature() {
|
||||
float temperature = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for(IClimatePosition position : this.positions.values()){
|
||||
if(position != null){
|
||||
positions++;
|
||||
temperature+=position.getTemperature();
|
||||
}
|
||||
}
|
||||
return temperature / positions;
|
||||
}
|
||||
|
||||
private float getExactHumidity() {
|
||||
float humidity = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for(IClimatePosition position : this.positions.values()){
|
||||
if(position != null){
|
||||
positions++;
|
||||
humidity+=position.getHumidity();
|
||||
}
|
||||
}
|
||||
return humidity / positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate() {
|
||||
for(Entry<BlockPos, IClimatePosition> position : positions.entrySet()){
|
||||
BlockPos pos = position.getKey();
|
||||
if(world.isBlockLoaded(pos)){
|
||||
updateSides(pos);
|
||||
if(!controller.isAssembled()){
|
||||
Biome biome = world.getBiome(pos);
|
||||
public void updateClimate(int ticks) {
|
||||
for(IClimateSource source : sources){
|
||||
if(source != null){
|
||||
if(ticks % source.getTicksForChange(this) == 0){
|
||||
source.changeClimate(ticks, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ticks % getTicksPerUpdate() == 0){
|
||||
for(Entry<BlockPos, IClimatePosition> position : positions.entrySet()){
|
||||
BlockPos pos = position.getKey();
|
||||
if(world.isBlockLoaded(pos)){
|
||||
updateSides(pos);
|
||||
|
||||
float biomeTemperature = biome.getTemperature();
|
||||
float biomeHumidity = biome.getRainfall();
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
|
||||
if(climatedInfo.getTemperature() != biomeTemperature){
|
||||
if(climatedInfo.getTemperature() > biomeTemperature){
|
||||
climatedInfo.addTemperature(-0.01F);
|
||||
}else{
|
||||
climatedInfo.addTemperature(0.01F);
|
||||
if(!controller.isAssembled()){
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
|
||||
if(climatedInfo.getTemperature() != climateControl.getControlTemperature()){
|
||||
if(climatedInfo.getTemperature() > climateControl.getControlTemperature()){
|
||||
climatedInfo.addTemperature(-Math.min(0.01F, climatedInfo.getTemperature() - climateControl.getControlTemperature()));
|
||||
}else{
|
||||
climatedInfo.addTemperature(Math.min(0.01F, climateControl.getControlTemperature() - climatedInfo.getTemperature()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(climatedInfo.getHumidity() != biomeHumidity){
|
||||
if(climatedInfo.getHumidity() > biomeHumidity){
|
||||
climatedInfo.addHumidity(-0.01F);
|
||||
}else{
|
||||
climatedInfo.addHumidity(0.01F);
|
||||
if(climatedInfo.getHumidity() != climateControl.getControlHumidity()){
|
||||
if(climatedInfo.getHumidity() > climateControl.getControlHumidity()){
|
||||
climatedInfo.addHumidity(-Math.min(0.01F, climatedInfo.getHumidity() - climateControl.getControlHumidity()));
|
||||
}else{
|
||||
climatedInfo.addHumidity(Math.min(0.01F, climateControl.getControlHumidity() - climatedInfo.getHumidity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,44 +150,51 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSides(BlockPos pos){
|
||||
protected void updateSides(BlockPos pos){
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
BlockPos facePos = pos.offset(facing);
|
||||
IClimatePosition climatedInfoFace = positions.get(facePos);
|
||||
if(climatedInfoFace != null){
|
||||
if(climatedInfoFace.getTemperature() >= 2.0F){
|
||||
if(climatedInfoFace.getTemperature() > 2.0F){
|
||||
climatedInfoFace.setTemperature(2.0F);
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
boolean hasChange = false;
|
||||
if(climateControl.getControlTemperature() != temperature || climateControl.getControlHumidity() != humidity) {
|
||||
boolean updateTemp = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
boolean updateHum = climatedInfo.getHumidity() >= climateControl.getControlHumidity();
|
||||
if(updateTemp || updateHum){
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
IClimatePosition climatedInfoFace = positions.get(pos.offset(facing));
|
||||
if(climatedInfoFace != null){
|
||||
if(climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getTemperature() - climatedInfoFace.getTemperature());
|
||||
climatedInfo.addTemperature(-change);
|
||||
climatedInfoFace.addTemperature(change);
|
||||
updateTemp = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
hasChange = true;
|
||||
}
|
||||
if(climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getHumidity() - climatedInfoFace.getHumidity());
|
||||
climatedInfo.addHumidity(-change);
|
||||
climatedInfoFace.addHumidity(change);
|
||||
updateHum = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
hasChange = true;
|
||||
}
|
||||
if(!updateTemp && !updateHum){
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}else if(climatedInfoFace.getTemperature() <= 0.0F){
|
||||
if(climatedInfoFace.getTemperature() < 0.0F){
|
||||
climatedInfoFace.setTemperature(0.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(climatedInfoFace.getHumidity() >= 2.0F){
|
||||
if(climatedInfoFace.getHumidity() > 2.0F){
|
||||
climatedInfoFace.setHumidity(2.0F);
|
||||
}
|
||||
continue;
|
||||
}else if(climatedInfoFace.getHumidity() <= 0.0F){
|
||||
if(climatedInfoFace.getHumidity() < 0.0F){
|
||||
climatedInfoFace.setHumidity(0.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F){
|
||||
climatedInfo.addTemperature(-0.01F);
|
||||
climatedInfoFace.addTemperature(0.01F);
|
||||
}
|
||||
if(climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F){
|
||||
climatedInfo.addHumidity(-0.01F);
|
||||
climatedInfoFace.addHumidity(0.01F);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasChange){
|
||||
temperature = getExactTemperature();
|
||||
humidity = getExactHumidity();
|
||||
}
|
||||
}
|
||||
|
||||
protected IClimateControl getControl(BlockPos pos){
|
||||
if(world.isBlockLoaded(pos)){
|
||||
if(!controller.isAssembled()){
|
||||
return BiomeClimateControl.getControl(world.getBiome(pos));
|
||||
}
|
||||
}
|
||||
return controller.getClimateControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,9 +203,9 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
for(Entry<BlockPos, IClimatePosition> entry : positions.entrySet()){
|
||||
BlockPos pos = entry.getKey();
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("XPos", pos.getX());
|
||||
tag.setInteger("YPos", pos.getY());
|
||||
tag.setInteger("ZPos", pos.getZ());
|
||||
tag.setInteger("X", pos.getX());
|
||||
tag.setInteger("Y", pos.getY());
|
||||
tag.setInteger("Z", pos.getZ());
|
||||
positionList.appendTag(entry.getValue().writeToNBT(tag));
|
||||
}
|
||||
nbt.setTag("Positions", positionList);
|
||||
@@ -149,13 +217,16 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
NBTTagList positionList = nbt.getTagList("Positions", 10);
|
||||
for(int i = 0;i < positionList.tagCount();i++){
|
||||
NBTTagCompound positionTag = positionList.getCompoundTagAt(i);
|
||||
int xPos = positionTag.getInteger("XPos");
|
||||
int yPos = positionTag.getInteger("YPos");
|
||||
int zPos = positionTag.getInteger("ZPos");
|
||||
int xPos = positionTag.getInteger("X");
|
||||
int yPos = positionTag.getInteger("Y");
|
||||
int zPos = positionTag.getInteger("Z");
|
||||
BlockPos pos = new BlockPos(xPos, yPos, zPos);
|
||||
ClimatePosition position = new ClimatePosition(this, pos);
|
||||
position.readFromNBT(positionTag);
|
||||
positions.put(pos, position);
|
||||
IClimatePosition position = positions.get(pos);
|
||||
if(position != null){
|
||||
position.readFromNBT(positionTag);
|
||||
}else{
|
||||
positions.put(pos, new ClimatePosition(this, pos, positionTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +245,35 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
return positions;
|
||||
}
|
||||
|
||||
protected void addPosition(BlockPos pos, float temperature, float humidity){
|
||||
IClimatePosition otherPosition = positions.get(pos);
|
||||
if(otherPosition != null){
|
||||
otherPosition.setHumidity(humidity);
|
||||
otherPosition.setTemperature(temperature);
|
||||
}else{
|
||||
positions.put(pos, new ClimatePosition(this, pos, temperature, humidity));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSource(IClimateSource source) {
|
||||
if(!sources.contains(source)){
|
||||
sources.add(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSource(IClimateSource source) {
|
||||
if(sources.contains(source)){
|
||||
sources.remove(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IClimateSource> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPos> getOtherPositions() {
|
||||
return wallPositions;
|
||||
@@ -190,6 +290,8 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
data.writeFloat(pos.getTemperature());
|
||||
data.writeFloat(pos.getHumidity());
|
||||
}
|
||||
data.writeFloat(temperature);
|
||||
data.writeFloat(humidity);
|
||||
}else{
|
||||
data.writeInt(0);
|
||||
}
|
||||
@@ -199,18 +301,23 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
int size = data.readInt();
|
||||
if(size != 0){
|
||||
positions = new HashMap<>();
|
||||
positions.clear();;
|
||||
for(int index = 0;index < size;index++){
|
||||
int xPos = data.readInt();
|
||||
int yPos = data.readInt();
|
||||
int zPos = data.readInt();
|
||||
float temperature = data.readFloat();
|
||||
float humidity = data.readFloat();
|
||||
|
||||
BlockPos pos = new BlockPos(xPos, yPos, zPos);
|
||||
positions.put(pos, new ClimatePosition(this, pos, temperature, humidity));
|
||||
addPosition(new BlockPos(data.readInt(), data.readInt(), data.readInt()), data.readFloat(), data.readFloat());
|
||||
}
|
||||
temperature = data.readFloat();
|
||||
humidity = data.readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimateSourceProvider;
|
||||
|
||||
public abstract class ClimateSource<P extends IClimateSourceProvider> implements IClimateSource {
|
||||
|
||||
protected P provider;
|
||||
protected final int ticksForChange;
|
||||
|
||||
public ClimateSource(int ticksForChange) {
|
||||
this.ticksForChange = ticksForChange;
|
||||
}
|
||||
|
||||
public void setProvider(P provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeClimate(int tickCount, IClimateRegion region) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksForChange(IClimateRegion region) {
|
||||
return ticksForChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateSourceProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
|
||||
public class ClimatiserDefinition implements IClimatiserDefinition {
|
||||
|
||||
protected final float change;
|
||||
protected final EnumClimatiserModes mode;
|
||||
protected final double range;
|
||||
protected final EnumClimatiserTypes type;
|
||||
|
||||
public ClimatiserDefinition(float change, EnumClimatiserModes mode, double range, EnumClimatiserTypes type) {
|
||||
this.change = change;
|
||||
this.mode = mode;
|
||||
this.range = range;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChange() {
|
||||
return change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumClimatiserTypes getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumClimatiserModes getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,9 +19,9 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IGenome;
|
||||
|
||||
@@ -14,13 +14,12 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -10,11 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
|
||||
@@ -12,10 +12,9 @@ package forestry.core.genetics.mutations;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class ContainerCamouflageSprayCan extends ContainerItemInventory<ItemInventoryCamouflageSprayCan> {
|
||||
|
||||
public ContainerCamouflageSprayCan(ItemInventoryCamouflageSprayCan inventory, InventoryPlayer playerInventory) {
|
||||
super(inventory, playerInventory, 8, 84);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,5 +58,9 @@ public abstract class ContainerItemInventory<I extends ItemInventory> extends Co
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public I getItemInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class GuiCamouflageSprayCan extends GuiForestry<ContainerCamouflageSprayCan, ItemInventoryCamouflageSprayCan> {
|
||||
|
||||
public GuiCamouflageSprayCan(EntityPlayer player, ItemInventoryCamouflageSprayCan inventory) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/camouflageSprayCan.png", new ContainerCamouflageSprayCan(inventory, player.inventory), inventory);
|
||||
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 80, 39, inventory, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
|
||||
String name = Translator.translateToLocal("for.gui.camouflage.spray.can");
|
||||
textLayout.line = 6;
|
||||
textLayout.drawCenteredLine(name, 0, fontColor.get("gui.title"));
|
||||
bindTexture(textureFile);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import forestry.apiculture.multiblock.TileAlvearySieve;
|
||||
import forestry.apiculture.tiles.TileApiary;
|
||||
import forestry.apiculture.tiles.TileBeeHouse;
|
||||
import forestry.core.items.ItemAlyzer;
|
||||
import forestry.core.items.ItemCamouflageSprayCan;
|
||||
import forestry.core.items.ItemSolderingIron;
|
||||
import forestry.core.tiles.TileAnalyzer;
|
||||
import forestry.core.tiles.TileEscritoire;
|
||||
@@ -105,7 +106,8 @@ public class GuiIdRegistry {
|
||||
ItemImprinter.class,
|
||||
ItemInfuser.class,
|
||||
ItemLetter.class,
|
||||
ItemSolderingIron.class
|
||||
ItemSolderingIron.class,
|
||||
ItemCamouflageSprayCan.class
|
||||
));
|
||||
|
||||
registerGuiHandlers(GuiType.Entity, Arrays.asList(
|
||||
|
||||
+3
-5
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.gui.widgets;
|
||||
package forestry.core.gui.widgets;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -25,8 +25,6 @@ import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
@@ -65,8 +63,8 @@ public class WidgetCamouflageSlot extends Widget {
|
||||
if (stack != null) {
|
||||
if (!CamouflageManager.camouflageAccess.isItemBlackListed(type, stack)) {
|
||||
for(ICamouflageItemHandler handler : CamouflageManager.camouflageAccess.getCamouflageItemHandler(type)){
|
||||
if(handler != null && handler.canHandle(stack, camouflageHandler)){
|
||||
camouflageHandler.setCamouflageBlock(type, stack.copy());
|
||||
if(handler != null && handler.canHandle(stack)){
|
||||
camouflageHandler.setCamouflageBlock(handler.getType(), stack.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package forestry.core.inventory;
|
||||
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.core.network.packets.CamouflageSelectionType;
|
||||
import forestry.core.network.packets.PacketCamouflageSelectServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemInventoryCamouflageSprayCan extends ItemInventory implements ICamouflageHandler {
|
||||
|
||||
public ItemInventoryCamouflageSprayCan(EntityPlayer player, ItemStack parent) {
|
||||
super(player, 1, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCamouflageBlock(String type) {
|
||||
return getStackInSlot(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDefaultCamouflageBlock(String type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandleType(String type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCamouflageBlock(String type, ItemStack camouflageBlock) {
|
||||
if(!ItemStackUtil.isIdenticalItem(camouflageBlock, getStackInSlot(0))){
|
||||
setInventorySlotContents(0, camouflageBlock);
|
||||
|
||||
World world = player.worldObj;
|
||||
if (world != null && world.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.ITEM));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCoordinates() {
|
||||
return new BlockPos(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ package forestry.core.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.blocks.IBlockRotatable;
|
||||
import forestry.core.blocks.IBlockWithMeta;
|
||||
import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
@@ -77,8 +77,8 @@ public class ItemBlockForestry<B extends Block> extends ItemBlock {
|
||||
}
|
||||
}
|
||||
|
||||
if (block instanceof BlockBase) {
|
||||
((BlockBase) block).rotateAfterPlacement(player, world, pos, side);
|
||||
if (block instanceof IBlockRotatable) {
|
||||
((IBlockRotatable) block).rotateAfterPlacement(player, world, pos, side);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package forestry.core.items;
|
||||
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.gui.ContainerCamouflageSprayCan;
|
||||
import forestry.core.gui.GuiCamouflageSprayCan;
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
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;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemCamouflageSprayCan extends ItemWithGui {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
return new GuiCamouflageSprayCan(player, new ItemInventoryCamouflageSprayCan(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
return new ContainerCamouflageSprayCan(new ItemInventoryCamouflageSprayCan(player, heldItem), player.inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
super.registerModel(item, manager);
|
||||
ModelBakery.registerItemVariants(item, new ResourceLocation("forestry:camouflageSprayCanFilled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
|
||||
ItemInventoryCamouflageSprayCan inventory = new ItemInventoryCamouflageSprayCan(player, stack);
|
||||
ItemStack camouflage = inventory.getStackInSlot(0);
|
||||
if(camouflage != null){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof ICamouflageHandler){
|
||||
ICamouflageHandler handler = (ICamouflageHandler) tile;
|
||||
String type = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflage).getType();
|
||||
if(type != null && handler.canHandleType(type)){
|
||||
if(world.isRemote){
|
||||
handler.setCamouflageBlock(type, camouflage);
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
|
||||
if (!worldIn.isRemote && playerIn.isSneaking()) {
|
||||
openGui(playerIn);
|
||||
}
|
||||
|
||||
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStackIn);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,6 +89,9 @@ public class ItemRegistryCore extends ItemRegistry {
|
||||
public final ItemForestry refractoryWax;
|
||||
public final ItemFruit fruits;
|
||||
|
||||
/* Camouflage */
|
||||
public final ItemCamouflageSprayCan camouflageSprayCan;
|
||||
|
||||
public ItemRegistryCore() {
|
||||
fertilizerBio = registerItem(new ItemForestry(), "fertilizerBio");
|
||||
fertilizerCompound = registerItem(new ItemFertilizer(), "fertilizerCompound");
|
||||
@@ -186,6 +189,9 @@ public class ItemRegistryCore extends ItemRegistry {
|
||||
ItemStack fruit = new ItemStack(fruits, 1, def.ordinal());
|
||||
OreDictionary.registerOre(def.getOreDict(), fruit);
|
||||
}
|
||||
|
||||
// CAMOUFLAGE
|
||||
camouflageSprayCan = registerItem(new ItemCamouflageSprayCan(), "camouflageSprayCan");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package forestry.core.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ModelCamouflageSprayCan extends BlankModel {
|
||||
|
||||
@Override
|
||||
protected ItemOverrideList createOverrides() {
|
||||
return new SprayCanOverrideList();
|
||||
}
|
||||
|
||||
private class SprayCanOverrideList extends ItemOverrideList{
|
||||
|
||||
public SprayCanOverrideList() {
|
||||
super(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
|
||||
IModel basicModel = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forestry:item/camouflageSprayCan"));
|
||||
IBakedModel model = basicModel.bake(basicModel.getDefaultState(), DefaultVertexFormats.ITEM, new DefaultTextureGetter());
|
||||
IBakedModel filledModel = basicModel.bake(basicModel.getDefaultState(), DefaultVertexFormats.ITEM, new DefaultTextureGetter());
|
||||
IBakedModel camouflageModel = null;
|
||||
|
||||
if(stack.hasTagCompound() && entity instanceof EntityPlayer){
|
||||
ItemInventoryCamouflageSprayCan inventory = new ItemInventoryCamouflageSprayCan((EntityPlayer) entity, stack);
|
||||
ItemStack camouflage = inventory.getStackInSlot(0);
|
||||
if(camouflage != null){
|
||||
IModel filledBasicModel = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forestry:item/camouflageSprayCanFilled"));
|
||||
filledModel = filledBasicModel.bake(filledBasicModel.getDefaultState(), DefaultVertexFormats.ITEM, new DefaultTextureGetter());
|
||||
|
||||
camouflageModel = new TRSRBakedModel(Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(camouflage), -0.0625F * 3, 0.0625F * 3, 0.0625F, 0.5F);
|
||||
}
|
||||
|
||||
}
|
||||
return new SprayCanModel(model, filledModel, camouflageModel, ModelManager.getInstance().DEFAULT_ITEM);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SprayCanModel extends BlankModel implements IPerspectiveAwareModel{
|
||||
|
||||
private final IBakedModel originalModel;
|
||||
private final IBakedModel camouflageModel;
|
||||
private final IModelState state;
|
||||
private final IBakedModel filledModel;
|
||||
|
||||
public SprayCanModel(IBakedModel originalModel, IBakedModel filledModel, IBakedModel camouflageModel, IModelState state) {
|
||||
this.originalModel = originalModel;
|
||||
this.filledModel = filledModel;
|
||||
this.camouflageModel = camouflageModel;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
quads.addAll(filledModel.getQuads(state, side, rand));
|
||||
if(camouflageModel != null){
|
||||
quads.addAll(camouflageModel.getQuads(state, side, rand));
|
||||
}
|
||||
return quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType) {
|
||||
if(cameraTransformType == TransformType.GUI){
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType);
|
||||
}
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(originalModel, state, cameraTransformType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ public enum PacketIdClient implements IPacketId {
|
||||
GUI_LAYOUT_SELECT,
|
||||
GUI_ENERGY,
|
||||
SOCKET_UPDATE,
|
||||
CAMOUFLAGE_SELECTION,
|
||||
|
||||
// Core Tile Entities
|
||||
TILE_FORESTRY_UPDATE,
|
||||
|
||||
@@ -23,15 +23,14 @@ public enum PacketIdServer implements IPacketId {
|
||||
PIPETTE_CLICK,
|
||||
CHIPSET_CLICK,
|
||||
SOLDERING_IRON_CLICK,
|
||||
CAMOUFLAGE_SELECTION,
|
||||
CLIMATE_CONTROL_UPDATE,
|
||||
|
||||
// JEI
|
||||
WORKTABLE_RECIPE_REQUEST,
|
||||
|
||||
// Apiculture
|
||||
BEE_LOGIC_ACTIVE_ENTITY_REQUEST,
|
||||
|
||||
//Greenhouse
|
||||
TILE_FORESTRY_CAMOUFLAGE,
|
||||
|
||||
// Mail
|
||||
LETTER_INFO_REQUEST,
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import forestry.core.network.packets.PacketCamouflageSelectClient;
|
||||
import forestry.core.network.packets.PacketCamouflageSelectServer;
|
||||
import forestry.core.network.packets.PacketChipsetClick;
|
||||
import forestry.core.network.packets.PacketErrorUpdate;
|
||||
import forestry.core.network.packets.PacketErrorUpdateEntity;
|
||||
@@ -26,6 +28,7 @@ import forestry.core.network.packets.PacketSocketUpdate;
|
||||
import forestry.core.network.packets.PacketSolderingIronClick;
|
||||
import forestry.core.network.packets.PacketTankLevelUpdate;
|
||||
import forestry.core.network.packets.PacketTileStream;
|
||||
import forestry.core.network.packets.PacketUpdateClimateControl;
|
||||
|
||||
public class PacketRegistryCore extends PacketRegistry {
|
||||
@Override
|
||||
@@ -42,10 +45,13 @@ public class PacketRegistryCore extends PacketRegistry {
|
||||
registerClientPacket(new PacketFXSignal());
|
||||
registerClientPacket(new PacketTankLevelUpdate());
|
||||
registerClientPacket(new PacketGenomeTrackerSync());
|
||||
registerClientPacket(new PacketCamouflageSelectClient());
|
||||
|
||||
registerServerPacket(new PacketGuiSelectRequest());
|
||||
registerServerPacket(new PacketPipetteClick());
|
||||
registerServerPacket(new PacketChipsetClick());
|
||||
registerServerPacket(new PacketSolderingIronClick());
|
||||
registerServerPacket(new PacketCamouflageSelectServer());
|
||||
registerServerPacket(new PacketUpdateClimateControl());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package forestry.core.network.packets;
|
||||
|
||||
public enum CamouflageSelectionType {
|
||||
TILE, MULTIBLOCK, ITEM;
|
||||
|
||||
public static final CamouflageSelectionType[] VALUES = values();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*******************************************************************************
|
||||
* 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.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
|
||||
public class PacketCamouflageSelectClient extends PacketCoordinates implements IForestryPacketClient{
|
||||
|
||||
private ItemStack camouflageStack;
|
||||
private String camouflageType;
|
||||
private CamouflageSelectionType selectionType;
|
||||
|
||||
public PacketCamouflageSelectClient() {
|
||||
}
|
||||
|
||||
public PacketCamouflageSelectClient(ICamouflageHandler handler, String camouflageType, CamouflageSelectionType selectionType) {
|
||||
super(handler.getCoordinates());
|
||||
this.camouflageStack = handler.getCamouflageBlock(camouflageType);
|
||||
this.selectionType = selectionType;
|
||||
this.camouflageType = camouflageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdClient getPacketId() {
|
||||
return PacketIdClient.CAMOUFLAGE_SELECTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(selectionType.ordinal());
|
||||
data.writeBoolean(camouflageType != null);
|
||||
if(camouflageType != null){
|
||||
data.writeUTF(camouflageType);
|
||||
}
|
||||
data.writeItemStack(camouflageStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
selectionType = CamouflageSelectionType.values()[data.readShort()];
|
||||
if(data.readBoolean()){
|
||||
camouflageType = data.readUTF();
|
||||
}
|
||||
camouflageStack = data.readItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
ICamouflageHandler handler = null;
|
||||
if(selectionType == CamouflageSelectionType.MULTIBLOCK){
|
||||
if (tile instanceof IMultiblockComponent) {
|
||||
IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController();
|
||||
|
||||
if (controller instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) controller;
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
for (IMultiblockComponent comp : controller.getComponents()) {
|
||||
if (comp instanceof ICamouflagedTile) {
|
||||
ICamouflagedTile camBlock = (ICamouflagedTile) comp;
|
||||
if (camouflageType != null && camBlock.getCamouflageType() != null && camBlock.getCamouflageType().equals(camouflageType)) {
|
||||
player.worldObj.markBlockRangeForRenderUpdate(camBlock.getCoordinates(), camBlock.getCoordinates());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(selectionType == CamouflageSelectionType.TILE){
|
||||
if (tile instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) tile;
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
player.worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null) {
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*******************************************************************************
|
||||
* 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.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.gui.ContainerCamouflageSprayCan;
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketCamouflageSelectServer extends PacketCoordinates implements IForestryPacketServer{
|
||||
|
||||
private ItemStack camouflageStack;
|
||||
private String camouflageType;
|
||||
private CamouflageSelectionType selectionType;
|
||||
|
||||
public PacketCamouflageSelectServer() {
|
||||
}
|
||||
|
||||
public PacketCamouflageSelectServer(ICamouflageHandler handler, String camouflageType, CamouflageSelectionType selectionType) {
|
||||
super(handler.getCoordinates());
|
||||
this.camouflageStack = handler.getCamouflageBlock(camouflageType);
|
||||
this.selectionType = selectionType;
|
||||
this.camouflageType = camouflageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.CAMOUFLAGE_SELECTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(selectionType.ordinal());
|
||||
data.writeBoolean(camouflageType != null);
|
||||
if(camouflageType != null){
|
||||
data.writeUTF(camouflageType);
|
||||
}
|
||||
data.writeItemStack(camouflageStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
selectionType = CamouflageSelectionType.values()[data.readShort()];
|
||||
if(data.readBoolean()){
|
||||
camouflageType = data.readUTF();
|
||||
}
|
||||
camouflageStack = data.readItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
ICamouflageHandler handler = null;
|
||||
if(selectionType == CamouflageSelectionType.MULTIBLOCK){
|
||||
if (tile instanceof IMultiblockComponent) {
|
||||
IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController();
|
||||
|
||||
if (controller instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) controller;
|
||||
}
|
||||
|
||||
}
|
||||
}else if(selectionType == CamouflageSelectionType.TILE){
|
||||
if (tile instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) tile;
|
||||
}
|
||||
}else{
|
||||
if(player.openContainer instanceof ContainerCamouflageSprayCan){
|
||||
ContainerCamouflageSprayCan container = (ContainerCamouflageSprayCan) player.openContainer;
|
||||
ItemInventoryCamouflageSprayCan itemInventoryCamouflageSprayCan = container.getItemInventory();
|
||||
if(itemInventoryCamouflageSprayCan != null){
|
||||
handler = itemInventoryCamouflageSprayCan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null) {
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
if(selectionType != CamouflageSelectionType.ITEM){
|
||||
Proxies.net.sendNetworkPacket(new PacketCamouflageSelectClient(handler, camouflageType, selectionType), player.worldObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PacketUpdateClimateControl extends PacketCoordinates implements IForestryPacketServer {
|
||||
|
||||
private float controlTemperature;
|
||||
private float controlHumidity;
|
||||
|
||||
public PacketUpdateClimateControl() {
|
||||
}
|
||||
|
||||
public PacketUpdateClimateControl(IClimateControlProvider provider) {
|
||||
super(provider.getCoordinates());
|
||||
|
||||
IClimateControl control = provider.getClimateControl();
|
||||
controlTemperature = control.getControlTemperature();
|
||||
controlHumidity = control.getControlHumidity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
data.writeFloat(controlTemperature);
|
||||
data.writeFloat(controlHumidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
controlTemperature = data.readFloat();
|
||||
controlHumidity = data.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.CLIMATE_CONTROL_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
IClimateControl control = null;
|
||||
if(tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
IMultiblockLogic logic = component.getMultiblockLogic();
|
||||
if(logic.isConnected() && logic.getController() instanceof IClimateControlProvider){
|
||||
control = ((IClimateControlProvider) logic.getController()).getClimateControl();
|
||||
}
|
||||
}else if(tile instanceof IClimateControlProvider){
|
||||
control = ((IClimateControlProvider) tile).getClimateControl();
|
||||
}
|
||||
if(control != null){
|
||||
control.setControlTemperature(controlTemperature);
|
||||
control.setControlHumidity(controlHumidity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import java.io.IOException;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -58,23 +59,22 @@ public class CamouflageUtil {
|
||||
}
|
||||
|
||||
public static ICamouflageHandler getCamouflageHandler(IBlockAccess world, BlockPos pos){
|
||||
if(pos == null){
|
||||
if(pos == null || world == null){
|
||||
return null;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof ICamouflagedTile){
|
||||
ICamouflagedTile block = (ICamouflagedTile) tile;
|
||||
String type = block.getCamouflageType();
|
||||
ItemStack camouflageStack = null;
|
||||
ICamouflageHandler handler = null;
|
||||
if(tile instanceof ICamouflageHandler){
|
||||
handler = (ICamouflageHandler) tile;
|
||||
camouflageStack = handler.getCamouflageBlock(type);
|
||||
}
|
||||
if(camouflageStack == null && tile instanceof IMultiblockComponent){
|
||||
if((handler == null || handler.getCamouflageBlock(type) == null) && tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
if(component.getMultiblockLogic().getController() instanceof ICamouflageHandler){
|
||||
handler = (ICamouflageHandler) component.getMultiblockLogic().getController();
|
||||
IMultiblockController controller = component.getMultiblockLogic().getController();
|
||||
if(controller instanceof ICamouflageHandler){
|
||||
handler = (ICamouflageHandler) controller;
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
@@ -83,7 +83,7 @@ public class CamouflageUtil {
|
||||
}
|
||||
|
||||
public static ItemStack getCamouflageBlock(IBlockAccess world, BlockPos pos){
|
||||
if(pos == null){
|
||||
if(pos == null || world == null){
|
||||
return null;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
@@ -91,18 +91,26 @@ public class CamouflageUtil {
|
||||
ICamouflagedTile block = (ICamouflagedTile) tile;
|
||||
String type = block.getCamouflageType();
|
||||
ItemStack camouflageStack = null;
|
||||
ICamouflageHandler tileHandler = null;
|
||||
ICamouflageHandler multiblockHandler = null;
|
||||
if(tile instanceof ICamouflageHandler){
|
||||
ICamouflageHandler handler = (ICamouflageHandler) tile;
|
||||
camouflageStack = handler.getCamouflageBlock(type);
|
||||
tileHandler = (ICamouflageHandler) tile;
|
||||
camouflageStack = tileHandler.getCamouflageBlock(type);
|
||||
}
|
||||
if(camouflageStack == null && tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
if(component.getMultiblockLogic().getController() instanceof ICamouflageHandler){
|
||||
ICamouflageHandler handler = (ICamouflageHandler) component.getMultiblockLogic().getController();
|
||||
camouflageStack = handler.getCamouflageBlock(type);
|
||||
if(camouflageStack == null){
|
||||
camouflageStack = handler.getDefaultCamouflageBlock(type);
|
||||
}
|
||||
IMultiblockController controller = component.getMultiblockLogic().getController();
|
||||
if(controller.isAssembled() && controller instanceof ICamouflageHandler){
|
||||
multiblockHandler = (ICamouflageHandler) controller;
|
||||
camouflageStack = multiblockHandler.getCamouflageBlock(type);
|
||||
}
|
||||
}
|
||||
if(camouflageStack == null){
|
||||
if(tileHandler != null){
|
||||
camouflageStack = tileHandler.getDefaultCamouflageBlock(type);
|
||||
}
|
||||
if(multiblockHandler != null && camouflageStack == null){
|
||||
camouflageStack = multiblockHandler.getDefaultCamouflageBlock(type);
|
||||
}
|
||||
}
|
||||
return camouflageStack;
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.core.climate.ClimateSource;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseClimatiser;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GreenhouseClimateSource<P extends TileGreenhouseClimatiser> extends ClimateSource<P> {
|
||||
|
||||
public GreenhouseClimateSource(int ticksForChange) {
|
||||
super(ticksForChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeClimate(int tickCount, IClimateRegion region) {
|
||||
World world = region.getWorld();
|
||||
IClimatiserDefinition definition = provider.getDefinition();
|
||||
IMultiblockLogic logic = provider.getMultiblockLogic();
|
||||
IMultiblockController controller = logic.getController();
|
||||
Iterable<BlockPos> positionsInRange = provider.getPositionsInRange();
|
||||
|
||||
boolean isActive = false;
|
||||
if(logic.isConnected() && controller.isAssembled() && controller instanceof IGreenhouseControllerInternal && positionsInRange != null && positionsInRange.iterator().hasNext() && region != null){
|
||||
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller;
|
||||
IClimateControl climateControl = getClimateControl(greenhouseInternal);
|
||||
float controlTemp = climateControl.getControlTemperature();
|
||||
float controlHum = climateControl.getControlHumidity();
|
||||
isActive = greenhouseInternal.canWork() && provider.canWork();
|
||||
EnumClimatiserTypes type = definition.getType();
|
||||
EnumClimatiserModes mode = definition.getMode();
|
||||
float maxChange = definition.getChange();
|
||||
if(isActive){
|
||||
if(canChange(type, EnumClimatiserTypes.TEMPERATURE)){
|
||||
if(region.getTemperature() < controlTemp) {
|
||||
if(!canChange(mode, EnumClimatiserModes.POSITIVE)){
|
||||
isActive = false;
|
||||
}
|
||||
}else if(region.getTemperature() > controlTemp){
|
||||
if(!canChange(mode, EnumClimatiserModes.NEGATIVE)){
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if(region.getTemperature() < controlHum) {
|
||||
if(!canChange(mode, EnumClimatiserModes.POSITIVE)){
|
||||
isActive = false;
|
||||
}
|
||||
}else if(region.getTemperature() > controlHum){
|
||||
if(!canChange(mode, EnumClimatiserModes.NEGATIVE)){
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isActive) {
|
||||
for(BlockPos pos : positionsInRange){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
if(position != null){
|
||||
double distance = pos.distanceSq(provider.getCoordinates());
|
||||
double range = definition.getRange();
|
||||
if(distance <= range){
|
||||
float change = maxChange;
|
||||
if(distance > 0){
|
||||
change = (float) (maxChange / distance);
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.TEMPERATURE)) {
|
||||
if(position.getTemperature() < controlTemp) {
|
||||
if(canChange(mode, EnumClimatiserModes.POSITIVE)){
|
||||
position.addTemperature(Math.min(change, controlTemp - position.getTemperature()));
|
||||
}
|
||||
}else if(position.getTemperature() > controlTemp){
|
||||
if(canChange(mode, EnumClimatiserModes.NEGATIVE)){
|
||||
position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if(position.getHumidity() < controlHum) {
|
||||
if(canChange(mode, EnumClimatiserModes.POSITIVE)){
|
||||
position.addHumidity(Math.min(change, controlHum - position.getHumidity()));
|
||||
}
|
||||
}else if(position.getHumidity() > controlHum){
|
||||
if(canChange(mode, EnumClimatiserModes.NEGATIVE)){
|
||||
position.addHumidity(-Math.min(position.getHumidity() - controlHum, change));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(provider.isActive() != isActive){
|
||||
provider.setActive(isActive);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canChange(EnumClimatiserTypes climatiserType, EnumClimatiserTypes type){
|
||||
if(type == climatiserType || climatiserType == EnumClimatiserTypes.NONE){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean canChange(EnumClimatiserModes climatiserMode, EnumClimatiserModes mode){
|
||||
if(mode == climatiserMode || climatiserMode == EnumClimatiserModes.NONE){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected IClimateControl getClimateControl(IGreenhouseControllerInternal greenhouseInternal){
|
||||
return greenhouseInternal.getClimateControl();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package forestry.greenhouse;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.core.climate.BiomeClimateControl;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow.WindowMode;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class GreenhouseClimateWindow extends GreenhouseClimateSource<TileGreenhouseWindow>{
|
||||
|
||||
private Biome biome;
|
||||
|
||||
public GreenhouseClimateWindow(int ticksForChange) {
|
||||
super(ticksForChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeClimate(int tickCount, IClimateRegion region) {
|
||||
World world = region.getWorld();
|
||||
IClimatiserDefinition definition = provider.getDefinition();
|
||||
IMultiblockLogic logic = provider.getMultiblockLogic();
|
||||
IMultiblockController controller = logic.getController();
|
||||
Iterable<BlockPos> positionsInRange = provider.getPositionsInRange();
|
||||
|
||||
WindowMode windowMode = provider.getMode();
|
||||
if(logic.isConnected() && controller.isAssembled() && controller instanceof IGreenhouseControllerInternal && positionsInRange != null && positionsInRange.iterator().hasNext() && region != null){
|
||||
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller;
|
||||
IClimateControl climateControl = getClimateControl(greenhouseInternal);
|
||||
float controlTemp = climateControl.getControlTemperature();
|
||||
float controlHum = climateControl.getControlHumidity();
|
||||
if(!greenhouseInternal.canWork()){
|
||||
if(windowMode == WindowMode.OPEN){
|
||||
provider.setMode(windowMode = WindowMode.CONTROL);
|
||||
}
|
||||
}else{
|
||||
if(windowMode == WindowMode.CONTROL){
|
||||
provider.setMode(windowMode = WindowMode.OPEN);
|
||||
}
|
||||
}
|
||||
if(windowMode == WindowMode.OPEN){
|
||||
int dimensionID = world.provider.getDimension();
|
||||
EnumClimatiserTypes type = definition.getType();
|
||||
EnumClimatiserModes mode = definition.getMode();
|
||||
float maxChange = definition.getChange();
|
||||
|
||||
for(BlockPos pos : positionsInRange){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
if(position != null){
|
||||
double distance = pos.distanceSq(provider.getCoordinates());
|
||||
double range = definition.getRange();
|
||||
if(distance <= range){
|
||||
float change = maxChange;
|
||||
if(distance > 0){
|
||||
change = (float) (maxChange / distance);
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.TEMPERATURE)) {
|
||||
if(position.getTemperature() < controlTemp) {
|
||||
if(canChange(mode, EnumClimatiserModes.POSITIVE)){
|
||||
position.addTemperature(Math.min(change, controlTemp - position.getTemperature()));
|
||||
}
|
||||
}else if(position.getTemperature() > controlTemp){
|
||||
if(canChange(mode, EnumClimatiserModes.NEGATIVE)){
|
||||
position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if(position.getHumidity() < controlHum) {
|
||||
if(canChange(mode, EnumClimatiserModes.POSITIVE)){
|
||||
position.addHumidity(Math.min(change, controlHum - position.getHumidity()));
|
||||
}
|
||||
}else if(position.getHumidity() > controlHum){
|
||||
if(canChange(mode, EnumClimatiserModes.NEGATIVE)){
|
||||
position.addHumidity(-Math.min(position.getHumidity() - controlHum, change));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IClimateControl getClimateControl(IGreenhouseControllerInternal greenhouseInternal) {
|
||||
if(biome == null){
|
||||
BlockPos pos = provider.getCoordinates();
|
||||
World world = provider.getWorld();
|
||||
biome = world.getBiome(pos);
|
||||
}
|
||||
return BiomeClimateControl.getControl(biome);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ package forestry.greenhouse;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
@@ -23,16 +24,15 @@ import forestry.core.PluginCore;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.items.EnumElectronTube;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.blocks.BlockRegistryGreenhouse;
|
||||
import forestry.greenhouse.logics.GreenhouseLogicGreenhouseDoor;
|
||||
import forestry.greenhouse.logics.GreenhouseLogicGreenhouseEffect;
|
||||
import forestry.greenhouse.network.PacketRegistryGreenhouse;
|
||||
import forestry.greenhouse.proxy.ProxyGreenhouse;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseClimateControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDryer;
|
||||
@@ -43,6 +43,7 @@ import forestry.greenhouse.tiles.TileGreenhouseHeater;
|
||||
import forestry.greenhouse.tiles.TileGreenhousePlain;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseValve;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
@@ -107,7 +108,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
" X ",
|
||||
"#T#",
|
||||
'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'#', "dustRedstone",
|
||||
'#', OreDictUtil.DUST_REDSTONE,
|
||||
'T', PluginCore.items.tubes.get(EnumElectronTube.GOLD, 1));
|
||||
|
||||
Block greenhouseGearBoxBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.GEARBOX);
|
||||
@@ -115,15 +116,15 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
" X ",
|
||||
"###",
|
||||
'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'#', "gearTin");
|
||||
'#', OreDictUtil.GEAR_TIN);
|
||||
|
||||
Block greenhouseValveBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.VALVE);
|
||||
RecipeUtil.addRecipe(greenhouseValveBlock,
|
||||
" X ",
|
||||
"#G#",
|
||||
'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'#', "blockGlass",
|
||||
'G', "gearTin");
|
||||
'#', OreDictUtil.BLOCK_GLASS,
|
||||
'G', OreDictUtil.GEAR_TIN);
|
||||
|
||||
Block greenhouseHeaterBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HEATER);
|
||||
RecipeUtil.addRecipe(greenhouseHeaterBlock,
|
||||
@@ -131,7 +132,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
"#X#",
|
||||
"T#T",
|
||||
'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'#', "ingotGold",
|
||||
'#', OreDictUtil.INGOT_TIN,
|
||||
'T', PluginCore.items.tubes.get(EnumElectronTube.GOLD, 1));
|
||||
|
||||
Block greenhouseFanlock = blocks.getGreenhouseBlock(BlockGreenhouseType.FAN);
|
||||
@@ -140,7 +141,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
"#X#",
|
||||
"T#T",
|
||||
'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'#', "ingotTin",
|
||||
'#', OreDictUtil.INGOT_IRON,
|
||||
'T', PluginCore.items.tubes.get(EnumElectronTube.TIN, 1));
|
||||
|
||||
Block greenhouseDryerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.DRYER);
|
||||
@@ -149,16 +150,17 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
"#X#",
|
||||
"T#T",
|
||||
'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'#', "ingotBronze",
|
||||
'#', OreDictUtil.INGOT_TIN,
|
||||
'T', PluginCore.items.tubes.get(EnumElectronTube.BLAZE, 1));
|
||||
|
||||
Block greenhouseSprinklerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.SPRINKLER);
|
||||
RecipeUtil.addRecipe(greenhouseSprinklerBlock,
|
||||
"TXT",
|
||||
"GIG",
|
||||
" I ",
|
||||
"III",
|
||||
'X', blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS),
|
||||
'I', "ingotIron",
|
||||
'I', OreDictUtil.INGOT_IRON,
|
||||
'G', OreDictUtil.GEAR_TIN,
|
||||
'T', PluginCore.items.tubes.get(EnumElectronTube.LAPIS, 1));
|
||||
|
||||
Block greenhouseDoorBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.DOOR);
|
||||
@@ -168,14 +170,60 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
"GG ",
|
||||
"GG ",
|
||||
'G', blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS));
|
||||
|
||||
Block greenhouseWindowBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.WINDOW);
|
||||
RecipeUtil.addRecipe(greenhouseWindowBlock,
|
||||
true,
|
||||
"GGS",
|
||||
"GGG",
|
||||
"GGS",
|
||||
'G', blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS),
|
||||
'S', OreDictUtil.STICK_WOOD);
|
||||
|
||||
Block greenhouseWindowRoofBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.WINDOW_UP);
|
||||
RecipeUtil.addRecipe(greenhouseWindowRoofBlock,
|
||||
true,
|
||||
"SGS",
|
||||
"GGG",
|
||||
"GGG",
|
||||
'G', blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS),
|
||||
'S', OreDictUtil.STICK_WOOD);
|
||||
|
||||
Block greenhouseClimateControlBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.CLIMATE_CONTROL);
|
||||
RecipeUtil.addRecipe(greenhouseClimateControlBlock,
|
||||
true,
|
||||
"IRG",
|
||||
"EBT",
|
||||
"GRI",
|
||||
'B', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'I', OreDictUtil.INGOT_BRONZE,
|
||||
'G', OreDictUtil.GEAR_TIN,
|
||||
'R', OreDictUtil.DUST_REDSTONE,
|
||||
'T', PluginCore.items.tubes.get(EnumElectronTube.LAPIS, 1),
|
||||
'E', PluginCore.items.tubes.get(EnumElectronTube.BLAZE, 1));
|
||||
|
||||
if(ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)){
|
||||
Block greenhouseButterflyHatchBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.BUTTERFLY_HATCH);
|
||||
RecipeUtil.addRecipe(greenhouseButterflyHatchBlock,
|
||||
true,
|
||||
"IRG",
|
||||
"SBS",
|
||||
"GRI",
|
||||
'R', OreDictUtil.DUST_REDSTONE,
|
||||
'I', OreDictUtil.INGOT_IRON,
|
||||
'G', OreDictUtil.GEAR_COPPER,
|
||||
'B', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN),
|
||||
'S', PluginCore.items.craftingMaterial.getSilkWisp());
|
||||
}
|
||||
|
||||
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FACTORY)) {
|
||||
RecipeManagers.carpenterManager.addRecipe(50, Fluids.BIOMASS.getFluid(500), null, PluginCore.items.craftingMaterial.getCamouflagedPaneling(4),
|
||||
" A ", "###", "RPR",
|
||||
'#', "plankWood",
|
||||
'A', "dustAsh",
|
||||
'R', "dustRedstone",
|
||||
'P', "pulpWood");
|
||||
'#', OreDictUtil.PLANK_WOOD,
|
||||
'A', OreDictUtil.DUST_ASH,
|
||||
'R', OreDictUtil.DUST_REDSTONE,
|
||||
'P', OreDictUtil.PULP_WOOD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +241,8 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.GreenhousePlain");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseDoor.class, "forestry.GreenhouseDoor");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseHatch.class, "forestry.GreenhouseHatch");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseClimateControl.class, "forestry.GreenhouseClimateControl");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseWindow.class, "forestry.GreenhouseWindow");
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
|
||||
GameRegistry.registerTileEntity(TileGreenhouseButterflyHatch.class, "forestry.GreenhouseButterflyHatch");
|
||||
}
|
||||
@@ -208,9 +258,4 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
GreenhouseManager.greenhouseHelper.addGreenhouseLogic(GreenhouseLogicGreenhouseDoor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPacketRegistry getPacketRegistry() {
|
||||
return new PacketRegistryGreenhouse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,20 +20,29 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumFacing.Plane;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -52,12 +61,18 @@ import forestry.api.core.ISpriteRegister;
|
||||
import forestry.api.core.ITextureManager;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.blocks.BlockStructure;
|
||||
import forestry.core.blocks.IBlockRotatable;
|
||||
import forestry.core.blocks.IColoredBlock;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.core.multiblock.MultiblockTileEntityForestry;
|
||||
import forestry.core.tiles.IActivatable;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseClimateControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDryer;
|
||||
@@ -68,11 +83,15 @@ import forestry.greenhouse.tiles.TileGreenhouseHeater;
|
||||
import forestry.greenhouse.tiles.TileGreenhousePlain;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseValve;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow.WindowMode;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
|
||||
public abstract class BlockGreenhouse extends BlockStructure implements ISpriteRegister, IColoredBlock {
|
||||
public abstract class BlockGreenhouse extends BlockStructure implements ISpriteRegister, IColoredBlock, IBlockRotatable {
|
||||
private static final AxisAlignedBB SPRINKLER_BOUNDS = new AxisAlignedBB(0.3125F, 0.25F, 0.3125F, 0.6875F, 1F, 0.6875F);
|
||||
public static final PropertyEnum<State> STATE = PropertyEnum.create("state", State.class);
|
||||
public static final PropertyBool BLOCKED = PropertyBool.create("blocked");
|
||||
public static final PropertyDirection FACING = PropertyDirection.create("facing", Plane.HORIZONTAL);
|
||||
|
||||
public enum State implements IStringSerializable {
|
||||
ON, OFF;
|
||||
@@ -106,7 +125,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
@Nonnull
|
||||
@Override
|
||||
public SoundType getSoundType() {
|
||||
if(type == BlockGreenhouseType.SPRINKLER || type == BlockGreenhouseType.GLASS){
|
||||
if(type == BlockGreenhouseType.SPRINKLER || type == BlockGreenhouseType.GLASS || type == BlockGreenhouseType.WINDOW || type == BlockGreenhouseType.WINDOW_UP){
|
||||
return SoundType.GLASS;
|
||||
}
|
||||
return super.getSoundType();
|
||||
@@ -125,6 +144,9 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
if (greenhouseType.activatable && greenhouseType != BlockGreenhouseType.SPRINKLER) {
|
||||
defaultState = defaultState.withProperty(STATE, State.OFF);
|
||||
}
|
||||
if(greenhouseType == BlockGreenhouseType.WINDOW || greenhouseType == BlockGreenhouseType.WINDOW_UP){
|
||||
defaultState = defaultState.withProperty(FACING, EnumFacing.NORTH);
|
||||
}
|
||||
setDefaultState(defaultState);
|
||||
|
||||
setHardness(1.0f);
|
||||
@@ -135,6 +157,78 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
setCreativeTab(CreativeTabForestry.tabForestry);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
if (player.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
if (!(tile instanceof MultiblockTileEntityForestry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MultiblockTileEntityForestry part = (MultiblockTileEntityForestry) tile;
|
||||
IMultiblockController controller = part.getMultiblockLogic().getController();
|
||||
if(player.getHeldItemMainhand() == null){
|
||||
if(tile instanceof TileGreenhouseWindow){
|
||||
TileGreenhouseWindow window = (TileGreenhouseWindow) tile;
|
||||
if(window.getMode() != WindowMode.CONTROL){
|
||||
if (!worldIn.isRemote) {
|
||||
if(window.isBlocked() == WindowMode.OPEN){
|
||||
if(window.getMode() == WindowMode.OPEN){
|
||||
window.setMode(WindowMode.PLAYER);
|
||||
}else{
|
||||
window.setMode(WindowMode.OPEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
worldIn.playEvent(player, getPlaySound(!window.isActive()), pos, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getHeldItemOffhand() == null) {
|
||||
// If the player's hands are empty and they right-click on a multiblock, they get a
|
||||
// multiblock-debugging message if the machine is not assembled.
|
||||
if (controller != null) {
|
||||
if (!controller.isAssembled()) {
|
||||
String validationError = controller.getLastValidationError();
|
||||
if (validationError != null) {
|
||||
long tick = worldIn.getTotalWorldTime();
|
||||
if (tick > previousMessageTick + 20) {
|
||||
player.addChatMessage(new TextComponentString(validationError));
|
||||
previousMessageTick = tick;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.addChatMessage(new TextComponentTranslation("for.multiblock.error.notConnected"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't open the GUI if the multiblock isn't assembled
|
||||
if (controller == null || !controller.isAssembled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!worldIn.isRemote) {
|
||||
part.openGui(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected int getPlaySound(boolean open){
|
||||
if (open){
|
||||
return 1007;
|
||||
}else{
|
||||
return 1013;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -153,14 +247,9 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
return super.getCollisionBoundingBox(blockState, worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
if (getGreenhouseType() != BlockGreenhouseType.SPRINKLER) {
|
||||
if (getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP) {
|
||||
return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos)
|
||||
.withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
|
||||
}
|
||||
@@ -171,7 +260,9 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
protected BlockStateContainer createBlockState() {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return new ExtendedBlockState(this, new IProperty[]{Properties.StaticProperty}, new IUnlistedProperty[]{Properties.AnimationProperty});
|
||||
} else if (getGreenhouseType().activatable) {
|
||||
}else if (getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP) {
|
||||
return new BlockStateContainer(this, STATE, FACING);
|
||||
} 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});
|
||||
@@ -183,10 +274,61 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return state.withProperty(Properties.StaticProperty, true);
|
||||
} else {
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
if(tile instanceof IActivatable){
|
||||
state = state.withProperty(STATE, ((IActivatable) tile).isActive() ? State.ON : State.OFF);
|
||||
}
|
||||
if(tile instanceof TileGreenhouseWindow){
|
||||
TileGreenhouseWindow window = (TileGreenhouseWindow) tile;
|
||||
}
|
||||
return super.getActualState(state, worldIn, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState withRotation(IBlockState state, Rotation rot) {
|
||||
EnumFacing facing = state.getValue(FACING);
|
||||
return state.withProperty(FACING, rot.rotate(facing));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
if(getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP){
|
||||
return getDefaultState().withProperty(FACING, EnumFacing.VALUES[meta + 2]);
|
||||
}
|
||||
return super.getStateFromMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
if(getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP){
|
||||
return state.getValue(FACING).ordinal() - 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
if(state.getProperties().containsKey(FACING)){
|
||||
world.setBlockState(pos, state.withProperty(FACING, player.getHorizontalFacing().getOpposite()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
|
||||
try {
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
if (tile instanceof TileGreenhouseWindow) {
|
||||
((TileGreenhouseWindow) tile).onNeighborBlockChange();
|
||||
}
|
||||
} catch (StackOverflowError error) {
|
||||
Log.error("Stack Overflow Error in BlockMachine.onNeighborBlockChange()", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
|
||||
@@ -213,6 +355,11 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
return new TileGreenhouseDoor();
|
||||
case CONTROL:
|
||||
return new TileGreenhouseControl();
|
||||
case CLIMATE_CONTROL:
|
||||
return new TileGreenhouseClimateControl();
|
||||
case WINDOW_UP:
|
||||
case WINDOW:
|
||||
return new TileGreenhouseWindow();
|
||||
case HATCH_INPUT:
|
||||
case HATCH_OUTPUT:
|
||||
return new TileGreenhouseHatch();
|
||||
@@ -252,7 +399,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public BlockRenderLayer getBlockLayer() {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.GLASS || getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.GLASS || getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP || getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return BlockRenderLayer.TRANSLUCENT;
|
||||
}
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
@@ -260,12 +407,12 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) {
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() != BlockGreenhouseType.SPRINKLER;
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) {
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() != BlockGreenhouseType.SPRINKLER;
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -280,6 +427,18 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
}
|
||||
return super.canPlaceBlockAt(worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileGreenhouseWindow){
|
||||
TileGreenhouseWindow window = (TileGreenhouseWindow) tile;
|
||||
if(!window.getWorld().isRemote){
|
||||
window.setMode(window.isBlocked());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -308,7 +467,11 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.sprinkler", "inventory"));
|
||||
} else {
|
||||
} else if (getGreenhouseType() == BlockGreenhouseType.WINDOW) {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.window", "inventory"));
|
||||
} else if (getGreenhouseType() == BlockGreenhouseType.WINDOW_UP) {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.window_up", "inventory"));
|
||||
} else {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse", "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.models.GreenhouseDoorStateMapper;
|
||||
@@ -247,13 +246,7 @@ public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMapper
|
||||
state = state.withProperty(FACING, iblockstate1.getValue(FACING)).withProperty(OPEN, iblockstate1.getValue(OPEN));
|
||||
}
|
||||
}
|
||||
TileGreenhouse tile = TileUtil.getTile(worldIn, pos, TileGreenhouse.class);
|
||||
boolean isCamouflaged = false;
|
||||
if(tile != null){
|
||||
ItemStack camouflage = CamouflageUtil.getCamouflageBlock(worldIn, pos);
|
||||
isCamouflaged = camouflage != null;
|
||||
}
|
||||
state = state.withProperty(CAMOUFLAGED, isCamouflaged);
|
||||
state = state.withProperty(CAMOUFLAGED, CamouflageUtil.getCamouflageBlock(worldIn, pos) != null);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ public enum BlockGreenhouseType {
|
||||
CONTROL(true),
|
||||
SPRINKLER(false, true),
|
||||
DOOR,
|
||||
CLIMATE_CONTROL(true),
|
||||
WINDOW(true),
|
||||
WINDOW_UP(true),
|
||||
BUTTERFLY_HATCH(true);
|
||||
|
||||
public static final BlockGreenhouseType[] VALUES = values();
|
||||
@@ -61,7 +64,7 @@ public enum BlockGreenhouseType {
|
||||
private static EnumMap<BlockGreenhouseSprites, TextureAtlasSprite> sprites;
|
||||
|
||||
private enum BlockGreenhouseSprites {
|
||||
PLAIN, GLASS, GEARS("gears"), VALVE("valve"), FAN_OFF("fan.off"), FAN_ON("fan.on"), HEATER_OFF("heater.off"), HEATER_ON("heater.on"), DRYER("dryer"), CONTROL("control"), HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output"), BUTTERFLY_HATCH("butterfly_hatch");
|
||||
GEARS("gears"), VALVE("valve"), FAN_OFF("fan.off"), FAN_ON("fan.on"), HEATER_OFF("heater.off"), HEATER_ON("heater.on"), DRYER("dryer"), CONTROL("control"), HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output"), CLIMATE_CONTROL("climate_control"), BUTTERFLY_HATCH("butterfly_hatch");
|
||||
|
||||
public static final BlockGreenhouseSprites[] VALUES = values();
|
||||
|
||||
@@ -70,10 +73,6 @@ public enum BlockGreenhouseType {
|
||||
BlockGreenhouseSprites(String spriteName) {
|
||||
this.spriteName = spriteName;
|
||||
}
|
||||
|
||||
BlockGreenhouseSprites() {
|
||||
this.spriteName = null;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -82,11 +81,9 @@ public enum BlockGreenhouseType {
|
||||
TextureMap map = Proxies.common.getClientInstance().getTextureMapBlocks();
|
||||
|
||||
for (BlockGreenhouseSprites sprite : BlockGreenhouseSprites.VALUES) {
|
||||
if (sprite != BlockGreenhouseSprites.PLAIN && sprite != BlockGreenhouseSprites.GLASS) {
|
||||
ResourceLocation location = new ResourceLocation(Constants.MOD_ID, "blocks/greenhouse/" + sprite.spriteName);
|
||||
TextureAtlasSprite textureAtlasSprite = map.registerSprite(location);
|
||||
sprites.put(sprite, textureAtlasSprite);
|
||||
}
|
||||
ResourceLocation location = new ResourceLocation(Constants.MOD_ID, "blocks/greenhouse/" + sprite.spriteName);
|
||||
TextureAtlasSprite textureAtlasSprite = map.registerSprite(location);
|
||||
sprites.put(sprite, textureAtlasSprite);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +137,11 @@ public enum BlockGreenhouseType {
|
||||
return sprites.get(BlockGreenhouseSprites.HATCH_INPUT);
|
||||
}
|
||||
return null;
|
||||
case CLIMATE_CONTROL:
|
||||
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
|
||||
return null;
|
||||
}
|
||||
return sprites.get(BlockGreenhouseSprites.CLIMATE_CONTROL);
|
||||
case BUTTERFLY_HATCH:
|
||||
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package forestry.greenhouse.entities;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class SprinklerWater extends Particle {
|
||||
|
||||
public SprinklerWater(World world, double x, double y, double z, Vec3d vector, ResourceLocation texture) {
|
||||
super(world, x, y, z, 0, 0, 0);
|
||||
this.particleScale = 0.3F;
|
||||
this.motionX = vector.xCoord;
|
||||
this.motionY = vector.yCoord;
|
||||
this.motionZ = vector.zCoord;
|
||||
this.particleMaxAge = 15;
|
||||
this.setSize(0.2f, 0.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFXLayer() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderParticle(VertexBuffer worldRenderer, Entity entity, float partialTicks, float f0, float f1, float f2, float f3, float f4) {
|
||||
float f6 = 0;
|
||||
float f7 = 1;
|
||||
float f8 = 0;
|
||||
float f9 = 1;
|
||||
float f10 = 0.1F * this.particleScale;
|
||||
float f11 = (float) (this.prevPosX + (this.posX - this.prevPosX) * f0 - interpPosX);
|
||||
float f12 = (float) (this.prevPosY + (this.posY - this.prevPosY) * f0 - interpPosY);
|
||||
float f13 = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * f0 - interpPosZ);
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(FluidRegistry.WATER.getStill());
|
||||
int i = this.getBrightnessForRender(partialTicks);
|
||||
int j = i >> 16 & 65535;
|
||||
int k = i & 65535;
|
||||
worldRenderer.pos((f11 - f1 * f10 - f4 * f10), (f12 - f2 * f10), (f13 - f3 * f10 - f6 * f10)).color(1F, 1F, 1F, 0.5F).tex(f7, f9).lightmap(j, k).endVertex();
|
||||
worldRenderer.pos((f11 - f1 * f10 + f4 * f10), (f12 + f2 * f10), (f13 - f3 * f10 + f6 * f10)).color(1F, 1F, 1F, 0.5F).tex(f7, f8).lightmap(j, k).endVertex();
|
||||
worldRenderer.pos((f11 + f1 * f10 + f4 * f10), (f12 + f2 * f10), (f13 + f3 * f10 + f6 * f10)).color(1F, 1F, 1F, 0.5F).tex(f6, f8).lightmap(j, k).endVertex();
|
||||
worldRenderer.pos((f11 + f1 * f10 - f4 * f10), (f12 - f2 * f10), (f13 + f3 * f10 - f6 * f10)).color(1F, 1F, 1F, 0.5F).tex(f6, f9).lightmap(j, k).endVertex();
|
||||
}
|
||||
|
||||
// avoid calculating lighting for water, it is too much processing
|
||||
@Override
|
||||
public int getBrightnessForRender(float p_189214_1_) {
|
||||
return 15728880;
|
||||
}
|
||||
}
|
||||
@@ -10,21 +10,55 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.primitives.Floats;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.ledgers.ClimateLedger;
|
||||
import forestry.core.gui.ledgers.Ledger;
|
||||
import forestry.core.gui.widgets.TankWidget;
|
||||
import forestry.core.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.core.network.packets.PacketUpdateClimateControl;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.greenhouse.multiblock.DefaultClimateControl;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouse;
|
||||
|
||||
public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse, TileGreenhouse> {
|
||||
|
||||
private static final Predicate<String> numberFilter = new Predicate<String>(){
|
||||
@Override
|
||||
public boolean apply(@Nullable String text){
|
||||
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.floatValue()) && f.floatValue() >= 0.0F;
|
||||
}
|
||||
};
|
||||
|
||||
private GuiTextField humidityField;
|
||||
private GuiTextField temperatureField;
|
||||
private boolean fieldsEnabeled;
|
||||
|
||||
public GuiGreenhouse(EntityPlayer player, TileGreenhouse tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/greenhouse.png", new ContainerGreenhouse(player.inventory, tile), tile);
|
||||
|
||||
@@ -38,7 +72,101 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse, TileGr
|
||||
|
||||
//Add the tile camouflage slots
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 35, 37, inventory, tile.getCamouflageType()));
|
||||
fieldsEnabeled = true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
temperatureField = new GuiTextField(0, fontRendererObj, guiLeft + 63, guiTop + 30, 50, 10);
|
||||
humidityField = new GuiTextField(1, fontRendererObj, guiLeft + 63, guiTop + 60, 50, 10);
|
||||
|
||||
temperatureField.setValidator(numberFilter);
|
||||
humidityField.setValidator(numberFilter);
|
||||
|
||||
IGreenhouseController controller = inventory.getMultiblockLogic().getController();
|
||||
if(controller == null || controller.getClimateControl() == null || controller.getClimateControl() == DefaultClimateControl.instance){
|
||||
temperatureField.setEnabled(false);
|
||||
temperatureField.setVisible(false);
|
||||
humidityField.setEnabled(false);
|
||||
humidityField.setVisible(false);
|
||||
fieldsEnabeled = false;
|
||||
}else{
|
||||
IClimateControl control = controller.getClimateControl();
|
||||
temperatureField.setText(Float.toString(control.getControlTemperature()));
|
||||
humidityField.setText(Float.toString(control.getControlHumidity()));
|
||||
}
|
||||
}
|
||||
|
||||
@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{
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@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 = inventory.getMultiblockLogic().getController();
|
||||
IClimateControl control = provider.getClimateControl();
|
||||
if(temperatureWasFocused && !temperatureField.isFocused()){
|
||||
float temp = parseField(temperatureField);
|
||||
temperatureField.setText(Float.toString(temp));
|
||||
control.setControlTemperature(temp);
|
||||
}else if(humidityWasFocused && !humidityField.isFocused()){
|
||||
float hum = parseField(humidityField);
|
||||
humidityField.setText(Float.toString(hum));
|
||||
control.setControlHumidity(parseField(humidityField));
|
||||
}
|
||||
Proxies.net.sendToServer(new PacketUpdateClimateControl(provider));
|
||||
}
|
||||
}
|
||||
|
||||
private float parseField(GuiTextField field){
|
||||
String text = temperatureField.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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
|
||||
if(temperatureField.getVisible()){
|
||||
textLayout.line = 20;
|
||||
textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.temperature"), 0, fontColor.get("gui.greenhouse.temperature.text"));
|
||||
temperatureField.drawTextBox();
|
||||
}
|
||||
if(humidityField.getVisible()){
|
||||
textLayout.line = 50;
|
||||
textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.humidity"), 0, fontColor.get("gui.greenhouse.humidity.text"));
|
||||
|
||||
humidityField.drawTextBox();
|
||||
}
|
||||
bindTexture(textureFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLedgers() {
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.ledgers.ClimateLedger;
|
||||
import forestry.greenhouse.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.core.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.IGreenhouseClimaLogic;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.CamouflageAccess;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
|
||||
public class GreenhouseLogicGreenhouseEffect extends DefaultGreenhouseLogic implements IGreenhouseClimaLogic {
|
||||
@@ -76,7 +75,7 @@ public class GreenhouseLogicGreenhouseEffect extends DefaultGreenhouseLogic impl
|
||||
if (block.getCamouflageType() == CamouflageManager.GLASS) {
|
||||
if (world.canBlockSeeSky(component.getCoordinates())) {
|
||||
ItemStack camouflageStack = CamouflageUtil.getCamouflageBlock(world, component.getCoordinates());
|
||||
ICamouflageItemHandler handler = CamouflageAccess.getHandlerFromItem(camouflageStack, controller);
|
||||
ICamouflageItemHandler handler = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflageStack);
|
||||
float camouflageLightTransmittance = handler.getLightTransmittance(camouflageStack, controller);
|
||||
|
||||
if (camouflageLightTransmittance < 1 && camouflageLightTransmittance > 0) {
|
||||
|
||||
@@ -25,11 +25,11 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.core.IModelBaker;
|
||||
import forestry.core.CamouflageAccess;
|
||||
import forestry.core.models.ModelBlockDefault;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
@@ -57,7 +57,7 @@ public class ModelGreenhouse extends ModelBlockDefault<BlockGreenhouse> {
|
||||
if (camouflageStack != null) {
|
||||
ICamouflageHandler camouflageHandler = CamouflageUtil.getCamouflageHandler(world, pos);
|
||||
ICamouflagedTile camouflageTile = (ICamouflagedTile) world.getTileEntity(pos);
|
||||
ICamouflageItemHandler itemHandler = CamouflageAccess.getHandlerFromItem(camouflageStack, camouflageHandler);
|
||||
ICamouflageItemHandler itemHandler = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflageStack);
|
||||
if(itemHandler != null){
|
||||
Pair<IBlockState, IBakedModel> model = itemHandler.getModel(camouflageStack, camouflageHandler, camouflageTile);
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package forestry.greenhouse.multiblock;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
|
||||
public class DefaultClimateControl implements IClimateControl {
|
||||
|
||||
public static final DefaultClimateControl instance = new DefaultClimateControl();
|
||||
|
||||
public DefaultClimateControl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlTemperature() {
|
||||
return 2.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlHumidity() {
|
||||
return 2.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlTemperature(float temperature) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlHumidity(float humidity) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,10 +18,12 @@ import java.util.Set;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.IGreenhouseLogic;
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.Listener;
|
||||
import forestry.core.fluids.FakeTankManager;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
@@ -115,4 +117,19 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateControl getClimateControl() {
|
||||
return DefaultClimateControl.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ButterflyHatch getButterflyHatch() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -31,14 +31,15 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSourceProvider;
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimateSource;
|
||||
import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
|
||||
import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent;
|
||||
@@ -49,6 +50,8 @@ 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.ClimateControl;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.Climatiser;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.climate.ClimateRoom;
|
||||
@@ -64,6 +67,8 @@ import forestry.core.multiblock.MultiblockValidationException;
|
||||
import forestry.core.multiblock.RectangularMultiblockControllerBase;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.packets.CamouflageSelectionType;
|
||||
import forestry.core.network.packets.PacketCamouflageSelectServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
@@ -74,7 +79,6 @@ import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouse;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
|
||||
public class GreenhouseController extends RectangularMultiblockControllerBase implements IGreenhouseControllerInternal, ILiquidTankTile {
|
||||
@@ -82,7 +86,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
private final Set<IInternalBlock> internalBlocks = new HashSet<>();
|
||||
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 List<IGreenhouseLogic> logics = new ArrayList<>();
|
||||
protected ClimateControl climateControl;
|
||||
protected ButterflyHatch butterflyHatch;
|
||||
|
||||
private final TankManager tankManager;
|
||||
private final StandardTank resourceTank;
|
||||
@@ -123,34 +130,18 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
int dimensionID = worldObj.provider.getDimension();
|
||||
float temperature = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for(IInternalBlock internalBlock : internalBlocks){
|
||||
IClimatePosition position = region.getPositions().get(internalBlock.getPos());
|
||||
if(position != null){
|
||||
positions++;
|
||||
temperature+=position.getTemperature();
|
||||
}
|
||||
if(region == null){
|
||||
return 0;
|
||||
}
|
||||
return temperature / positions;
|
||||
return region.getTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
int dimensionID = worldObj.provider.getDimension();
|
||||
float humidity = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for(IInternalBlock internalBlock : internalBlocks){
|
||||
IClimatePosition position = region.getPositions().get(internalBlock.getPos());
|
||||
if(position != null){
|
||||
positions++;
|
||||
humidity+=position.getHumidity();
|
||||
}
|
||||
if(region == null){
|
||||
return 0;
|
||||
}
|
||||
return humidity / positions;
|
||||
return region.getHumidity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,7 +203,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
|
||||
if(data.hasKey("Region")){
|
||||
NBTTagCompound nbtTag = data.getCompoundTag("Region");
|
||||
region = new ClimateRoom(this, nbtTag);
|
||||
if(region != null){
|
||||
region.readFromNBT(nbtTag);
|
||||
}else{
|
||||
region = new ClimateRoom(this, getWallPositions(), nbtTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,18 +294,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageUpdate(this, type, true));
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
if (comp instanceof ICamouflagedTile) {
|
||||
ICamouflagedTile camBlock = (ICamouflagedTile) comp;
|
||||
if (camBlock.getCamouflageType() == type) {
|
||||
worldObj.markBlockRangeForRenderUpdate(camBlock.getCoordinates(), camBlock.getCoordinates());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (worldObj != null && worldObj.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.MULTIBLOCK));
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(this, null, this, type));
|
||||
@@ -421,17 +406,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
}
|
||||
}
|
||||
ForestryAPI.climateManager.removeRegion(region);
|
||||
region = new ClimateRoom(region, internalPositions, wallPositions);
|
||||
region = new ClimateRoom(region, internalPositions, getWallPositions());
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
}else{
|
||||
Map<BlockPos, IClimatePosition> internalPositions = new HashMap<>();
|
||||
List<BlockPos> wallPositions = new ArrayList<>();
|
||||
for(IMultiblockComponent comp : connectedParts){
|
||||
if(comp != null){
|
||||
wallPositions.add(comp.getCoordinates());
|
||||
}
|
||||
}
|
||||
region = new ClimateRoom(this, internalPositions, wallPositions);
|
||||
region = new ClimateRoom(this, internalPositions, getWallPositions());
|
||||
for(IInternalBlock block : internalBlocks){
|
||||
if(block != null){
|
||||
internalPositions.put(block.getPos(), new ClimatePosition(region, block.getPos()));
|
||||
@@ -439,6 +418,16 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
}
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
}
|
||||
|
||||
for(IClimateSourceProvider source : climatiserComponents){
|
||||
ForestryAPI.climateManager.addSource(source);
|
||||
}
|
||||
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
if (comp instanceof ICamouflagedTile) {
|
||||
worldObj.markBlockRangeForRenderUpdate(comp.getCoordinates(), comp.getCoordinates());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -447,6 +436,16 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
|
||||
internalBlocks.clear();
|
||||
logics.clear();
|
||||
|
||||
for(IClimateSourceProvider source : climatiserComponents){
|
||||
ForestryAPI.climateManager.removeSource(source);
|
||||
}
|
||||
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
if (comp instanceof ICamouflagedTile) {
|
||||
worldObj.markBlockRangeForRenderUpdate(comp.getCoordinates(), comp.getCoordinates());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -454,7 +453,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
if (newPart instanceof IGreenhouseComponent.Listener) {
|
||||
listenerComponents.add((IGreenhouseComponent.Listener) newPart);
|
||||
} else if (newPart instanceof IGreenhouseComponent.Climatiser) {
|
||||
ForestryAPI.climateManager.addSource((IClimateSource) newPart);
|
||||
climatiserComponents.add((Climatiser) newPart);
|
||||
} else if (newPart instanceof IGreenhouseComponent.Active) {
|
||||
activeComponents.add((IGreenhouseComponent.Active) newPart);
|
||||
}
|
||||
@@ -465,7 +464,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
if (oldPart instanceof IGreenhouseComponent.Listener) {
|
||||
listenerComponents.remove(oldPart);
|
||||
} else if (oldPart instanceof IGreenhouseComponent.Climatiser) {
|
||||
ForestryAPI.climateManager.removeSource((IClimateSource) oldPart);
|
||||
climatiserComponents.remove(oldPart);
|
||||
ForestryAPI.climateManager.removeSource((IClimateSourceProvider) oldPart);
|
||||
} else if (oldPart instanceof IGreenhouseComponent.Active) {
|
||||
activeComponents.remove(oldPart);
|
||||
}
|
||||
@@ -477,13 +477,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
IGreenhouseControllerInternal internal = (IGreenhouseControllerInternal) assimilated;
|
||||
if(region != null){
|
||||
ForestryAPI.climateManager.removeRegion(region);
|
||||
List<BlockPos> wallPositions = new ArrayList<>();
|
||||
for(IMultiblockComponent comp : connectedParts){
|
||||
if(comp != null){
|
||||
wallPositions.add(comp.getCoordinates());
|
||||
}
|
||||
}
|
||||
region = new ClimateRoom(region,internal.getRegion().getPositions(), wallPositions);
|
||||
region = new ClimateRoom(region, internal.getRegion().getPositions(), getWallPositions());
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
}
|
||||
}
|
||||
@@ -640,34 +634,55 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
internalBlocks.clear();
|
||||
|
||||
if (isNextRoof) {
|
||||
Stack<IInternalBlock> blocksToCheck = new Stack<>();
|
||||
IInternalBlock internalBlock = createInternalBlock(new InternalBlock(getMinimumCoord().add(1, 1, 1)));
|
||||
blocksToCheck.add(internalBlock);
|
||||
while (!blocksToCheck.isEmpty()) {
|
||||
IInternalBlock blockToCheck = blocksToCheck.pop();
|
||||
List<IInternalBlock> newBlocksToCheck = checkInternalBlock(blockToCheck);
|
||||
blocksToCheck.addAll(newBlocksToCheck);
|
||||
}
|
||||
checkInternalBlocks();
|
||||
}
|
||||
|
||||
if (internalBlocks.isEmpty()) {
|
||||
throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.space.closed"));
|
||||
}
|
||||
|
||||
int hatches = 0;
|
||||
Set<ButterflyHatch> hatches = new HashSet<>();
|
||||
Set<ClimateControl> controls = new HashSet<>();
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
if (comp instanceof IGreenhouseComponent.ButterflyHatch) {
|
||||
hatches++;
|
||||
if (comp instanceof ButterflyHatch) {
|
||||
hatches.add((ButterflyHatch) comp);
|
||||
}else if(comp instanceof ClimateControl){
|
||||
controls.add((ClimateControl) comp);
|
||||
}
|
||||
}
|
||||
if (hatches > 1) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateClient(int tickCount) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all internal blocks.
|
||||
* @throws MultiblockValidationException
|
||||
*/
|
||||
private void checkInternalBlocks() throws MultiblockValidationException{
|
||||
Stack<IInternalBlock> blocksToCheck = new Stack<>();
|
||||
IInternalBlock internalBlock = createInternalBlock(new InternalBlock(getMinimumCoord().add(1, 1, 1)));
|
||||
blocksToCheck.add(internalBlock);
|
||||
while (!blocksToCheck.isEmpty()) {
|
||||
IInternalBlock blockToCheck = blocksToCheck.pop();
|
||||
List<IInternalBlock> newBlocksToCheck = checkInternalBlock(blockToCheck);
|
||||
blocksToCheck.addAll(newBlocksToCheck);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of more internal blocks to check.
|
||||
@@ -732,17 +747,17 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
return internalBlocks;
|
||||
}
|
||||
|
||||
public static ButterflyHatch getGreenhouseButterflyHatch(World world, BlockPos pos) {
|
||||
if (GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos) == null) {
|
||||
return null;
|
||||
@Override
|
||||
public IClimateControl getClimateControl() {
|
||||
if(climateControl == null){
|
||||
return DefaultClimateControl.instance;
|
||||
}
|
||||
IGreenhouseController controller = GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos);
|
||||
for (IMultiblockComponent greenhouse : controller.getComponents()) {
|
||||
if (greenhouse instanceof ButterflyHatch) {
|
||||
return (ButterflyHatch) greenhouse;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return climateControl.getClimateControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ButterflyHatch getButterflyHatch() {
|
||||
return butterflyHatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -778,5 +793,26 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
public Set<IGreenhouseComponent.Listener> getListenerComponents() {
|
||||
return listenerComponents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork() {
|
||||
boolean canWork = true;
|
||||
for (IGreenhouseComponent.Listener listenerComponent : listenerComponents) {
|
||||
if(canWork){
|
||||
canWork = listenerComponent.getGreenhouseListener().canWork(this, canWork);
|
||||
}
|
||||
}
|
||||
return canWork;
|
||||
}
|
||||
|
||||
protected List<BlockPos> getWallPositions(){
|
||||
List<BlockPos> wallPositions = new ArrayList<>();
|
||||
for(IMultiblockComponent comp : connectedParts){
|
||||
if(comp != null){
|
||||
wallPositions.add(comp.getCoordinates());
|
||||
}
|
||||
}
|
||||
return wallPositions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,5 +55,9 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM
|
||||
*/
|
||||
void clearRegion();
|
||||
|
||||
boolean canWork();
|
||||
|
||||
Set<IGreenhouseComponent.Listener> getListenerComponents();
|
||||
|
||||
IGreenhouseComponent.ButterflyHatch getButterflyHatch();
|
||||
}
|
||||
@@ -1,21 +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.network;
|
||||
|
||||
import forestry.core.network.PacketRegistry;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
|
||||
public class PacketRegistryGreenhouse extends PacketRegistry {
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
registerServerPacket(new PacketCamouflageUpdate());
|
||||
}
|
||||
}
|
||||
@@ -1,91 +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.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.network.packets.PacketCoordinates;
|
||||
|
||||
public class PacketCamouflageUpdate extends PacketCoordinates implements IForestryPacketServer{
|
||||
|
||||
private ItemStack camouflageStack;
|
||||
private String type;
|
||||
private boolean isMultiblock;
|
||||
|
||||
public PacketCamouflageUpdate() {
|
||||
}
|
||||
|
||||
public PacketCamouflageUpdate(ICamouflageHandler tile, String type, boolean isMultiblock) {
|
||||
super(tile.getCoordinates());
|
||||
this.camouflageStack = tile.getCamouflageBlock(type);
|
||||
this.isMultiblock = isMultiblock;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public PacketCamouflageUpdate(ICamouflageHandler tile, String type) {
|
||||
super(tile.getCoordinates());
|
||||
this.camouflageStack = tile.getCamouflageBlock(type);
|
||||
this.isMultiblock = false;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.TILE_FORESTRY_CAMOUFLAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(isMultiblock);
|
||||
data.writeUTF(type);
|
||||
data.writeItemStack(camouflageStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
isMultiblock = data.readBoolean();
|
||||
type = data.readUTF();
|
||||
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) {
|
||||
handler = (ICamouflageHandler) tile;
|
||||
}
|
||||
|
||||
if (handler != null) {
|
||||
handler.setCamouflageBlock(type, camouflageStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ public class ProxyGreenhouseClient extends ProxyGreenhouse {
|
||||
if(!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)){
|
||||
continue;
|
||||
}
|
||||
}else if(greenhouseType == BlockGreenhouseType.WINDOW || greenhouseType == BlockGreenhouseType.WINDOW_UP){
|
||||
continue;
|
||||
}
|
||||
|
||||
Block greenhouseBlock = PluginGreenhouse.blocks.getGreenhouseBlock(greenhouseType);
|
||||
|
||||
@@ -39,6 +39,8 @@ import forestry.core.multiblock.MultiblockTileEntityForestry;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.packets.CamouflageSelectionType;
|
||||
import forestry.core.network.packets.PacketCamouflageSelectServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.ITitled;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
@@ -48,7 +50,6 @@ import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.gui.ContainerGreenhouse;
|
||||
import forestry.greenhouse.gui.GuiGreenhouse;
|
||||
import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
|
||||
public abstract class TileGreenhouse extends MultiblockTileEntityForestry<MultiblockLogicGreenhouse> implements IGreenhouseComponent, IHintSource, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile {
|
||||
|
||||
@@ -106,11 +107,8 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
|
||||
if(!ItemStackUtil.isIdenticalItem(camouflageBlock, this.camouflageBlock)){
|
||||
this.camouflageBlock = camouflageBlock;
|
||||
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageUpdate(this, type));
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
if (worldObj != null && worldObj.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.TILE));
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(getMultiblockLogic().getController(), this, this, type));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ public class TileGreenhouseButterflyHatch extends TileGreenhouse implements IGre
|
||||
public TileGreenhouseButterflyHatch() {
|
||||
this.inventory = new InventoryGreenhouseButterflyHatch(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TileGreenhouseClimateControl extends TileGreenhouse implements IGreenhouseComponent.ClimateControl {
|
||||
|
||||
private final forestry.core.climate.ClimateControl climateControl;
|
||||
|
||||
public TileGreenhouseClimateControl() {
|
||||
super();
|
||||
climateControl = new forestry.core.climate.ClimateControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
super.decodeDescriptionPacket(packetData);
|
||||
climateControl.readFromNBT(packetData);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
super.encodeDescriptionPacket(packetData);
|
||||
climateControl.writeToNBT(packetData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
climateControl.readFromNBT(data);
|
||||
super.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
climateControl.writeToNBT(data);
|
||||
return super.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
climateControl.writeData(data);
|
||||
super.writeGuiData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
climateControl.readData(data);
|
||||
super.readGuiData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateControl getClimateControl() {
|
||||
return climateControl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,52 +10,47 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.apiculture.network.packets.PacketActiveUpdate;
|
||||
import forestry.core.climate.ClimateSource;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.IActivatable;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.GreenhouseClimateSource;
|
||||
|
||||
public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivatable, IGreenhouseComponent.Climatiser {
|
||||
|
||||
protected static final int WORK_CYCLES = 1;
|
||||
protected static final int ENERGY_PER_OPERATION = 150;
|
||||
|
||||
protected enum ClimitiserType {
|
||||
TEMPERATURE, HUMIDITY
|
||||
}
|
||||
|
||||
protected interface IClimitiserDefinition {
|
||||
float getChange();
|
||||
|
||||
boolean isPositiv();
|
||||
|
||||
int getClimitiseRange();
|
||||
|
||||
ClimitiserType getType();
|
||||
}
|
||||
|
||||
private final IClimitiserDefinition definition;
|
||||
private final IClimatiserDefinition definition;
|
||||
private final ClimateSource source;
|
||||
|
||||
protected EnumFacing inwards;
|
||||
protected EnumFacing leftwards;
|
||||
protected BlockPos maxPos;
|
||||
protected BlockPos minPos;
|
||||
|
||||
protected int workingTime = 0;
|
||||
|
||||
private boolean active;
|
||||
|
||||
protected TileGreenhouseClimatiser(IClimitiserDefinition definition) {
|
||||
protected TileGreenhouseClimatiser(IClimatiserDefinition definition, int ticksForChange) {
|
||||
this(definition, new GreenhouseClimateSource(ticksForChange));
|
||||
}
|
||||
|
||||
protected TileGreenhouseClimatiser(IClimatiserDefinition definition, ClimateSource source) {
|
||||
this.definition = definition;
|
||||
this.source = source;
|
||||
this.source.setProvider(this);
|
||||
}
|
||||
|
||||
protected TileGreenhouseClimatiser(IClimatiserDefinition definition) {
|
||||
this(definition, 20 + ENERGY_PER_OPERATION / 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,114 +65,24 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
@Override
|
||||
public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) {
|
||||
recalculateDirections(minCoord, maxCoord);
|
||||
int range = Math.round((float)definition.getRange() / 2);
|
||||
|
||||
if(leftwards != null){
|
||||
maxPos = getPos().offset(inwards, definition.getClimitiseRange() / 2).offset(leftwards, definition.getClimitiseRange() / 2).offset(EnumFacing.UP, definition.getClimitiseRange() / 2);
|
||||
minPos = getPos().offset(inwards).offset(leftwards.getOpposite(), definition.getClimitiseRange() / 2).offset(EnumFacing.DOWN, definition.getClimitiseRange() / 2);
|
||||
maxPos = getCoordinates().offset(inwards, range).offset(leftwards, range).offset(EnumFacing.UP, range);
|
||||
minPos = getCoordinates().offset(inwards).offset(leftwards.getOpposite(), range).offset(EnumFacing.DOWN, range);
|
||||
|
||||
}else{
|
||||
maxPos = getPos().offset(inwards, definition.getClimitiseRange() / 2).offset(EnumFacing.EAST, definition.getClimitiseRange() / 2).offset(EnumFacing.NORTH, definition.getClimitiseRange() / 2);
|
||||
minPos = getPos().offset(inwards).offset(EnumFacing.WEST, definition.getClimitiseRange() / 2).offset(EnumFacing.SOUTH, definition.getClimitiseRange() / 2);
|
||||
maxPos = getCoordinates().offset(inwards, range).offset(EnumFacing.EAST, range).offset(EnumFacing.NORTH, range);
|
||||
minPos = getCoordinates().offset(inwards).offset(EnumFacing.WEST, range).offset(EnumFacing.SOUTH, range);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksForChange(IClimateRegion region) {
|
||||
return 20;
|
||||
public BlockPos getMinPos() {
|
||||
return minPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeClimate(int tick, IClimateRegion region) {
|
||||
IMultiblockController controller = getMultiblockLogic().getController();
|
||||
if(getMultiblockLogic().isConnected() && controller != null && controller.isAssembled() && minPos != null && maxPos != null && region != null){
|
||||
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller;
|
||||
boolean canWork = true;
|
||||
for (IGreenhouseComponent.Listener listenerComponent : greenhouseInternal.getListenerComponents()) {
|
||||
if(canWork){
|
||||
canWork = listenerComponent.getGreenhouseListener().canWork(greenhouseInternal, canWork);
|
||||
}
|
||||
}
|
||||
if (canWork && workingTime == 0 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) {
|
||||
int dimensionID = worldObj.provider.getDimension();
|
||||
|
||||
for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
if(position != null){
|
||||
if (definition.getType() == ClimitiserType.TEMPERATURE) {
|
||||
if(definition.isPositiv()){
|
||||
if(position.getTemperature() >= 2.0F){
|
||||
if(position.getTemperature() > 2.0F){
|
||||
position.setTemperature(2.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}else{
|
||||
if(position.getTemperature() <= 0.0F){
|
||||
if(position.getTemperature() < 0.0F){
|
||||
position.setTemperature(0.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(definition.isPositiv()){
|
||||
if(position.getHumidity() >= 2.0F){
|
||||
if(position.getHumidity() > 2.0F){
|
||||
position.setHumidity(2.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}else{
|
||||
if(position.getHumidity() <= 0.0F){
|
||||
if(position.getHumidity() < 0.0F){
|
||||
position.setHumidity(0.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double distance = pos.distanceSq(this.pos);
|
||||
int maxDistance = definition.getClimitiseRange();
|
||||
if(distance <= maxDistance){
|
||||
if (definition.getType() == ClimitiserType.TEMPERATURE) {
|
||||
position.addTemperature((definition.isPositiv() ? +1 : -1) * ((distance == 0) ? definition.getChange() : (float) (definition.getChange() / distance)));
|
||||
}else{
|
||||
position.addHumidity((definition.isPositiv() ? +1 : -1) * ((distance == 0) ? definition.getChange() : (float) (definition.getChange() / distance)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add config entry for a time modifier and a energy modifier.
|
||||
// one tick of work for every 10 RF
|
||||
workingTime += ENERGY_PER_OPERATION / 25;
|
||||
}
|
||||
|
||||
if (workingTime > 0) {
|
||||
workingTime--;
|
||||
}
|
||||
|
||||
setActive(workingTime > 0);
|
||||
}else if(isActive()){
|
||||
setActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/* LOADING & SAVING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
workingTime = nbttagcompound.getInteger("Heating");
|
||||
setActive(workingTime > 0);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound = super.writeToNBT(nbttagcompound);
|
||||
nbttagcompound.setInteger("Heating", workingTime);
|
||||
return nbttagcompound;
|
||||
public BlockPos getMaxPos() {
|
||||
return maxPos;
|
||||
}
|
||||
|
||||
/* Network */
|
||||
@@ -204,29 +109,29 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
leftwards = null;
|
||||
|
||||
int facesMatching = 0;
|
||||
if (maxCoord.getX() == getPos().getX() || minCoord.getX() == getPos().getX()) {
|
||||
if (maxCoord.getX() == getCoordinates().getX() || minCoord.getX() == getCoordinates().getX()) {
|
||||
facesMatching++;
|
||||
}
|
||||
if (maxCoord.getY() == getPos().getY() || minCoord.getY() == getPos().getY()) {
|
||||
if (maxCoord.getY() == getCoordinates().getY() || minCoord.getY() == getCoordinates().getY()) {
|
||||
facesMatching++;
|
||||
}
|
||||
if (maxCoord.getZ() == getPos().getZ() || minCoord.getZ() == getPos().getZ()) {
|
||||
if (maxCoord.getZ() == getCoordinates().getZ() || minCoord.getZ() == getCoordinates().getZ()) {
|
||||
facesMatching++;
|
||||
}
|
||||
if (facesMatching == 1) {
|
||||
if (maxCoord.getX() == getPos().getX()) {
|
||||
if (maxCoord.getX() == getCoordinates().getX()) {
|
||||
inwards = EnumFacing.WEST;
|
||||
leftwards = EnumFacing.SOUTH;
|
||||
} else if (minCoord.getX() == getPos().getX()) {
|
||||
} else if (minCoord.getX() == getCoordinates().getX()) {
|
||||
inwards = EnumFacing.EAST;
|
||||
leftwards = EnumFacing.NORTH;
|
||||
} else if (maxCoord.getZ() == getPos().getZ()) {
|
||||
} else if (maxCoord.getZ() == getCoordinates().getZ()) {
|
||||
inwards = EnumFacing.NORTH;
|
||||
leftwards = EnumFacing.WEST;
|
||||
} else if (minCoord.getZ() == getPos().getZ()) {
|
||||
} else if (minCoord.getZ() == getCoordinates().getZ()) {
|
||||
inwards = EnumFacing.SOUTH;
|
||||
leftwards = EnumFacing.EAST;
|
||||
} else if (maxCoord.getY() == getPos().getY()) {
|
||||
} else if (maxCoord.getY() == getCoordinates().getY()) {
|
||||
inwards = EnumFacing.DOWN;
|
||||
} else {
|
||||
inwards = EnumFacing.UP;
|
||||
@@ -236,9 +141,30 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
}
|
||||
}
|
||||
|
||||
public IClimitiserDefinition getDefinition() {
|
||||
@Override
|
||||
public IClimatiserDefinition getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateSource getClimateSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public boolean canWork(){
|
||||
IMultiblockLogic logic = getMultiblockLogic();
|
||||
if(logic == null || !logic.isConnected() || getMultiblockLogic().getController().getEnergyManager() == null){
|
||||
return false;
|
||||
}
|
||||
return getMultiblockLogic().getController().getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION);
|
||||
}
|
||||
|
||||
public Iterable<BlockPos> getPositionsInRange(){
|
||||
if(maxPos == null || minPos == null){
|
||||
return null;
|
||||
}
|
||||
return BlockPos.getAllInBox(maxPos, minPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
@@ -250,7 +176,7 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote) {
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
worldObj.markBlockRangeForRenderUpdate(getCoordinates(), getCoordinates());
|
||||
} else {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), worldObj);
|
||||
}
|
||||
|
||||
@@ -10,35 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
|
||||
public class TileGreenhouseDryer extends TileGreenhouseClimatiser {
|
||||
|
||||
private static final DryerDefinition definition = new DryerDefinition();
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5D, EnumClimatiserTypes.HUMIDITY);
|
||||
|
||||
public TileGreenhouseDryer() {
|
||||
super(definition);
|
||||
}
|
||||
|
||||
private static class DryerDefinition implements IClimitiserDefinition {
|
||||
|
||||
@Override
|
||||
public float getChange() {
|
||||
return 0.015F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPositiv() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClimitiseRange() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClimitiserType getType() {
|
||||
return ClimitiserType.HUMIDITY;
|
||||
}
|
||||
super(DEFINITION);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,36 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
|
||||
public class TileGreenhouseFan extends TileGreenhouseClimatiser {
|
||||
|
||||
private static final FanDefinition definition = new FanDefinition();
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5D, EnumClimatiserTypes.TEMPERATURE);
|
||||
|
||||
public TileGreenhouseFan() {
|
||||
super(definition);
|
||||
}
|
||||
|
||||
private static class FanDefinition implements IClimitiserDefinition {
|
||||
|
||||
@Override
|
||||
public float getChange() {
|
||||
return 0.015F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClimitiseRange() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClimitiserType getType() {
|
||||
return ClimitiserType.TEMPERATURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPositiv() {
|
||||
return false;
|
||||
}
|
||||
super(DEFINITION);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,6 +45,8 @@ import forestry.core.gui.IHintSource;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.packets.CamouflageSelectionType;
|
||||
import forestry.core.network.packets.PacketCamouflageSelectServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
@@ -52,8 +54,6 @@ import forestry.core.utils.PlayerUtil;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
@@ -144,11 +144,8 @@ public class TileGreenhouseHatch extends MultiblockTileEntityBase<MultiblockLogi
|
||||
if(!ItemStackUtil.isIdenticalItem(camouflageBlock, this.camouflageBlock)){
|
||||
this.camouflageBlock = camouflageBlock;
|
||||
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageUpdate(this, type));
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
if (worldObj != null && worldObj.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.TILE));
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(getMultiblockLogic().getController(), this, this, type));
|
||||
}
|
||||
|
||||
@@ -10,35 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
|
||||
public class TileGreenhouseHeater extends TileGreenhouseClimatiser {
|
||||
|
||||
private static final HeaterDefinition definition = new HeaterDefinition();
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.POSITIVE, 5D, EnumClimatiserTypes.TEMPERATURE);
|
||||
|
||||
public TileGreenhouseHeater() {
|
||||
super(definition);
|
||||
}
|
||||
|
||||
private static class HeaterDefinition implements IClimitiserDefinition {
|
||||
|
||||
@Override
|
||||
public ClimitiserType getType() {
|
||||
return ClimitiserType.TEMPERATURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChange() {
|
||||
return 0.015F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClimitiseRange() {
|
||||
return 7;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPositiv() {
|
||||
return true;
|
||||
}
|
||||
super(DEFINITION);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,32 +14,32 @@ import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.common.animation.TimeValues;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.model.animation.CapabilityAnimation;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
|
||||
public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
|
||||
|
||||
private final IAnimationStateMachine asm;
|
||||
private final TimeValues.VariableValue cycleLength = new TimeValues.VariableValue(4);
|
||||
private final TimeValues.VariableValue cycleLength = new TimeValues.VariableValue(20);
|
||||
private final TimeValues.VariableValue clickTime = new TimeValues.VariableValue(Float.NEGATIVE_INFINITY);
|
||||
|
||||
protected static final int WATER_PER_OPERATION = 25;
|
||||
private static final SprinklerDefinition definition = new SprinklerDefinition();
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.005F, EnumClimatiserModes.POSITIVE, 9, EnumClimatiserTypes.HUMIDITY);
|
||||
|
||||
public TileGreenhouseSprinkler() {
|
||||
super(definition);
|
||||
super(DEFINITION, 20 + WATER_PER_OPERATION / 10);
|
||||
asm = Proxies.render.loadAnimationState(new ResourceLocation(Constants.MOD_ID, "asms/block/sprinkler.json"), ImmutableMap.of(
|
||||
"cycle_length", cycleLength,
|
||||
"click_time", clickTime
|
||||
@@ -52,47 +52,12 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeClimate(int tick, IClimateRegion region) {
|
||||
IMultiblockController controller = getMultiblockLogic().getController();
|
||||
if(getMultiblockLogic().isConnected() && controller != null && controller.isAssembled() && minPos != null && maxPos != null && region != null){
|
||||
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller;
|
||||
boolean canWork = true;
|
||||
for (IGreenhouseComponent.Listener listenerComponent : greenhouseInternal.getListenerComponents()) {
|
||||
if(canWork){
|
||||
canWork = listenerComponent.getGreenhouseListener().canWork(greenhouseInternal, canWork);
|
||||
}
|
||||
}
|
||||
if (canWork && workingTime == 0 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) {
|
||||
|
||||
for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
if(position != null){
|
||||
if(position.getHumidity() >= 2.0F){
|
||||
if(position.getHumidity() > 2.0F){
|
||||
position.setHumidity(2.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
double distance = pos.distanceSq(pos);
|
||||
int maxDistance = definition.getClimitiseRange();
|
||||
if(distance <= maxDistance){
|
||||
position.setHumidity((float) (position.getHumidity() + ((distance == 0) ? definition.getChange() : (definition.getChange() / distance))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
workingTime += WATER_PER_OPERATION / 10;
|
||||
}
|
||||
|
||||
if (workingTime > 0) {
|
||||
workingTime--;
|
||||
}
|
||||
|
||||
setActive(workingTime > 0);
|
||||
}else if(isActive()){
|
||||
setActive(false);
|
||||
public boolean canWork() {
|
||||
IMultiblockLogic logic = getMultiblockLogic();
|
||||
if(logic == null || !logic.isConnected() || getMultiblockLogic().getController().getTankManager() == null || getMultiblockLogic().getController().getTankManager().getTank(0) == null){
|
||||
return false;
|
||||
}
|
||||
return consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, getMultiblockLogic().getController().getTankManager().getTank(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,14 +75,14 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean consumeWaterToDoWork(int ticksPerWorkCycle, int fluidPerWorkCycle, StandardTank tank) {
|
||||
public boolean consumeWaterToDoWork(int ticksPerWorkCycle, int fluidPerWorkCycle, IFluidTank tank) {
|
||||
int fluidPerCycle = (int) Math.ceil(fluidPerWorkCycle / (float) ticksPerWorkCycle);
|
||||
if (tank.getFluid() == null || tank.getFluid().amount < fluidPerCycle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tank.drain(fluidPerCycle, true);
|
||||
return true;
|
||||
FluidStack drained = tank.drain(fluidPerCycle, true);
|
||||
|
||||
return drained != null && drained.amount > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,27 +103,4 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
|
||||
return super.getCapability(capability, side);
|
||||
}
|
||||
|
||||
private static class SprinklerDefinition implements IClimitiserDefinition {
|
||||
|
||||
@Override
|
||||
public ClimitiserType getType() {
|
||||
return ClimitiserType.HUMIDITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChange() {
|
||||
return 0.005F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClimitiseRange() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPositiv() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
import forestry.greenhouse.GreenhouseClimateWindow;
|
||||
import forestry.greenhouse.PluginGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class TileGreenhouseWindow extends TileGreenhouseClimatiser{
|
||||
|
||||
private WindowMode mode;
|
||||
|
||||
public TileGreenhouseWindow() {
|
||||
super(new ClimatiserDefinition(0.001F, EnumClimatiserModes.NONE, 5D, EnumClimatiserTypes.NONE), new GreenhouseClimateWindow(20));
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange() {
|
||||
WindowMode otherMode = isBlocked();
|
||||
if(getMode() != WindowMode.PLAYER && getMode() != WindowMode.CONTROL && otherMode != getMode()){
|
||||
setMode(otherMode);
|
||||
}
|
||||
}
|
||||
|
||||
public WindowMode isBlocked(){
|
||||
if(worldObj == null){
|
||||
return WindowMode.BLOCK;
|
||||
}
|
||||
IBlockState state = worldObj.getBlockState(pos);
|
||||
if(state == null){
|
||||
return WindowMode.BLOCK;
|
||||
}
|
||||
BlockPos blockedPos;
|
||||
if(state.getBlock() == PluginGreenhouse.blocks.getGreenhouseBlock(BlockGreenhouseType.WINDOW_UP)){
|
||||
blockedPos = getCoordinates().offset(EnumFacing.UP);
|
||||
}else{
|
||||
blockedPos = getCoordinates().offset(state.getValue(BlockGreenhouse.FACING));
|
||||
}
|
||||
return worldObj.isAirBlock(blockedPos) ? WindowMode.OPEN : WindowMode.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
if(mode != null){
|
||||
data.setShort("mode", (short) mode.ordinal());
|
||||
}
|
||||
return super.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
if(data.hasKey("mode")){
|
||||
setMode(WindowMode.values()[data.getShort("mode")]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
super.decodeDescriptionPacket(packetData);
|
||||
if(packetData.hasKey("mode")){
|
||||
setMode(WindowMode.values()[packetData.getShort("mode")]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
if(mode != null){
|
||||
packetData.setShort("mode", (short) mode.ordinal());
|
||||
}
|
||||
super.encodeDescriptionPacket(packetData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setMode(WindowMode mode){
|
||||
this.mode = mode;
|
||||
setActive(mode == WindowMode.OPEN);
|
||||
}
|
||||
|
||||
public WindowMode getMode(){
|
||||
return mode;
|
||||
}
|
||||
|
||||
public static enum WindowMode{
|
||||
PLAYER, BLOCK, CONTROL, OPEN
|
||||
}
|
||||
|
||||
}
|
||||
Loaded 100 of 121 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user