diff --git a/formatting-settings.jar b/formatting-settings.jar index f4b53734f..31a286e8a 100644 Binary files a/formatting-settings.jar and b/formatting-settings.jar differ diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 4ce2dafa5..1a065a780 100755 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -31,7 +31,6 @@ import net.minecraftforge.fml.common.registry.GameRegistry; import forestry.api.core.ForestryAPI; import forestry.core.EventHandlerCore; -import forestry.core.climate.ClimateEventHandler; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.GameMode; @@ -58,7 +57,8 @@ import forestry.plugins.compat.PluginIC2; acceptedMinecraftVersions = "[1.12]", dependencies = "required-after:forge@[14.21.1.2395,);" + "after:jei@[4.7.0,);" - + "after:" + PluginIC2.modId + ";") + + "after:" + PluginIC2.modId + ";" + + "after:toughasnails;") public class Forestry { @SuppressWarnings("NullableProblems") @@ -91,7 +91,7 @@ public class Forestry { EventHandlerCore eventHandlerCore = new EventHandlerCore(); MinecraftForge.EVENT_BUS.register(eventHandlerCore); MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler()); - MinecraftForge.EVENT_BUS.register(new ClimateEventHandler()); + MinecraftForge.EVENT_BUS.register(Config.class); Proxies.common.registerEventHandlers(); configFolder = new File(event.getModConfigurationDirectory(), Constants.MOD_ID); diff --git a/src/main/java/forestry/api/apiculture/ApicultureCapabilities.java b/src/main/java/forestry/api/apiculture/ApicultureCapabilities.java index 2608aa485..9f4a06393 100644 --- a/src/main/java/forestry/api/apiculture/ApicultureCapabilities.java +++ b/src/main/java/forestry/api/apiculture/ApicultureCapabilities.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.apiculture; import net.minecraftforge.common.capabilities.Capability; diff --git a/src/main/java/forestry/api/apiculture/IHiveTile.java b/src/main/java/forestry/api/apiculture/IHiveTile.java index 15efc3777..b74b85231 100644 --- a/src/main/java/forestry/api/apiculture/IHiveTile.java +++ b/src/main/java/forestry/api/apiculture/IHiveTile.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.apiculture; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/forestry/api/arboriculture/ArboricultureCapabilities.java b/src/main/java/forestry/api/arboriculture/ArboricultureCapabilities.java index 713a82d64..0ca778d1a 100644 --- a/src/main/java/forestry/api/arboriculture/ArboricultureCapabilities.java +++ b/src/main/java/forestry/api/arboriculture/ArboricultureCapabilities.java @@ -1,9 +1,15 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.arboriculture; -import forestry.api.core.IArmorNaturalist; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; +import forestry.api.core.IArmorNaturalist; + public class ArboricultureCapabilities { /** * Capability for {@link IArmorNaturalist}. diff --git a/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java b/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java index c126fedbe..8d2fbe0a3 100644 --- a/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java +++ b/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.arboriculture; import java.util.Locale; diff --git a/src/main/java/forestry/api/arboriculture/IGrowthProvider.java b/src/main/java/forestry/api/arboriculture/IGrowthProvider.java index 27f1cd490..ff9114841 100644 --- a/src/main/java/forestry/api/arboriculture/IGrowthProvider.java +++ b/src/main/java/forestry/api/arboriculture/IGrowthProvider.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright 2011-2014 SirSengir - * + * * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.arboriculture; diff --git a/src/main/java/forestry/api/arboriculture/IWoodType.java b/src/main/java/forestry/api/arboriculture/IWoodType.java index 4fc8bd3d3..7e8415473 100644 --- a/src/main/java/forestry/api/arboriculture/IWoodType.java +++ b/src/main/java/forestry/api/arboriculture/IWoodType.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.arboriculture; import net.minecraft.util.IStringSerializable; diff --git a/src/main/java/forestry/api/arboriculture/WoodBlockKind.java b/src/main/java/forestry/api/arboriculture/WoodBlockKind.java index e1994031b..776013df3 100755 --- a/src/main/java/forestry/api/arboriculture/WoodBlockKind.java +++ b/src/main/java/forestry/api/arboriculture/WoodBlockKind.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.arboriculture; import com.google.common.collect.ImmutableMap; diff --git a/src/main/java/forestry/api/circuits/CircuitSocketType.java b/src/main/java/forestry/api/circuits/CircuitSocketType.java index f7f67091a..b5b336143 100644 --- a/src/main/java/forestry/api/circuits/CircuitSocketType.java +++ b/src/main/java/forestry/api/circuits/CircuitSocketType.java @@ -8,6 +8,7 @@ package forestry.api.circuits; public enum CircuitSocketType implements ICircuitSocketType { NONE("none"), FARM("forestry.farm"), + GREENHOUSE_CLIMATISER("forestry.greenhouse.climatiser"), ELECTRIC_ENGINE("forestry.electric.engine"), MACHINE("forestry.machine"); diff --git a/src/main/java/forestry/api/climate/BlankClimateModifier.java b/src/main/java/forestry/api/climate/BlankClimateModifier.java new file mode 100644 index 000000000..fa5bdc107 --- /dev/null +++ b/src/main/java/forestry/api/climate/BlankClimateModifier.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.nbt.NBTTagCompound; + +public class BlankClimateModifier implements IClimateModifier { + @Override + public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, ImmutableClimateState oldState, NBTTagCompound data) { + return newState; + } + + @Override + public void addData(IClimateContainer container, IClimateState climateState, NBTTagCompound nbtData, IClimateData data) { + } + + @Override + public int getPriority() { + return 0; + } +} diff --git a/src/main/java/forestry/api/climate/ClimateChange.java b/src/main/java/forestry/api/climate/ClimateChange.java new file mode 100644 index 000000000..fab209443 --- /dev/null +++ b/src/main/java/forestry/api/climate/ClimateChange.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.climate; + +import com.google.common.base.Objects; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.MathHelper; + +import forestry.api.core.INbtReadable; + +/** + * A {@link IClimateState} that has a range from 0.0F to 2.0F and can be positiv an negativ. + * + * + * It is mainly used by {@link IClimateSource} to change the {@link IClimateState} of the {@link IClimateContainer}. + */ +public class ClimateChange implements IClimateState, INbtReadable{ + + private static final String TEMPERATURE_NBT_KEY = "TEMP"; + private static final String HUMIDITY_NBT_KEY = "HUMID"; + public static final ClimateChange ORIGIN = new ClimateChange(0.0F, 0.0F); + + + public float temperature; + public float humidity; + + public ClimateChange(float temperature, float humidity) { + addTemperature(temperature); + addHumidity(humidity); + } + + public ClimateChange(NBTTagCompound compound) { + readFromNBT(compound); + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setFloat(TEMPERATURE_NBT_KEY, temperature); + compound.setFloat(HUMIDITY_NBT_KEY, humidity); + return compound; + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + this.temperature = compound.getFloat(TEMPERATURE_NBT_KEY); + this.humidity = compound.getFloat(HUMIDITY_NBT_KEY); + } + + @Override + public float getTemperature() { + return temperature; + } + + @Override + public float getHumidity() { + return humidity; + } + + public void setTemperature(float temperature) { + this.temperature = 0; + addTemperature(temperature); + } + + public void setHumidity(float humidity) { + this.humidity = 0; + addHumidity(humidity); + } + + @Override + public ClimateChange add(IClimateState state){ + addTemperature(state.getTemperature()); + addHumidity(state.getHumidity()); + return this; + } + + @Override + public ClimateChange remove(IClimateState state){ + addTemperature(-state.getTemperature()); + addHumidity(-state.getHumidity()); + return this; + } + + @Override + public ClimateChange addTemperature(float temperature){ + this.temperature = MathHelper.clamp(this.temperature + temperature, -2.0F, 2.0F); + return this; + } + + @Override + public ClimateChange addHumidity(float humidity){ + this.humidity = MathHelper.clamp(this.humidity + humidity, -2.0F, 2.0F); + return this; + } + + @Override + public ImmutableClimateState toImmutable() { + return new ImmutableClimateState(temperature, humidity); + } + + @Override + public ClimateState toMutable() { + return new ClimateState(temperature, humidity); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("temperature", temperature).add("humidity", humidity).toString(); + } + +} diff --git a/src/main/java/forestry/api/climate/ClimateState.java b/src/main/java/forestry/api/climate/ClimateState.java new file mode 100644 index 000000000..a810eafde --- /dev/null +++ b/src/main/java/forestry/api/climate/ClimateState.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.climate; + +import com.google.common.base.Objects; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.MathHelper; + +import forestry.api.core.INbtReadable; + +import static forestry.api.climate.ImmutableClimateState.MAX; +import static forestry.api.climate.ImmutableClimateState.MIN; + +/** + * A {@link IClimateState} that has a range from 0.0F to 2.0F. + */ +public class ClimateState implements IClimateState, INbtReadable{ + + private static final String TEMPERATURE_NBT_KEY = "TEMP"; + private static final String HUMIDITY_NBT_KEY = "HUMID"; + + protected float temperature; + protected float humidity; + + public ClimateState(float temperature, float humidity) { + addTemperature(temperature); + addHumidity(humidity); + } + + public ClimateState(NBTTagCompound compound) { + readFromNBT(compound); + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setFloat(TEMPERATURE_NBT_KEY, temperature); + compound.setFloat(HUMIDITY_NBT_KEY, humidity); + return compound; + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + this.temperature = compound.getFloat(TEMPERATURE_NBT_KEY); + this.humidity = compound.getFloat(HUMIDITY_NBT_KEY); + } + + public void setTemperature(float temperature) { + this.temperature = MathHelper.clamp(temperature, MIN.temperature, MAX.temperature); + } + + public void setHumidity(float humidity) { + this.humidity = MathHelper.clamp(humidity, MIN.humidity, MAX.humidity); + } + + @Override + public ClimateState addTemperature(float temperature){ + setTemperature(this.temperature + temperature); + return this; + } + + @Override + public ClimateState addHumidity(float humidity){ + setHumidity(this.humidity + humidity); + return this; + } + + @Override + public ClimateState add(IClimateState state){ + addTemperature(state.getTemperature()); + addHumidity(state.getHumidity()); + return this; + } + + @Override + public ClimateState remove(IClimateState state){ + addTemperature(-state.getTemperature()); + addHumidity(-state.getHumidity()); + return this; + } + + @Override + public float getTemperature() { + return temperature; + } + + @Override + public float getHumidity() { + return humidity; + } + + @Override + public ImmutableClimateState toImmutable(){ + return new ImmutableClimateState(temperature, humidity); + } + + @Override + public ClimateState toMutable(){ + return this; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof IClimateState)){ + return false; + } + IClimateState otherState = (IClimateState) obj; + return otherState.getTemperature() == temperature && otherState.getHumidity() == humidity; + } + + @Override + public int hashCode() { + return Float.hashCode(temperature) + Float.hashCode(humidity); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("temperature", temperature).add("humidity", humidity).toString(); + } + +} diff --git a/src/main/java/forestry/api/climate/ClimateType.java b/src/main/java/forestry/api/climate/ClimateType.java new file mode 100644 index 000000000..ca821c5ff --- /dev/null +++ b/src/main/java/forestry/api/climate/ClimateType.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.climate; + +import java.util.Locale; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.ForestryAPI; + +public enum ClimateType { + TEMPERATURE, HUMIDITY; + + @SideOnly(Side.CLIENT) + public TextureAtlasSprite getSprite() { + return ForestryAPI.textureManager.getDefault("misc/" + getName()); + } + + public String getName(){ + return name().toLowerCase(Locale.ENGLISH); + } + +} diff --git a/src/main/java/forestry/api/climate/EnumClimatiserModes.java b/src/main/java/forestry/api/climate/EnumClimatiserModes.java deleted file mode 100644 index b9e64b163..000000000 --- a/src/main/java/forestry/api/climate/EnumClimatiserModes.java +++ /dev/null @@ -1,7 +0,0 @@ -package forestry.api.climate; - -public enum EnumClimatiserModes { - - POSITIVE, NEGATIVE, BOTH - -} diff --git a/src/main/java/forestry/api/climate/EnumClimatiserTypes.java b/src/main/java/forestry/api/climate/EnumClimatiserTypes.java deleted file mode 100644 index 143d2f728..000000000 --- a/src/main/java/forestry/api/climate/EnumClimatiserTypes.java +++ /dev/null @@ -1,7 +0,0 @@ -package forestry.api.climate; - -public enum EnumClimatiserTypes { - - TEMPERATURE, HUMIDITY, BOTH - -} diff --git a/src/main/java/forestry/api/climate/GreenhouseState.java b/src/main/java/forestry/api/climate/GreenhouseState.java new file mode 100644 index 000000000..14626f074 --- /dev/null +++ b/src/main/java/forestry/api/climate/GreenhouseState.java @@ -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 enum GreenhouseState { + CLOSED, + //If the greenhouse is not closed. + OPEN, + //If one chunk of the greenhouse is unloaded. + UNLOADED_CHUNK, + //The greenhouse has this state 20 ticks after all chunks are loaded, needed to load all climate sources. + UNLOADED, + //If the greenhouse is not assembled. + UNREADY +} diff --git a/src/main/java/forestry/api/climate/IClimateContainer.java b/src/main/java/forestry/api/climate/IClimateContainer.java new file mode 100644 index 000000000..a33c2861d --- /dev/null +++ b/src/main/java/forestry/api/climate/IClimateContainer.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.climate; + +import javax.annotation.Nullable; +import java.util.Collection; + +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; + +public interface IClimateContainer extends INbtReadable, INbtWritable, IClimateSourceContainer { + + /** + * @return The parent of this container. + */ + IClimateHousing getParent(); + + /** + * @return The current climate state. + */ + IClimateState getState(); + + World getWorld(); + + /** + * Update the climate in a region. + */ + void updateClimate(int ticks); + + /** + * Add a listener to this container. + */ + void addListaner(IClimateContainerListener listener); + + /** + * Remove a listener to this container. + */ + void removeListener(IClimateContainerListener listener); + + /** + * All listeners of this container. + */ + Collection getListeners(); + + /** + * @return the state that the container targets to get his climate state to. + */ + ImmutableClimateState getTargetedState(); + + void setTargetedState(ImmutableClimateState state); + + @Nullable + @SideOnly(Side.CLIENT) + IClimateData getData(); + +} diff --git a/src/main/java/forestry/api/climate/IClimateSourceProvider.java b/src/main/java/forestry/api/climate/IClimateContainerListener.java similarity index 56% rename from src/main/java/forestry/api/climate/IClimateSourceProvider.java rename to src/main/java/forestry/api/climate/IClimateContainerListener.java index 502a27d92..c45849880 100644 --- a/src/main/java/forestry/api/climate/IClimateSourceProvider.java +++ b/src/main/java/forestry/api/climate/IClimateContainerListener.java @@ -5,14 +5,13 @@ ******************************************************************************/ package forestry.api.climate; -import java.util.Set; +public interface IClimateContainerListener { -import forestry.api.core.ILocatable; -import net.minecraft.util.math.BlockPos; - -public interface IClimateSourceProvider extends ILocatable { - - IClimateSource getClimateSource(); + /** + * Test if the container is closed. + * + * @return true to let the container slowly set his climate state back to the default climate state. + */ + boolean isClosed(IClimateContainer container); - Set getPositionsInRange(); } diff --git a/src/main/java/forestry/api/climate/IClimatiserDefinition.java b/src/main/java/forestry/api/climate/IClimateData.java similarity index 64% rename from src/main/java/forestry/api/climate/IClimatiserDefinition.java rename to src/main/java/forestry/api/climate/IClimateData.java index 2c224a191..c3ff6c7db 100644 --- a/src/main/java/forestry/api/climate/IClimatiserDefinition.java +++ b/src/main/java/forestry/api/climate/IClimateData.java @@ -5,14 +5,11 @@ ******************************************************************************/ package forestry.api.climate; -public interface IClimatiserDefinition { +import java.util.Map; - float getChange(); +public interface IClimateData { - float getRange(); - - EnumClimatiserModes getMode(); - - EnumClimatiserTypes getType(); + IClimateData addData(ClimateType type, String displayName, float value); + Map getData(ClimateType type); } diff --git a/src/main/java/forestry/api/climate/IClimateControlProvider.java b/src/main/java/forestry/api/climate/IClimateFactory.java similarity index 62% rename from src/main/java/forestry/api/climate/IClimateControlProvider.java rename to src/main/java/forestry/api/climate/IClimateFactory.java index 8507fc2b3..931591e7a 100644 --- a/src/main/java/forestry/api/climate/IClimateControlProvider.java +++ b/src/main/java/forestry/api/climate/IClimateFactory.java @@ -5,12 +5,13 @@ ******************************************************************************/ package forestry.api.climate; -import forestry.api.core.ILocatable; +public interface IClimateFactory { -public interface IClimateControlProvider extends ILocatable { - - IClimateInfo getControlClimate(); + /** + * @param climatedRegion + * + * @return Creates a climate container. + */ + IClimateContainer createContainer(IClimateHousing climatedRegion); - void setControlClimate(IClimateInfo climateControl); - } diff --git a/src/main/java/forestry/api/climate/IClimateHousing.java b/src/main/java/forestry/api/climate/IClimateHousing.java new file mode 100644 index 000000000..91ec426d3 --- /dev/null +++ b/src/main/java/forestry/api/climate/IClimateHousing.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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 IClimateHousing { + + /** + * @return The climate container of this region. + */ + IClimateContainer getClimateContainer(); + + /** + * @return The size of the region in blocks. + */ + int getSize(); + + void onUpdateClimate(); + + /** + * @return The default climate state. It is calculated out of all biomedata that this region contains. + */ + ImmutableClimateState getDefaultClimate(); + + /** + * Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 + * + * @return The position at that the housing is. + */ + BlockPos getCoordinates(); + + /** + * Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 + * + * @return The world in that the housing is. + */ + World getWorldObj(); + +} diff --git a/src/main/java/forestry/api/climate/IClimateInfo.java b/src/main/java/forestry/api/climate/IClimateInfo.java deleted file mode 100644 index bd03fdb11..000000000 --- a/src/main/java/forestry/api/climate/IClimateInfo.java +++ /dev/null @@ -1,9 +0,0 @@ -package forestry.api.climate; - -public interface IClimateInfo { - - float getTemperature(); - - float getHumidity(); - -} diff --git a/src/main/java/forestry/api/climate/IClimateManager.java b/src/main/java/forestry/api/climate/IClimateManager.java index 1bd42dfa9..f5710a12d 100644 --- a/src/main/java/forestry/api/climate/IClimateManager.java +++ b/src/main/java/forestry/api/climate/IClimateManager.java @@ -6,36 +6,42 @@ package forestry.api.climate; import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; +import java.util.Collection; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import forestry.api.greenhouse.Position2D; + public interface IClimateManager { - - IClimateInfo createInfo(float temperature, float humidity); - IClimateInfo getInfo(World world, BlockPos pos); + /** + * @return The current state of a container at this position if one exists. + * @since 5.3.4 + */ + @Nullable + IClimateContainer getContainer(World world, BlockPos pos); + + /** + * Gets the current state of a container at this position or setSettings one with the datas from the biome. + * @since 5.3.4 + */ + IClimateState getClimateState(World world, BlockPos pos); + + /** + * Creates a climate state with the help of the biome on this position. + */ + ImmutableClimateState getBiomeState(World world, BlockPos pos); + /** + * @return Create a climate manager. + */ IClimateProvider getDefaultClimate(World world, BlockPos pos); - - void addRegion(IClimateRegion region); - - void removeRegion(IClimateRegion region); - - void addSource(IClimateSourceProvider source); - - void removeSource(IClimateSourceProvider source); - - void onWorldUnload(World world); - @Nullable - IClimatePosition getPosition(World world, BlockPos pos); + void addSource(IClimateSourceOwner owner); + + void removeSource(IClimateSourceOwner owner); - @Nullable - IClimateRegion getRegionForPos(World world, BlockPos pos); - - Map> getRegions(); + Collection getSources(World world, Position2D position); } diff --git a/src/main/java/forestry/api/climate/IClimateModifier.java b/src/main/java/forestry/api/climate/IClimateModifier.java new file mode 100644 index 000000000..6118e4f02 --- /dev/null +++ b/src/main/java/forestry/api/climate/IClimateModifier.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.nbt.NBTTagCompound; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +/** + * This modifier is used by {@link IClimateContainer}s. + */ +public interface IClimateModifier { + + /** + * Is called every 20 ticks by the {@link IClimateContainer} to change its climate state. + * + * @param container the climate container + * @param newState the new climate state + * @param oldState the climate static of the previous modification. + * @param data A {@link NBTTagCompound} that can be used to save custom data or to send it to the client to add it to the {@link IClimateData}. + * @return a modify newState or the newState. + */ + IClimateState modifyTarget(IClimateContainer container, IClimateState newState, ImmutableClimateState oldState, NBTTagCompound data); + + @SideOnly(Side.CLIENT) + void addData(IClimateContainer container, IClimateState climateState, NBTTagCompound nbtData, IClimateData data); + + /** + * @return The priority of this modifier. The modifier with the highest priority is called first and the modifier with the lowest at last. + */ + int getPriority(); + +} diff --git a/src/main/java/forestry/api/climate/IClimatePosition.java b/src/main/java/forestry/api/climate/IClimatePosition.java deleted file mode 100644 index 15eeb8e33..000000000 --- a/src/main/java/forestry/api/climate/IClimatePosition.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * 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.INbtReadable; -import forestry.api.core.INbtWritable; -import net.minecraft.util.math.BlockPos; - -/** - * A IClimatePosition contains the climate infos (temperature and humidity) of one position. - */ -public interface IClimatePosition extends INbtReadable, INbtWritable { - - IClimateRegion getClimateRegion(); - - BlockPos getPos(); - - void setTemperature(float temperature); - - void addTemperature(float temperature); - - float getTemperature(); - - void setHumidity(float humidity); - - void addHumidity(float humidity); - - float getHumidity(); - - IClimateInfo getInfo(); - -} diff --git a/src/main/java/forestry/api/climate/IClimateProvider.java b/src/main/java/forestry/api/climate/IClimateProvider.java index 027111f69..266bbe499 100644 --- a/src/main/java/forestry/api/climate/IClimateProvider.java +++ b/src/main/java/forestry/api/climate/IClimateProvider.java @@ -5,9 +5,10 @@ ******************************************************************************/ package forestry.api.climate; +import net.minecraft.world.biome.Biome; + import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import net.minecraft.world.biome.Biome; public interface IClimateProvider { Biome getBiome(); diff --git a/src/main/java/forestry/api/climate/IClimateRegion.java b/src/main/java/forestry/api/climate/IClimateRegion.java deleted file mode 100644 index 762e4a2f3..000000000 --- a/src/main/java/forestry/api/climate/IClimateRegion.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright 2011-2014 SirSengir - * - * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. - ******************************************************************************/ -package forestry.api.climate; - -import java.util.Collection; -import javax.annotation.Nullable; - -import forestry.api.core.INbtReadable; -import forestry.api.core.INbtWritable; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -public interface IClimateRegion extends INbtReadable, INbtWritable { - - World getWorld(); - - int getTicksPerUpdate(); - - void setPosition(BlockPos pos, float temperature, float humidity); - - @Nullable - IClimatePosition getPosition(BlockPos pos); - - Collection getPositions(); - - void addSource(IClimateSource source); - - void removeSource(IClimateSource source); - - Collection getSources(); - - void calculateAverageClimate(); - - float getAverageTemperature(); - - float getAverageHumidity(); - - /** - * Update the climate in a region. - */ - void updateClimate(int ticks); - -} diff --git a/src/main/java/forestry/api/climate/IClimateSource.java b/src/main/java/forestry/api/climate/IClimateSource.java index 99b23026b..dc09d4bb1 100644 --- a/src/main/java/forestry/api/climate/IClimateSource.java +++ b/src/main/java/forestry/api/climate/IClimateSource.java @@ -8,23 +8,49 @@ package forestry.api.climate; import javax.annotation.Nullable; /** - * A climate source is used to change the climate in a region. + * A climate source is stored in a {@link IClimateSourceOwner}. It is used by the {@link IClimateSourceContainer}s to change the climate of a {@link IClimateContainer}. + * One {@link IClimateSource} can only be used by one {@link IClimateSourceContainer} at the same time. + *

+ * In forestry it is used in a part of a {@link IClimateModifier}. */ public interface IClimateSource { - + /** - * @param tickCount The current tick count. - * @param region The climate region, in that the source stands. - * @return Return true if the the climate has changed. + * The owner of this source. */ - boolean changeClimate(int tickCount, IClimateRegion region); - - /** - * @return The ticks that are required for one change. - */ - int getTicksForChange(IClimateRegion region); - @Nullable - IClimateSourceProvider getProvider(); + IClimateSourceOwner getOwner(); + + /** + * The range of this source. + */ + float getBoundaryModifier(ClimateType type, boolean boundaryUp); + + /** + * @return true if this source affects this sourceType of climate. + */ + boolean affectClimateType(ClimateType type); + + /** + * @param state the {@link IClimateState} that the source has to work on. + * @param target the by the {@link IClimateContainer} targeted {@link IClimateState}. + * + */ + ClimateChange work(IClimateState state, ImmutableClimateState target); + + /** + * @return true if source has changed the climate at the last work cicle. + */ + boolean isActive(); + + /** + * Called if the source is added to a {@link IClimateContainer}. + */ + void onAdded(IClimateContainer container); + + /** + * Called if the source is removed form a {@link IClimateContainer}. + */ + void onRemoved(IClimateContainer container); } diff --git a/src/main/java/forestry/api/climate/IClimateControl.java b/src/main/java/forestry/api/climate/IClimateSourceCircuitable.java similarity index 53% rename from src/main/java/forestry/api/climate/IClimateControl.java rename to src/main/java/forestry/api/climate/IClimateSourceCircuitable.java index 612b2ed49..d22039d28 100644 --- a/src/main/java/forestry/api/climate/IClimateControl.java +++ b/src/main/java/forestry/api/climate/IClimateSourceCircuitable.java @@ -5,18 +5,11 @@ ******************************************************************************/ package forestry.api.climate; -public interface IClimateControl { - - IClimateInfo getControlClimate(); - - void setControlClimate(IClimateInfo climateInfo); - - float getControlTemperature(); - - float getControlHumidity(); - - void setControlTemperature(float temperature); - - void setControlHumidity(float humidity); +import forestry.api.circuits.ICircuit; +public interface IClimateSourceCircuitable extends IClimateSource { + /** + * Called by the {@link IClimateSourceOwner} if its {@link ICircuit} changes. + */ + void changeSourceConfig(ClimateType type, float changeChange, float rangeChange); } diff --git a/src/main/java/forestry/api/climate/IClimateSourceContainer.java b/src/main/java/forestry/api/climate/IClimateSourceContainer.java new file mode 100644 index 000000000..afffe8ffa --- /dev/null +++ b/src/main/java/forestry/api/climate/IClimateSourceContainer.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.climate; + +import java.util.Collection; + +/** + * @since 5.3.4 + * + */ +public interface IClimateSourceContainer { + + /** + * Add a climate source to this container. + */ + void addClimateSource(IClimateSource source); + + /** + * Remove a climate source from this container. + */ + void removeClimateSource(IClimateSource source); + + /** + * @return All climate sources of this container. + */ + Collection getClimateSources(); + + /** + * The climate of the {@link IClimateContainer} that results out of the {@link IClimateState} modifications of the {@link IClimateSource}s can not be higher than this bound. + */ + IClimateState getBoundaryUp(); + + /** + * The climate of the {@link IClimateContainer} that results out of the {@link IClimateState} modifications of the {@link IClimateSource}s can not be lower than this bound. + */ + IClimateState getBoundaryDown(); + + /** + * Has to be called if any range of a {@link IClimateSource} changes. It calculates the range of all {@link IClimateSource}s together. + */ + void recalculateBoundaries(double sizeModifier); + +} diff --git a/src/main/java/forestry/api/climate/IClimateSourceOwner.java b/src/main/java/forestry/api/climate/IClimateSourceOwner.java new file mode 100644 index 000000000..b2e87091c --- /dev/null +++ b/src/main/java/forestry/api/climate/IClimateSourceOwner.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.item.ItemStack; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.circuits.ICircuit; +import forestry.api.core.ILocatable; + +public interface IClimateSourceOwner extends ILocatable { + IClimateSource getClimateSource(); + + @SideOnly(Side.CLIENT) + ItemStack getItemStack(); + + boolean isActive(); + + /** + * @return true if this climate source owner can hold a {@link ICircuit} + */ + boolean isCircuitable(); +} diff --git a/src/main/java/forestry/api/climate/IClimateState.java b/src/main/java/forestry/api/climate/IClimateState.java new file mode 100644 index 000000000..c50d12064 --- /dev/null +++ b/src/main/java/forestry/api/climate/IClimateState.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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.world.biome.Biome; + +import forestry.api.core.INbtWritable; + +/** + * A {@link IClimateState} is used to store and handle temperature and humidity. + * + * The range of the value of this two goes from 0.0F to 2.0F. And is oriented on the values of {@link Biome#getTemperature()} and {@link Biome#getRainfall()}. + * + * Default inmplementations are: {@link ImmutableClimateState}, {@link ClimateState} and {@link ClimateChange}. + */ +public interface IClimateState extends INbtWritable { + + float getTemperature(); + + float getHumidity(); + + IClimateState addTemperature(float temperature); + + IClimateState addHumidity(float humidity); + + IClimateState add(IClimateState state); + + IClimateState remove(IClimateState state); + + default float get(ClimateType type){ + return type == ClimateType.HUMIDITY ? getHumidity() : getTemperature(); + } + + ImmutableClimateState toImmutable(); + + ClimateState toMutable(); + +} diff --git a/src/main/java/forestry/api/climate/ImmutableClimateState.java b/src/main/java/forestry/api/climate/ImmutableClimateState.java new file mode 100644 index 000000000..c86e2e5f7 --- /dev/null +++ b/src/main/java/forestry/api/climate/ImmutableClimateState.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.climate; + +import com.google.common.base.Objects; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.MathHelper; + +import forestry.api.core.INbtWritable; + +/** + * A {@link IClimateState} that has a range from 0.0F to 2.0F and can not be changed. + */ +public class ImmutableClimateState implements IClimateState, INbtWritable{ + + // The minimum climate state. + public static final ImmutableClimateState MIN = new ImmutableClimateState(0.0F, 0.0F); + // The climate state of a plain biome. + public static final ImmutableClimateState PLAIN = new ImmutableClimateState(0.8F, 0.4F); + // The maximum climate state. + public static final ImmutableClimateState MAX = new ImmutableClimateState(2.0F, 2.0F); + + private static final String TEMPERATURE_NBT_KEY = "TEMP"; + private static final String HUMIDITY_NBT_KEY = "HUMID"; + + protected final float temperature; + protected final float humidity; + + public ImmutableClimateState(float temperature, float humidity) { + this.temperature = MathHelper.clamp(temperature, 0.0F, 2.0F); + this.humidity = MathHelper.clamp(humidity, 0.0F, 2.0F); + + } + + public ImmutableClimateState(NBTTagCompound compound) { + float temperature = compound.getFloat(TEMPERATURE_NBT_KEY); + float humidity = compound.getFloat(HUMIDITY_NBT_KEY); + this.temperature = MathHelper.clamp(temperature, 0.0F, 2.0F); + this.humidity = MathHelper.clamp(humidity, 0.0F, 2.0F); + + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setFloat(TEMPERATURE_NBT_KEY, temperature); + compound.setFloat(HUMIDITY_NBT_KEY, humidity); + return compound; + } + + @Override + public float getTemperature() { + return temperature; + } + + @Override + public float getHumidity() { + return humidity; + } + + @Override + public ImmutableClimateState addTemperature(float temperature){ + return new ImmutableClimateState(this.temperature + temperature, humidity); + } + + @Override + public ImmutableClimateState addHumidity(float humidity){ + return new ImmutableClimateState(this.temperature, this.humidity + humidity); + } + + @Override + public ImmutableClimateState remove(IClimateState state) { + return new ImmutableClimateState(temperature - state.getTemperature(), humidity - state.getHumidity()); + } + + @Override + public ImmutableClimateState add(IClimateState state) { + return new ImmutableClimateState(temperature + state.getTemperature(), humidity + state.getHumidity()); + } + + @Override + public ImmutableClimateState toImmutable(){ + return this; + } + + @Override + public ClimateState toMutable(){ + return new ClimateState(temperature, humidity); + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof IClimateState)){ + return false; + } + IClimateState otherState = (IClimateState) obj; + return otherState.getTemperature() == temperature && otherState.getHumidity() == humidity; + } + + @Override + public int hashCode() { + return Float.hashCode(temperature) + Float.hashCode(humidity); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("temperature", temperature).add("humidity", humidity).toString(); + } + +} diff --git a/src/main/java/forestry/api/climate/package-info.java b/src/main/java/forestry/api/climate/package-info.java index e627a6ed8..058273a46 100644 --- a/src/main/java/forestry/api/climate/package-info.java +++ b/src/main/java/forestry/api/climate/package-info.java @@ -5,10 +5,11 @@ ******************************************************************************/ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -@API(apiVersion = "2.1.0", owner = "Forestry", provides = "ForestryAPI|climate") +@API(apiVersion = "5.0.0", owner = "Forestry", provides = "ForestryAPI|climate") package forestry.api.climate; import javax.annotation.ParametersAreNonnullByDefault; -import mcp.MethodsReturnNonnullByDefault; import net.minecraftforge.fml.common.API; + +import mcp.MethodsReturnNonnullByDefault; diff --git a/src/main/java/forestry/api/core/BiomeHelper.java b/src/main/java/forestry/api/core/BiomeHelper.java index 8a3002124..0a3b4f26c 100644 --- a/src/main/java/forestry/api/core/BiomeHelper.java +++ b/src/main/java/forestry/api/core/BiomeHelper.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.core; import java.util.HashMap; diff --git a/src/main/java/forestry/api/core/CamouflageManager.java b/src/main/java/forestry/api/core/CamouflageManager.java index 9fd64ac31..472940368 100644 --- a/src/main/java/forestry/api/core/CamouflageManager.java +++ b/src/main/java/forestry/api/core/CamouflageManager.java @@ -9,12 +9,4 @@ public class CamouflageManager { public static ICamouflageAccess camouflageAccess; - public static final String BLOCK = "block"; - - public static final String GLASS = "glass"; - - public static final String DOOR = "door"; - - public static final String NONE = "none"; - } diff --git a/src/main/java/forestry/api/core/EnumHumidity.java b/src/main/java/forestry/api/core/EnumHumidity.java index f546bb59c..0f2302d32 100644 --- a/src/main/java/forestry/api/core/EnumHumidity.java +++ b/src/main/java/forestry/api/core/EnumHumidity.java @@ -20,6 +20,8 @@ public enum EnumHumidity { */ DAMP("Damp"); + public static final EnumHumidity[] VALUES = values(); + public final String name; EnumHumidity(String name) { diff --git a/src/main/java/forestry/api/core/EnumTemperature.java b/src/main/java/forestry/api/core/EnumTemperature.java index 1606368a4..ca220ac38 100644 --- a/src/main/java/forestry/api/core/EnumTemperature.java +++ b/src/main/java/forestry/api/core/EnumTemperature.java @@ -5,6 +5,7 @@ ******************************************************************************/ package forestry.api.core; +import forestry.api.climate.IClimateState; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -73,7 +74,8 @@ public enum EnumTemperature { if (BiomeHelper.isBiomeHellish(biome)) { return HELLISH; } - float temperature = ForestryAPI.climateManager.getInfo(world, pos).getTemperature(); + IClimateState state = ForestryAPI.climateManager.getClimateState(world, pos); + float temperature = state.getTemperature(); return getFromValue(temperature); } } diff --git a/src/main/java/forestry/api/core/ForestryAPI.java b/src/main/java/forestry/api/core/ForestryAPI.java index 7b2e3840e..4f8d4b8d6 100644 --- a/src/main/java/forestry/api/core/ForestryAPI.java +++ b/src/main/java/forestry/api/core/ForestryAPI.java @@ -7,11 +7,13 @@ package forestry.api.core; import java.util.Set; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.IClimateFactory; import forestry.api.climate.IClimateManager; import forestry.api.farming.IFarmRegistry; import forestry.api.farming.ISimpleFarmLogic; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; /** * Forestry's API is divided into several subcategories to make it easier to understand. @@ -48,6 +50,12 @@ public class ForestryAPI { public static IModelManager modelManager; public static IClimateManager climateManager; + + /** + * A factory to create climate related things. + * @since 5.3.4 + */ + public static IClimateFactory climateFactory; /** * A registry for register fertilizers, {@link IFarmabeles}s and {@link ISimpleFarmLogic}s diff --git a/src/main/java/forestry/api/core/ICamouflageAccess.java b/src/main/java/forestry/api/core/ICamouflageAccess.java index d18dc2021..33ec3d062 100644 --- a/src/main/java/forestry/api/core/ICamouflageAccess.java +++ b/src/main/java/forestry/api/core/ICamouflageAccess.java @@ -7,6 +7,8 @@ package forestry.api.core; import java.util.List; +import javax.annotation.Nullable; + import net.minecraft.item.ItemStack; public interface ICamouflageAccess { @@ -16,21 +18,20 @@ public interface ICamouflageAccess { * * @param itemHandler The handler that is to register. */ - void registerCamouflageItemHandler(ICamouflageItemHandler itemHandler); + void registerItemHandler(ICamouflageItemHandler itemHandler); /** * @return A list of all item camouflage handler's that are registered for that camouflage type. */ - List getCamouflageItemHandler(String type); + List getItemHandlers(); - void addItemToBlackList(String type, ItemStack camouflageBlock); + void addItemToBlackList(ItemStack camouflageBlock); - void addModIdToBlackList(String type, String modID); + void addModIdToBlackList(String modID); - boolean isItemBlackListed(String type, ItemStack camouflageBlock); - - ICamouflageItemHandler getNoneItemHandler(); + boolean isItemBlackListed(ItemStack camouflageBlock); - ICamouflageItemHandler getHandlerFromItem(ItemStack stack); + @Nullable + ICamouflageItemHandler getHandler(ItemStack stack); } diff --git a/src/main/java/forestry/api/core/ICamouflageHandler.java b/src/main/java/forestry/api/core/ICamouflageHandler.java index 034c464c1..010c49ed1 100644 --- a/src/main/java/forestry/api/core/ICamouflageHandler.java +++ b/src/main/java/forestry/api/core/ICamouflageHandler.java @@ -12,22 +12,17 @@ public interface ICamouflageHandler extends ILocatable { /** * @return The item of the block that is the camouflage of this handler for the type. */ - ItemStack getCamouflageBlock(String type); + ItemStack getCamouflageBlock(); /** * @return The default camouflage block item for the type. */ - ItemStack getDefaultCamouflageBlock(String type); - - /** - * @return True if the handler can handle this type of camouflage. - */ - boolean canHandleType(String type); + ItemStack getDefaultCamouflageBlock(); /** * Set the camouflage block item for the type. * * @return True if the block has chanced. */ - boolean setCamouflageBlock(String type, ItemStack camouflageBlock, boolean sendClientUpdate); + boolean setCamouflageBlock(ItemStack camouflageBlock, boolean sendClientUpdate); } diff --git a/src/main/java/forestry/api/core/ICamouflageItemHandler.java b/src/main/java/forestry/api/core/ICamouflageItemHandler.java index 23f30eb86..e5d6b7622 100644 --- a/src/main/java/forestry/api/core/ICamouflageItemHandler.java +++ b/src/main/java/forestry/api/core/ICamouflageItemHandler.java @@ -5,21 +5,19 @@ ******************************************************************************/ package forestry.api.core; +import org.apache.commons.lang3.tuple.Pair; + import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.item.ItemStack; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; public interface ICamouflageItemHandler { - + boolean canHandle(ItemStack stack); - String getType(); - - float getLightTransmittance(ItemStack stack, ICamouflageHandler camouflageHandler); - @SideOnly(Side.CLIENT) Pair getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile); diff --git a/src/main/java/forestry/api/core/ICamouflagedTile.java b/src/main/java/forestry/api/core/ICamouflagedTile.java index b7aacfa41..63ea468f4 100644 --- a/src/main/java/forestry/api/core/ICamouflagedTile.java +++ b/src/main/java/forestry/api/core/ICamouflagedTile.java @@ -5,12 +5,6 @@ ******************************************************************************/ package forestry.api.core; -import net.minecraft.util.math.BlockPos; - -public interface ICamouflagedTile { - - String getCamouflageType(); - - BlockPos getCoordinates(); +public interface ICamouflagedTile extends ILocatable { } diff --git a/src/main/java/forestry/api/core/ILocatable.java b/src/main/java/forestry/api/core/ILocatable.java index dae1dfa12..0f1f110f8 100644 --- a/src/main/java/forestry/api/core/ILocatable.java +++ b/src/main/java/forestry/api/core/ILocatable.java @@ -1,23 +1,20 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.core; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +/** + * Interface for things, that have a location. + * Must not be named "getWorld" and "getPos" to avoid + * SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 + */ public interface ILocatable { BlockPos getCoordinates(); - /** - * Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 - */ World getWorldObj(); } diff --git a/src/main/java/forestry/api/core/IModelBaker.java b/src/main/java/forestry/api/core/IModelBaker.java index 3cf19674a..9ff8c5acc 100644 --- a/src/main/java/forestry/api/core/IModelBaker.java +++ b/src/main/java/forestry/api/core/IModelBaker.java @@ -34,6 +34,8 @@ public interface IModelBaker { void addBakedModel(@Nullable IBlockState state, IBakedModel model); + void addBakedModelPost(@Nullable IBlockState state, IBakedModel model); + void addFace(EnumFacing facing, TextureAtlasSprite sprite); void setModelState(@Nullable IModelState modelState); diff --git a/src/main/java/forestry/api/core/INbtReadable.java b/src/main/java/forestry/api/core/INbtReadable.java index af6691caf..0e8007aa8 100644 --- a/src/main/java/forestry/api/core/INbtReadable.java +++ b/src/main/java/forestry/api/core/INbtReadable.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.core; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/main/java/forestry/api/core/IToolPipette.java b/src/main/java/forestry/api/core/IToolPipette.java index 8873fa489..82497aae1 100644 --- a/src/main/java/forestry/api/core/IToolPipette.java +++ b/src/main/java/forestry/api/core/IToolPipette.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.core; diff --git a/src/main/java/forestry/api/farming/IFarmRegistry.java b/src/main/java/forestry/api/farming/IFarmRegistry.java index a3a0b8f0d..b5b3992e6 100644 --- a/src/main/java/forestry/api/farming/IFarmRegistry.java +++ b/src/main/java/forestry/api/farming/IFarmRegistry.java @@ -5,6 +5,7 @@ ******************************************************************************/ package forestry.api.farming; +import javax.annotation.Nullable; import java.util.Collection; import net.minecraft.item.ItemStack; @@ -22,7 +23,10 @@ public interface IFarmRegistry { /** * Can be used to create a simple version of a farm logic, like the vanilla vegetable or wheat farm logic. + * + * @return Null if the farming plugin is not active. */ + @Nullable IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic); /** diff --git a/src/main/java/forestry/api/genetics/AlleleRegisterEvent.java b/src/main/java/forestry/api/genetics/AlleleRegisterEvent.java index 195dd2db8..327c20a36 100644 --- a/src/main/java/forestry/api/genetics/AlleleRegisterEvent.java +++ b/src/main/java/forestry/api/genetics/AlleleRegisterEvent.java @@ -1,6 +1,10 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.genetics; -import forestry.api.arboriculture.IAlleleFruit; import net.minecraftforge.fml.common.eventhandler.Event; /** diff --git a/src/main/java/forestry/api/genetics/AlleleSpeciesRegisterEvent.java b/src/main/java/forestry/api/genetics/AlleleSpeciesRegisterEvent.java index 81e03299f..574cf9d27 100644 --- a/src/main/java/forestry/api/genetics/AlleleSpeciesRegisterEvent.java +++ b/src/main/java/forestry/api/genetics/AlleleSpeciesRegisterEvent.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.genetics; /** diff --git a/src/main/java/forestry/api/genetics/IAlleleFactory.java b/src/main/java/forestry/api/genetics/IAlleleFactory.java index ad23dfeea..9c51480a3 100644 --- a/src/main/java/forestry/api/genetics/IAlleleFactory.java +++ b/src/main/java/forestry/api/genetics/IAlleleFactory.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.genetics; import net.minecraft.util.math.Vec3i; diff --git a/src/main/java/forestry/api/genetics/IAlleleProperty.java b/src/main/java/forestry/api/genetics/IAlleleProperty.java index 9a2fe8f54..ebd1ad4a3 100644 --- a/src/main/java/forestry/api/genetics/IAlleleProperty.java +++ b/src/main/java/forestry/api/genetics/IAlleleProperty.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.genetics; public interface IAlleleProperty> extends IAllele, Comparable { diff --git a/src/main/java/forestry/api/genetics/IAlleleRegistry.java b/src/main/java/forestry/api/genetics/IAlleleRegistry.java index 8a78621a0..b651ad529 100644 --- a/src/main/java/forestry/api/genetics/IAlleleRegistry.java +++ b/src/main/java/forestry/api/genetics/IAlleleRegistry.java @@ -207,7 +207,7 @@ public interface IAlleleRegistry { * @param handler IAlleleHandler to register. */ void registerAlleleHandler(IAlleleHandler handler); - + /* BLACKLIST */ /** diff --git a/src/main/java/forestry/api/genetics/IAlyzerPlugin.java b/src/main/java/forestry/api/genetics/IAlyzerPlugin.java index 923a73df1..8a020b462 100644 --- a/src/main/java/forestry/api/genetics/IAlyzerPlugin.java +++ b/src/main/java/forestry/api/genetics/IAlyzerPlugin.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.genetics; import java.util.List; diff --git a/src/main/java/forestry/api/genetics/ICheckPollinatable.java b/src/main/java/forestry/api/genetics/ICheckPollinatable.java index 3a36f6508..aacbc1c86 100644 --- a/src/main/java/forestry/api/genetics/ICheckPollinatable.java +++ b/src/main/java/forestry/api/genetics/ICheckPollinatable.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.genetics; diff --git a/src/main/java/forestry/api/genetics/IClimateHelper.java b/src/main/java/forestry/api/genetics/IClimateHelper.java index ae56808e8..b88ca690e 100644 --- a/src/main/java/forestry/api/genetics/IClimateHelper.java +++ b/src/main/java/forestry/api/genetics/IClimateHelper.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.genetics; import java.util.Collection; diff --git a/src/main/java/forestry/api/genetics/ISpeciesRootPollinatable.java b/src/main/java/forestry/api/genetics/ISpeciesRootPollinatable.java index e216824e4..0af35beca 100644 --- a/src/main/java/forestry/api/genetics/ISpeciesRootPollinatable.java +++ b/src/main/java/forestry/api/genetics/ISpeciesRootPollinatable.java @@ -1,11 +1,17 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.genetics; import javax.annotation.Nullable; -import com.mojang.authlib.GameProfile; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import com.mojang.authlib.GameProfile; + /** * @author Nedelosk * @since 5.12.16 diff --git a/src/main/java/forestry/api/greenhouse/GreenhouseEvents.java b/src/main/java/forestry/api/greenhouse/GreenhouseEvents.java deleted file mode 100644 index c560ab91d..000000000 --- a/src/main/java/forestry/api/greenhouse/GreenhouseEvents.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright 2011-2014 SirSengir - * - * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. - ******************************************************************************/ -package forestry.api.greenhouse; - -import forestry.api.multiblock.IGreenhouseController; -import net.minecraftforge.fml.common.eventhandler.Event; - -public class GreenhouseEvents extends Event { - - public final IGreenhouseController controller; - - public GreenhouseEvents(IGreenhouseController state) { - this.controller = state; - } - - public static class InternalBlockEvent extends GreenhouseEvents { - public final IInternalBlock internalBlock; - - public InternalBlockEvent(IGreenhouseController controller, IInternalBlock internalBlock) { - super(controller); - - this.internalBlock = internalBlock; - } - } - - public static class CreateInternalBlockEvent extends InternalBlockEvent { - public CreateInternalBlockEvent(IGreenhouseController controller, IInternalBlock internalBlock) { - super(controller, internalBlock); - } - } - - public static class CheckInternalBlockFaceEvent extends InternalBlockEvent { - public final IInternalBlockFace face; - - public CheckInternalBlockFaceEvent(IGreenhouseController controller, IInternalBlock internalBlock, IInternalBlockFace face) { - super(controller, internalBlock); - - this.face = face; - } - } - -} diff --git a/src/main/java/forestry/api/greenhouse/GreenhouseManager.java b/src/main/java/forestry/api/greenhouse/GreenhouseManager.java index fc1142af5..1a00d99e3 100644 --- a/src/main/java/forestry/api/greenhouse/GreenhouseManager.java +++ b/src/main/java/forestry/api/greenhouse/GreenhouseManager.java @@ -8,5 +8,7 @@ package forestry.api.greenhouse; public class GreenhouseManager { public static IGreenhouseHelper greenhouseHelper; + + public static IGreenhouseBlockManager greenhouseBlockManager; } diff --git a/src/main/java/forestry/api/greenhouse/IBlankBlock.java b/src/main/java/forestry/api/greenhouse/IBlankBlock.java new file mode 100644 index 000000000..ec5d7da32 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IBlankBlock.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import javax.annotation.Nullable; + +import net.minecraft.util.EnumFacing; + +public interface IBlankBlock extends IGreenhouseBlock { + + @Override + @Nullable + IBlankBlock getRoot(); + + /** + * @return test if a face was already tested, false if not. + */ + boolean isFaceTested(EnumFacing facing); + + void setFaceTested(EnumFacing facing, boolean isTested); + + /** + * @return if this block has a {@link IWallBlock} next to him. + */ + boolean isNearWall(); + + void setNearWall(boolean nearWall); + + /** + * Called after the block is created. + */ + void validate(); + + /** + * Called before the block will be removed. + */ + void invalidate(boolean chunkUnloading); + + boolean isValid(); + +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseBlock.java b/src/main/java/forestry/api/greenhouse/IGreenhouseBlock.java new file mode 100644 index 000000000..fb04a2e35 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseBlock.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import javax.annotation.Nullable; +import java.util.Set; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +public interface IGreenhouseBlock { + + /** + * @return the position of this block. + */ + BlockPos getPos(); + + /** + * @return the root block of this block. + */ + @Nullable + IGreenhouseBlock getRoot(); + + /** + * @return the side of this block that shows to the root block. + */ + @Nullable + EnumFacing getRootFace(); + + /** + * @return the manager of this block. + */ + IGreenhouseProvider getProvider(); + + /** + * Called if a neighbor block of this block is removed. + */ + void onNeighborRemoved(IBlankBlock changedBlock, EnumFacing facing, boolean forcedRemove, Set blocksToCheck); + + IGreenhouseBlockHandler getHandler(); + +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseBlockHandler.java b/src/main/java/forestry/api/greenhouse/IGreenhouseBlockHandler.java new file mode 100644 index 000000000..e55e50f7c --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseBlockHandler.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import javax.annotation.Nullable; +import java.util.List; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +import forestry.greenhouse.multiblock.blocks.GreenhouseException; + +public interface IGreenhouseBlockHandler { + + void onRemoveBlock(IGreenhouseBlockStorage storage, B blockToRemove); + + B createBlock(IGreenhouseBlockStorage storage, @Nullable R root, @Nullable EnumFacing rootFacing, @Nullable BlockPos position); + + B getBlock(IGreenhouseBlockStorage storage, BlockPos position); + + List checkNeighborBlocks(IGreenhouseBlockStorage storage, B blockToCheck) throws GreenhouseException; + + boolean onCheckPosition(IGreenhouseBlockStorage storage, R rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck) throws GreenhouseException; + + Class getBlockClass(); +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseBlockManager.java b/src/main/java/forestry/api/greenhouse/IGreenhouseBlockManager.java new file mode 100644 index 000000000..8920a9a03 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseBlockManager.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import javax.annotation.Nullable; +import java.util.List; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; + +public interface IGreenhouseBlockManager { + + /** + * @return the {@link IGreenhouseBlockHandler} that is used to handle blank blocks in the {@link IGreenhouseProvider} + */ + IGreenhouseBlockHandler getBlankBlockHandler(); + + /** + * @return the {@link IGreenhouseBlockHandler} that is used to handle wall blocks in the {@link IGreenhouseProvider} + */ + IGreenhouseBlockHandler getWallBlockHandler(); + + /** + * Tries to get a {@link IGreenhouseBlock} from all managers that are located at the chunk of the pos. + * + * @return a {@link IGreenhouseBlock} if any manager of the chunk at this position has one block at this position, otherwise null. + */ + @Nullable + IGreenhouseBlock getBlock(World world, BlockPos pos); + + /** + * + * @return the chunk that is at this position. + */ + @Nullable + IGreenhouseChunk getChunk(World world, long chunkPos); + + /** + * @return the chunk that is at this position or if there is no it creates one. + */ + IGreenhouseChunk getOrCreateChunk(World world, long chunkPos); + + /** + * @return creates a chunk and add it at this position + */ + IGreenhouseChunk createChunk(World world, long chunkPos); + + default IGreenhouseChunk getChunk(World world, int xPos, int yPos){ + return getChunk(world, ChunkPos.asLong(xPos, yPos)); + } + + default IGreenhouseChunk getOrCreateChunk(World world, int xPos, int yPos){ + return getOrCreateChunk(world, ChunkPos.asLong(xPos, yPos)); + } + + default IGreenhouseChunk createChunk(World world, int xPos, int yPos){ + return createChunk(world, ChunkPos.asLong(xPos, yPos)); + } + + @Nullable + void markChunkDirty(World world, long pos); + + @Nullable + List getDirtyChunks(World world); + + @Nullable + void markBlockDirty(World world, BlockPos pos); + + void markProviderDirty(World world, BlockPos pos, IGreenhouseProvider provider); +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseBlockStorage.java b/src/main/java/forestry/api/greenhouse/IGreenhouseBlockStorage.java new file mode 100644 index 000000000..1d73adaa4 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseBlockStorage.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import javax.annotation.Nullable; + +import net.minecraft.util.math.BlockPos; + +public interface IGreenhouseBlockStorage { + /** + * @return a {@link IGreenhouseBlock} if there is one on this position. + */ + @Nullable + IGreenhouseBlock getBlock(BlockPos pos); + + /** + * Sets a {@link IGreenhouseBlock} to a position in the world. + */ + boolean setBlock(BlockPos pos, @Nullable IGreenhouseBlock block); + + /** + * @return The number of {@link IBlankBlock}s that this provider contains. + */ + int getBlockCount(); + + /** + * Removes a {@link IGreenhouseBlock} from this provider and add its neighbor blocks to the set. + */ + void removeBlock(IGreenhouseBlock block); + + IGreenhouseProvider getProvider(); +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseChunk.java b/src/main/java/forestry/api/greenhouse/IGreenhouseChunk.java new file mode 100644 index 000000000..57f286210 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseChunk.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import javax.annotation.Nullable; +import java.util.Collection; + +import net.minecraft.util.math.BlockPos; + +/** + * A greenhouse chunk is used to save the greenhouse managers from the greenhouses that are located in the world chunk on this chunk position. + */ +public interface IGreenhouseChunk { + /** + * @return a {@link Collection} with all greenhouse managers of the greenhouses that are located in the world chunk on this chunk position. + */ + Collection getProviders(); + + /** + * Marks the manager, that has a {@link IGreenhouseBlock} on this position, as dirty. + */ + void markProviderDirty(BlockPos pos); + + /** + * @return A {@link java.util.Collection} with all managers that were modified in the last tick. + */ + Collection getDirtyProviders(); + + /** + * Tries to get a {@link IGreenhouseBlock} from all managers that are located in this chunk. + * + * @return A {@link IGreenhouseBlock} if any manager has one block at this position, otherwise null. + */ + @Nullable + IGreenhouseBlock get(BlockPos pos); + + /** + * Adds a manager to this chunk. + */ + void add(IGreenhouseProvider manager); + + /** + * Removed a manager from this chunk. + */ + void remove(IGreenhouseProvider manager); +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java b/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java index a36a4a4e4..e22868ce4 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java @@ -5,17 +5,29 @@ ******************************************************************************/ package forestry.api.greenhouse; -import javax.annotation.Nullable; +import java.util.Collection; + +import net.minecraft.item.ItemStack; + +import forestry.api.climate.IClimateModifier; import forestry.api.multiblock.IGreenhouseController; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; public interface IGreenhouseHelper { - - /** - * @return A {@link IGreenhouseController} of a greenhouse, when the pos is a greenhouse - */ - @Nullable - IGreenhouseController getGreenhouseController(World world, BlockPos pos); + + void registerWindowGlass(String name, ItemStack item, String texture); + + ItemStack getGlassItem(String name); + + String getGlassTexture(String name); + + Collection getWindowGlasses(); + + void registerLogic(IGreenhouseLogicFactory logicFactory); + + Collection createLogics(IGreenhouseController controller); + + void registerModifier(IClimateModifier modifier); + + Collection getModifiers(); } diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java index cc301461e..9c64b2cb4 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java @@ -5,26 +5,43 @@ ******************************************************************************/ package forestry.api.greenhouse; +import javax.annotation.Nullable; + +import forestry.api.climate.IClimateHousing; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.IErrorLogicSource; -import net.minecraft.world.World; - -public interface IGreenhouseHousing extends IErrorLogicSource { - - EnumTemperature getTemperature(); - - EnumHumidity getHumidity(); - - float getExactTemperature(); - - float getExactHumidity(); +public interface IGreenhouseHousing extends IErrorLogicSource, IClimateHousing{ + /** - * Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 - * - * @return The world in that the housing is. + * @return The current tempreture as an enum. */ - World getWorldObj(); - + EnumTemperature getTemperature(); + + /** + * @return The current humidity as an enum. + */ + EnumHumidity getHumidity(); + + /** + * @return The current tempreture as an float. Range: 0.0F ~ 2.0F + */ + float getExactTemperature(); + + /** + * @return The current humidity as an float. Range: 0.0F ~ 2.0F + */ + float getExactHumidity(); + + /** + * @return the manager of this housing. + */ + IGreenhouseProvider getProvider(); + + /** + * @return the maximal and minimal settings of this housing. + */ + @Nullable + IGreenhouseLimits getLimits(); } diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseLimits.java b/src/main/java/forestry/api/greenhouse/IGreenhouseLimits.java new file mode 100644 index 000000000..d5f5c67e3 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseLimits.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +/** + * The limits that a greenhouse has. Used in the {@link IGreenhouseProvider} to test if the greenhouse is tested. + * At the test the provider stops if the currently tested position is out of this limits and marks the greenhouse as open. + */ +public interface IGreenhouseLimits { + + /** + * @return The maximum bounding-box coordinate. + */ + Position2D getMaximumCoordinates(); + + /** + * @return The minimum bounding-box coordinate. + */ + Position2D getMinimumCoordinates(); + + /** + * @return the maximal height of the manager on the y axis. + */ + int getHeight(); + + /** + * @return the maximal depth of the manager on the y axis. + */ + int getDepth(); +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseLogic.java b/src/main/java/forestry/api/greenhouse/IGreenhouseLogic.java new file mode 100644 index 000000000..d8d2d0699 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseLogic.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; + +public interface IGreenhouseLogic extends INbtReadable, INbtWritable{ + + void work(int ticks); + + String getUID(); + +} diff --git a/src/main/java/forestry/api/greenhouse/IInternalBlock.java b/src/main/java/forestry/api/greenhouse/IGreenhouseLogicFactory.java similarity index 57% rename from src/main/java/forestry/api/greenhouse/IInternalBlock.java rename to src/main/java/forestry/api/greenhouse/IGreenhouseLogicFactory.java index abe7be4a0..e9c4ee5b1 100644 --- a/src/main/java/forestry/api/greenhouse/IInternalBlock.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseLogicFactory.java @@ -5,18 +5,10 @@ ******************************************************************************/ package forestry.api.greenhouse; -import javax.annotation.Nullable; -import java.util.Collection; +import forestry.api.multiblock.IGreenhouseController; -import net.minecraft.util.math.BlockPos; - -public interface IInternalBlock { - - BlockPos getPos(); - - @Nullable - IInternalBlock getRoot(); - - Collection getFaces(); +public interface IGreenhouseLogicFactory { + IGreenhouseLogic createLogic(IGreenhouseController controller); + } diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseProvider.java b/src/main/java/forestry/api/greenhouse/IGreenhouseProvider.java new file mode 100644 index 000000000..1a09900af --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseProvider.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import javax.annotation.Nullable; +import java.util.Collection; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.climate.GreenhouseState; +import forestry.api.climate.IClimateContainer; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; + +/** + * Can be used to test if a space is closed. Is used by the greenhouse. + * + */ +public interface IGreenhouseProvider { + + /** + * @return the climate container of this provider. + */ + @Nullable + IClimateContainer getClimateContainer(); + + /** + * Adds a listener to this provider. + */ + void addListener(IGreenhouseProviderListener listener); + + /** + * @return All listeners that this provider has. + */ + Collection getListeners(); + + /** + * @param centerPos The position at that the provider starts to test. + */ + void init(BlockPos centerPos, IGreenhouseLimits limits); + + /** + * Invalidate and delete all {@link IGreenhouseBlock}s of this provider. + */ + void clear(boolean chunkUnloading); + + /** + * @return The last error that has coded that the provider is not closed. + */ + String getLastNotClosedError(); + + /** + * Called from the thread if a {@link IGreenhouseBlock} was modified by the player. + */ + void recreate(); + + void onUnloadChunk(long chunkPos); + + void onLoadChunk(long chunkPos); + + /** + * @return True if the provider waits for a chunk to be loaded, before he can test if it is closed. + */ + boolean hasUnloadedChunks(); + + /** + * @return The position from that the provider tests if it is closed. + */ + BlockPos getCenterPos(); + + /** + * @return The limits that a greenhouse has. Used to test if the greenhouse is tested. + * At the test the provider stops if the currently tested position is out of this limits and marks the greenhouse as open. + */ + IGreenhouseLimits getLimits(); + + /** + * Null if the provider is not created. + */ + @Nullable + IGreenhouseLimits getUsedLimits(); + + GreenhouseState getState(); + + World getWorld(); + + /** + * @return true if the space is closed. + */ + boolean isClosed(); + + /** + * Test if the provider is closed. + */ + void checkPosition(BlockPos position) throws GreenhouseException; + + int getSize(); + + /** + * @return All {@link IGreenhouseBlockHandler}s that this provider uses. + */ + Collection getHandlers(); + + IGreenhouseBlockStorage getStorage(); + + void onBlockChange(); + + void scheduledUpdate(); +} diff --git a/src/main/java/forestry/api/greenhouse/IInternalBlockFace.java b/src/main/java/forestry/api/greenhouse/IGreenhouseProviderListener.java similarity index 67% rename from src/main/java/forestry/api/greenhouse/IInternalBlockFace.java rename to src/main/java/forestry/api/greenhouse/IGreenhouseProviderListener.java index a189ec066..452dfeb9d 100644 --- a/src/main/java/forestry/api/greenhouse/IInternalBlockFace.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseProviderListener.java @@ -5,17 +5,10 @@ ******************************************************************************/ package forestry.api.greenhouse; -import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -public interface IInternalBlockFace { - - boolean isTested(); - - void setTested(boolean tested); - - EnumFacing getFace(); - - BlockPos getPos(); - +public interface IGreenhouseProviderListener { + + void onCheckPosition(BlockPos pos); + } diff --git a/src/main/java/forestry/api/greenhouse/IWallBlock.java b/src/main/java/forestry/api/greenhouse/IWallBlock.java new file mode 100644 index 000000000..fbf1b6289 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IWallBlock.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import net.minecraft.util.EnumFacing; + +import forestry.api.climate.IClimateSource; + +public interface IWallBlock extends IGreenhouseBlock { + + void setRoot(IBlankBlock parent); + + void setRootFace(EnumFacing facing); + + void onCreate(); + + void onRemove(); + + void add(IClimateSource source); + +} diff --git a/src/main/java/forestry/api/greenhouse/Position2D.java b/src/main/java/forestry/api/greenhouse/Position2D.java new file mode 100644 index 000000000..95dbcfc16 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/Position2D.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import com.google.common.base.Objects; + +import javax.annotation.concurrent.Immutable; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3i; + +import forestry.api.core.INbtWritable; + +@Immutable +public class Position2D implements Comparable, INbtWritable { + public static final Position2D NULL_POSITION = new Position2D(0, 0); + /** X coordinate */ + private final int x; + /** Z coordinate */ + private final int z; + + public Position2D(Vec3i pos) { + this(pos.getX(), pos.getZ()); + } + + public Position2D(Position2D pos) { + this(pos.getX(), pos.getZ()); + } + + public Position2D(int xIn, int zIn) { + this.x = xIn; + this.z = zIn; + } + + public Position2D(NBTTagCompound nbtTagCompound) { + this.x = nbtTagCompound.getInteger("xPosition"); + this.z = nbtTagCompound.getInteger("zPosition"); + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (o instanceof Vec3i) { + Vec3i position = (Vec3i) o; + return this.getX() == position.getX() && this.getZ() == position.getZ(); + } else if (!(o instanceof Position2D)) { + return false; + } else { + Position2D position = (Position2D) o; + return this.getX() == position.getX() && this.getZ() == position.getZ(); + } + } + + public Position2D clamp(Position2D min, Position2D max) { + int x = MathHelper.clamp(this.x, min.getX(), max.getX()); + int z = MathHelper.clamp(this.z, min.getZ(), max.getZ()); + return new Position2D(x, z); + } + + public Position2D add(int x, int z) { + return x == 0 && z == 0 ? this : new Position2D(this.getX() + x, this.getZ() + z); + } + + public int hashCode() { + return (this.getZ() + this.getX() * 31); + } + + public int compareTo(Position2D o) { + return this.getZ() == o.getZ() ? this.getX() - o.getX() : this.getZ() - o.getZ(); + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + nbt.setInteger("xPosition", x); + nbt.setInteger("zPosition", z); + return nbt; + } + + /** + * Gets the X coordinate. + */ + public int getX() { + return this.x; + } + + /** + * Gets the Z coordinate. + */ + public int getZ() { + return this.z; + } + + public double getDistance(int xIn, int zIn) { + double d0 = (double) (this.getX() - xIn); + double d2 = (double) (this.getZ() - zIn); + return Math.sqrt(d0 * d0 + d2 * d2); + } + + public double distanceSq(double toX, double toZ) { + double d0 = (double) this.getX() - toX; + double d2 = (double) this.getZ() - toZ; + return d0 * d0 + d2 * d2; + } + + public double distanceSqToCenter(double xIn, double zIn) { + double d0 = (double) this.getX() + 0.5D - xIn; + double d2 = (double) this.getZ() + 0.5D - zIn; + return d0 * d0 + d2 * d2; + } + + public double distanceSq(Position2D to) { + return this.distanceSq((double) to.getX(), (double) to.getZ()); + } + + public String toString() { + return Objects.toStringHelper(this).add("x", this.getX()).add("z", this.getZ()).toString(); + } +} \ No newline at end of file diff --git a/src/main/java/forestry/api/greenhouse/package-info.java b/src/main/java/forestry/api/greenhouse/package-info.java index 277b4b76c..f3fdc39ff 100644 --- a/src/main/java/forestry/api/greenhouse/package-info.java +++ b/src/main/java/forestry/api/greenhouse/package-info.java @@ -10,5 +10,6 @@ package forestry.api.greenhouse; import javax.annotation.ParametersAreNonnullByDefault; -import mcp.MethodsReturnNonnullByDefault; import net.minecraftforge.fml.common.API; + +import mcp.MethodsReturnNonnullByDefault; diff --git a/src/main/java/forestry/api/lepidopterology/ButterflyManager.java b/src/main/java/forestry/api/lepidopterology/ButterflyManager.java index 8425797aa..d0b589be6 100644 --- a/src/main/java/forestry/api/lepidopterology/ButterflyManager.java +++ b/src/main/java/forestry/api/lepidopterology/ButterflyManager.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.lepidopterology; diff --git a/src/main/java/forestry/api/lepidopterology/IAlleleButterflyCocoon.java b/src/main/java/forestry/api/lepidopterology/IAlleleButterflyCocoon.java index e5699996a..8a9ca90c3 100644 --- a/src/main/java/forestry/api/lepidopterology/IAlleleButterflyCocoon.java +++ b/src/main/java/forestry/api/lepidopterology/IAlleleButterflyCocoon.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.lepidopterology; diff --git a/src/main/java/forestry/api/lepidopterology/IAlleleButterflySpeciesBuilder.java b/src/main/java/forestry/api/lepidopterology/IAlleleButterflySpeciesBuilder.java index 7a06074f1..4e8f01ec3 100644 --- a/src/main/java/forestry/api/lepidopterology/IAlleleButterflySpeciesBuilder.java +++ b/src/main/java/forestry/api/lepidopterology/IAlleleButterflySpeciesBuilder.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.lepidopterology; diff --git a/src/main/java/forestry/api/lepidopterology/IButterflyCocoon.java b/src/main/java/forestry/api/lepidopterology/IButterflyCocoon.java index 4d2613781..7e3e65bd4 100644 --- a/src/main/java/forestry/api/lepidopterology/IButterflyCocoon.java +++ b/src/main/java/forestry/api/lepidopterology/IButterflyCocoon.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.lepidopterology; diff --git a/src/main/java/forestry/api/lepidopterology/IButterflyFactory.java b/src/main/java/forestry/api/lepidopterology/IButterflyFactory.java index f3ddc15ba..31e913f23 100644 --- a/src/main/java/forestry/api/lepidopterology/IButterflyFactory.java +++ b/src/main/java/forestry/api/lepidopterology/IButterflyFactory.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.lepidopterology; diff --git a/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java b/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java index 84456a2f2..392443363 100644 --- a/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java +++ b/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java @@ -5,14 +5,7 @@ ******************************************************************************/ package forestry.api.multiblock; -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 forestry.api.lepidopterology.IButterflyNursery; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; public interface IGreenhouseComponent extends IMultiblockComponent { @Override @@ -21,22 +14,7 @@ public interface IGreenhouseComponent exte interface Listener extends IGreenhouseComponent { IGreenhouseListener getGreenhouseListener(); } - - interface ClimateControl extends IGreenhouseComponent, IClimateControlProvider { - - } - - interface Door extends IGreenhouseComponent { - } - - interface Climatiser extends IGreenhouseComponent, IClimateSourceProvider { - IClimatiserDefinition getDefinition(); - } - - interface Nursery extends IGreenhouseComponent, IButterflyNursery { - void addCocoonLoot(IButterflyCocoon cocoon, NonNullList loot); - } - + interface Active extends IGreenhouseComponent { void updateServer(int tickCount); diff --git a/src/main/java/forestry/api/multiblock/IGreenhouseController.java b/src/main/java/forestry/api/multiblock/IGreenhouseController.java index b942aef6b..fde2e4e6e 100644 --- a/src/main/java/forestry/api/multiblock/IGreenhouseController.java +++ b/src/main/java/forestry/api/multiblock/IGreenhouseController.java @@ -5,35 +5,19 @@ ******************************************************************************/ package forestry.api.multiblock; -import java.util.Set; +import net.minecraft.util.math.BlockPos; -import forestry.api.climate.IClimateControlProvider; -import forestry.api.climate.IClimateRegion; import forestry.api.core.ICamouflageHandler; import forestry.api.greenhouse.IGreenhouseHousing; -import forestry.api.greenhouse.IInternalBlock; -import forestry.api.lepidopterology.IButterfly; -import forestry.api.lepidopterology.IButterflyCocoon; -public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlProvider { +public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler { /** - * @return All internal blocks of the greenhouse. + * + * @return the position of the block at the top of the greenhouse structure that shows the state of the greenhouse. */ - Set getInternalBlocks(); + BlockPos getCenterCoordinates(); - /** - * spawns a butterfly in a greenhouse - * @return true if it has spawned it, and false if it has not - */ - boolean spawnButterfly(IGreenhouseComponent.Nursery nursery); + void setCenterCoordinates(BlockPos coordinates); - /** - * @deprecated use {@link #spawnButterfly(IButterflyCocoon)} - */ - @Deprecated - boolean spawnButterfly(IButterfly butterfly); - - IClimateRegion getRegion(); - } diff --git a/src/main/java/forestry/api/recipes/IFabricatorSmeltingManager.java b/src/main/java/forestry/api/recipes/IFabricatorSmeltingManager.java index 000569eb4..d935992fe 100644 --- a/src/main/java/forestry/api/recipes/IFabricatorSmeltingManager.java +++ b/src/main/java/forestry/api/recipes/IFabricatorSmeltingManager.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.recipes; diff --git a/src/main/java/forestry/api/recipes/IFabricatorSmeltingRecipe.java b/src/main/java/forestry/api/recipes/IFabricatorSmeltingRecipe.java index 5ccd79b68..6ef226009 100644 --- a/src/main/java/forestry/api/recipes/IFabricatorSmeltingRecipe.java +++ b/src/main/java/forestry/api/recipes/IFabricatorSmeltingRecipe.java @@ -1,12 +1,7 @@ /******************************************************************************* - * 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 + * Copyright 2011-2014 SirSengir * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ package forestry.api.recipes; diff --git a/src/main/java/forestry/api/recipes/IFermenterManager.java b/src/main/java/forestry/api/recipes/IFermenterManager.java index 3ffd8eec8..4c5ae4d5b 100644 --- a/src/main/java/forestry/api/recipes/IFermenterManager.java +++ b/src/main/java/forestry/api/recipes/IFermenterManager.java @@ -49,4 +49,33 @@ public interface IFermenterManager extends ICraftingProvider { * @throws NullPointerException if resource, output or liquid is null */ void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output); + + /** + * Add a recipe to the fermenter + * + * @param resource String representing the resource as a {@link net.minecraftforge.oredict.OreDictionary} name. + * @param fermentationValue Value of the given resource, i.e. how much needs + * to be fermented for the output to be deposited into the product tank. + * @param modifier Modifies the amount of liquid output per work cycle. + * (water = 1.0f, honey = 1.5f) + * @param output LiquidStack representing output liquid. Amount is + * determined by fermentationValue*modifier. + * @param liquid LiquidStack representing resource liquid and amount. + * @throws NullPointerException if resource, output or liquid is null + */ + void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid); + + /** + * Add a recipe to the fermenter. Defaults to water as input liquid. + * + * @param resource String representing the resource as a {@link net.minecraftforge.oredict.OreDictionary} name. + * @param modifier Modifies the amount of liquid output per work cycle. + * (water = 1.0f, honey = 1.5f) + * @param fermentationValue Value of the given resource, i.e. how much needs + * to be fermented for the output to be deposited into the product tank. + * @param output LiquidStack representing output liquid. Amount is + * determined by fermentationValue*modifier. + * @throws NullPointerException if resource, output or liquid is null + */ + void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output); } diff --git a/src/main/java/forestry/api/recipes/IFermenterRecipe.java b/src/main/java/forestry/api/recipes/IFermenterRecipe.java index fc5c49df3..46baeded5 100644 --- a/src/main/java/forestry/api/recipes/IFermenterRecipe.java +++ b/src/main/java/forestry/api/recipes/IFermenterRecipe.java @@ -5,16 +5,26 @@ ******************************************************************************/ package forestry.api.recipes; +import javax.annotation.Nullable; + import net.minecraft.item.ItemStack; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; -public interface IFermenterRecipe extends IForestryRecipe { +public interface IFermenterRecipe extends IForestryRecipe, Comparable { + /** * @return ItemStack representing the input resource. */ ItemStack getResource(); + /** + * @return String representing the input resource as a {@link net.minecraftforge.oredict.OreDictionary} name. + */ + @Nullable + String getResourceOreName(); + /** * @return FluidStack representing the input fluid resource. */ diff --git a/src/main/java/forestry/api/storage/IBackpackFilterConfigurable.java b/src/main/java/forestry/api/storage/IBackpackFilterConfigurable.java index fc78e720c..4dc24712e 100644 --- a/src/main/java/forestry/api/storage/IBackpackFilterConfigurable.java +++ b/src/main/java/forestry/api/storage/IBackpackFilterConfigurable.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ package forestry.api.storage; import java.util.function.Predicate; diff --git a/src/main/java/forestry/apiculture/blocks/BlockAlveary.java b/src/main/java/forestry/apiculture/blocks/BlockAlveary.java index 9305072d5..22f253f83 100755 --- a/src/main/java/forestry/apiculture/blocks/BlockAlveary.java +++ b/src/main/java/forestry/apiculture/blocks/BlockAlveary.java @@ -22,9 +22,11 @@ import net.minecraft.block.SoundType; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -38,6 +40,13 @@ import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraft.block.SoundType; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.IBlockState; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IStringSerializable; +import net.minecraft.world.World; + import forestry.api.core.IModelManager; import forestry.api.core.IStateMapperRegister; import forestry.api.core.Tabs; @@ -56,6 +65,7 @@ import forestry.core.blocks.BlockStructure; import forestry.core.tiles.IActivatable; import forestry.core.tiles.TileUtil; import forestry.core.utils.BlockUtil; +import forestry.core.utils.ItemTooltipUtil; import forestry.core.utils.NetworkUtil; import forestry.core.utils.Translator; @@ -263,6 +273,10 @@ public abstract class BlockAlveary extends BlockStructure implements IStateMappe @SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack stack, @Nullable World world, List tooltip, ITooltipFlag advanced) { - tooltip.add(Translator.translateToLocal("tile.for.alveary.tooltip")); + if(GuiScreen.isShiftKeyDown()){ + tooltip.add(Translator.translateToLocal("tile.for.alveary.tooltip")); + }else{ + ItemTooltipUtil.addShiftInformation(stack, world, tooltip, advanced.isAdvanced()); + } } } diff --git a/src/main/java/forestry/apiculture/genetics/BeeDefinition.java b/src/main/java/forestry/apiculture/genetics/BeeDefinition.java index c55f55e0d..a8febe271 100644 --- a/src/main/java/forestry/apiculture/genetics/BeeDefinition.java +++ b/src/main/java/forestry/apiculture/genetics/BeeDefinition.java @@ -16,6 +16,14 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.Locale; +import org.apache.commons.lang3.text.WordUtils; + +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.common.MinecraftForge; + import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.EnumBeeType; @@ -36,11 +44,6 @@ import forestry.core.PluginCore; import forestry.core.config.Constants; import forestry.core.genetics.alleles.AlleleHelper; import forestry.core.genetics.alleles.EnumAllele; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.BiomeDictionary; -import net.minecraftforge.common.MinecraftForge; -import org.apache.commons.lang3.text.WordUtils; public enum BeeDefinition implements IBeeDefinition { /* HONEY BRANCH */ diff --git a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java index b73d492e5..188983836 100644 --- a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java +++ b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java @@ -21,11 +21,9 @@ import forestry.api.apiculture.IBeeListener; import forestry.api.apiculture.IBeeModifier; import forestry.api.apiculture.IBeekeepingLogic; import forestry.api.climate.IClimateControlled; -import forestry.api.climate.IClimatePosition; import forestry.api.core.BiomeHelper; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.api.core.ForestryAPI; import forestry.api.multiblock.IAlvearyComponent; import forestry.api.multiblock.IMultiblockComponent; import forestry.apiculture.AlvearyBeeModifier; @@ -429,10 +427,6 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple data.writeVarInt(beekeepingLogic.getBeeProgressPercent()); data.writeVarInt(Math.round(tempChange * 100)); data.writeVarInt(Math.round(humidChange * 100)); - IClimatePosition position = ForestryAPI.climateManager.getPosition(world, getReferenceCoord()); - if (position != null) { - ClimateUtil.writePositionData(position, data); - } } @Override @@ -440,9 +434,5 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple breedingProgressPercent = data.readVarInt(); tempChange = data.readVarInt() / 100.0F; humidChange = data.readVarInt() / 100.0F; - IClimatePosition position = ForestryAPI.climateManager.getPosition(world, getReferenceCoord()); - if (position != null) { - ClimateUtil.readPositionData(position, data); - } } } diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java index 9fc458ff3..c2d0fd41e 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyHygroregulator.java @@ -12,6 +12,22 @@ package forestry.apiculture.multiblock; import javax.annotation.Nullable; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; + +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.api.climate.IClimateControlled; import forestry.api.multiblock.IAlvearyComponent; import forestry.apiculture.blocks.BlockAlvearyType; @@ -24,20 +40,8 @@ import forestry.core.fluids.FluidHelper; import forestry.core.fluids.Fluids; import forestry.core.fluids.TankManager; import forestry.core.inventory.IInventoryAdapter; +import forestry.core.recipes.HygroregulatorRecipe; import forestry.core.tiles.ILiquidTankTile; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; public class TileAlvearyHygroregulator extends TileAlveary implements IInventory, ILiquidTankTile, IAlvearyComponent.Climatiser { private final HygroregulatorRecipe[] recipes; @@ -186,18 +190,4 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory public Container getContainer(EntityPlayer player, int data) { return new ContainerAlvearyHygroregulator(player.inventory, this); } - - private static class HygroregulatorRecipe { - public final FluidStack liquid; - public final int transferTime; - public final float humidChange; - public final float tempChange; - - public HygroregulatorRecipe(FluidStack liquid, int transferTime, float humidChange, float tempChange) { - this.liquid = liquid; - this.transferTime = transferTime; - this.humidChange = humidChange; - this.tempChange = tempChange; - } - } } diff --git a/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java b/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java index cea74cdd7..164736f7c 100644 --- a/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java +++ b/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java @@ -16,10 +16,8 @@ import com.mojang.authlib.GameProfile; import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeekeepingLogic; -import forestry.api.climate.IClimatePosition; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.api.core.ForestryAPI; import forestry.apiculture.gui.IGuiBeeHousingDelegate; import forestry.core.network.IStreamableGui; import forestry.core.network.PacketBufferForestry; @@ -162,19 +160,11 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing @Override public void writeGuiData(PacketBufferForestry data) { data.writeVarInt(beeLogic.getBeeProgressPercent()); - IClimatePosition position = ForestryAPI.climateManager.getPosition(world, getPos()); - if (position != null) { - ClimateUtil.writePositionData(position, data); - } } @Override public void readGuiData(PacketBufferForestry data) throws IOException { breedingProgressPercent = data.readVarInt(); - IClimatePosition position = ForestryAPI.climateManager.getPosition(world, getPos()); - if (position != null) { - ClimateUtil.readPositionData(position, data); - } } // / IBEEHOUSING diff --git a/src/main/java/forestry/arboriculture/CamouflageHandlerArbDoor.java b/src/main/java/forestry/arboriculture/CamouflageHandlerArbDoor.java deleted file mode 100755 index 58f26e35e..000000000 --- a/src/main/java/forestry/arboriculture/CamouflageHandlerArbDoor.java +++ /dev/null @@ -1,77 +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.arboriculture; - -import com.google.common.base.Preconditions; - -import org.apache.commons.lang3.tuple.Pair; - -import net.minecraft.block.BlockDoor; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockModelShapes; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.core.ICamouflageItemHandler; -import forestry.api.core.ICamouflagedTile; -import forestry.arboriculture.items.ItemBlockWoodDoor; - -public class CamouflageHandlerArbDoor implements ICamouflageItemHandler { - - @Override - public boolean canHandle(ItemStack stack) { - return stack.getItem() instanceof ItemBlockWoodDoor; - } - - @Override - public String getType() { - return CamouflageManager.DOOR; - } - - @Override - public float getLightTransmittance(ItemStack stack, ICamouflageHandler camouflageHandler) { - return 0F; - } - - @SideOnly(Side.CLIENT) - @Override - public Pair getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile) { - Preconditions.checkArgument(!stack.isEmpty(), "Stack must not be empty"); - Preconditions.checkArgument(stack.getItem() instanceof ItemBlockWoodDoor, "Item must be ItemBlockWoodDoor"); - - World world = camouflageHandler.getWorldObj(); - BlockPos pos = camouflageTile.getCoordinates(); - IBlockState blockState = world.getBlockState(pos); - IBlockState currentState = blockState.getActualState(world, pos); - - ItemBlockWoodDoor itemDoor = (ItemBlockWoodDoor) stack.getItem(); - - IBlockState doorState = itemDoor.getBlock().getDefaultState() - .withProperty(BlockDoor.FACING, currentState.getValue(BlockDoor.FACING)) - .withProperty(BlockDoor.HINGE, currentState.getValue(BlockDoor.HINGE)) - .withProperty(BlockDoor.OPEN, currentState.getValue(BlockDoor.OPEN)) - .withProperty(BlockDoor.POWERED, currentState.getValue(BlockDoor.POWERED)) - .withProperty(BlockDoor.HALF, currentState.getValue(BlockDoor.HALF)); - - BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); - - return Pair.of(doorState, modelShapes.getModelForState(doorState)); - } - -} diff --git a/src/main/java/forestry/arboriculture/PluginArboriculture.java b/src/main/java/forestry/arboriculture/PluginArboriculture.java index 73d52cb97..e3c1f788a 100755 --- a/src/main/java/forestry/arboriculture/PluginArboriculture.java +++ b/src/main/java/forestry/arboriculture/PluginArboriculture.java @@ -26,6 +26,7 @@ import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockNewLeaf; import net.minecraft.block.BlockOldLeaf; import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -40,11 +41,13 @@ import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage; +import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.common.registry.GameRegistry; @@ -60,7 +63,6 @@ import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.IWoodType; import forestry.api.arboriculture.TreeManager; import forestry.api.arboriculture.WoodBlockKind; -import forestry.api.core.CamouflageManager; import forestry.api.core.ForestryAPI; import forestry.api.core.IArmorNaturalist; import forestry.api.genetics.AlleleManager; @@ -218,14 +220,6 @@ public class PluginArboriculture extends BlankForestryPlugin { // Commands PluginCore.rootCommand.addChildCommand(new CommandTree()); - - CamouflageManager.camouflageAccess.registerCamouflageItemHandler(new CamouflageHandlerArbDoor()); - TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.CLAY, 3)); - TreeManager.pileWalls.add(new CharcoalPileWall(PluginArboriculture.getBlocks().loam, 5)); - TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.END_STONE, 6)); - TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.END_BRICKS, 6)); - TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.DIRT, 2)); - TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.NETHERRACK, 4)); } @Override @@ -277,6 +271,18 @@ public class PluginArboriculture extends BlankForestryPlugin { } } + @Override + public void postInit() { + TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.CLAY, 3)); + TreeManager.pileWalls.add(new CharcoalPileWall(PluginArboriculture.getBlocks().loam, 4)); + TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.END_STONE, 6)); + TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.END_BRICKS, 6)); + TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.DIRT, 2)); + TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.GRAVEL, 1)); + TreeManager.pileWalls.add(new CharcoalPileWall(Blocks.NETHERRACK, 3)); + TreeManager.pileWalls.add(new CharcoalPileWall(PluginCore.getBlocks().ashBrick, 5)); + } + @Override public void registerCrates() { ICrateRegistry crateRegistry = StorageManager.crateRegistry; @@ -459,9 +465,19 @@ public class PluginArboriculture extends BlankForestryPlugin { //Wood Pile RecipeUtil.addShapelessRecipe("wood_pile", new ItemStack(blocks.woodPile), OreDictUtil.LOG_WOOD, OreDictUtil.LOG_WOOD, OreDictUtil.LOG_WOOD, OreDictUtil.LOG_WOOD); + RecipeUtil.addShapelessRecipe("wood_pile_decorative", new ItemStack(blocks.woodPile), blocks.woodPileDecorative); + RecipeUtil.addShapelessRecipe("decorative_wood_pile", new ItemStack(blocks.woodPileDecorative), blocks.woodPile); + + //Charcoal + RecipeUtil.addRecipe("charcoal_block", blocks.charcoal, + "###", + "###", + "###", + '#', new ItemStack(Items.COAL, 1, 1)); + RecipeUtil.addShapelessRecipe("charcoal", new ItemStack(Items.COAL, 9, 1), blocks.charcoal); //Dirt Pile Block - RecipeUtil.addShapelessRecipe("loam", new ItemStack(blocks.loam, 4), Items.CLAY_BALL, coreItems.compost, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, coreItems.compost, Items.CLAY_BALL); + RecipeUtil.addShapelessRecipe("loam", new ItemStack(blocks.loam, 4), Items.CLAY_BALL, coreItems.fertilizerBio, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, coreItems.fertilizerBio, Items.CLAY_BALL); } private static void registerAlleles() { diff --git a/src/main/java/forestry/arboriculture/blocks/BlockAbstractLeaves.java b/src/main/java/forestry/arboriculture/blocks/BlockAbstractLeaves.java index 6fc57747f..e939cab0d 100755 --- a/src/main/java/forestry/arboriculture/blocks/BlockAbstractLeaves.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockAbstractLeaves.java @@ -51,8 +51,10 @@ public abstract class BlockAbstractLeaves extends BlockLeaves implements IItemMo LeafDecayHelper.leafDecay(this, world, pos); } + @Override public abstract int getMetaFromState(IBlockState state); + @Override public abstract IBlockState getStateFromMeta(int meta); @Override @@ -184,7 +186,7 @@ public abstract class BlockAbstractLeaves extends BlockLeaves implements IItemMo getLeafDrop(drops, world, playerProfile, pos, saplingModifier, fortune); this.drops.set(drops); } - + @Override public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { List ret = this.drops.get(); @@ -196,6 +198,6 @@ public abstract class BlockAbstractLeaves extends BlockLeaves implements IItemMo getLeafDrop(drops, (World) world, null, pos, 1.0f, fortune); } } - + protected abstract void getLeafDrop(NonNullList drops, World world, @Nullable GameProfile playerProfile, BlockPos pos, float saplingModifier, int fortune); } diff --git a/src/main/java/forestry/arboriculture/blocks/BlockAsh.java b/src/main/java/forestry/arboriculture/blocks/BlockAsh.java new file mode 100644 index 000000000..8d6766502 --- /dev/null +++ b/src/main/java/forestry/arboriculture/blocks/BlockAsh.java @@ -0,0 +1,86 @@ +package forestry.arboriculture.blocks; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyInteger; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.statemap.StateMap; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import net.minecraftforge.client.model.ModelLoader; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.IItemModelRegister; +import forestry.api.core.IModelManager; +import forestry.api.core.IStateMapperRegister; +import forestry.core.PluginCore; + +public class BlockAsh extends Block implements IStateMapperRegister, IItemModelRegister { + + public static final PropertyInteger AMOUNT = PropertyInteger.create("amount", 0, 15); + + public BlockAsh() { + super(Material.GROUND, MapColor.BLACK); + setSoundType(SoundType.SAND); + setHarvestLevel("shovel", 0); + } + + @Override + protected BlockStateContainer createBlockState() { + return new BlockStateContainer(this, AMOUNT); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + for(int i = 0;i < 16;i++){ + manager.registerItemModel(item, i, "ash_block"); + } + } + + @Override + public int damageDropped(IBlockState state) { + return getMetaFromState(state); + } + + @Override + public int getMetaFromState(IBlockState state) { + return state.getValue(AMOUNT); + } + + @Override + public IBlockState getStateFromMeta(int meta) { + return getDefaultState().withProperty(AMOUNT, meta); + } + + @Override + public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { + List drops = new ArrayList<>(); + Random rand = world instanceof World ? ((World)world).rand : new Random(); + int amount = state.getValue(AMOUNT) + 9 + rand.nextInt(1 + fortune); + drops.add(new ItemStack(Items.COAL, amount, 1)); + drops.add(new ItemStack(PluginCore.getItems().ash, 1 + rand.nextInt(amount / 4))); + return drops; + } + + @SideOnly(Side.CLIENT) + @Override + public void registerStateMapper() { + ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(AMOUNT).build()); + } + +} diff --git a/src/main/java/forestry/arboriculture/blocks/BlockCharcoal.java b/src/main/java/forestry/arboriculture/blocks/BlockCharcoal.java index b9935f46f..b3734cec2 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockCharcoal.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockCharcoal.java @@ -4,30 +4,16 @@ import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.PropertyInteger; -import net.minecraft.block.state.BlockStateContainer; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.renderer.block.statemap.StateMap; -import net.minecraft.init.Items; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; - -import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import forestry.api.core.IItemModelRegister; import forestry.api.core.IModelManager; -import forestry.api.core.IStateMapperRegister; import forestry.api.core.Tabs; -public class BlockCharcoal extends Block implements IStateMapperRegister, IItemModelRegister { - - public static final PropertyInteger AMOUNT = PropertyInteger.create("amount", 0, 15); +public class BlockCharcoal extends Block implements IItemModelRegister { public BlockCharcoal() { super(Material.ROCK, MapColor.BLACK); @@ -35,43 +21,13 @@ public class BlockCharcoal extends Block implements IStateMapperRegister, IItemM setResistance(10.0F); setSoundType(SoundType.STONE); setCreativeTab(Tabs.tabArboriculture); - } - - @Override - protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, AMOUNT); + setHarvestLevel("pickaxe", 1); } @SideOnly(Side.CLIENT) @Override public void registerModel(Item item, IModelManager manager) { - for(int i = 0;i < 16;i++){ - manager.registerItemModel(item, i); - } - } - - @Override - public int getMetaFromState(IBlockState state) { - return state.getValue(AMOUNT); - } - - @Override - public IBlockState getStateFromMeta(int meta) { - return getDefaultState().withProperty(AMOUNT, meta); - } - - @Override - public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { - if(state.getValue(AMOUNT) > 0){ - drops.add(new ItemStack(Items.COAL, state.getValue(AMOUNT) + 9, 1)); - } - super.getDrops(drops, world, pos, state, fortune); - } - - @SideOnly(Side.CLIENT) - @Override - public void registerStateMapper() { - ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(AMOUNT).build()); + manager.registerItemModel(item, 0); } } diff --git a/src/main/java/forestry/arboriculture/blocks/BlockDecorativeWoodPile.java b/src/main/java/forestry/arboriculture/blocks/BlockDecorativeWoodPile.java new file mode 100644 index 000000000..486ee0b20 --- /dev/null +++ b/src/main/java/forestry/arboriculture/blocks/BlockDecorativeWoodPile.java @@ -0,0 +1,126 @@ +package forestry.arboriculture.blocks; + +import net.minecraft.block.BlockRotatedPillar; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.Rotation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.IItemModelRegister; +import forestry.api.core.IModelManager; +import forestry.api.core.Tabs; + +public class BlockDecorativeWoodPile extends BlockRotatedPillar implements IItemModelRegister { + public static final PropertyEnum AXIS = PropertyEnum.create("axis", EnumFacing.Axis.class); + + public BlockDecorativeWoodPile() { + super(Material.WOOD); + setSoundType(SoundType.WOOD); + setHardness(1.5f); + setCreativeTab(Tabs.tabArboriculture); + } + + @Override + public boolean isOpaqueCube(IBlockState state) { + return false; + } + + @Override + public boolean isNormalCube(IBlockState state) { + return false; + } + + @Override + public boolean isFullBlock(IBlockState state) { + return false; + } + + @Override + public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) { + return 12; + } + + @Override + public boolean isFlammable(IBlockAccess world, BlockPos pos, EnumFacing face) { + return true; + } + + @Override + public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) { + return 25; + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + for(int i = 0;i < 3;i++) { + manager.registerItemModel(item, i, "wood_pile"); + } + } + + @Override + public boolean rotateBlock(net.minecraft.world.World world, BlockPos pos, EnumFacing axis) { + net.minecraft.block.state.IBlockState state = world.getBlockState(pos); + for (net.minecraft.block.properties.IProperty prop : state.getProperties().keySet()) { + if (prop.getName().equals("axis")) { + world.setBlockState(pos, state.cycleProperty(prop)); + return true; + } + } + return false; + } + public IBlockState withRotation(IBlockState state, Rotation rot) { + switch (rot) { + case COUNTERCLOCKWISE_90: + case CLOCKWISE_90: + + switch ((EnumFacing.Axis)state.getValue(AXIS)) { + case X: + return state.withProperty(AXIS, EnumFacing.Axis.Z); + case Z: + return state.withProperty(AXIS, EnumFacing.Axis.X); + default: + return state; + } + + default: + return state; + } + } + + public IBlockState getStateFromMeta(int meta) { + return this.getDefaultState().withProperty(AXIS, EnumFacing.Axis.values()[meta]); + } + + public int getMetaFromState(IBlockState state) { + return state.getValue(AXIS).ordinal(); + } + + protected BlockStateContainer createBlockState() + { + return new BlockStateContainer(this, new IProperty[] {AXIS}); + } + + protected ItemStack getSilkTouchDrop(IBlockState state) + { + return new ItemStack(Item.getItemFromBlock(this)); + } + + public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { + return super.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(AXIS, facing.getAxis()); + } + +} diff --git a/src/main/java/forestry/arboriculture/blocks/BlockDefaultLeaves.java b/src/main/java/forestry/arboriculture/blocks/BlockDefaultLeaves.java index dd93c88f4..dacff37a1 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockDefaultLeaves.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockDefaultLeaves.java @@ -113,6 +113,7 @@ public abstract class BlockDefaultLeaves extends BlockAbstractLeaves { return i; } + @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, getVariant(), CHECK_DECAY, DECAYABLE); } diff --git a/src/main/java/forestry/arboriculture/blocks/BlockRegistryArboriculture.java b/src/main/java/forestry/arboriculture/blocks/BlockRegistryArboriculture.java index 8dbc6743a..24ecfec82 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockRegistryArboriculture.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockRegistryArboriculture.java @@ -10,13 +10,20 @@ ******************************************************************************/ package forestry.arboriculture.blocks; +import com.google.common.base.Preconditions; + import javax.annotation.Nullable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import com.google.common.base.Preconditions; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.common.MinecraftForge; + import forestry.api.arboriculture.EnumForestryWoodType; import forestry.api.arboriculture.EnumVanillaWoodType; import forestry.api.arboriculture.IAlleleFruit; @@ -31,11 +38,6 @@ import forestry.arboriculture.items.ItemBlockWoodSlab; import forestry.core.blocks.BlockRegistry; import forestry.core.items.ItemBlockForestry; import forestry.core.utils.OreDictUtil; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLeaves; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.MinecraftForge; public class BlockRegistryArboriculture extends BlockRegistry { public final List logs; @@ -71,6 +73,8 @@ public class BlockRegistryArboriculture extends BlockRegistry { public final BlockCharcoal charcoal; public final BlockWoodPile woodPile; + public final BlockDecorativeWoodPile woodPileDecorative; + public final BlockAsh ash; public final Block loam; public final BlockArboriculture treeChest; @@ -287,7 +291,19 @@ public class BlockRegistryArboriculture extends BlockRegistry { } }; registerBlock(woodPile, itemBlockWoodPile, "wood_pile"); - + + woodPileDecorative = new BlockDecorativeWoodPile(); + ItemBlockForestry itemBlockWoodPileDecorative = new ItemBlockForestry(woodPileDecorative) { + @Override + public int getItemBurnTime(ItemStack itemStack) { + return 1200; + } + }; + registerBlock(woodPileDecorative, itemBlockWoodPileDecorative, "wood_pile_decorative"); + + ash = new BlockAsh(); + registerBlock(ash, new ItemBlockForestry(ash), "ash_block"); + loam = new BlockLoam(); registerBlock(loam, new ItemBlockForestry(loam), "loam"); diff --git a/src/main/java/forestry/arboriculture/blocks/BlockWoodPile.java b/src/main/java/forestry/arboriculture/blocks/BlockWoodPile.java index 0ec0386d4..1aaabaae4 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockWoodPile.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockWoodPile.java @@ -2,13 +2,6 @@ package forestry.arboriculture.blocks; import java.util.Random; -import forestry.api.arboriculture.ICharcoalPileWall; -import forestry.api.arboriculture.TreeManager; -import forestry.api.core.IItemModelRegister; -import forestry.api.core.IModelManager; -import forestry.api.core.IStateMapperRegister; -import forestry.api.core.Tabs; -import forestry.arboriculture.PluginArboriculture; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; @@ -26,20 +19,30 @@ import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; + import net.minecraftforge.client.model.ModelLoader; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.api.arboriculture.ICharcoalPileWall; +import forestry.api.arboriculture.TreeManager; +import forestry.api.core.IItemModelRegister; +import forestry.api.core.IModelManager; +import forestry.api.core.IStateMapperRegister; +import forestry.api.core.Tabs; +import forestry.arboriculture.PluginArboriculture; + public class BlockWoodPile extends Block implements IItemModelRegister, IStateMapperRegister { public static final PropertyBool IS_ACTIVE = PropertyBool.create("active"); public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7); - public static final int RANDOM_TICK = 40; + public static final int RANDOM_TICK = 160; + public static final int CHANCE = 25; public BlockWoodPile() { super(Material.WOOD); setHardness(1.5f); - setTickRandomly(true); setCreativeTab(Tabs.tabArboriculture); setSoundType(SoundType.WOOD); } @@ -62,7 +65,7 @@ public class BlockWoodPile extends Block implements IItemModelRegister, IStateMa @Override public int tickRate(World world) { - return 40; + return 960; } @Override @@ -74,7 +77,7 @@ public class BlockWoodPile extends Block implements IItemModelRegister, IStateMa public boolean isNormalCube(IBlockState state) { return false; } - + @Override public boolean isFullBlock(IBlockState state) { return false; @@ -95,38 +98,48 @@ public class BlockWoodPile extends Block implements IItemModelRegister, IStateMa } @Override - public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) { - IBlockState fromState = world.getBlockState(fromPos); + public void neighborChanged(IBlockState state, World world, BlockPos pos, Block fromBlock, BlockPos fromPos) { boolean isActive = state.getValue(IS_ACTIVE); - if(fromState.getBlock() == this){ - if(fromState.getValue(IS_ACTIVE) && !isActive){ - world.setBlockState(pos, state.withProperty(IS_ACTIVE, true)); - world.scheduleUpdate(pos, this, this.tickRate(world) + world.rand.nextInt(RANDOM_TICK)); - } - } else if(fromState.getBlock() == Blocks.FIRE) { + if(fromBlock == Blocks.FIRE) { if(!isActive){ - world.setBlockState(pos, state.withProperty(IS_ACTIVE, true)); - world.scheduleUpdate(pos, this, this.tickRate(world) + world.rand.nextInt(RANDOM_TICK)); + activatePile(state, world, pos, true); } } } + + private void activatePile(IBlockState state, World world, BlockPos pos, boolean scheduleUpdate){ + world.setBlockState(pos, state.withProperty(IS_ACTIVE, true), 2); + if(scheduleUpdate){ + world.scheduleUpdate(pos, this, (this.tickRate(world) + world.rand.nextInt(RANDOM_TICK)) / 4); + } + } @Override public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { if(state.getValue(IS_ACTIVE)){ for(EnumFacing facing : EnumFacing.VALUES){ - if(world.isAirBlock(pos.offset(facing))){ - world.setBlockState(pos.offset(facing), Blocks.FIRE.getDefaultState()); - } - if(rand.nextInt(150) == 0){ - if(state.getValue(AGE) < 7){ - world.setBlockState(pos, state.withProperty(AGE, state.getValue(AGE) + 1)); - }else{ - world.setBlockState(pos, PluginArboriculture.getBlocks().charcoal.getDefaultState().withProperty(BlockCharcoal.AMOUNT, Math.round(getCharcoalAmount(world, pos)))); + BlockPos position = pos.offset(facing); + IBlockState blockState = world.getBlockState(position); + Block block = blockState.getBlock(); + if(block == this){ + if(!state.getValue(IS_ACTIVE) && blockState.getValue(IS_ACTIVE)){ + activatePile(state, world, pos, false); + }else if(!blockState.getValue(IS_ACTIVE) && state.getValue(IS_ACTIVE)){ + activatePile(blockState, world, position, true); } + } else if(world.isAirBlock(position) || !blockState.isSideSolid(world, position, facing.getOpposite()) || block.isFlammable(world, position, facing.getOpposite())){ + world.setBlockState(position, Blocks.FIRE.getDefaultState()); } - world.scheduleUpdate(pos, this, this.tickRate(world) + world.rand.nextInt(RANDOM_TICK)); } + if(rand.nextFloat() < 0.5F){ + if(state.getValue(AGE) < 7){ + world.setBlockState(pos, state.withProperty(AGE, state.getValue(AGE) + 1), 2); + }else{ + IBlockState ashState = PluginArboriculture.getBlocks().ash.getDefaultState(); + world.setBlockState(pos, ashState.withProperty(BlockAsh.AMOUNT, Math.round(getCharcoalAmount(world, pos))), 2); + } + } + world.scheduleUpdate(pos, this, this.tickRate(world) + world.rand.nextInt(RANDOM_TICK)); } } @@ -157,7 +170,7 @@ public class BlockWoodPile extends Block implements IItemModelRegister, IStateMa @Override public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) { if (state.getValue(IS_ACTIVE)) { - if (rand.nextInt(24) == 0){ + if (rand.nextDouble() < 0.1D){ world.playSound(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, SoundEvents.BLOCK_FIRE_AMBIENT, SoundCategory.BLOCKS, 1.0F + rand.nextFloat(), rand.nextFloat() * 0.7F + 0.3F, false); } float f = pos.getX() + 0.5F; @@ -165,10 +178,10 @@ public class BlockWoodPile extends Block implements IItemModelRegister, IStateMa float f2 = pos.getZ() + 0.5F; float f3 = 0.52F; float f4 = rand.nextFloat() * 0.6F - 0.3F; - if(rand.nextInt(12) == 0){ - world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, f + f3 - 0.5, f1 + 1, f2 + f4, 0.0D, 0.0D, 0.0D); + if(rand.nextDouble() < 0.2D){ + world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, f + f3 - 0.5, f1 + 1, f2 + f4, 0.0D, 0.15D, 0.0D); }else{ - world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, f + f3 - 0.5, f1 + 1, f2 + f4, 0.0D, 0.05D, 0.0D); + world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, f + f3 - 0.5, f1 + 1, f2 + f4, 0.0D, 0.15D, 0.0D); } } } @@ -189,22 +202,20 @@ public class BlockWoodPile extends Block implements IItemModelRegister, IStateMa private int getCharcoalFaceAmount(World world, BlockPos pos, EnumFacing facing){ int faceAmount = 0; - for(int i = 0;i < 18;i++){ + for(int i = 0;i < 16;i++){ BlockPos testPos = pos.offset(facing, i); IBlockState state = world.getBlockState(testPos); if(state.getBlock() == Blocks.AIR){ - faceAmount = 0; + break; }else if(state.getBlock() == this || state.getBlock() == PluginArboriculture.getBlocks().charcoal){ - if(i == 17){ + if(i == 15){ return getCharcoalFaceAmount(world, testPos, facing); } continue; - }else{ - for(ICharcoalPileWall wall : TreeManager.pileWalls){ - if(wall.matches(state)){ - faceAmount = wall.getCharcoalAmount(); - break; - } + } + for(ICharcoalPileWall wall : TreeManager.pileWalls){ + if(wall.matches(state)){ + return wall.getCharcoalAmount(); } } break; diff --git a/src/main/java/forestry/arboriculture/charcoal/jei/CharcoalPileWallCategory.java b/src/main/java/forestry/arboriculture/charcoal/jei/CharcoalPileWallCategory.java index 0d65d3850..988e6c717 100644 --- a/src/main/java/forestry/arboriculture/charcoal/jei/CharcoalPileWallCategory.java +++ b/src/main/java/forestry/arboriculture/charcoal/jei/CharcoalPileWallCategory.java @@ -1,18 +1,21 @@ package forestry.arboriculture.charcoal.jei; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + import forestry.arboriculture.PluginArboriculture; import forestry.core.config.Constants; import forestry.core.recipes.jei.ForestryRecipeCategory; +import forestry.core.recipes.jei.ForestryTooltipCallback; + import mezz.jei.api.IGuiHelper; import mezz.jei.api.gui.IDrawableAnimated; +import mezz.jei.api.gui.IDrawableAnimated.StartDirection; import mezz.jei.api.gui.IDrawableStatic; import mezz.jei.api.gui.IGuiItemStackGroup; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.IDrawableAnimated.StartDirection; import mezz.jei.api.ingredients.IIngredients; -import net.minecraft.client.Minecraft; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; public class CharcoalPileWallCategory extends ForestryRecipeCategory { @@ -48,6 +51,7 @@ public class CharcoalPileWallCategory extends ForestryRecipeCategory outputs = ImmutableList.of( + charcoal, + ash + ); + ingredients.setOutputs(ItemStack.class, outputs); } } diff --git a/src/main/java/forestry/arboriculture/items/ItemBlockLeaves.java b/src/main/java/forestry/arboriculture/items/ItemBlockLeaves.java index ccadd67f9..cd50fbbe5 100644 --- a/src/main/java/forestry/arboriculture/items/ItemBlockLeaves.java +++ b/src/main/java/forestry/arboriculture/items/ItemBlockLeaves.java @@ -12,7 +12,6 @@ package forestry.arboriculture.items; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.blocks.BlockAbstractLeaves; -import forestry.arboriculture.blocks.BlockForestryLeaves; import forestry.arboriculture.tiles.TileLeaves; import forestry.core.items.IColoredItem; import forestry.core.items.ItemBlockForestry; diff --git a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java index 07ff86226..03ccb9573 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java @@ -48,7 +48,6 @@ import forestry.core.network.packets.PacketTileStream; import forestry.core.utils.ClimateUtil; import forestry.core.utils.ColourUtil; import forestry.core.utils.GeneticsUtil; -import forestry.core.utils.Log; import forestry.core.utils.NetworkUtil; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/forestry/core/CamouflageHandlerDoor.java b/src/main/java/forestry/core/CamouflageHandlerDoor.java deleted file mode 100644 index f277b1cfc..000000000 --- a/src/main/java/forestry/core/CamouflageHandlerDoor.java +++ /dev/null @@ -1,79 +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.core; - -import com.google.common.base.Preconditions; -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.core.ICamouflageItemHandler; -import forestry.api.core.ICamouflagedTile; -import net.minecraft.block.Block; -import net.minecraft.block.BlockDoor; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockModelShapes; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.item.ItemDoor; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; - -public class CamouflageHandlerDoor implements ICamouflageItemHandler { - - @Override - public boolean canHandle(ItemStack stack) { - return stack.getItem() instanceof ItemDoor; - } - - @Override - public String getType() { - return CamouflageManager.DOOR; - } - - @Override - public float getLightTransmittance(ItemStack stack, ICamouflageHandler camouflageHandler) { - return 0.25F; - } - - @SideOnly(Side.CLIENT) - @Override - public Pair getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile) { - Preconditions.checkNotNull(camouflageHandler); - Preconditions.checkArgument(stack.getItem() instanceof ItemDoor, "Item must be a door"); - - World world = camouflageHandler.getWorldObj(); - BlockPos pos = camouflageTile.getCoordinates(); - IBlockState blockState = world.getBlockState(pos); - IBlockState currentState = blockState.getActualState(world, pos); - - ItemDoor itemDoor = (ItemDoor) stack.getItem(); - Block doorBlock = ObfuscationReflectionHelper.getPrivateValue(ItemDoor.class, itemDoor, 0); - - if (doorBlock == null) { - throw new IllegalStateException("Can't render Door : block is null for" + stack); - } - IBlockState doorState = doorBlock.getDefaultState() - .withProperty(BlockDoor.FACING, currentState.getValue(BlockDoor.FACING)) - .withProperty(BlockDoor.HINGE, currentState.getValue(BlockDoor.HINGE)) - .withProperty(BlockDoor.OPEN, currentState.getValue(BlockDoor.OPEN)) - .withProperty(BlockDoor.POWERED, currentState.getValue(BlockDoor.POWERED)) - .withProperty(BlockDoor.HALF, currentState.getValue(BlockDoor.HALF)); - - BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); - - return Pair.of(doorState, modelShapes.getModelForState(doorState)); - } - -} diff --git a/src/main/java/forestry/core/CamouflageHandlerGlass.java b/src/main/java/forestry/core/CamouflageHandlerGlass.java deleted file mode 100644 index 9e3e51858..000000000 --- a/src/main/java/forestry/core/CamouflageHandlerGlass.java +++ /dev/null @@ -1,64 +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.core; - -import com.google.common.base.Preconditions; -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.core.ICamouflageItemHandler; -import forestry.api.core.ICamouflagedTile; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockModelShapes; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; - -public class CamouflageHandlerGlass implements ICamouflageItemHandler { - - @Override - public boolean canHandle(ItemStack stack) { - if (stack.isEmpty() || Block.getBlockFromItem(stack.getItem()) == Blocks.AIR) { - return false; - } - Block block = Block.getBlockFromItem(stack.getItem()); - IBlockState stateFromMeta = block.getStateFromMeta(stack.getItemDamage()); - - return !stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && !stateFromMeta.isBlockNormalCube(); - } - - @Override - public String getType() { - return CamouflageManager.GLASS; - } - - @Override - public float getLightTransmittance(ItemStack stack, ICamouflageHandler camouflageHandler) { - return 0.25F; - } - - @SideOnly(Side.CLIENT) - @Override - public Pair getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile) { - BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); - Block block = Block.getBlockFromItem(stack.getItem()); - Preconditions.checkArgument(block != Blocks.AIR, "stack has no block"); - - IBlockState state = block.getStateFromMeta(stack.getItemDamage()); - - return Pair.of(state, modelShapes.getModelForState(state)); - } - -} diff --git a/src/main/java/forestry/core/CamouflageHandlerNone.java b/src/main/java/forestry/core/CamouflageHandlerNone.java deleted file mode 100644 index e3fe06ca7..000000000 --- a/src/main/java/forestry/core/CamouflageHandlerNone.java +++ /dev/null @@ -1,35 +0,0 @@ -package forestry.core; - -import org.apache.commons.lang3.tuple.Pair; - -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.core.ICamouflageItemHandler; -import forestry.api.core.ICamouflagedTile; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.item.ItemStack; - -public class CamouflageHandlerNone implements ICamouflageItemHandler { - - @Override - public boolean canHandle(ItemStack stack) { - return true; - } - - @Override - public String getType() { - return CamouflageManager.NONE; - } - - @Override - public float getLightTransmittance(ItemStack stack, ICamouflageHandler camouflageHandler) { - return 0; - } - - @Override - public Pair getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile) { - return Pair.of(null, null); - } - -} diff --git a/src/main/java/forestry/core/EventHandlerCore.java b/src/main/java/forestry/core/EventHandlerCore.java index 79dd3d3a2..b554f9389 100755 --- a/src/main/java/forestry/core/EventHandlerCore.java +++ b/src/main/java/forestry/core/EventHandlerCore.java @@ -23,6 +23,7 @@ import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.event.LootTableLoadEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.world.WorldEvent; + import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent; @@ -36,6 +37,7 @@ import forestry.api.genetics.ISpeciesRoot; import forestry.core.config.Constants; import forestry.core.errors.ErrorStateRegistry; import forestry.core.models.ModelBlockCached; +import forestry.core.models.ModelBlockCustomCached; import forestry.core.render.TextureManagerForestry; import forestry.plugins.PluginManager; @@ -100,6 +102,7 @@ public class EventHandlerCore { ErrorStateRegistry.initSprites(); TextureManagerForestry.initDefaultSprites(); ModelBlockCached.clear(); + ModelBlockCustomCached.clear(); } @SubscribeEvent diff --git a/src/main/java/forestry/core/PluginCore.java b/src/main/java/forestry/core/PluginCore.java index 2905606a0..153b43a71 100644 --- a/src/main/java/forestry/core/PluginCore.java +++ b/src/main/java/forestry/core/PluginCore.java @@ -18,7 +18,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.command.ICommand; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -31,13 +30,16 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.RecipeSorter; +import net.minecraftforge.fml.common.IFuelHandler; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; + import forestry.api.circuits.ChipsetManager; -import forestry.api.core.CamouflageManager; import forestry.api.core.ForestryAPI; import forestry.api.genetics.AlleleManager; import forestry.api.multiblock.MultiblockManager; @@ -49,6 +51,7 @@ import forestry.core.blocks.BlockRegistryCore; import forestry.core.blocks.EnumResourceType; import forestry.core.circuits.CircuitRegistry; import forestry.core.circuits.SolderManager; +import forestry.core.climate.ClimateFactory; import forestry.core.climate.ClimateManager; import forestry.core.commands.CommandPlugins; import forestry.core.commands.RootCommand; @@ -62,8 +65,6 @@ import forestry.core.items.EnumContainerType; import forestry.core.items.ItemRegistryCore; import forestry.core.items.ItemRegistryFluids; import forestry.core.loot.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; @@ -75,6 +76,7 @@ import forestry.core.render.TextureManagerForestry; import forestry.core.utils.ClimateUtil; import forestry.core.utils.ForestryModEnvWarningCallable; import forestry.core.utils.OreDictUtil; +import forestry.core.utils.World2ObjectMap; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; import forestry.plugins.ForestryPluginUids; @@ -122,9 +124,8 @@ public class PluginCore extends BlankForestryPlugin { LootFunctionManager.registerFunction(new SetSpeciesNBT.Serializer()); MultiblockManager.logicFactory = new MultiblockLogicFactory(); - ForestryAPI.climateManager = new ClimateManager(); - - CamouflageManager.camouflageAccess = new CamouflageAccess(); + ForestryAPI.climateManager = ClimateManager.getInstance(); + ForestryAPI.climateFactory = new ClimateFactory(); } @Override @@ -140,12 +141,9 @@ public class PluginCore extends BlankForestryPlugin { GameProfileDataSerializer.register(); MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(World2ObjectMap.class); rootCommand.addChildCommand(new CommandPlugins()); - - CamouflageManager.camouflageAccess.registerCamouflageItemHandler(new CamouflageHandlerBlock()); - CamouflageManager.camouflageAccess.registerCamouflageItemHandler(new CamouflageHandlerGlass()); - CamouflageManager.camouflageAccess.registerCamouflageItemHandler(new CamouflageHandlerDoor()); } @Override @@ -293,9 +291,6 @@ public class PluginCore extends BlankForestryPlugin { // / WRENCH RecipeUtil.addRecipe("wrench", items.wrench, "# #", " # ", " # ", '#', OreDictUtil.INGOT_BRONZE); - - // / CAMOUFLAGE SPRAY CAN - RecipeUtil.addRecipe("camoflage_spray_can", items.camouflageSprayCan, "TTT", "TCT", "TCT", 'T', OreDictUtil.INGOT_TIN, 'C', items.craftingMaterial.getCamouflagedPaneling()); // / WEB RecipeUtil.addRecipe("silk_wisp_to_web", new ItemStack(Blocks.WEB, 4), "# #", " # ", "# #", '#', items.craftingMaterial.getSilkWisp()); @@ -441,6 +436,23 @@ public class PluginCore extends BlankForestryPlugin { RecipeUtil.addShapelessRecipe("block_to_bronze", ingotBronze, OreDictUtil.BLOCK_BRONZE); } + if(!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)){ + RecipeUtil.addSmelting(new ItemStack(items.ash, 2), new ItemStack(Items.COAL, 1, 1), 0.15F); + } + + RecipeUtil.addRecipe("ash_brick", blocks.ashBrick, + "A#A", + "# #", + "A#A", + '#', Items.BRICK, + 'A', OreDictUtil.DUST_ASH); + RecipeUtil.addRecipe("ash_stairs", blocks.ashStairs, + true, + "# ", + "## ", + "###", + '#', Items.BRICK); + // alternate recipes if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.APICULTURE)) { RecipeManagers.centrifugeManager.addRecipe(5, new ItemStack(Items.STRING), ImmutableMap.of( @@ -473,11 +485,7 @@ public class PluginCore extends BlankForestryPlugin { @SubscribeEvent @SideOnly(Side.CLIENT) public void onBakeModels(ModelBakeEvent event) { - ModelResourceLocation modelLocation = new ModelResourceLocation("forestry:camouflage_spray_can", "inventory"); - ModelEntry blockModelIndex = new ModelEntry(modelLocation, new ModelCamouflageSprayCan()); - ModelManager modelManager = ModelManager.getInstance(); - modelManager.registerCustomModel(blockModelIndex); - modelManager.onBakeModels(event); + ModelManager.getInstance().onBakeModels(event); } @SubscribeEvent diff --git a/src/main/java/forestry/core/blocks/BlockAshBrick.java b/src/main/java/forestry/core/blocks/BlockAshBrick.java new file mode 100644 index 000000000..ae1316813 --- /dev/null +++ b/src/main/java/forestry/core/blocks/BlockAshBrick.java @@ -0,0 +1,32 @@ +package forestry.core.blocks; + +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraft.item.Item; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.IItemModelRegister; +import forestry.api.core.IModelManager; +import forestry.core.CreativeTabForestry; + +public class BlockAshBrick extends Block implements IItemModelRegister { + + public BlockAshBrick() { + super(Material.ROCK, MapColor.STONE); + setCreativeTab(CreativeTabForestry.tabForestry); + setHardness(2.0F); + setResistance(10.0F); + setSoundType(SoundType.STONE); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + manager.registerItemModel(item, 0); + } + +} diff --git a/src/main/java/forestry/core/blocks/BlockHumus.java b/src/main/java/forestry/core/blocks/BlockHumus.java index 779e6307a..3471ce8e9 100755 --- a/src/main/java/forestry/core/blocks/BlockHumus.java +++ b/src/main/java/forestry/core/blocks/BlockHumus.java @@ -143,9 +143,8 @@ public class BlockHumus extends Block implements IItemModelRegister { @Override @SideOnly(Side.CLIENT) public void registerModel(Item item, IModelManager manager) { - manager.registerItemModel(item, 0, "soil/humus"); - manager.registerItemModel(item, 1, "soil/humus"); - manager.registerItemModel(item, 2, "soil/humus"); - manager.registerItemModel(item, 3, "soil/humus"); + for(int i = 0;i < degradeDelimiter;i++){ + manager.registerItemModel(item, i, "soil/humus"); + } } } diff --git a/src/main/java/forestry/core/blocks/BlockRegistryCore.java b/src/main/java/forestry/core/blocks/BlockRegistryCore.java index 2567b1f22..849049777 100644 --- a/src/main/java/forestry/core/blocks/BlockRegistryCore.java +++ b/src/main/java/forestry/core/blocks/BlockRegistryCore.java @@ -10,18 +10,24 @@ ******************************************************************************/ package forestry.core.blocks; -import forestry.core.items.ItemBlockForestry; -import forestry.core.utils.OreDictUtil; +import net.minecraft.block.BlockStairs; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; + import net.minecraftforge.oredict.OreDictionary; +import forestry.core.blocks.properties.BlockAshStairs; +import forestry.core.items.ItemBlockForestry; +import forestry.core.utils.OreDictUtil; + public class BlockRegistryCore extends BlockRegistry { public final BlockCore analyzer; public final BlockCore escritoire; public final BlockBogEarth bogEarth; public final BlockHumus humus; public final BlockResourceOre resources; + public final BlockAshBrick ashBrick; + public final BlockStairs ashStairs; public final ItemStack resourceStorageApatite; public final ItemStack resourceStorageTin; public final ItemStack resourceStorageCopper; @@ -65,6 +71,12 @@ public class BlockRegistryCore extends BlockRegistry { resourceStorageBronze = resourceStorage.get(EnumResourceType.BRONZE); OreDictionary.registerOre(OreDictUtil.BLOCK_BRONZE, resourceStorageBronze); + ashBrick = new BlockAshBrick(); + registerBlock(ashBrick, new ItemBlockForestry(ashBrick), "ash_brick"); + + ashStairs = new BlockAshStairs(ashBrick.getDefaultState()); + registerBlock(ashStairs, new ItemBlockForestry(ashStairs), "ash_stairs"); + // register some common oreDict names for our recipes OreDictionary.registerOre(OreDictUtil.CRAFTING_TABLE_WOOD, Blocks.CRAFTING_TABLE); OreDictionary.registerOre(OreDictUtil.TRAPDOOR_WOOD, Blocks.TRAPDOOR); diff --git a/src/main/java/forestry/core/blocks/properties/BlockAshStairs.java b/src/main/java/forestry/core/blocks/properties/BlockAshStairs.java new file mode 100644 index 000000000..583690f91 --- /dev/null +++ b/src/main/java/forestry/core/blocks/properties/BlockAshStairs.java @@ -0,0 +1,25 @@ +package forestry.core.blocks.properties; + +import net.minecraft.block.BlockStairs; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.IItemModelRegister; +import forestry.api.core.IModelManager; +import forestry.core.CreativeTabForestry; + +public class BlockAshStairs extends BlockStairs implements IItemModelRegister { + public BlockAshStairs(IBlockState modelState) { + super(modelState); + setCreativeTab(CreativeTabForestry.tabForestry); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + manager.registerItemModel(item, 0); + } +} diff --git a/src/main/java/forestry/core/circuits/Circuits.java b/src/main/java/forestry/core/circuits/Circuits.java index 707f33859..33bc11a1f 100644 --- a/src/main/java/forestry/core/circuits/Circuits.java +++ b/src/main/java/forestry/core/circuits/Circuits.java @@ -32,4 +32,8 @@ public class Circuits { public static ICircuit machineSpeedUpgrade1; public static ICircuit machineSpeedUpgrade2; public static ICircuit machineEfficiencyUpgrade1; + public static ICircuit greenhouseClimatiserTemperature1; + public static ICircuit greenhouseClimatiserTemperature2; + public static ICircuit greenhouseClimatiserHumidity1; + public static ICircuit greenhouseClimatiserHumidity2; } diff --git a/src/main/java/forestry/core/climate/BiomeClimateInfo.java b/src/main/java/forestry/core/climate/BiomeClimateInfo.java deleted file mode 100644 index 17402f53e..000000000 --- a/src/main/java/forestry/core/climate/BiomeClimateInfo.java +++ /dev/null @@ -1,35 +0,0 @@ -package forestry.core.climate; - -import java.util.HashMap; -import java.util.Map; - -import forestry.api.climate.IClimateInfo; -import net.minecraft.world.biome.Biome; - -public class BiomeClimateInfo implements IClimateInfo { - - private static final Map climateControls = new HashMap<>(); - - public static BiomeClimateInfo getInfo(Biome biome) { - if (!climateControls.containsKey(biome)) { - climateControls.put(biome, new BiomeClimateInfo(biome)); - } - return climateControls.get(biome); - } - - private final Biome biome; - - private BiomeClimateInfo(Biome biome) { - this.biome = biome; - } - - @Override - public float getTemperature() { - return biome.getTemperature(); - } - - @Override - public float getHumidity() { - return biome.getRainfall(); - } -} diff --git a/src/main/java/forestry/core/climate/ClimateContainer.java b/src/main/java/forestry/core/climate/ClimateContainer.java new file mode 100644 index 000000000..47fd9bd9d --- /dev/null +++ b/src/main/java/forestry/core/climate/ClimateContainer.java @@ -0,0 +1,328 @@ +/******************************************************************************* + * 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 javax.annotation.Nullable; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.ClimateState; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateContainerListener; +import forestry.api.climate.IClimateData; +import forestry.api.climate.IClimateHousing; +import forestry.api.climate.IClimateModifier; +import forestry.api.climate.IClimateSource; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.greenhouse.GreenhouseManager; +import forestry.core.network.IStreamable; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.packets.PacketUpdateClimate; +import forestry.core.utils.NetworkUtil; + +public class ClimateContainer implements IClimateContainer, IStreamable { + public static final float CLIMATE_CHANGE = 0.01F; + + protected final IClimateHousing parent; + protected final ClimateContainerListeners listeners; + protected final Set sources; + private int delay; + protected ClimateState state; + protected ImmutableClimateState targetedState; + protected IClimateState boundaryUp; + protected IClimateState boundaryDown; + private NBTTagCompound modifierData; + + /** + * Creates an empty region. + */ + public ClimateContainer(IClimateHousing parent) { + this.parent = parent; + this.listeners = new ClimateContainerListeners(); + this.sources = new HashSet<>(); + this.delay = 20; + this.targetedState = parent.getDefaultClimate(); + this.state = parent.getDefaultClimate().toMutable(); + this.modifierData = new NBTTagCompound(); + this.boundaryUp = ImmutableClimateState.MIN; + this.boundaryDown = ImmutableClimateState.MIN; + } + + public ClimateContainer(IClimateHousing parent, NBTTagCompound nbtTag) { + this(parent); + readFromNBT(nbtTag); + } + + @Override + public IClimateHousing getParent() { + return parent; + } + + @Override + public void updateClimate(int ticks) { + if (ticks % getTickDelay() == 0) { + if(!listeners.isClosed(this)) { + returnClimateToDefault(); + }else{ + ImmutableClimateState oldState = state.toImmutable(); + state = parent.getDefaultClimate().toMutable(); + for(IClimateModifier modifier : GreenhouseManager.greenhouseHelper.getModifiers()){ + state = modifier.modifyTarget(this, state, oldState, modifierData).toMutable(); + } + if(!state.equals(oldState)) { + BlockPos coordinates = parent.getCoordinates(); + NetworkUtil.sendNetworkPacket(new PacketUpdateClimate(coordinates, this), coordinates, parent.getWorldObj()); + } + } + } + } + + protected void returnClimateToDefault(){ + ImmutableClimateState defaultState = parent.getDefaultClimate(); + float biomeTemperature = defaultState.getTemperature(); + float biomeHumidity = defaultState.getHumidity(); + float temperature = state.getTemperature(); + float humidity = state.getHumidity(); + if (temperature != biomeTemperature) { + if (temperature > biomeTemperature) { + state.addTemperature(-Math.min(CLIMATE_CHANGE, temperature - biomeTemperature)); + } else { + state.addTemperature(Math.min(CLIMATE_CHANGE, biomeTemperature - temperature)); + } + } + if (humidity != biomeHumidity) { + if (humidity > biomeHumidity) { + state.addHumidity(-Math.min(CLIMATE_CHANGE, humidity - biomeHumidity)); + } else { + state.addHumidity(Math.min(CLIMATE_CHANGE, biomeHumidity - humidity)); + } + } + } + + @Override + public void recalculateBoundaries(double sizeModifier){ + float temperatureBoundaryUp = 0.0F; + float humidityBoundaryUp = 0.0F; + float temperatureBoundaryDown = 0.0F; + float humidityBoundaryDown = 0.0F; + for(IClimateSource source : sources){ + if(source.affectClimateType(ClimateType.HUMIDITY)){ + humidityBoundaryUp+=source.getBoundaryModifier(ClimateType.HUMIDITY, true); + humidityBoundaryDown+=source.getBoundaryModifier(ClimateType.HUMIDITY, false); + } + if(source.affectClimateType(ClimateType.TEMPERATURE)){ + temperatureBoundaryUp+= source.getBoundaryModifier(ClimateType.TEMPERATURE, true); + temperatureBoundaryDown+= source.getBoundaryModifier(ClimateType.TEMPERATURE, false); + } + } + if(temperatureBoundaryUp != 0){ + temperatureBoundaryUp/=sizeModifier; + } + if(temperatureBoundaryDown != 0){ + temperatureBoundaryDown/=sizeModifier; + } + if(humidityBoundaryUp != 0){ + humidityBoundaryUp/=sizeModifier; + } + if(humidityBoundaryDown != 0){ + humidityBoundaryDown/=sizeModifier; + } + boundaryUp = parent.getDefaultClimate().add(new ClimateState(temperatureBoundaryUp, humidityBoundaryUp)); + boundaryDown = parent.getDefaultClimate().remove(new ClimateState(temperatureBoundaryDown, humidityBoundaryDown)); + } + + @Override + public IClimateState getBoundaryDown() { + return boundaryDown; + } + + @Override + public IClimateState getBoundaryUp() { + return boundaryUp; + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + state.writeToNBT(nbt); + nbt.setTag("Target", targetedState.writeToNBT(new NBTTagCompound())); + nbt.setTag("modifierData", modifierData); + return nbt; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + state.readFromNBT(nbt); + targetedState = new ImmutableClimateState(nbt.getCompoundTag("Target")); + modifierData = nbt.getCompoundTag("modifierData"); + } + + @Override + public void setTargetedState(ImmutableClimateState state) { + this.targetedState = state; + } + + @Override + public ImmutableClimateState getTargetedState() { + return targetedState; + } + + public void setDelay(int delay) { + this.delay = delay; + } + + /** + * @return The ticks between updates. + */ + public int getTickDelay() { + return delay; + } + + public void setState(ClimateState state) { + this.state = state; + } + + @Override + public World getWorld() { + return parent.getWorldObj(); + } + + @Override + public void addClimateSource(IClimateSource source) { + if (!sources.contains(source)) { + sources.add(source); + } + } + + @Override + public void removeClimateSource(IClimateSource source) { + if (sources.contains(source)) { + sources.remove(source); + } + } + + @Override + public Collection getClimateSources() { + return sources; + } + + @Override + public void writeData(PacketBufferForestry data) { + data.writeFloat(state.getTemperature()); + data.writeFloat(state.getHumidity()); + data.writeFloat(boundaryUp.getTemperature()); + data.writeFloat(boundaryUp.getHumidity()); + data.writeFloat(boundaryDown.getTemperature()); + data.writeFloat(boundaryDown.getHumidity()); + data.writeFloat(targetedState.getTemperature()); + data.writeFloat(targetedState.getHumidity()); + data.writeCompoundTag(modifierData); + } + + @Override + public void readData(PacketBufferForestry data) throws IOException { + state.setTemperature(data.readFloat()); + state.setHumidity(data.readFloat()); + boundaryUp = new ImmutableClimateState(data.readFloat(), data.readFloat()); + boundaryDown = new ImmutableClimateState(data.readFloat(), data.readFloat()); + targetedState = new ImmutableClimateState(data.readFloat(), data.readFloat()); + modifierData = data.readCompoundTag(); + } + + @Override + public ClimateState getState() { + return state; + } + + @Override + public void addListaner(IClimateContainerListener listener) { + listeners.addListaner(listener); + } + + @Override + public void removeListener(IClimateContainerListener listener) { + listeners.removeListener(listener); + } + + @Override + public Collection getListeners() { + return listeners.getListeners(); + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof IClimateContainer)){ + return false; + } + IClimateContainer container = (IClimateContainer) obj; + IClimateHousing parent = container.getParent(); + if(parent == null || this.parent == null){ + return false; + } + return this.parent.getCoordinates().equals(parent.getCoordinates()); + } + + @Override + public int hashCode() { + return parent.getCoordinates().hashCode(); + } + + @Nullable + @Override + @SideOnly(Side.CLIENT) + public IClimateData getData() { + IClimateData data = new ClimateData(); + for(IClimateModifier modifier : GreenhouseManager.greenhouseHelper.getModifiers()){ + modifier.addData(this, state, modifierData, data); + } + return data; + } + + private static final class ClimateContainerListeners implements IClimateContainerListener{ + private List listeners = new LinkedList<>(); + + @Override + public boolean isClosed(IClimateContainer container) { + for(IClimateContainerListener listener : listeners){ + if(!listener.isClosed(container)){ + return false; + } + } + return true; + } + + public void addListaner(IClimateContainerListener listener) { + listeners.add(listener); + } + + public void removeListener(IClimateContainerListener listener) { + listeners.remove(listener); + } + + public Collection getListeners() { + return listeners; + } + + } + +} diff --git a/src/main/java/forestry/core/climate/ClimateData.java b/src/main/java/forestry/core/climate/ClimateData.java new file mode 100644 index 000000000..53579ff10 --- /dev/null +++ b/src/main/java/forestry/core/climate/ClimateData.java @@ -0,0 +1,29 @@ +package forestry.core.climate; + +import java.util.LinkedHashMap; +import java.util.Map; + +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateData; + +public class ClimateData implements IClimateData { + private final Map temperatureData = new LinkedHashMap<>(); + private final Map humidityData = new LinkedHashMap<>(); + + @Override + public ClimateData addData(ClimateType type, String displayName, float value) { + if(type == ClimateType.HUMIDITY){ + humidityData.put(displayName, value); + }else{ + temperatureData.put(displayName, value); + } + return this; + } + + public Map getData(ClimateType type){ + if(type == ClimateType.HUMIDITY){ + return humidityData; + } + return temperatureData; + } +} diff --git a/src/main/java/forestry/core/climate/ClimateEventHandler.java b/src/main/java/forestry/core/climate/ClimateEventHandler.java deleted file mode 100644 index 8edc51b6c..000000000 --- a/src/main/java/forestry/core/climate/ClimateEventHandler.java +++ /dev/null @@ -1,181 +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.core.climate; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import forestry.api.climate.IClimateRegion; -import forestry.api.core.ForestryAPI; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.World; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -public class ClimateEventHandler { - - private final Map serverTicks; - - public ClimateEventHandler() { - serverTicks = new HashMap<>(); - } - - //Climate test mode - /*public static Pair recalculateMinMaxCoords(Collection positions) { - BlockPos minimumCoord = new BlockPos(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); - BlockPos maximumCoord = new BlockPos(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); - - for (BlockPos position : positions) { - int minX = minimumCoord.getX(); - int minY = minimumCoord.getY(); - int minZ = minimumCoord.getZ(); - int maxX = maximumCoord.getX(); - int maxY = maximumCoord.getY(); - int maxZ = maximumCoord.getZ(); - if (position.getX() < minimumCoord.getX()) { - minX = position.getX(); - } - if (position.getX() > maximumCoord.getX()) { - maxX = position.getX(); - } - if (position.getY() < minimumCoord.getY()) { - minY = position.getY(); - } - if (position.getY() > maximumCoord.getY()) { - maxY = position.getY(); - } - if (position.getZ() < minimumCoord.getZ()) { - minZ = position.getZ(); - } - if (position.getZ() > maximumCoord.getZ()) { - maxZ = position.getZ(); - } - minimumCoord = new BlockPos(minX, minY, minZ); - maximumCoord = new BlockPos(maxX, maxY, maxZ); - } - return Pair.of(minimumCoord, maximumCoord); - } - - @SubscribeEvent - public void onWorldRenderLast(RenderWorldLastEvent event){ - try{ - Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer buffer = tessellator.getBuffer(); - float partialTicks = event.getPartialTicks(); - EntityPlayer entityplayer = Minecraft.getMinecraft().player; - double d0 = entityplayer.lastTickPosX + (entityplayer.posX - entityplayer.lastTickPosX) * partialTicks; - double d1 = entityplayer.lastTickPosY + (entityplayer.posY - entityplayer.lastTickPosY) * partialTicks; - double d2 = entityplayer.lastTickPosZ + (entityplayer.posZ - entityplayer.lastTickPosZ) * partialTicks; - GlStateManager.pushMatrix(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); - GlStateManager.disableTexture2D(); - GlStateManager.glLineWidth(5.0F); - World world = Minecraft.getMinecraft().world; - List regions = ForestryAPI.climateManager.getRegions().get(Integer.valueOf(world.provider.getDimension())); - for(IClimateRegion region : regions){ - if(region != null){ - Map positions = region.getPositions(); - Pair posPair = recalculateMinMaxCoords(positions.keySet()); - int deltaX = posPair.getRight().getX() - posPair.getLeft().getX(); - deltaX+=2; - int deltaZ = posPair.getRight().getZ() - posPair.getLeft().getZ(); - deltaZ+=3; - getClass(); - for(Entry positionEntry : positions.entrySet()){ - BlockPos pos = positionEntry.getKey(); - if(pos != null && world.isBlockLoaded(pos)){ - IClimatePosition position = positionEntry.getValue(); - float red = 1.0F; - float green = 1.0F; - float blue = 1.0F; - int offset = 0; - if(position.getTemperature() >= 2){ - green = 0F; - blue = 0F; - } - else if(position.getTemperature() > 1.75){ - green = 0.25F; - blue = 0.25F; - offset = 1; - } - else if(position.getTemperature() > 1.5){ - green = 0.5F; - blue = 0.5F; - offset = 2; - } - else if(position.getTemperature() > 1.25){ - green = 0.75F; - blue = 0.75F; - offset = 3; - } - else if(position.getTemperature() > 0.75){ - green = 0.25F; - red = 0.25F; - offset = 4; - } - else if(position.getTemperature() > 0.5){ - green = 0.5F; - red = 0.5F; - offset = 5; - } - else if(position.getTemperature() > 0.25){ - green = 0.75F; - red = 0.75F; - offset = 6; - } - event.getContext().drawSelectionBoundingBox(Block.FULL_BLOCK_AABB.offset(pos.getX() -d0, pos.getY() -d1, pos.getZ() -d2).offset(new BlockPos(deltaX - 1 * deltaX, 0, deltaZ)), red, green, blue, 0.35F); - event.getContext().renderFilledBox(Block.FULL_BLOCK_AABB.offset(pos.getX() -d0, pos.getY() -d1, pos.getZ() -d2).offset(new BlockPos(deltaX - 1 * deltaX, 0, deltaZ)), red, green, blue, 0.35F); - event.getContext().drawSelectionBoundingBox(Block.FULL_BLOCK_AABB.offset(pos.getX() -d0, pos.getY() -d1, pos.getZ() -d2).offset(new BlockPos(deltaX + offset * deltaX, 0, deltaZ)), red, green, blue, 0.35F); - event.getContext().renderFilledBox(Block.FULL_BLOCK_AABB.offset(pos.getX() -d0, pos.getY() -d1, pos.getZ() -d2).offset(new BlockPos(deltaX + offset * deltaX, 0, deltaZ)), red, green, blue, 0.35F); - } - } - } - } - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - GlStateManager.popMatrix(); - }catch(Exception e){ - - } - }*/ - - @SubscribeEvent() - public void onWorldUnload(WorldEvent.Unload unloadWorldEvent) { - ForestryAPI.climateManager.onWorldUnload(unloadWorldEvent.getWorld()); - } - - @SubscribeEvent - public void onWorldTick(TickEvent.WorldTickEvent event) { - World world = event.world; - if (event.phase == TickEvent.Phase.END) { - MinecraftServer server = world.getMinecraftServer(); - if (server != null) { - server.addScheduledTask(() -> { - if (!serverTicks.containsKey(world)) { - serverTicks.put(world, 1); - } - int ticks = serverTicks.get(world); - Map> regions = ForestryAPI.climateManager.getRegions(); - if (regions.containsKey(world)) { - for (IClimateRegion region : regions.get(world)) { - region.updateClimate(ticks); - } - } - serverTicks.put(world, ticks + 1); - }); - } - } - } - -} diff --git a/src/main/java/forestry/core/climate/ClimateFactory.java b/src/main/java/forestry/core/climate/ClimateFactory.java new file mode 100644 index 000000000..3751a3c3e --- /dev/null +++ b/src/main/java/forestry/core/climate/ClimateFactory.java @@ -0,0 +1,14 @@ +package forestry.core.climate; + +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateFactory; +import forestry.api.climate.IClimateHousing; + +public class ClimateFactory implements IClimateFactory{ + + @Override + public IClimateContainer createContainer(IClimateHousing climatedRegion) { + return new ClimateContainer(climatedRegion); + } + +} diff --git a/src/main/java/forestry/core/climate/ClimateInfo.java b/src/main/java/forestry/core/climate/ClimateInfo.java deleted file mode 100644 index 53be66e72..000000000 --- a/src/main/java/forestry/core/climate/ClimateInfo.java +++ /dev/null @@ -1,63 +0,0 @@ -package forestry.core.climate; - -import java.io.IOException; -import forestry.api.climate.IClimateInfo; -import forestry.core.network.PacketBufferForestry; -import net.minecraft.nbt.NBTTagCompound; - -public class ClimateInfo implements IClimateInfo{ - - public static final ClimateInfo MIN = new ClimateInfo(false); - public static final ClimateInfo MAX = new ClimateInfo(true); - - private final float temperature; - private final float humidity; - - private ClimateInfo(boolean isMax) { - if(isMax){ - this.temperature = 2.0F; - this.humidity = 2.0F; - }else{ - this.temperature = 0.0F; - this.humidity = 0.0F; - } - } - - public ClimateInfo(float temperature, float humidity) { - if (temperature > MAX.getTemperature()) { - temperature = MAX.getTemperature(); - } - if (humidity > MAX.getHumidity()) { - humidity = MAX.getHumidity(); - } - if (temperature < MIN.getTemperature()) { - temperature = MIN.getTemperature(); - } - if (humidity < MIN.getHumidity()) { - humidity = MIN.getHumidity(); - } - this.temperature = temperature; - this.humidity = humidity; - } - - public ClimateInfo(NBTTagCompound compound) { - this.temperature = compound.getFloat("Temperature"); - this.humidity = compound.getFloat("Humidity"); - } - - public ClimateInfo(PacketBufferForestry data) throws IOException { - this.temperature = data.readFloat(); - this.humidity = data.readFloat(); - } - - @Override - public float getTemperature() { - return temperature; - } - - @Override - public float getHumidity() { - return humidity; - } - -} diff --git a/src/main/java/forestry/core/climate/ClimateManager.java b/src/main/java/forestry/core/climate/ClimateManager.java index 625b0984f..9d60a90ea 100644 --- a/src/main/java/forestry/core/climate/ClimateManager.java +++ b/src/main/java/forestry/core/climate/ClimateManager.java @@ -10,154 +10,112 @@ ******************************************************************************/ package forestry.core.climate; -import java.util.ArrayList; +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; -import forestry.api.climate.IClimateInfo; -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.api.core.ForestryAPI; -import forestry.core.DefaultClimateProvider; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; + +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateManager; +import forestry.api.climate.IClimateProvider; +import forestry.api.climate.IClimateSourceOwner; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.core.ILocatable; +import forestry.api.greenhouse.Position2D; +import forestry.core.DefaultClimateProvider; +import forestry.core.utils.World2ObjectMap; public class ClimateManager implements IClimateManager { - protected final Map> regions; - private final Object regionsMutex; + private static final ClimateManager INSTANCE = new ClimateManager(); + + private static final Map BIOME_STATES = new HashMap<>(); + + private final World2ObjectMap managers; - public ClimateManager() { - regions = new HashMap<>(); - regionsMutex = new Object(); + private ClimateManager() { + managers = new World2ObjectMap(world->new ClimateWorldManager(this)); } - - @Override - public void addRegion(IClimateRegion region) { - synchronized (regionsMutex) { - World world = region.getWorld(); - if (!regions.containsKey(world)) { - this.regions.put(world, new ArrayList<>()); - } - List regions = this.regions.get(world); - if (!regions.contains(region)) { - if(!regions.isEmpty()){ - for (IClimatePosition pos : region.getPositions()) { - if (getRegionForPos(world, pos.getPos()) != null) { - return; - } - } - } - regions.add(region); - } - } - } - - @Override - public void removeRegion(IClimateRegion region) { - synchronized (regionsMutex) { - World world = region.getWorld(); - if (!regions.containsKey(world)) { - this.regions.put(world, new ArrayList<>()); - } - List regions = this.regions.get(world); - regions.remove(region); - } - } - - @Override - public void removeSource(IClimateSourceProvider source) { - synchronized (regionsMutex) { - World world = source.getWorldObj(); - if (!regions.containsKey(world)) { - regions.put(world, new ArrayList<>()); - } - IClimateRegion region = getRegionForPos(source.getWorldObj(), source.getCoordinates()); - if (region != null) { - if (region.getSources().contains(source.getClimateSource())) { - region.removeSource(source.getClimateSource()); - } - } - } - } - - @Override - public void addSource(IClimateSourceProvider source) { - synchronized (regionsMutex) { - World world = source.getWorldObj(); - if (!regions.containsKey(world)) { - regions.put(world, new ArrayList<>()); - } - IClimateRegion region = getRegionForPos(source.getWorldObj(), source.getCoordinates()); - if (region != null) { - if (!region.getSources().contains(source.getClimateSource())) { - region.addSource(source.getClimateSource()); - } - } - } + + public static ClimateManager getInstance(){ + return INSTANCE; } @Override - public IClimateInfo createInfo(float temperature, float humidity) { - return new ClimateInfo(temperature, humidity); + public ImmutableClimateState getBiomeState(World world, BlockPos pos) { + Biome biome = world.getBiome(pos); + return getBiomeState(biome); + } + + private ImmutableClimateState getBiomeState(Biome biome) { + if (!BIOME_STATES.containsKey(biome)) { + BIOME_STATES.put(biome, new ImmutableClimateState(biome.getTemperature(), biome.getRainfall())); + } + return BIOME_STATES.get(biome); } @Override - public IClimateInfo getInfo(World world, BlockPos pos) { - IClimatePosition position = ForestryAPI.climateManager.getPosition(world, pos); - - if (position != null) { - return position.getInfo(); + public IClimateState getClimateState(World world, BlockPos pos) { + ClimateWorldManager manager = managers.get(world); + if(manager == null){ + return getBiomeState(world, pos); } - return BiomeClimateInfo.getInfo(world.getBiome(pos)); + return manager.getClimateState(world, pos); } + @Nullable @Override - public Map> getRegions() { - return regions; - } - - @Override - public IClimatePosition getPosition(World world, BlockPos pos) { - if (!regions.containsKey(world)) { - regions.put(world, new ArrayList<>()); + public IClimateContainer getContainer(World world, BlockPos pos) { + ClimateWorldManager manager = managers.get(world); + if(manager == null){ return null; } - for (IClimateRegion region : regions.get(world)) { - IClimatePosition position = region.getPosition(pos); - if(position != null){ - return position; - } - } - return null; - } - - @Override - public IClimateRegion getRegionForPos(World world, BlockPos pos) { - if (!regions.containsKey(world)) { - this.regions.put(world, new ArrayList<>()); - } - List regions = this.regions.get(world); - for (IClimateRegion region : regions) { - if (region.getPosition(pos) != null) { - return region; - } - } - return null; + return manager.getContainer(world, pos); } - @Override - public void onWorldUnload(World world) { - regions.remove(world); + @Nullable + private IClimateContainer getContainer(ILocatable locatable){ + return getContainer(locatable.getWorldObj(), locatable.getCoordinates()); } @Override public IClimateProvider getDefaultClimate(World world, BlockPos pos) { return new DefaultClimateProvider(world, pos); } + + @Override + public void addSource(IClimateSourceOwner owner){ + World world = owner.getWorldObj(); + ClimateWorldManager manager = managers.get(world); + if(manager == null){ + return; + } + manager.addSource(owner); + } + + @Override + public void removeSource(IClimateSourceOwner owner){ + World world = owner.getWorldObj(); + ClimateWorldManager manager = managers.get(world); + if(manager == null){ + return; + } + manager.removeSource(owner); + } + + @Override + public Collection getSources(World world, Position2D position) { + ClimateWorldManager manager = managers.get(world); + if(manager == null){ + return Collections.emptyList(); + } + return manager.getSources(position); + } } diff --git a/src/main/java/forestry/core/climate/ClimatePosition.java b/src/main/java/forestry/core/climate/ClimatePosition.java deleted file mode 100644 index d095bd7ae..000000000 --- a/src/main/java/forestry/core/climate/ClimatePosition.java +++ /dev/null @@ -1,105 +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.core.climate; - -import forestry.api.climate.IClimateInfo; -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; - -public class ClimatePosition implements IClimatePosition { - protected final IClimateRegion region; - - protected final BlockPos pos; - protected float temperature; - protected float humidity; - - public ClimatePosition(IClimateRegion rRegion, BlockPos pos, NBTTagCompound nbtTag) { - this.region = rRegion; - this.pos = pos; - readFromNBT(nbtTag); - } - - public ClimatePosition(IClimateRegion region, BlockPos pos) { - Biome biome = region.getWorld().getBiome(pos); - this.region = region; - this.pos = pos; - this.temperature = biome.getTemperature(); - this.humidity = biome.getRainfall(); - } - - public ClimatePosition(IClimateRegion region, BlockPos pos, float temperature, float humidity) { - this.region = region; - this.pos = pos; - this.temperature = temperature; - this.humidity = humidity; - } - - @Override - public IClimateRegion getClimateRegion() { - return region; - } - - @Override - public BlockPos getPos() { - return pos; - } - - @Override - public void setTemperature(float temperature) { - this.temperature = temperature; - } - - @Override - public float getTemperature() { - return temperature; - } - - @Override - public void addTemperature(float temperature) { - setTemperature(getTemperature() + temperature); - } - - @Override - public void addHumidity(float humidity) { - setHumidity(getHumidity() + humidity); - } - - @Override - public void setHumidity(float humidity) { - this.humidity = humidity; - } - - @Override - public float getHumidity() { - return humidity; - } - - @Override - public IClimateInfo getInfo() { - return new ClimateInfo(temperature, humidity); - } - - @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; - } -} diff --git a/src/main/java/forestry/core/climate/ClimateRegion.java b/src/main/java/forestry/core/climate/ClimateRegion.java deleted file mode 100644 index 6cf30f15f..000000000 --- a/src/main/java/forestry/core/climate/ClimateRegion.java +++ /dev/null @@ -1,313 +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.core.climate; - -import java.io.IOException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import forestry.api.climate.IClimateInfo; -import forestry.api.climate.IClimatePosition; -import forestry.api.climate.IClimateRegion; -import forestry.api.climate.IClimateSource; -import forestry.core.network.IStreamable; -import forestry.core.network.PacketBufferForestry; -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; - -public class ClimateRegion implements IClimateRegion, IStreamable { - public static final float CLIMATE_CHANGE = 0.01F; - - protected final World world; - protected final IGreenhouseControllerInternal controller; - protected final Set positions; - protected final Set sources; - protected float temperature; - protected float humidity; - - public ClimateRegion(IGreenhouseControllerInternal controller, Set positions) { - this.world = controller.getWorldObj(); - this.controller = controller; - this.positions = positions; - this.sources = new HashSet<>(); - calculateAverageClimate(); - } - - /** - * Creates an empty region. - */ - public ClimateRegion(IGreenhouseControllerInternal controller) { - this.world = controller.getWorldObj(); - this.controller = controller; - this.positions = new HashSet<>(); - this.sources = new HashSet<>(); - } - - - public ClimateRegion(IGreenhouseControllerInternal controller, NBTTagCompound nbtTag) { - this.world = controller.getWorldObj(); - this.controller = controller; - this.positions = new HashSet<>(); - this.sources = new HashSet<>(); - readFromNBT(nbtTag); - calculateAverageClimate(); - } - - @Override - public void calculateAverageClimate(){ - humidity = 0.0F; - temperature = 0.0F; - if(!positions.isEmpty()){ - int positions = 0; - for (IClimatePosition position : this.positions) { - if (position != null) { - positions++; - humidity += position.getHumidity(); - temperature += position.getTemperature(); - } - } - - temperature /= positions; - humidity /= positions; - } - } - - @Override - public void updateClimate(int ticks) { - boolean hasChange = false; - for (IClimateSource source : sources) { - if (source != null) { - if (ticks % source.getTicksForChange(this) == 0) { - hasChange |= source.changeClimate(ticks, this); - } - } - } - if (ticks % getTicksPerUpdate() == 0) { - for (IClimatePosition position : positions) { - BlockPos pos = position.getPos(); - if (world.isBlockLoaded(pos)) { - hasChange |= updateSides(position); - if (!controller.isAssembled()) { - hasChange |= returnClimateToDefault(position); - } - } - } - } - if (hasChange) { - calculateAverageClimate(); - } - } - - protected boolean updateSides(IClimatePosition position) { - BlockPos pos = position.getPos(); - IClimateInfo climateInfo = getControl(pos); - boolean hasChange = false; - if (climateInfo.getTemperature() != temperature || climateInfo.getHumidity() != humidity) { - for (EnumFacing facing : EnumFacing.VALUES) { - IClimatePosition infoFace = getPosition(pos.offset(facing)); - if (infoFace != null) { - float infoTemp = infoFace.getTemperature(); - float infoHumid = infoFace.getHumidity(); - float posTemp = position.getTemperature(); - float posHumid = position.getHumidity(); - if (posTemp > infoTemp + CLIMATE_CHANGE) { - float change = Math.min(CLIMATE_CHANGE, posTemp - infoTemp); - position.addTemperature(-change); - infoFace.addTemperature(change); - hasChange = true; - } - if (posHumid > infoHumid + CLIMATE_CHANGE) { - float change = Math.min(CLIMATE_CHANGE, posHumid - infoHumid); - position.addHumidity(-change); - infoFace.addHumidity(change); - hasChange = true; - } - } - } - } - return hasChange; - } - - protected boolean returnClimateToDefault(IClimatePosition position){ - BlockPos pos = position.getPos(); - IClimateInfo climateInfo = getControl(pos); - boolean hasChange = false; - - float infoTemp = climateInfo.getTemperature(); - float infoHumid = climateInfo.getHumidity(); - float posTemp = position.getTemperature(); - float posHumid = position.getHumidity(); - if (posTemp != infoTemp) { - if (posTemp > infoTemp) { - position.addTemperature(-Math.min(CLIMATE_CHANGE, posTemp - infoTemp)); - hasChange = true; - } else { - position.addTemperature(Math.min(CLIMATE_CHANGE, infoTemp - posTemp)); - hasChange = true; - } - } - if (posHumid != infoHumid) { - if (posHumid > infoHumid) { - position.addHumidity(-Math.min(CLIMATE_CHANGE, posHumid - infoHumid)); - hasChange = true; - } else { - position.addHumidity(Math.min(CLIMATE_CHANGE, infoHumid - posHumid)); - hasChange = true; - } - } - return hasChange; - } - - protected IClimateInfo getControl(BlockPos pos) { - if (world.isBlockLoaded(pos)) { - if (!controller.isAssembled()) { - return BiomeClimateInfo.getInfo(world.getBiome(pos)); - } - } - return controller.getControlClimate(); - } - - @Override - public Collection getPositions() { - return positions; - } - - @Override - public IClimatePosition getPosition(BlockPos pos) { - for(IClimatePosition position : positions){ - if(position.getPos().equals(pos)){ - return position; - } - } - return null; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound nbt) { - NBTTagList positionList = new NBTTagList(); - for (IClimatePosition positon : positions) { - BlockPos pos = positon.getPos(); - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger("X", pos.getX()); - tag.setInteger("Y", pos.getY()); - tag.setInteger("Z", pos.getZ()); - positionList.appendTag(positon.writeToNBT(tag)); - } - nbt.setTag("Positions", positionList); - return nbt; - } - - @Override - public void readFromNBT(NBTTagCompound nbt) { - NBTTagList positionList = nbt.getTagList("Positions", 10); - for (int i = 0; i < positionList.tagCount(); i++) { - NBTTagCompound positionTag = positionList.getCompoundTagAt(i); - int xPos = positionTag.getInteger("X"); - int yPos = positionTag.getInteger("Y"); - int zPos = positionTag.getInteger("Z"); - BlockPos pos = new BlockPos(xPos, yPos, zPos); - IClimatePosition position = getPosition(pos); - if (position != null) { - position.readFromNBT(positionTag); - } else { - positions.add(new ClimatePosition(this, pos, positionTag)); - } - } - } - - @Override - public int getTicksPerUpdate() { - return 20; - } - - @Override - public World getWorld() { - return world; - } - - @Override - public synchronized void setPosition(BlockPos pos, float temperature, float humidity) { - IClimatePosition position = getPosition(pos); - if (position != null) { - position.setHumidity(humidity); - position.setTemperature(temperature); - } else { - positions.add(new ClimatePosition(this, pos, temperature, humidity)); - } - } - - @Override - public synchronized void addSource(IClimateSource source) { - if (!sources.contains(source)) { - sources.add(source); - } - } - - @Override - public synchronized void removeSource(IClimateSource source) { - if (sources.contains(source)) { - sources.remove(source); - } - } - - @Override - public Collection getSources() { - return sources; - } - - @Override - public void writeData(PacketBufferForestry data) { - if (!positions.isEmpty()) { - data.writeInt(positions.size()); - data.writeFloat(temperature); - data.writeFloat(humidity); - } else { - data.writeInt(0); - } - } - - @Override - public void readData(PacketBufferForestry data) throws IOException { - int size = data.readInt(); - if (size != 0) { - temperature = data.readFloat(); - humidity = data.readFloat(); - } - } - - @Override - public float getAverageTemperature() { - return temperature; - } - - @Override - public float getAverageHumidity() { - return humidity; - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof ClimateRegion)){ - return false; - } - ClimateRegion region = (ClimateRegion) obj; - if(region.controller != controller){ - return false; - } - return true; - } - -} diff --git a/src/main/java/forestry/core/climate/ClimateSource.java b/src/main/java/forestry/core/climate/ClimateSource.java index b8e78a17c..aa9c4b701 100644 --- a/src/main/java/forestry/core/climate/ClimateSource.java +++ b/src/main/java/forestry/core/climate/ClimateSource.java @@ -12,37 +12,195 @@ package forestry.core.climate; import javax.annotation.Nullable; -import forestry.api.climate.IClimateRegion; +import net.minecraft.world.World; + +import forestry.api.climate.ClimateChange; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; import forestry.api.climate.IClimateSource; -import forestry.api.climate.IClimateSourceProvider; +import forestry.api.climate.IClimateSourceOwner; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.core.ForestryAPI; -public abstract class ClimateSource

implements IClimateSource { - @Nullable - protected P provider; - protected final int ticksForChange; +public abstract class ClimateSource implements IClimateSource { + + protected O owner; + protected float change; + protected final float range; + protected final ClimateSourceType sourceType; + protected ClimateSourceMode temperatureMode; + protected ClimateSourceMode humidityMode; + protected IClimateContainer container; + protected boolean addedToManager; + protected boolean isActive; - public ClimateSource(int ticksForChange) { - this.ticksForChange = ticksForChange; + public ClimateSource(float change, float range, ClimateSourceType sourceType) { + this.change = change; + this.range = range; + this.sourceType = sourceType; + this.temperatureMode = ClimateSourceMode.NONE; + this.humidityMode = ClimateSourceMode.NONE; } - - public void setProvider(P provider) { - this.provider = provider; + + public void setHumidityMode(ClimateSourceMode humidityMode) { + this.humidityMode = humidityMode; + } + + public void setTemperatureMode(ClimateSourceMode temperatureMode) { + this.temperatureMode = temperatureMode; + } + + public void setOwner(O owner) { + this.owner = owner; + } + + @Override + public float getBoundaryModifier(ClimateType type, boolean boundaryUp) { + if(type == ClimateType.HUMIDITY){ + if(humidityMode == ClimateSourceMode.POSITIVE && boundaryUp){ + return getRange(ClimateType.HUMIDITY); + }else if(humidityMode == ClimateSourceMode.NEGATIVE && !boundaryUp){ + return getRange(ClimateType.HUMIDITY); + } + }else { + if(temperatureMode == ClimateSourceMode.POSITIVE && boundaryUp){ + return getRange(ClimateType.TEMPERATURE); + }else if(temperatureMode == ClimateSourceMode.NEGATIVE && !boundaryUp){ + return getRange(ClimateType.TEMPERATURE); + } + } + return 0; + } + + protected float getRange(ClimateType type){ + return range; + } + + protected float getChange(ClimateType type) { + return change; + } + + @Override + public boolean isActive() { + return isActive; + } + + @Override + public boolean affectClimateType(ClimateType type) { + return sourceType.affectClimateType(type); } @Override - public boolean changeClimate(int tickCount, IClimateRegion region) { + public IClimateSourceOwner getOwner() { + return owner; + } + + @Override + public void onAdded(IClimateContainer container) { + this.container = container; + } + + @Override + public void onRemoved(IClimateContainer container) { + this.container = null; + } + + public void update() { + if(!addedToManager){ + onLoad(); + } + } + + public void onLoad() { + World world = owner.getWorldObj(); + if(!addedToManager && !world.isRemote) { + ForestryAPI.climateManager.addSource(owner); + } + + } + + public void invalidate() { + this.onChunkUnload(); + } + + public void onChunkUnload() { + World world = owner.getWorldObj(); + if(addedToManager &&!world.isRemote) { + ForestryAPI.climateManager.removeSource(owner); + } + + } + + @Override + public ClimateChange work(IClimateState state, ImmutableClimateState target) { + beforeWork(); + ClimateSourceType validType = getValidType(state, target); + if(validType == null){ + isNotValid(); + isActive = false; + return ClimateChange.ORIGIN; + } + if(!canWork(state, target)){ + isActive = false; + return ClimateChange.ORIGIN; + } + removeResources(state, target); + isActive = true; + return getChange(validType, state, target); + } + + protected void isNotValid(){ + + } + + protected void beforeWork(){ + } + + /** + * @param state the {@link IClimateState} that the source has to work on. + * @param target the by the {@link IClimateContainer} targeted {@link IClimateState}. + * + * @return true if the source can work, false if it can not. + */ + protected abstract boolean canWork(IClimateState state, ImmutableClimateState target); + + protected abstract void removeResources(IClimateState state, ImmutableClimateState target); + + protected abstract ClimateChange getChange(ClimateSourceType type, IClimateState state, ImmutableClimateState target); + + @Nullable + private ClimateSourceType getValidType(IClimateState state, ImmutableClimateState target){ + boolean canChangeHumidity = false; + boolean canChangeTemperature = false; + if(sourceType.canChangeHumidity()){ + if(canChange(state.getHumidity(), target.getHumidity(), humidityMode)){ + canChangeHumidity = true; + } + } + if(sourceType.canChangeTemperature()){ + if(canChange(state.getTemperature(), target.getTemperature(), temperatureMode)){ + canChangeTemperature = true; + } + } + if(canChangeHumidity){ + if(canChangeTemperature){ + return ClimateSourceType.BOTH; + } + return ClimateSourceType.HUMIDITY; + }else if(canChangeTemperature){ + return ClimateSourceType.TEMPERATURE; + } + return null; + } + + private boolean canChange(float value, float target, ClimateSourceMode mode){ + if(mode == ClimateSourceMode.POSITIVE && value < target){ + return true; + }else if(mode == ClimateSourceMode.NEGATIVE && value > target){ + return true; + } return false; } - @Override - public int getTicksForChange(IClimateRegion region) { - return ticksForChange; - } - - @Override - @Nullable - public IClimateSourceProvider getProvider() { - return provider; - } - } diff --git a/src/main/java/forestry/core/climate/ClimateSourceMode.java b/src/main/java/forestry/core/climate/ClimateSourceMode.java new file mode 100644 index 000000000..47c82c0e3 --- /dev/null +++ b/src/main/java/forestry/core/climate/ClimateSourceMode.java @@ -0,0 +1,7 @@ +package forestry.core.climate; + +public enum ClimateSourceMode { + + POSITIVE, NEGATIVE, NONE; + +} diff --git a/src/main/java/forestry/core/climate/ClimateSourceType.java b/src/main/java/forestry/core/climate/ClimateSourceType.java new file mode 100644 index 000000000..868275a87 --- /dev/null +++ b/src/main/java/forestry/core/climate/ClimateSourceType.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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.ClimateType; +import forestry.api.climate.IClimateSource; +import forestry.api.climate.IClimateState; + +/** + * The possible types of the {@link IClimateSource}. Which values the {@link IClimateSource} changes in a {@link IClimateState}. + */ +public enum ClimateSourceType { + + TEMPERATURE{ + + @Override + public boolean canChangeHumidity() { + return false; + } + + @Override + public boolean canChangeTemperature() { + return true; + } + }, HUMIDITY{ + + @Override + public boolean canChangeHumidity() { + return true; + } + + @Override + public boolean canChangeTemperature() { + return false; + } + }, BOTH{ + + @Override + public boolean canChangeHumidity() { + return true; + } + + @Override + public boolean canChangeTemperature() { + return true; + } + }; + + public boolean affectClimateType(ClimateType type){ + return this == BOTH || type == ClimateType.HUMIDITY && this == HUMIDITY || type == ClimateType.TEMPERATURE && this == TEMPERATURE; + } + + /** + * @return true if this sourceType can change the temperature on a {@link IClimateState}, false if can not. + */ + public abstract boolean canChangeTemperature(); + + /** + * @return true if this sourceType can change the humidity on a {@link IClimateState}, false if can not. + */ + public abstract boolean canChangeHumidity(); + +} diff --git a/src/main/java/forestry/core/climate/ClimateWorldManager.java b/src/main/java/forestry/core/climate/ClimateWorldManager.java new file mode 100644 index 000000000..5bfd38501 --- /dev/null +++ b/src/main/java/forestry/core/climate/ClimateWorldManager.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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 com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateSourceOwner; +import forestry.api.climate.IClimateState; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.greenhouse.Position2D; +import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; + +public class ClimateWorldManager{ + + private final Set containers; + private final Cache stateCache; + private final ClimateManager parent; + private final Map> owners; + + public ClimateWorldManager(ClimateManager parent) { + this.containers = new HashSet<>(); + this.stateCache = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.SECONDS).build(); + this.parent = parent; + this.owners = new HashMap<>(); + } + + public IClimateState getClimateState(World world, BlockPos pos) { + IClimateState cacheState = stateCache.getIfPresent(pos); + if(cacheState == null){ + IClimateContainer container = getContainer(world, pos); + + if (container != null) { + cacheState = container.getState(); + } + if(cacheState == null){ + cacheState = parent.getBiomeState(world, pos); + } + stateCache.put(pos, cacheState); + } + return cacheState; + } + + public IClimateContainer getContainer(World world, BlockPos pos) { + IGreenhouseBlock logicBlock = GreenhouseBlockManager.getInstance().getBlock(world, pos); + if(logicBlock != null){ + IGreenhouseProvider provider = logicBlock.getProvider(); + if(!provider.isClosed()) { + return null; + } + return provider.getClimateContainer(); + } + return null; + } + + public Set getContainers() { + return containers; + } + + public void addSource(IClimateSourceOwner owner){ + BlockPos pos = owner.getCoordinates(); + Position2D position = new Position2D(pos); + Map positionedOwners = owners.computeIfAbsent(position, k->new HashMap<>()); + positionedOwners.put(pos.getY(), owner); + } + + public void removeSource(IClimateSourceOwner owner){ + BlockPos pos = owner.getCoordinates(); + Position2D position = new Position2D(pos); + Map positionedOwners = owners.computeIfAbsent(position, k->new HashMap<>()); + positionedOwners.remove(pos.getY()); + } + + public Collection getSources(Position2D position) { + Map positionedOwners = owners.get(position); + if(positionedOwners == null){ + return Collections.emptyList(); + } + return positionedOwners.values(); + } + +} \ No newline at end of file diff --git a/src/main/java/forestry/core/climate/ClimatiserDefinition.java b/src/main/java/forestry/core/climate/ClimatiserDefinition.java deleted file mode 100644 index bee37fe6c..000000000 --- a/src/main/java/forestry/core/climate/ClimatiserDefinition.java +++ /dev/null @@ -1,51 +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.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 float range; - protected final EnumClimatiserTypes type; - - public ClimatiserDefinition(float change, EnumClimatiserModes mode, float range, EnumClimatiserTypes type) { - this.change = change; - this.mode = mode; - this.range = range; - this.type = type; - } - - @Override - public float getChange() { - return change; - } - - @Override - public float getRange() { - return range; - } - - @Override - public EnumClimatiserTypes getType() { - return type; - } - - @Override - public EnumClimatiserModes getMode() { - return mode; - } - -} diff --git a/src/main/java/forestry/core/climate/package-info.java b/src/main/java/forestry/core/climate/package-info.java index 0b98471d5..3d2499456 100644 --- a/src/main/java/forestry/core/climate/package-info.java +++ b/src/main/java/forestry/core/climate/package-info.java @@ -6,4 +6,5 @@ package forestry.core.climate; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index 4ce247750..5d84e0a8e 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -26,6 +26,10 @@ import java.util.Properties; import java.util.Set; import net.minecraftforge.common.config.Property; + +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import forestry.Forestry; @@ -59,6 +63,11 @@ public class Config { //Humus public static int humusDegradeDelimiter = 3; + //Greenhouse + public static int climateSourceRange = 36; + public static int greenhouseSize = 4; + public static boolean showClimateTable = true; + // Genetics public static boolean pollinateVanillaTrees = true; public static float researchMutationBoostMultiplier = 1.5f; @@ -80,8 +89,6 @@ public class Config { // Performance public static boolean enableBackpackResupply = true; - //public static int planterThrottle = 10; - //public static int harvesterThrottle = 200; // Customization private static boolean craftingBronzeEnabled = true; @@ -137,17 +144,26 @@ public class Config { public static void load(Side side) { File configCommonFile = new File(Forestry.instance.getConfigFolder(), CATEGORY_COMMON + ".cfg"); - loadConfigCommon(side, configCommonFile); + configCommon = new LocalizedConfiguration(configCommonFile, "1.2.0"); + loadConfigCommon(side); File configFluidsFile = new File(Forestry.instance.getConfigFolder(), CATEGORY_FLUIDS + ".cfg"); - loadConfigFluids(configFluidsFile); + configFluid = new LocalizedConfiguration(configFluidsFile, "1.0.0"); + loadConfigFluids(); loadHints(); } - private static void loadConfigCommon(Side side, File configFileCommon) { + @SubscribeEvent + public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { + if (!event.getModID().equals(Constants.MOD_ID)) { + return; + } + loadConfigCommon(FMLCommonHandler.instance().getSide()); + loadConfigFluids(); + } - configCommon = new LocalizedConfiguration(configFileCommon, "1.2.0"); + private static void loadConfigCommon(Side side) { gameMode = configCommon.getStringLocalized("difficulty", "game.mode", "EASY", new String[]{"OP, EASY, NORMAL, HARD"}); @@ -219,12 +235,6 @@ public class Config { enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply); humusDegradeDelimiter = configCommon.getIntLocalized("tweaks.humus", "degradeDelimiter", humusDegradeDelimiter, 1, 10); - - //planterThrottle = configCommon.getIntLocalized("performance", "performance.planter", planterThrottle, 1, 2000); - //propThrottle.Comment = "higher numbers increase working speeds of planters but also increase cpu load."; - - //harvesterThrottle = configCommon.getIntLocalized("performance", "performance.harvester", harvesterThrottle, 1, 2000); - //propThrottle.Comment = "higher numbers increase working speeds of harvesters but also increase cpu load."; if (side == Side.CLIENT) { mailAlertEnabled = configCommon.getBooleanLocalized("tweaks.gui.mail.alert", "enabled", mailAlertEnabled); @@ -243,6 +253,10 @@ public class Config { enableExUtilEnderLily = configCommon.getBooleanLocalized("tweaks.farms", "enderlily", enableExUtilEnderLily); enableMagicalCropsSupport = configCommon.getBooleanLocalized("tweaks.farms", "magicalcrops", enableMagicalCropsSupport); + climateSourceRange = configCommon.getIntLocalized("tweaks.greenhouse", "range", climateSourceRange, 9, 270); + greenhouseSize = configCommon.getIntLocalized("tweaks.greenhouse", "size", greenhouseSize, 1, 5); + showClimateTable = configCommon.getBooleanLocalized("tweaks.greenhouse", "table", showClimateTable); + String[] availableStructures = new String[]{"alveary3x3", "farm3x3", "farm3x4", "farm3x5", "farm4x4", "farm5x5"}; String[] disabledStructureArray = disabledStructures.toArray(new String[disabledStructures.size()]); disabledStructureArray = configCommon.getStringListLocalized("structures", "disabled", disabledStructureArray, availableStructures); @@ -257,9 +271,7 @@ public class Config { configCommon.save(); } - private static void loadConfigFluids(File configFile) { - configFluid = new LocalizedConfiguration(configFile, "1.0.0"); - + private static void loadConfigFluids() { for (Fluids fluid : Fluids.values()) { String fluidName = Translator.translateToLocal("fluid." + fluid.getTag()); diff --git a/src/main/java/forestry/core/config/Constants.java b/src/main/java/forestry/core/config/Constants.java index 50518515c..5c12f0a75 100644 --- a/src/main/java/forestry/core/config/Constants.java +++ b/src/main/java/forestry/core/config/Constants.java @@ -10,10 +10,12 @@ ******************************************************************************/ package forestry.core.config; -import forestry.api.core.IForestryConstants; import net.minecraft.util.ResourceLocation; + import net.minecraftforge.fluids.Fluid; +import forestry.api.core.IForestryConstants; + public class Constants implements IForestryConstants { // System public static final String MOD_NAME = "Forestry"; diff --git a/src/main/java/forestry/core/gui/ContainerCamouflageSprayCan.java b/src/main/java/forestry/core/gui/ContainerCamouflageSprayCan.java deleted file mode 100644 index ff9cbbcf1..000000000 --- a/src/main/java/forestry/core/gui/ContainerCamouflageSprayCan.java +++ /dev/null @@ -1,12 +0,0 @@ -package forestry.core.gui; - -import forestry.core.inventory.ItemInventoryCamouflageSprayCan; -import net.minecraft.entity.player.InventoryPlayer; - -public class ContainerCamouflageSprayCan extends ContainerItemInventory { - - public ContainerCamouflageSprayCan(ItemInventoryCamouflageSprayCan inventory, InventoryPlayer playerInventory) { - super(inventory, playerInventory, 8, 84); - } - -} diff --git a/src/main/java/forestry/core/gui/GuiCamouflageSprayCan.java b/src/main/java/forestry/core/gui/GuiCamouflageSprayCan.java deleted file mode 100644 index 39b250bb6..000000000 --- a/src/main/java/forestry/core/gui/GuiCamouflageSprayCan.java +++ /dev/null @@ -1,34 +0,0 @@ -package forestry.core.gui; - -import forestry.api.core.CamouflageManager; -import forestry.core.config.Constants; -import forestry.core.gui.widgets.WidgetCamouflageSlot; -import forestry.core.inventory.ItemInventoryCamouflageSprayCan; -import forestry.core.render.ColourProperties; -import forestry.core.utils.Translator; -import net.minecraft.entity.player.EntityPlayer; - -public class GuiCamouflageSprayCan extends GuiForestry { - - public GuiCamouflageSprayCan(EntityPlayer player, ItemInventoryCamouflageSprayCan inventory) { - super(Constants.TEXTURE_PATH_GUI + "/camouflage_spray_can.png", new ContainerCamouflageSprayCan(inventory, player.inventory)); - - widgetManager.add(new WidgetCamouflageSlot(widgetManager, 80, 39, inventory, CamouflageManager.NONE)); - } - - @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, ColourProperties.INSTANCE.get("gui.title")); - bindTexture(textureFile); - } - - @Override - protected void addLedgers() { - - } - -} diff --git a/src/main/java/forestry/core/gui/GuiIdRegistry.java b/src/main/java/forestry/core/gui/GuiIdRegistry.java index 93860f0c2..7409acce7 100644 --- a/src/main/java/forestry/core/gui/GuiIdRegistry.java +++ b/src/main/java/forestry/core/gui/GuiIdRegistry.java @@ -26,7 +26,6 @@ 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; @@ -46,7 +45,13 @@ import forestry.factory.tiles.TileSqueezer; import forestry.factory.tiles.TileStill; import forestry.factory.tiles.TileWorktable; import forestry.farming.tiles.TileFarm; +import forestry.greenhouse.items.ItemCamouflageSprayCan; +import forestry.greenhouse.tiles.TileDehumidifier; +import forestry.greenhouse.tiles.TileFan; import forestry.greenhouse.tiles.TileGreenhouse; +import forestry.greenhouse.tiles.TileHeater; +import forestry.greenhouse.tiles.TileHumidifier; +import forestry.greenhouse.tiles.TileHygroregulator; import forestry.mail.items.ItemCatalogue; import forestry.mail.items.ItemLetter; import forestry.mail.tiles.TileMailbox; @@ -86,6 +91,11 @@ public class GuiIdRegistry { TileFarm.class, TileGreenhouse.class, + TileHeater.class, + TileFan.class, + TileHumidifier.class, + TileDehumidifier.class, + TileHygroregulator.class, TileEngineBiogas.class, TileEngineElectric.class, diff --git a/src/main/java/forestry/core/gui/tables/Table.java b/src/main/java/forestry/core/gui/tables/Table.java new file mode 100644 index 000000000..d38cfc935 --- /dev/null +++ b/src/main/java/forestry/core/gui/tables/Table.java @@ -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.gui.tables; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; + +public class Table { + private final List lines = new ArrayList<>(); + + public Table() { + } + + public Table(String title) { + lines.add(new TableTitle(title)); + } + + public Table addValueEntry(String textKey, String value) { + lines.add(new TableValueText(textKey + ": ", value)); + return this; + } + + public Table addCenteredEntry(String textKey) { + lines.add(new TableTextCentered(textKey)); + return this; + } + + public Table addEmptyEntry() { + lines.add(new TableEmptyLine()); + return this; + } + + public Table addEntry(TableEntry entry) { + lines.add(entry); + return this; + } + + public void draw(int x, int y, int fontColor, boolean drawBackground){ + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + int lineWidth = getLineWidth(); + int lineStart = x + 2; + int lineEnd = lineStart + lineWidth; + int rowTopY = y + 1; + + for (TableEntry entry : lines) { + int rowBottomY = rowTopY + entry.getHeight(fontRenderer) - 1; + entry.draw(fontRenderer, x, y, lineWidth, lineStart, lineEnd, rowTopY, rowBottomY, fontColor, drawBackground); + rowTopY += + entry.getHeight(fontRenderer) - 1; + } + } + + public Collection getEntrys() { + return lines; + } + + public int getHeight() { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + int height = 0; + for (TableEntry entry : lines) { + height += entry.getHeight(fontRenderer); + } + return height; + } + + public int getLineWidth() { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + int lineWidth = 0; + + for (TableEntry entry : lines) { + lineWidth = Math.max(entry.getLineWidth(fontRenderer), lineWidth); + } + + return lineWidth; + } +} diff --git a/src/main/java/forestry/core/gui/tables/TableEmptyLine.java b/src/main/java/forestry/core/gui/tables/TableEmptyLine.java new file mode 100644 index 000000000..423cbdb06 --- /dev/null +++ b/src/main/java/forestry/core/gui/tables/TableEmptyLine.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.gui.tables; + +import net.minecraft.client.gui.FontRenderer; + +class TableEmptyLine extends TableEntry { + @Override + public void draw(FontRenderer fontRenderer, int x, int y, int lineWidth, int lineStart, int lineEnd, int rowTopY, int rowBottomY, int fontColor, boolean drawBackground) { + } + + @Override + public int getLineWidth(FontRenderer fontRenderer) { + return 0; + } +} diff --git a/src/main/java/forestry/core/gui/tables/TableEntry.java b/src/main/java/forestry/core/gui/tables/TableEntry.java new file mode 100644 index 000000000..05e8113a4 --- /dev/null +++ b/src/main/java/forestry/core/gui/tables/TableEntry.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.gui.tables; + +import net.minecraft.client.gui.FontRenderer; + +public abstract class TableEntry { + public static final int TITLE_BACKGROUND = 1610612736; + public static final int DEFAULT_BACKGROUND = 1342177280; + public static final int DEFAULT_FONT = 553648127; + + public int getHeight(FontRenderer fontRenderer) { + return fontRenderer.FONT_HEIGHT + 1; + } + + public abstract int getLineWidth(FontRenderer fontRenderer); + + public abstract void draw(FontRenderer fontRenderer, int x, int y, int lineWidth, int lineStart, int lineEnd, int rowTopY, int rowBottomY, int fontColor, boolean drawBackground); +} diff --git a/src/main/java/forestry/core/gui/tables/TableText.java b/src/main/java/forestry/core/gui/tables/TableText.java new file mode 100644 index 000000000..8693f0f47 --- /dev/null +++ b/src/main/java/forestry/core/gui/tables/TableText.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.gui.tables; + +import net.minecraft.client.gui.FontRenderer; + +abstract class TableText extends TableEntry { + String text; + + public TableText(String text) { + this.text = text; + } + + @Override + public int getLineWidth(FontRenderer fontRenderer) { + return fontRenderer.getStringWidth(text); + } +} diff --git a/src/main/java/forestry/core/gui/tables/TableTextCentered.java b/src/main/java/forestry/core/gui/tables/TableTextCentered.java new file mode 100644 index 000000000..53011ec49 --- /dev/null +++ b/src/main/java/forestry/core/gui/tables/TableTextCentered.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.gui.tables; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; + +class TableTextCentered extends TableText { + public TableTextCentered(String text) { + super(text); + } + + @Override + public void draw(FontRenderer fontRenderer, int x, int y, int lineWidth, int lineStart, int lineEnd, int rowTopY, int rowBottomY, int fontColor, boolean drawBackground) { + if(drawBackground) { + Gui.drawRect(x, y + fontRenderer.FONT_HEIGHT, lineEnd, y, DEFAULT_BACKGROUND); + } + fontRenderer.drawString(text, lineStart + lineWidth / 2 - fontRenderer.getStringWidth(text) / 2, y + 1, fontColor); + } +} diff --git a/src/main/java/forestry/core/gui/tables/TableTitle.java b/src/main/java/forestry/core/gui/tables/TableTitle.java new file mode 100644 index 000000000..a06b41712 --- /dev/null +++ b/src/main/java/forestry/core/gui/tables/TableTitle.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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.gui.tables; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; + +class TableTitle extends TableText { + public TableTitle(String text) { + super(text); + } + + @Override + public void draw(FontRenderer fontRenderer, int x, int y, int lineWidth, int lineStart, int lineEnd, int rowTopY, int rowBottomY, int fontColor, boolean drawBackground) { + if(drawBackground) { + Gui.drawRect(x, rowBottomY - 1, lineEnd, y, TITLE_BACKGROUND); + Gui.drawRect(x, rowBottomY, lineEnd, rowBottomY - 1, DEFAULT_BACKGROUND); + } + fontRenderer.drawString(text, lineStart + lineWidth / 2 - fontRenderer.getStringWidth(text) / 2, y + 1, fontColor); + } +} \ No newline at end of file diff --git a/src/main/java/forestry/core/gui/tables/TableValueText.java b/src/main/java/forestry/core/gui/tables/TableValueText.java new file mode 100644 index 000000000..681f66a04 --- /dev/null +++ b/src/main/java/forestry/core/gui/tables/TableValueText.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.gui.tables; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; + +class TableValueText extends TableText { + String value; + + public TableValueText(String text, String value) { + super(text); + this.value = value; + } + + @Override + public void draw(FontRenderer fontRenderer, int x, int y, int lineWidth, int lineStart, int lineEnd, int rowTopY, int rowBottomY, int fontColor, boolean drawBackground) { + if(drawBackground) { + Gui.drawRect(x, rowBottomY, lineEnd, rowTopY, DEFAULT_BACKGROUND); + } + fontRenderer.drawString(text, lineStart, rowTopY, fontColor); + fontRenderer.drawString(value, lineEnd - fontRenderer.getStringWidth(value), rowTopY, fontColor); + } + + @Override + public int getLineWidth(FontRenderer fontRenderer) { + return fontRenderer.getStringWidth(text + value); + } +} diff --git a/src/main/java/forestry/core/inventory/ItemInventory.java b/src/main/java/forestry/core/inventory/ItemInventory.java index 27ba0c419..8a74b1bd2 100755 --- a/src/main/java/forestry/core/inventory/ItemInventory.java +++ b/src/main/java/forestry/core/inventory/ItemInventory.java @@ -102,6 +102,17 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate, } return parent; } + + @Nullable + protected EnumHand getHand(){ + for (EnumHand hand : EnumHand.values()) { + ItemStack held = player.getHeldItem(hand); + if (isSameItemInventory(held, parent)) { + return hand; + } + } + return null; + } private static boolean isSameItemInventory(ItemStack base, ItemStack comparison) { if (base.isEmpty() || comparison.isEmpty()) { diff --git a/src/main/java/forestry/core/inventory/ItemInventoryCamouflageSprayCan.java b/src/main/java/forestry/core/inventory/ItemInventoryCamouflageSprayCan.java deleted file mode 100644 index ed0655ff7..000000000 --- a/src/main/java/forestry/core/inventory/ItemInventoryCamouflageSprayCan.java +++ /dev/null @@ -1,57 +0,0 @@ -package forestry.core.inventory; - -import forestry.api.core.ICamouflageHandler; -import forestry.core.network.packets.CamouflageSelectionType; -import forestry.core.network.packets.PacketCamouflageSelectServer; -import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.NetworkUtil; -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 ItemStack.EMPTY; - } - - @Override - public boolean canHandleType(String type) { - return true; - } - - @Override - public boolean setCamouflageBlock(String type, ItemStack camouflageBlock, boolean sendClientUpdate) { - if (!ItemStackUtil.isIdenticalItem(camouflageBlock, getStackInSlot(0))) { - setInventorySlotContents(0, camouflageBlock); - - World world = player.world; - if (sendClientUpdate && world != null && world.isRemote) { - NetworkUtil.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.ITEM)); - } - return true; - } - return false; - } - - @Override - public BlockPos getCoordinates() { - return new BlockPos(player); - } - - @Override - public World getWorldObj() { - return null; - } -} diff --git a/src/main/java/forestry/core/items/ItemElectronTube.java b/src/main/java/forestry/core/items/ItemElectronTube.java index 88419e25e..dddd6cf05 100755 --- a/src/main/java/forestry/core/items/ItemElectronTube.java +++ b/src/main/java/forestry/core/items/ItemElectronTube.java @@ -17,6 +17,10 @@ import javax.annotation.Nullable; import java.util.Collection; import java.util.List; + +import java.util.Collection; +import java.util.List; + import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; @@ -25,6 +29,7 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -36,6 +41,8 @@ import forestry.core.circuits.SolderManager; import forestry.core.config.Config; import forestry.core.utils.Translator; +import forestry.core.utils.ItemTooltipUtil; + public class ItemElectronTube extends ItemOverlay { public ItemElectronTube() { @@ -57,7 +64,7 @@ public class ItemElectronTube extends ItemOverlay { } } } else { - list.add(TextFormatting.ITALIC + "<" + Translator.translateToLocal("for.gui.tooltip.tmi") + ">"); + ItemTooltipUtil.addShiftInformation(itemstack, world, list, flag); } } else { list.add("<" + Translator.translateToLocal("for.gui.noeffect") + ">"); diff --git a/src/main/java/forestry/core/items/ItemRegistryCore.java b/src/main/java/forestry/core/items/ItemRegistryCore.java index acbdfebf0..e854ac51c 100644 --- a/src/main/java/forestry/core/items/ItemRegistryCore.java +++ b/src/main/java/forestry/core/items/ItemRegistryCore.java @@ -10,12 +10,14 @@ ******************************************************************************/ package forestry.core.items; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.oredict.OreDictionary; + import forestry.api.core.Tabs; import forestry.core.circuits.ItemCircuitBoard; import forestry.core.genetics.ItemResearchNote; import forestry.core.utils.OreDictUtil; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; public class ItemRegistryCore extends ItemRegistry { /* Fertilizer */ @@ -87,9 +89,6 @@ public class ItemRegistryCore extends ItemRegistry { public final ItemForestry refractoryWax; public final ItemFruit fruits; - /* Camouflage */ - public final ItemCamouflageSprayCan camouflageSprayCan; - public ItemRegistryCore() { compost = registerItem(new ItemForestry(), "fertilizer_bio"); fertilizerCompound = registerItem(new ItemFertilizer(), "fertilizer_compound"); @@ -199,9 +198,6 @@ public class ItemRegistryCore extends ItemRegistry { ItemStack fruit = new ItemStack(fruits, 1, def.ordinal()); OreDictionary.registerOre(def.getOreDict(), fruit); } - - // CAMOUFLAGE - camouflageSprayCan = registerItem(new ItemCamouflageSprayCan(), "camouflage_spray_can"); } } diff --git a/src/main/java/forestry/core/models/ModelBlockCustom.java b/src/main/java/forestry/core/models/ModelBlockCustom.java new file mode 100644 index 000000000..e04faa4d7 --- /dev/null +++ b/src/main/java/forestry/core/models/ModelBlockCustom.java @@ -0,0 +1,146 @@ +package forestry.core.models; + +import java.util.Collections; +import java.util.List; + +import javax.annotation.Nullable; + +import com.google.common.base.Preconditions; + +import forestry.core.blocks.properties.UnlistedBlockAccess; +import forestry.core.blocks.properties.UnlistedBlockPos; +import net.minecraft.block.Block; +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; +import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public abstract class ModelBlockCustom implements IBakedModel { + @Nullable + private ItemOverrideList overrideList; + + protected final Class blockClass; + + @Nullable + protected IBakedModel blockModel; + @Nullable + protected IBakedModel itemModel; + + protected ModelBlockCustom(Class blockClass) { + this.blockClass = blockClass; + } + + protected IBakedModel bakeModel(IBlockState state, K key, B block) { + if (state instanceof IExtendedBlockState) { + IExtendedBlockState stateExtended = (IExtendedBlockState) state; + IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS); + BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS); + } + return blockModel = bakeBlock(block, key, false); + } + + protected IBakedModel getModel(IBlockState state) { + Preconditions.checkArgument(blockClass.isInstance(state.getBlock())); + + K worldKey = getWorldKey(state); + B block = blockClass.cast(state.getBlock()); + return bakeModel(state, worldKey, block); + } + + protected IBakedModel bakeModel(ItemStack stack, World world, K key) { + Block block = Block.getBlockFromItem(stack.getItem()); + Preconditions.checkArgument(blockClass.isInstance(block)); + B bBlock = blockClass.cast(block); + + return itemModel = bakeBlock(bBlock, key, true); + } + + protected IBakedModel getModel(ItemStack stack, World world) { + return bakeModel(stack, world, getInventoryKey(stack)); + } + + @Override + public List getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) { + Preconditions.checkNotNull(state); + IBakedModel model = getModel(state); + return model.getQuads(state, side, rand); + } + + @Override + public boolean isAmbientOcclusion() { + return (itemModel != null || blockModel != null) && + (blockModel != null ? blockModel.isAmbientOcclusion() : itemModel.isAmbientOcclusion()); + } + + @Override + public boolean isGui3d() { + return itemModel != null && itemModel.isGui3d(); + } + + @Override + public boolean isBuiltInRenderer() { + return (itemModel != null || blockModel != null) && + (blockModel != null ? blockModel.isBuiltInRenderer() : itemModel.isBuiltInRenderer()); + } + + @Override + public TextureAtlasSprite getParticleTexture() { + if (blockModel != null) { + return blockModel.getParticleTexture(); + } + return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite(); + } + + @Override + public ItemCameraTransforms getItemCameraTransforms() { + if (itemModel == null) { + return ItemCameraTransforms.DEFAULT; + } + return itemModel.getItemCameraTransforms(); + } + + protected ItemOverrideList createOverrides() { + return new DefaultItemOverrideList(); + } + + @Override + public ItemOverrideList getOverrides() { + if (overrideList == null) { + overrideList = createOverrides(); + } + return overrideList; + } + + protected abstract K getInventoryKey(ItemStack stack); + + protected abstract K getWorldKey(IBlockState state); + + protected abstract IBakedModel bakeBlock(B block, K key, boolean inventory); + + private class DefaultItemOverrideList extends ItemOverrideList { + public DefaultItemOverrideList() { + super(Collections.emptyList()); + } + + @Override + public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { + if (world == null) { + world = Minecraft.getMinecraft().world; + } + return getModel(stack, world); + } + } +} diff --git a/src/main/java/forestry/core/models/ModelBlockCustomCached.java b/src/main/java/forestry/core/models/ModelBlockCustomCached.java new file mode 100644 index 000000000..b8375aa5c --- /dev/null +++ b/src/main/java/forestry/core/models/ModelBlockCustomCached.java @@ -0,0 +1,68 @@ +package forestry.core.models; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public abstract class ModelBlockCustomCached extends ModelBlockCustom { + private static final Set CACHE_PROVIDERS = new HashSet<>(); + + private final Cache inventoryCache; + private final Cache worldCache; + + public static void clear() { + for (ModelBlockCustomCached modelBlockCached : CACHE_PROVIDERS) { + modelBlockCached.worldCache.invalidateAll(); + modelBlockCached.inventoryCache.invalidateAll(); + modelBlockCached.onClearCaches(); + } + } + + protected void onClearCaches(){ + + } + + protected ModelBlockCustomCached(Class blockClass) { + super(blockClass); + + worldCache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build(); + inventoryCache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build(); + + CACHE_PROVIDERS.add(this); + } + + @Override + protected IBakedModel getModel(IBlockState state) { + K key = getWorldKey(state); + + IBakedModel model = worldCache.getIfPresent(key); + if (model == null) { + model = super.getModel(state); + worldCache.put(key, model); + } + return model; + } + + @Override + protected IBakedModel getModel(ItemStack stack, World world) { + K key = getInventoryKey(stack); + + IBakedModel model = inventoryCache.getIfPresent(key); + if (model == null) { + model = bakeModel(stack, world, key); + inventoryCache.put(key, model); + } + return model; + } +} diff --git a/src/main/java/forestry/core/models/ModelBlockDefault.java b/src/main/java/forestry/core/models/ModelBlockDefault.java index dc373d392..66cbd9afb 100644 --- a/src/main/java/forestry/core/models/ModelBlockDefault.java +++ b/src/main/java/forestry/core/models/ModelBlockDefault.java @@ -119,7 +119,7 @@ public abstract class ModelBlockDefault implements IBakedMod return (itemModel != null || blockModel != null) && (blockModel != null ? blockModel.isBuiltInRenderer() : itemModel.isBuiltInRenderer()); } - + @Override public TextureAtlasSprite getParticleTexture() { if (blockModel != null) { @@ -128,7 +128,6 @@ public abstract class ModelBlockDefault implements IBakedMod return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite(); } - @Override public ItemCameraTransforms getItemCameraTransforms() { if (itemModel == null) { diff --git a/src/main/java/forestry/core/models/baker/ModelBaker.java b/src/main/java/forestry/core/models/baker/ModelBaker.java index ff79a0f5d..d9bbde3f8 100644 --- a/src/main/java/forestry/core/models/baker/ModelBaker.java +++ b/src/main/java/forestry/core/models/baker/ModelBaker.java @@ -14,9 +14,8 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import forestry.api.core.IModelBaker; -import forestry.api.core.IModelBakerModel; -import forestry.core.models.ModelManager; +import org.apache.commons.lang3.tuple.Pair; + import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -29,12 +28,18 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; + import net.minecraftforge.common.model.IModelState; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; + import org.lwjgl.util.vector.Vector3f; +import forestry.api.core.IModelBaker; +import forestry.api.core.IModelBakerModel; +import forestry.core.models.ModelManager; + /** * A model baker to make custom block models with more than one texture layer. */ @@ -48,6 +53,7 @@ public final class ModelBaker implements IModelBaker { private final List faces = new ArrayList<>(); private final List> bakedModels = new ArrayList<>(); + private final List> bakedModelsPost = new ArrayList<>(); protected final ModelBakerModel currentModel = new ModelBakerModel(ModelManager.getInstance().getDefaultBlockState()); @@ -103,6 +109,11 @@ public final class ModelBaker implements IModelBaker { this.bakedModels.add(Pair.of(state, model)); } + @Override + public void addBakedModelPost(@Nullable IBlockState state, IBakedModel model) { + this.bakedModelsPost.add(Pair.of(state, model)); + } + @Override public void addFace(EnumFacing facing, TextureAtlasSprite sprite) { if (sprite != Minecraft.getMinecraft().getTextureMapBlocks().missingImage) { @@ -123,6 +134,10 @@ public final class ModelBaker implements IModelBaker { currentModel.addModelQuads(bakedModel); } + for (Pair bakedModel : bakedModelsPost) { + currentModel.addModelQuadsPost(bakedModel); + } + for (ModelBakerFace face : faces) { EnumFacing facing = face.face; BlockFaceUV uvFace = new BlockFaceUV(UVS, 0); diff --git a/src/main/java/forestry/core/models/baker/ModelBakerModel.java b/src/main/java/forestry/core/models/baker/ModelBakerModel.java index af6e29b67..f70393981 100755 --- a/src/main/java/forestry/core/models/baker/ModelBakerModel.java +++ b/src/main/java/forestry/core/models/baker/ModelBakerModel.java @@ -34,6 +34,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.client.model.PerspectiveMapWrapper; import net.minecraftforge.common.model.IModelState; import net.minecraftforge.common.model.TRSRTransformation; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -53,6 +54,7 @@ public class ModelBakerModel implements IModelBakerModel { private final Map> faceQuads; private final List generalQuads; private final List> models; + private final List> modelsPost; private float[] rotation = getDefaultRotation(); private float[] translation = getDefaultTranslation(); @@ -60,6 +62,7 @@ public class ModelBakerModel implements IModelBakerModel { public ModelBakerModel(IModelState modelState) { models = new ArrayList<>(); + modelsPost = new ArrayList<>(); faceQuads = new EnumMap<>(EnumFacing.class); generalQuads = new ArrayList<>(); particleSprite = Minecraft.getMinecraft().getTextureMapBlocks().missingImage; @@ -72,8 +75,9 @@ public class ModelBakerModel implements IModelBakerModel { } } - private ModelBakerModel(List> models, Map> faceQuads, List generalQuads, boolean isGui3d, boolean isAmbientOcclusion, IModelState modelState, float[] rotation, float[] translation, float[] scale, TextureAtlasSprite particleSprite) { + private ModelBakerModel(List> models, List> modelsPost, Map> faceQuads, List generalQuads, boolean isGui3d, boolean isAmbientOcclusion, IModelState modelState, float[] rotation, float[] translation, float[] scale, TextureAtlasSprite particleSprite) { this.models = models; + this.modelsPost = modelsPost; this.faceQuads = faceQuads; this.generalQuads = generalQuads; this.isGui3d = isGui3d; @@ -181,6 +185,10 @@ public class ModelBakerModel implements IModelBakerModel { this.models.add(model); } + public void addModelQuadsPost(Pair model) { + this.modelsPost.add(model); + } + @Override public void addQuad(@Nullable EnumFacing facing, BakedQuad quad) { if (facing != null) { @@ -203,11 +211,17 @@ public class ModelBakerModel implements IModelBakerModel { quads.addAll(faceQuads.get(side)); } quads.addAll(generalQuads); + for (Pair model : this.modelsPost) { + List modelQuads = model.getRight().getQuads(model.getLeft(), side, rand); + if (!modelQuads.isEmpty()) { + quads.addAll(modelQuads); + } + } return quads; } public ModelBakerModel copy() { - return new ModelBakerModel(models, faceQuads, generalQuads, isGui3d, isAmbientOcclusion, modelState, rotation, translation, scale, particleSprite); + return new ModelBakerModel(models, modelsPost, faceQuads, generalQuads, isGui3d, isAmbientOcclusion, modelState, rotation, translation, scale, particleSprite); } @Override diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index 9ed7863c4..ea1468af7 100755 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -434,7 +434,7 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI return; } - if (onlyUpdateWhenAssembled() && this.assemblyState != AssemblyState.Assembled) { + if (this.assemblyState != AssemblyState.Assembled) { // Not assembled - don't run game logic return; } @@ -472,7 +472,11 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI * @return True if the multiblock should save data, i.e. its internal game state has changed. False otherwise. */ protected abstract boolean updateServer(int tickCount); - + + protected int getTickCount() { + return tickCount; + } + /** * Client-side update loop. Generally, this shouldn't do anything, but if you want * to do some interpolation or something, do it here. @@ -869,8 +873,4 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI private static boolean isInvalid(IMultiblockComponent part) { return part instanceof TileEntity && ((TileEntity) part).isInvalid(); } - - protected boolean onlyUpdateWhenAssembled() { - return true; - } } diff --git a/src/main/java/forestry/core/multiblock/MultiblockUtil.java b/src/main/java/forestry/core/multiblock/MultiblockUtil.java index 561cd0c77..01032f306 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockUtil.java +++ b/src/main/java/forestry/core/multiblock/MultiblockUtil.java @@ -10,16 +10,21 @@ ******************************************************************************/ package forestry.core.multiblock; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import forestry.api.multiblock.IMultiblockComponent; -import forestry.core.tiles.TileUtil; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; +import forestry.api.multiblock.IMultiblockComponent; +import forestry.api.multiblock.IMultiblockController; +import forestry.api.multiblock.IMultiblockLogic; +import forestry.core.tiles.TileUtil; + public class MultiblockUtil { /** * Returns an array containing references to neighboring IMultiblockComponent tile entities. @@ -52,4 +57,28 @@ public class MultiblockUtil { } return neighborParts; } + + @Nullable + public static C getComponent(IBlockAccess world, BlockPos pos, Class componentClass){ + return TileUtil.getTile(world, pos, componentClass); + } + + @Nullable + public static L getLogic(IBlockAccess world, BlockPos pos, Class componentClass){ + C component = getComponent(world, pos, componentClass); + if(component == null){ + return null; + } + return (L) component.getMultiblockLogic(); + } + + @Nullable + public static M getController(IBlockAccess world, BlockPos pos, Class componentClass){ + L logic = getLogic(world, pos, componentClass); + if(logic == null || !logic.isConnected()){ + return null; + } + return (M) logic.getController(); + } + } diff --git a/src/main/java/forestry/core/network/PacketBufferForestry.java b/src/main/java/forestry/core/network/PacketBufferForestry.java index 0eab65d6f..84d085015 100644 --- a/src/main/java/forestry/core/network/PacketBufferForestry.java +++ b/src/main/java/forestry/core/network/PacketBufferForestry.java @@ -4,17 +4,21 @@ import javax.annotation.Nullable; import java.io.IOException; import java.util.List; -import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.util.NonNullList; import net.minecraft.world.World; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; +import forestry.api.greenhouse.Position2D; + +import io.netty.buffer.ByteBuf; + public class PacketBufferForestry extends PacketBuffer { public PacketBufferForestry(ByteBuf wrapped) { super(wrapped); @@ -83,6 +87,15 @@ public class PacketBufferForestry extends PacketBuffer { return null; } + public void writePosition(Position2D position) { + writeInt(position.getX()); + writeInt(position.getZ()); + } + + public Position2D readPosition() { + return new Position2D(readInt(), readInt()); + } + public void writeEntityById(Entity entity) { writeVarInt(entity.getEntityId()); } @@ -110,6 +123,16 @@ public class PacketBufferForestry extends PacketBuffer { } return enumValues[ordinal]; } + + public void writeStreamable(@Nullable Object object) { + if (object != null && object instanceof IStreamable) { + IStreamable streamable = (IStreamable) object; + writeBoolean(true); + streamable.writeData(this); + } else { + writeBoolean(false); + } + } public void writeStreamable(@Nullable IStreamable streamable) { if (streamable != null) { diff --git a/src/main/java/forestry/core/network/PacketIdClient.java b/src/main/java/forestry/core/network/PacketIdClient.java index 2e6e1638e..4c6aff15c 100644 --- a/src/main/java/forestry/core/network/PacketIdClient.java +++ b/src/main/java/forestry/core/network/PacketIdClient.java @@ -13,10 +13,11 @@ package forestry.core.network; import javax.annotation.Nullable; -import forestry.core.network.packets.PacketHandlerDummyClient; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.core.network.packets.PacketHandlerDummyClient; + /** * Packets sent to the client from the server */ @@ -31,7 +32,6 @@ public enum PacketIdClient implements IPacketId { GUI_LAYOUT_SELECT, GUI_ENERGY, SOCKET_UPDATE, - CAMOUFLAGE_SELECTION, // Core Tile Entities TILE_FORESTRY_UPDATE, @@ -62,6 +62,11 @@ public enum PacketIdClient implements IPacketId { TRADING_ADDRESS_RESPONSE, LETTER_INFO_RESPONSE, POBOX_INFO_RESPONSE, + + // Greenhouse + GREENHOUSE_DATA, + UPDATE_CLIMATE, + CAMOUFLAGE_SELECTION, // JEI RECIPE_TRANSFER_UPDATE; diff --git a/src/main/java/forestry/core/network/PacketIdServer.java b/src/main/java/forestry/core/network/PacketIdServer.java index 14c95fb66..6422e0e10 100644 --- a/src/main/java/forestry/core/network/PacketIdServer.java +++ b/src/main/java/forestry/core/network/PacketIdServer.java @@ -24,8 +24,11 @@ public enum PacketIdServer implements IPacketId { PIPETTE_CLICK, CHIPSET_CLICK, SOLDERING_IRON_CLICK, + + // Greenhouse CAMOUFLAGE_SELECTION, - CLIMATE_CONTROL_UPDATE, + SELECT_CLIMATE_TARGETED, + GREENHOUSE_DATA_REQUEST, // JEI WORKTABLE_RECIPE_REQUEST, diff --git a/src/main/java/forestry/core/network/PacketRegistryCore.java b/src/main/java/forestry/core/network/PacketRegistryCore.java index 46248e368..c92300722 100644 --- a/src/main/java/forestry/core/network/PacketRegistryCore.java +++ b/src/main/java/forestry/core/network/PacketRegistryCore.java @@ -10,8 +10,9 @@ ******************************************************************************/ package forestry.core.network; -import forestry.core.network.packets.PacketCamouflageSelectClient; -import forestry.core.network.packets.PacketCamouflageSelectServer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.core.network.packets.PacketChipsetClick; import forestry.core.network.packets.PacketErrorUpdate; import forestry.core.network.packets.PacketErrorUpdateEntity; @@ -28,9 +29,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; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.core.network.packets.PacketUpdateClimate; public class PacketRegistryCore implements IPacketRegistry { @Override @@ -39,8 +38,6 @@ public class PacketRegistryCore implements IPacketRegistry { PacketIdServer.PIPETTE_CLICK.setPacketHandler(new PacketPipetteClick.Handler()); PacketIdServer.CHIPSET_CLICK.setPacketHandler(new PacketChipsetClick.Handler()); PacketIdServer.SOLDERING_IRON_CLICK.setPacketHandler(new PacketSolderingIronClick.Handler()); - PacketIdServer.CAMOUFLAGE_SELECTION.setPacketHandler(new PacketCamouflageSelectServer.Handler()); - PacketIdServer.CLIMATE_CONTROL_UPDATE.setPacketHandler(new PacketUpdateClimateControl.Handler()); } @Override @@ -58,6 +55,6 @@ public class PacketRegistryCore implements IPacketRegistry { PacketIdClient.FX_SIGNAL.setPacketHandler(new PacketFXSignal.Handler()); PacketIdClient.TANK_LEVEL_UPDATE.setPacketHandler(new PacketTankLevelUpdate.Handler()); PacketIdClient.GENOME_TRACKER_UPDATE.setPacketHandler(new PacketGenomeTrackerSync.Handler()); - PacketIdClient.CAMOUFLAGE_SELECTION.setPacketHandler(new PacketCamouflageSelectClient.Handler()); + PacketIdClient.UPDATE_CLIMATE.setPacketHandler(new PacketUpdateClimate.Handler()); } } diff --git a/src/main/java/forestry/core/network/packets/CamouflageSelectionType.java b/src/main/java/forestry/core/network/packets/CamouflageSelectionType.java deleted file mode 100644 index f39b81ad9..000000000 --- a/src/main/java/forestry/core/network/packets/CamouflageSelectionType.java +++ /dev/null @@ -1,8 +0,0 @@ -package forestry.core.network.packets; - -public enum CamouflageSelectionType { - TILE, MULTIBLOCK, ITEM; - - public static final CamouflageSelectionType[] VALUES = values(); - -} diff --git a/src/main/java/forestry/core/network/packets/PacketCamouflageSelectServer.java b/src/main/java/forestry/core/network/packets/PacketCamouflageSelectServer.java deleted file mode 100644 index d413c0f2d..000000000 --- a/src/main/java/forestry/core/network/packets/PacketCamouflageSelectServer.java +++ /dev/null @@ -1,99 +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.core.network.packets; - -import java.io.IOException; - -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.ForestryPacket; -import forestry.core.network.IForestryPacketHandlerServer; -import forestry.core.network.IForestryPacketServer; -import forestry.core.network.PacketBufferForestry; -import forestry.core.network.PacketIdServer; -import forestry.core.tiles.TileUtil; -import forestry.core.utils.NetworkUtil; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; - -public class PacketCamouflageSelectServer extends ForestryPacket implements IForestryPacketServer { - private final BlockPos pos; - private final ItemStack camouflageStack; - private final String camouflageType; - private final CamouflageSelectionType selectionType; - - public PacketCamouflageSelectServer(ICamouflageHandler handler, String camouflageType, CamouflageSelectionType selectionType) { - this.pos = 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(PacketBufferForestry data) throws IOException { - data.writeBlockPos(pos); - data.writeShort(selectionType.ordinal()); - data.writeString(camouflageType); - data.writeItemStack(camouflageStack); - } - - public static class Handler implements IForestryPacketHandlerServer { - - @Override - public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException { - BlockPos pos = data.readBlockPos(); - CamouflageSelectionType selectionType = CamouflageSelectionType.values()[data.readShort()]; - String camouflageType = data.readString(); - ItemStack camouflageStack = data.readItemStack(); - - TileEntity tile = TileUtil.getTile(player.world, pos); - 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.isEmpty()) { - handler = itemInventoryCamouflageSprayCan; - } - } - } - - if (handler != null) { - if (handler.setCamouflageBlock(camouflageType, camouflageStack, true) && selectionType != CamouflageSelectionType.ITEM) { - NetworkUtil.sendNetworkPacket(new PacketCamouflageSelectClient(handler, camouflageType, selectionType), pos, player.world); - } - } - } - } -} diff --git a/src/main/java/forestry/core/network/packets/PacketUpdateClimate.java b/src/main/java/forestry/core/network/packets/PacketUpdateClimate.java new file mode 100644 index 000000000..f7961d400 --- /dev/null +++ b/src/main/java/forestry/core/network/packets/PacketUpdateClimate.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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.util.math.BlockPos; + +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateHousing; +import forestry.core.climate.ClimateContainer; +import forestry.core.network.ForestryPacket; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.IForestryPacketHandlerClient; +import forestry.core.network.IStreamable; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.PacketIdClient; +import forestry.core.tiles.TileUtil; + +public class PacketUpdateClimate extends ForestryPacket implements IForestryPacketClient { + + BlockPos pos; + ClimateContainer container; + + public PacketUpdateClimate(BlockPos pos, ClimateContainer container) { + this.pos = pos; + this.container = container; + } + + @Override + public PacketIdClient getPacketId() { + return PacketIdClient.UPDATE_CLIMATE; + } + + @Override + protected void writeData(PacketBufferForestry data) throws IOException { + data.writeBlockPos(pos); + container.writeData(data); + } + + public static class Handler implements IForestryPacketHandlerClient { + @Override + public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { + BlockPos position = data.readBlockPos(); + IClimateHousing housing = TileUtil.getTile(player.world, position, IClimateHousing.class); + if(housing != null){ + IClimateContainer container = housing.getClimateContainer(); + if(container != null && container instanceof IStreamable){ + IStreamable streamable = (IStreamable) container; + streamable.readData(data); + IClimateHousing parent = container.getParent(); + parent.onUpdateClimate(); + } + } + } + } +} diff --git a/src/main/java/forestry/core/network/packets/PacketUpdateClimateControl.java b/src/main/java/forestry/core/network/packets/PacketUpdateClimateControl.java deleted file mode 100644 index 28a2fcde9..000000000 --- a/src/main/java/forestry/core/network/packets/PacketUpdateClimateControl.java +++ /dev/null @@ -1,66 +0,0 @@ -package forestry.core.network.packets; - -import java.io.IOException; - -import forestry.api.climate.IClimateControlProvider; -import forestry.api.climate.IClimateInfo; -import forestry.api.multiblock.IMultiblockComponent; -import forestry.api.multiblock.IMultiblockLogic; -import forestry.core.climate.ClimateInfo; -import forestry.core.network.ForestryPacket; -import forestry.core.network.IForestryPacketHandlerServer; -import forestry.core.network.IForestryPacketServer; -import forestry.core.network.PacketBufferForestry; -import forestry.core.network.PacketIdServer; -import forestry.core.tiles.TileUtil; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; - -public class PacketUpdateClimateControl extends ForestryPacket implements IForestryPacketServer { - private final BlockPos pos; - private final IClimateInfo climateInfo; - - public PacketUpdateClimateControl(IClimateControlProvider provider) { - pos = provider.getCoordinates(); - - climateInfo = provider.getControlClimate(); - } - - @Override - public PacketIdServer getPacketId() { - return PacketIdServer.CLIMATE_CONTROL_UPDATE; - } - - @Override - protected void writeData(PacketBufferForestry data) throws IOException { - data.writeBlockPos(pos); - data.writeFloat(climateInfo.getTemperature()); - data.writeFloat(climateInfo.getHumidity()); - } - - public static class Handler implements IForestryPacketHandlerServer { - @Override - public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException { - BlockPos pos = data.readBlockPos(); - float tmperature = data.readFloat(); - float humidity = data.readFloat(); - - TileEntity tile = TileUtil.getTile(player.world, pos); - IClimateControlProvider 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(); - } - } else if (tile instanceof IClimateControlProvider) { - control = (IClimateControlProvider) tile; - } - - if (control != null) { - control.setControlClimate(new ClimateInfo(tmperature, humidity)); - } - } - } -} diff --git a/src/main/java/forestry/core/proxy/ProxyClient.java b/src/main/java/forestry/core/proxy/ProxyClient.java index d8087a1c0..907104006 100644 --- a/src/main/java/forestry/core/proxy/ProxyClient.java +++ b/src/main/java/forestry/core/proxy/ProxyClient.java @@ -12,20 +12,23 @@ package forestry.core.proxy; import java.io.File; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; + +import net.minecraftforge.common.MinecraftForge; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.core.TickHandlerCoreClient; import forestry.core.models.ModelManager; import forestry.core.multiblock.MultiblockClientTickHandler; import forestry.core.multiblock.MultiblockEventHandlerClient; import forestry.core.render.TextureManagerForestry; import forestry.core.worldgen.WorldGenerator; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; @SuppressWarnings("unused") @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/core/recipes/HygroregulatorRecipe.java b/src/main/java/forestry/core/recipes/HygroregulatorRecipe.java new file mode 100644 index 000000000..b8a44bf9d --- /dev/null +++ b/src/main/java/forestry/core/recipes/HygroregulatorRecipe.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.recipes; + +import net.minecraftforge.fluids.FluidStack; + +public class HygroregulatorRecipe { + public final FluidStack liquid; + public final int transferTime; + public final float humidChange; + public final float tempChange; + + public HygroregulatorRecipe(FluidStack liquid, int transferTime, float humidChange, float tempChange) { + this.liquid = liquid; + this.transferTime = transferTime; + this.humidChange = humidChange; + this.tempChange = tempChange; + } +} diff --git a/src/main/java/forestry/core/recipes/jei/ForestryRecipeCategory.java b/src/main/java/forestry/core/recipes/jei/ForestryRecipeCategory.java index 83690fed0..8a6825d7a 100644 --- a/src/main/java/forestry/core/recipes/jei/ForestryRecipeCategory.java +++ b/src/main/java/forestry/core/recipes/jei/ForestryRecipeCategory.java @@ -2,6 +2,7 @@ package forestry.core.recipes.jei; import forestry.core.config.Constants; import forestry.core.utils.Translator; + import mezz.jei.api.gui.IDrawable; import mezz.jei.api.recipe.IRecipeCategory; import mezz.jei.api.recipe.IRecipeWrapper; diff --git a/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java b/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java index 2be1954b3..76d5e9b2f 100644 --- a/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java +++ b/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java @@ -1,14 +1,17 @@ package forestry.core.recipes.jei; +import com.google.common.collect.ArrayListMultimap; + import java.text.NumberFormat; import java.util.List; -import com.google.common.collect.ArrayListMultimap; -import forestry.core.utils.Translator; -import mezz.jei.api.gui.ITooltipCallback; import net.minecraft.item.ItemStack; import net.minecraft.util.text.TextFormatting; +import forestry.core.utils.Translator; + +import mezz.jei.api.gui.ITooltipCallback; + public class ForestryTooltipCallback implements ITooltipCallback { private final ArrayListMultimap tooltips = ArrayListMultimap.create(); @@ -21,6 +24,10 @@ public class ForestryTooltipCallback implements ITooltipCallback { } } + public void addFortuneTooltip(int index) { + tooltips.get(index).add(TextFormatting.GRAY + Translator.translateToLocalFormatted("for.jei.fortune")); + } + public void addChanceTooltip(int index, float chance) { if (chance < 0) { chance = 0; diff --git a/src/main/java/forestry/core/render/ParticleRender.java b/src/main/java/forestry/core/render/ParticleRender.java index 47009b185..f194230ed 100755 --- a/src/main/java/forestry/core/render/ParticleRender.java +++ b/src/main/java/forestry/core/render/ParticleRender.java @@ -159,4 +159,16 @@ public class ParticleRender { effectRenderer.addEffect(particle); } } + + public static void addEntityBiodustFX(World world, double x, double y, double z){ + if (!shouldSpawnParticle(world)) { + return; + } + + ParticleManager effectRenderer = Minecraft.getMinecraft().effectRenderer; + Particle particle = effectRenderer.spawnEffectParticle(EnumParticleTypes.VILLAGER_HAPPY.ordinal(), x, y, z, 0, 0, 0); + if (particle != null) { + effectRenderer.addEffect(particle); + } + } } diff --git a/src/main/java/forestry/core/render/TextureManagerForestry.java b/src/main/java/forestry/core/render/TextureManagerForestry.java index 1acc1174e..abdf135b3 100644 --- a/src/main/java/forestry/core/render/TextureManagerForestry.java +++ b/src/main/java/forestry/core/render/TextureManagerForestry.java @@ -13,10 +13,6 @@ package forestry.core.render; import java.util.ArrayList; import java.util.List; -import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpriteRegister; -import forestry.api.core.ITextureManager; -import forestry.core.config.Constants; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -24,9 +20,15 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.api.core.ForestryAPI; +import forestry.api.core.ISpriteRegister; +import forestry.api.core.ITextureManager; +import forestry.core.config.Constants; + @SideOnly(Side.CLIENT) public class TextureManagerForestry implements ITextureManager { public static final ResourceLocation LOCATION_FORESTRY_TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/atlas/gui"); @@ -53,7 +55,7 @@ public class TextureManagerForestry implements ITextureManager { public static void initDefaultSprites() { String[] defaultIconNames = new String[]{"habitats/desert", "habitats/end", "habitats/forest", "habitats/hills", "habitats/jungle", "habitats/mushroom", "habitats/nether", "habitats/ocean", "habitats/plains", "habitats/snow", "habitats/swamp", "habitats/taiga", - "misc/access.shared", "misc/energy", "misc/hint", + "misc/access.shared", "misc/energy", "misc/hint", "misc/humidity", "misc/temperature", "analyzer/anything", "analyzer/bee", "analyzer/cave", "analyzer/closed", "analyzer/drone", "analyzer/flyer", "analyzer/item", "analyzer/nocturnal", "analyzer/princess", "analyzer/pure_breed", "analyzer/pure_cave", "analyzer/pure_flyer", "analyzer/pure_nocturnal", "analyzer/queen", diff --git a/src/main/java/forestry/core/utils/CamouflageUtil.java b/src/main/java/forestry/core/utils/CamouflageUtil.java index eeef4d6ee..430126f74 100644 --- a/src/main/java/forestry/core/utils/CamouflageUtil.java +++ b/src/main/java/forestry/core/utils/CamouflageUtil.java @@ -11,65 +11,28 @@ package forestry.core.utils; import javax.annotation.Nullable; -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.PacketBufferForestry; import forestry.core.tiles.TileUtil; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; public class CamouflageUtil { - public static void writeCamouflageBlockToNBT(NBTTagCompound data, ICamouflageHandler handler, String type) { - ItemStack camouflageBlock = handler.getCamouflageBlock(type); - if (!camouflageBlock.isEmpty()) { - NBTTagCompound nbtTag = new NBTTagCompound(); - camouflageBlock.writeToNBT(nbtTag); - data.setTag("Camouflage" + type, nbtTag); - } - } - - public static void readCamouflageBlockFromNBT(NBTTagCompound data, ICamouflageHandler handler, String type) { - if (data.hasKey("Camouflage" + type)) { - handler.setCamouflageBlock(type, new ItemStack(data.getCompoundTag("Camouflage" + type)), false); - } - } - - public static void writeCamouflageBlockToData(PacketBufferForestry data, ICamouflageHandler handler, String type) { - ItemStack camouflageBlock = handler.getCamouflageBlock(type); - if (!camouflageBlock.isEmpty()) { - data.writeShort(1); - data.writeString(type); - data.writeItemStack(camouflageBlock); - } else { - data.writeShort(0); - } - } - - public static void readCamouflageBlockFromData(PacketBufferForestry data, ICamouflageHandler handler) throws IOException { - if (data.readShort() == 1) { - handler.setCamouflageBlock(data.readString(), data.readItemStack(), false); - } - } - @Nullable public static ICamouflageHandler getCamouflageHandler(IBlockAccess world, BlockPos pos) { TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class); if (tile instanceof ICamouflagedTile) { ICamouflagedTile block = (ICamouflagedTile) tile; - String type = block.getCamouflageType(); ICamouflageHandler handler = null; if (tile instanceof ICamouflageHandler) { handler = (ICamouflageHandler) tile; } - if ((handler == null || handler.getCamouflageBlock(type).isEmpty()) && tile instanceof IMultiblockComponent) { + if ((handler == null || handler.getCamouflageBlock().isEmpty()) && tile instanceof IMultiblockComponent) { IMultiblockComponent component = (IMultiblockComponent) tile; IMultiblockController controller = component.getMultiblockLogic().getController(); if (controller instanceof ICamouflageHandler) { @@ -81,23 +44,29 @@ public class CamouflageUtil { return null; } - public static ItemStack getCamouflageBlock(IBlockAccess world, BlockPos pos) { + public static ItemStack getCamouflageBlock(@Nullable IBlockAccess world, @Nullable BlockPos pos) { + if(world == null || pos == null){ + return ItemStack.EMPTY; + } TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class); if (tile instanceof ICamouflagedTile) { ICamouflagedTile block = (ICamouflagedTile) tile; - String type = block.getCamouflageType(); ItemStack camouflageStack = ItemStack.EMPTY; if (tile instanceof ICamouflageHandler) { ICamouflageHandler tileHandler = (ICamouflageHandler) tile; - camouflageStack = tileHandler.getCamouflageBlock(type); + ItemStack tileCamouflageStack = tileHandler.getCamouflageBlock(); + ItemStack defaultCamouflageStack = tileHandler.getDefaultCamouflageBlock(); + if(!ItemStackUtil.isIdenticalItem(tileCamouflageStack, defaultCamouflageStack)){ + camouflageStack = tileCamouflageStack; + } } if (camouflageStack.isEmpty() && tile instanceof IMultiblockComponent) { IMultiblockComponent component = (IMultiblockComponent) tile; IMultiblockController controller = component.getMultiblockLogic().getController(); if (controller.isAssembled() && controller instanceof ICamouflageHandler) { ICamouflageHandler multiblockHandler = (ICamouflageHandler) controller; - camouflageStack = multiblockHandler.getCamouflageBlock(type); + camouflageStack = multiblockHandler.getCamouflageBlock(); } } diff --git a/src/main/java/forestry/core/utils/ClimateUtil.java b/src/main/java/forestry/core/utils/ClimateUtil.java index a40ccceea..8780555b7 100644 --- a/src/main/java/forestry/core/utils/ClimateUtil.java +++ b/src/main/java/forestry/core/utils/ClimateUtil.java @@ -14,8 +14,11 @@ import java.util.ArrayList; import java.util.Locale; import java.util.Set; -import forestry.api.climate.IClimateInfo; -import forestry.api.climate.IClimatePosition; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.climate.ClimateState; +import forestry.api.climate.IClimateState; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.ForestryAPI; @@ -23,11 +26,7 @@ import forestry.api.core.IErrorState; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.EnumTolerance; import forestry.api.genetics.IClimateHelper; -import forestry.core.climate.ClimateRegion; import forestry.core.errors.EnumErrorCode; -import forestry.core.network.PacketBufferForestry; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; public class ClimateUtil implements IClimateHelper { @@ -48,26 +47,9 @@ public class ClimateUtil implements IClimateHelper { public boolean isWithinLimits(EnumHumidity humidity, EnumHumidity baseHumid, EnumTolerance tolHumid) { return getToleratedHumidity(baseHumid, tolHumid).contains(humidity); } - - public static boolean isWithinLimits(IClimateInfo minInfo, IClimateInfo maxInfo, IClimateInfo info){ - if(0.0F != minInfo.getTemperature() && info.getTemperature() < minInfo.getTemperature()){ - return false; - } - if(0.0F != minInfo.getHumidity() && info.getHumidity() < minInfo.getHumidity()){ - return false; - } - if(0.0F != maxInfo.getTemperature() && info.getTemperature() > maxInfo.getTemperature()){ - return false; - } - if(0.0F != maxInfo.getHumidity() & info.getHumidity() > maxInfo.getHumidity()){ - return false; - } - return true; - } @Override public ArrayList getToleratedHumidity(EnumHumidity prefered, EnumTolerance tolerance) { - ArrayList tolerated = new ArrayList<>(); tolerated.add(prefered); @@ -77,18 +59,18 @@ public class ClimateUtil implements IClimateHelper { case BOTH_4: case BOTH_3: case BOTH_2: - if (prefered.ordinal() + 2 < EnumHumidity.values().length) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() + 2]); + if (prefered.ordinal() + 2 < EnumHumidity.VALUES.length) { + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() + 2]); } if (prefered.ordinal() - 2 >= 0) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() - 2]); + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() - 2]); } case BOTH_1: - if (prefered.ordinal() + 1 < EnumHumidity.values().length) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() + 1]); + if (prefered.ordinal() + 1 < EnumHumidity.VALUES.length) { + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() + 1]); } if (prefered.ordinal() - 1 >= 0) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() - 1]); + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() - 1]); } return tolerated; @@ -96,12 +78,12 @@ public class ClimateUtil implements IClimateHelper { case UP_4: case UP_3: case UP_2: - if (prefered.ordinal() + 2 < EnumHumidity.values().length) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() + 2]); + if (prefered.ordinal() + 2 < EnumHumidity.VALUES.length) { + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() + 2]); } case UP_1: - if (prefered.ordinal() + 1 < EnumHumidity.values().length) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() + 1]); + if (prefered.ordinal() + 1 < EnumHumidity.VALUES.length) { + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() + 1]); } return tolerated; @@ -110,11 +92,11 @@ public class ClimateUtil implements IClimateHelper { case DOWN_3: case DOWN_2: if (prefered.ordinal() - 2 >= 0) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() - 2]); + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() - 2]); } case DOWN_1: if (prefered.ordinal() - 1 >= 0) { - tolerated.add(EnumHumidity.values()[prefered.ordinal() - 1]); + tolerated.add(EnumHumidity.VALUES[prefered.ordinal() - 1]); } return tolerated; @@ -126,90 +108,89 @@ public class ClimateUtil implements IClimateHelper { @Override public ArrayList getToleratedTemperature(EnumTemperature prefered, EnumTolerance tolerance) { - ArrayList tolerated = new ArrayList<>(); tolerated.add(prefered); switch (tolerance) { case BOTH_5: - if (prefered.ordinal() + 5 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 5]); + if (prefered.ordinal() + 5 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 5]); } if (prefered.ordinal() - 5 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 5]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 5]); } case BOTH_4: - if (prefered.ordinal() + 4 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 4]); + if (prefered.ordinal() + 4 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 4]); } if (prefered.ordinal() - 4 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 4]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 4]); } case BOTH_3: - if (prefered.ordinal() + 3 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 3]); + if (prefered.ordinal() + 3 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 3]); } if (prefered.ordinal() - 3 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 3]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 3]); } case BOTH_2: - if (prefered.ordinal() + 2 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 2]); + if (prefered.ordinal() + 2 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 2]); } if (prefered.ordinal() - 2 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 2]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 2]); } case BOTH_1: - if (prefered.ordinal() + 1 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 1]); + if (prefered.ordinal() + 1 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 1]); } if (prefered.ordinal() - 1 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 1]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 1]); } return tolerated; case UP_5: - if (prefered.ordinal() + 5 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 5]); + if (prefered.ordinal() + 5 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 5]); } case UP_4: - if (prefered.ordinal() + 4 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 4]); + if (prefered.ordinal() + 4 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 4]); } case UP_3: - if (prefered.ordinal() + 3 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 3]); + if (prefered.ordinal() + 3 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 3]); } case UP_2: - if (prefered.ordinal() + 2 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 2]); + if (prefered.ordinal() + 2 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 2]); } case UP_1: - if (prefered.ordinal() + 1 < EnumTemperature.values().length) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() + 1]); + if (prefered.ordinal() + 1 < EnumTemperature.VALUES.length) { + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() + 1]); } return tolerated; case DOWN_5: if (prefered.ordinal() - 5 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 5]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 5]); } case DOWN_4: if (prefered.ordinal() - 4 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 4]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 4]); } case DOWN_3: if (prefered.ordinal() - 3 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 3]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 3]); } case DOWN_2: if (prefered.ordinal() - 2 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 2]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 2]); } case DOWN_1: if (prefered.ordinal() - 1 >= 0) { - tolerated.add(EnumTemperature.values()[prefered.ordinal() - 1]); + tolerated.add(EnumTemperature.VALUES[prefered.ordinal() - 1]); } return tolerated; @@ -249,30 +230,70 @@ public class ClimateUtil implements IClimateHelper { } } + public static boolean addHumidity(ClimateState state, IClimateState targetedState, float value){ + float humidity = state.getHumidity(); + float targetedHumidity = targetedState.getHumidity(); + if(Float.isNaN(humidity)){ + state.setHumidity(humidity = 0); + } + if (humidity != targetedHumidity) { + if (humidity > targetedHumidity) { + value=Math.min(value, humidity - targetedHumidity); + } else { + value=Math.min(value, targetedHumidity - humidity); + } + state.addHumidity(value); + return true; + } + return false; + } + + public static boolean addTemperature(ClimateState state, IClimateState targetedState, float value){ + float temperature = state.getTemperature(); + float targetedTemperature = targetedState.getTemperature(); + if(Float.isNaN(temperature)){ + state.setTemperature(temperature = 0); + } + if (temperature != targetedTemperature) { + if (temperature > targetedTemperature) { + value=Math.min(value, temperature - targetedTemperature); + } else { + value=Math.min(value, targetedTemperature - temperature); + } + state.addTemperature(value); + return true; + } + return false; + } + public static float getTemperature(World world, BlockPos pos){ - return ForestryAPI.climateManager.getInfo(world, pos).getTemperature(); + IClimateState state = ForestryAPI.climateManager.getClimateState(world, pos); + return state.getTemperature(); } public static float getHumidity(World world, BlockPos pos){ - return ForestryAPI.climateManager.getInfo(world, pos).getHumidity(); + IClimateState state = ForestryAPI.climateManager.getClimateState(world, pos); + return state.getHumidity(); } - - public static void writeRoomPositionData(IClimatePosition position, PacketBufferForestry data) { - data.writeBlockPos(position.getPos()); - writePositionData(position, data); - } - - public static void writePositionData(IClimatePosition position, PacketBufferForestry data) { - data.writeFloat(position.getTemperature()); - data.writeFloat(position.getHumidity()); - } - - public static void readRoomPositionData(ClimateRegion room, PacketBufferForestry data) { - room.setPosition(data.readBlockPos(), data.readFloat(), data.readFloat()); - } - - public static void readPositionData(IClimatePosition position, PacketBufferForestry data) { - position.setTemperature(data.readFloat()); - position.setHumidity(data.readFloat()); + + public static int getColor(EnumTemperature temperature){ + switch (temperature){ + case ICY: + return 0xe6e6fa; + case COLD: + return 0x31698a; + case NORMAL: + return 0xf0e9cc; + case WARM: + return 0xcd9b1d; + case HOT: + return 0xdf512e; + case HELLISH: + return 0x9c433e; + case NONE: + return 0x011f4b; + default: + return 16777215; + } } } diff --git a/src/main/java/forestry/core/utils/ItemTooltipUtil.java b/src/main/java/forestry/core/utils/ItemTooltipUtil.java index 79e2067e0..ea19a20a3 100755 --- a/src/main/java/forestry/core/utils/ItemTooltipUtil.java +++ b/src/main/java/forestry/core/utils/ItemTooltipUtil.java @@ -6,6 +6,7 @@ import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; @@ -23,4 +24,9 @@ public class ItemTooltipUtil { tooltip.addAll(tooltipInfoWrapped); } } + + @SideOnly(Side.CLIENT) + public static void addShiftInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { + tooltip.add(TextFormatting.ITALIC .toString() + '<' + Translator.translateToLocal("for.gui.tooltip.tmi") + '>'); + } } diff --git a/src/main/java/forestry/core/utils/JeiUtil.java b/src/main/java/forestry/core/utils/JeiUtil.java index b567dbe3d..764a68266 100644 --- a/src/main/java/forestry/core/utils/JeiUtil.java +++ b/src/main/java/forestry/core/utils/JeiUtil.java @@ -3,13 +3,15 @@ package forestry.core.utils; import java.util.ArrayList; import java.util.List; -import mezz.jei.api.IModRegistry; import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; + import net.minecraftforge.oredict.OreDictionary; +import mezz.jei.api.IModRegistry; + public class JeiUtil { public static void addDescription(IModRegistry registry, String itemKey, Item... items) { List itemStacks = new ArrayList<>(); diff --git a/src/main/java/forestry/core/utils/MigrationHelper.java b/src/main/java/forestry/core/utils/MigrationHelper.java index 1e4707444..cd5f284db 100755 --- a/src/main/java/forestry/core/utils/MigrationHelper.java +++ b/src/main/java/forestry/core/utils/MigrationHelper.java @@ -16,6 +16,7 @@ import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + import net.minecraftforge.fml.common.registry.ForgeRegistries; @Mod.EventBusSubscriber @@ -27,15 +28,27 @@ public class MigrationHelper { static { ignoredMappings.add("greenhouse.sprinkler"); - itemRemappings.put("greenhouse.dryer", "greenhouse.dehumidifier"); - blockRemappings.put("greenhouse.dryer", "greenhouse.dehumidifier"); - itemRemappings.put("greenhouse.butterfly_hatch", "greenhouse.nursery"); - blockRemappings.put("greenhouse.butterfly_hatch", "greenhouse.nursery"); + itemRemappings.put("greenhouse.plain", "greenhouse"); + blockRemappings.put("greenhouse.plain", "greenhouse"); + itemRemappings.put("greenhouse.gearbox", "greenhouse"); + blockRemappings.put("greenhouse.gearbox", "greenhouse"); + itemRemappings.put("greenhouse.control", "greenhouse"); + blockRemappings.put("greenhouse.control", "greenhouse"); + itemRemappings.put("greenhouse.fan", "climatiser.fan"); + blockRemappings.put("greenhouse.fan", "climatiser.fan"); + blockRemappings.put("greenhouse.heater", "climatiser.heater"); + itemRemappings.put("greenhouse.heater", "climatiser.heater"); + blockRemappings.put("greenhouse.dehumidifier", "climatiser.dehumidifier"); + itemRemappings.put("greenhouse.dehumidifier", "climatiser.dehumidifier"); + blockRemappings.put("greenhouse.humidifier", "climatiser.humidifier"); + itemRemappings.put("greenhouse.humidifier", "climatiser.humidifier"); + itemRemappings.put("greenhouse.dryer", "climatiser.dehumidifier"); + blockRemappings.put("greenhouse.dryer", "climatiser.dehumidifier"); itemRemappings.put("pile_dirt", "loam"); blockRemappings.put("pile_dirt", "loam"); itemRemappings.put("pile_wood", "wood_pile"); blockRemappings.put("pile_wood", "wood_pile"); - blockRemappings.put("pile_ash", "charcoal"); + blockRemappings.put("pile_ash", "ash_block"); } public static Pattern underscores = Pattern.compile("_"); @@ -54,12 +67,12 @@ public class MigrationHelper { remappings.put(nameWithoutUnderscores, name); } } - + @SubscribeEvent public static void onMissingBlockMappings(RegistryEvent.MissingMappings event) { for (RegistryEvent.MissingMappings.Mapping missingMapping : event.getMappings()) { ResourceLocation resourceLocation = missingMapping.key; - + String resourcePath = resourceLocation.getResourcePath(); if (ignoredMappings.contains(resourcePath)) { missingMapping.ignore(); @@ -74,12 +87,12 @@ public class MigrationHelper { } } } - + @SubscribeEvent public static void onMissingItemMappings(RegistryEvent.MissingMappings event) { for (RegistryEvent.MissingMappings.Mapping missingMapping : event.getMappings()) { ResourceLocation resourceLocation = missingMapping.key; - + String resourcePath = resourceLocation.getResourcePath(); if (ignoredMappings.contains(resourcePath)) { missingMapping.ignore(); diff --git a/src/main/java/forestry/core/utils/OreDictUtil.java b/src/main/java/forestry/core/utils/OreDictUtil.java index b875ebc65..4ab885cf3 100644 --- a/src/main/java/forestry/core/utils/OreDictUtil.java +++ b/src/main/java/forestry/core/utils/OreDictUtil.java @@ -53,9 +53,13 @@ public class OreDictUtil { public static final String CROP_DATE = "cropDate"; public static final String CROP_PAPAYA = "cropPapaya"; + public static final String CROP_WHEAT = "cropWheat"; + public static final String CROP_POTATO = "cropPotato"; + public static final String CROP_CARROT = "cropCarrot"; + public static final String SUGARCANE = "sugarcane"; + public static final String PANE_GLASS = "paneGlass"; public static final String SAND = "sand"; - public static final String CROP_WHEAT = "cropWheat"; public static final String DUST_REDSTONE = "dustRedstone"; public static final String GEM_DIAMOND = "gemDiamond"; public static final String STICK_WOOD = "stickWood"; @@ -67,6 +71,7 @@ public class OreDictUtil { public static final String GEM_QUARTZ = "gemQuartz"; public static final String CHEST_WOOD = "chestWood"; public static final String LEATHER = "leather"; + public static final String BLOCK_CACTUS = "blockCactus"; public static final String DYE_YELLOW = "dyeYellow"; public static final String DYE_BLUE = "dyeBlue"; diff --git a/src/main/java/forestry/core/utils/World2ObjectMap.java b/src/main/java/forestry/core/utils/World2ObjectMap.java new file mode 100644 index 000000000..9fcf21d1b --- /dev/null +++ b/src/main/java/forestry/core/utils/World2ObjectMap.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.utils; + +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import net.minecraft.world.World; + +import net.minecraftforge.event.world.WorldEvent; + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +/** + * This is a implementation of a map that works with worlds. + * A world is automatically removed from this map if it unloads and added if it loads. + */ +public final class World2ObjectMap { + private static final Set MAPS = new HashSet<>(); + + private final Map delegate; + private final Factory factory; + @Nullable + private final Listener listener; + + public World2ObjectMap(Factory factory) { + this(factory, null); + } + + public World2ObjectMap(Factory factory, @Nullable Listener listener) { + this.delegate = new HashMap<>(); + MAPS.add(this); + this.factory = factory; + this.listener = listener; + } + + @Nullable + public O get(World world){ + return delegate.get(getIndex(world)); + } + + public Collection values(){ + return delegate.values(); + } + + private int getIndex(World world){ + return Integer.hashCode(world.provider.getDimension()) + Boolean.hashCode(world.isRemote); + } + + @SubscribeEvent + public static void onWorldUnload(WorldEvent.Unload event) { + World world = event.getWorld(); + for(World2ObjectMap map : MAPS){ + map.delegate.remove(map.getIndex(world)); + if(map.listener != null) { + map.listener.onWorldStateChange(world, false, event); + } + } + } + + @SubscribeEvent + public static void onWorldLoad(WorldEvent.Load event) { + World world = event.getWorld(); + for(World2ObjectMap map : MAPS){ + map.delegate.put(map.getIndex(world), map.factory.createValue(world)); + if(map.listener != null) { + map.listener.onWorldStateChange(world, false, event); + } + } + } + + public interface Factory{ + O createValue(World world); + } + + public interface Listener{ + /** + * @param event A WorldEvent.Unload or WorldEvent.Load event + */ + void onWorldStateChange(World world, boolean load, WorldEvent event); + } +} diff --git a/src/main/java/forestry/core/worldgen/WorldGenHelper.java b/src/main/java/forestry/core/worldgen/WorldGenHelper.java index ce30bc423..5e4d01f41 100644 --- a/src/main/java/forestry/core/worldgen/WorldGenHelper.java +++ b/src/main/java/forestry/core/worldgen/WorldGenHelper.java @@ -35,7 +35,7 @@ public class WorldGenHelper { } /** - * Uses startPos and girth of a tree to calculate the center + * Uses centerPos and girth of a tree to calculate the center */ public static void generateCylinderFromTreeStartPos(World world, ITreeBlockType block, BlockPos startPos, int girth, float radius, int height, EnumReplaceMode replace) { generateCylinderFromPos(world, block, startPos.add(girth / 2, 0, girth / 2), radius, height, replace); diff --git a/src/main/java/forestry/energy/gui/GuiEngine.java b/src/main/java/forestry/energy/gui/GuiEngine.java index f7e36c741..915791f37 100755 --- a/src/main/java/forestry/energy/gui/GuiEngine.java +++ b/src/main/java/forestry/energy/gui/GuiEngine.java @@ -26,12 +26,6 @@ public abstract class GuiEngine exten this.tile = tile; } - @Override - public void initGui() { - super.initGui(); - ledgerManager.insert(new EngineLedger()); - } - protected class EngineLedger extends Ledger { public EngineLedger() { diff --git a/src/main/java/forestry/factory/DummyManagers.java b/src/main/java/forestry/factory/DummyManagers.java index e99a8221a..62249a027 100644 --- a/src/main/java/forestry/factory/DummyManagers.java +++ b/src/main/java/forestry/factory/DummyManagers.java @@ -10,11 +10,17 @@ ******************************************************************************/ package forestry.factory; +import com.google.common.collect.ImmutableSet; + import javax.annotation.Nullable; import java.util.Map; import java.util.Set; -import com.google.common.collect.ImmutableSet; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; + +import net.minecraftforge.fluids.FluidStack; + import forestry.api.recipes.ICarpenterManager; import forestry.api.recipes.ICarpenterRecipe; import forestry.api.recipes.ICentrifugeManager; @@ -33,9 +39,6 @@ import forestry.api.recipes.ISqueezerManager; import forestry.api.recipes.ISqueezerRecipe; import forestry.api.recipes.IStillManager; import forestry.api.recipes.IStillRecipe; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraftforge.fluids.FluidStack; public class DummyManagers { @@ -110,6 +113,16 @@ public class DummyManagers { public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output) { } + + @Override + public void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) { + + } + + @Override + public void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output) { + + } } public static class DummyMoistenerManager extends DummyCraftingProvider implements IMoistenerManager { diff --git a/src/main/java/forestry/factory/PluginFactory.java b/src/main/java/forestry/factory/PluginFactory.java index 4ef722ee3..90a6b25a8 100755 --- a/src/main/java/forestry/factory/PluginFactory.java +++ b/src/main/java/forestry/factory/PluginFactory.java @@ -56,6 +56,7 @@ import forestry.core.items.ItemRegistryCore; import forestry.core.items.ItemRegistryFluids; import forestry.core.network.IPacketRegistry; import forestry.core.recipes.RecipeUtil; +import forestry.core.utils.OreDictUtil; import forestry.core.utils.datastructures.FluidMap; import forestry.core.utils.datastructures.ItemStackMap; import forestry.factory.blocks.BlockRegistryFactory; @@ -383,14 +384,12 @@ public class PluginFactory extends BlankForestryPlugin { RecipeManagers.moistenerManager.addRecipe(new ItemStack(Blocks.LEAVES, 1, EnumType.SPRUCE.ordinal()), new ItemStack(Blocks.DIRT, 1, DirtType.PODZOL.ordinal()), 5000); // FERMENTER - for (int i = 0; i < 6; i++) { - RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.SAPLING, 1, i), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); - } + RecipeUtil.addFermenterRecipes(OreDictUtil.TREE_SAPLING, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.CACTUS), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cactus"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Items.WHEAT), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Items.POTATO), 2 * ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); - RecipeUtil.addFermenterRecipes(new ItemStack(Items.REEDS), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cane"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(OreDictUtil.BLOCK_CACTUS, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cactus"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(OreDictUtil.CROP_WHEAT, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(OreDictUtil.CROP_POTATO, 2 * ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.addFermenterRecipes(OreDictUtil.SUGARCANE, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cane"), Fluids.BIOMASS); RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.BROWN_MUSHROOM), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.RED_MUSHROOM), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); diff --git a/src/main/java/forestry/factory/recipes/FermenterRecipe.java b/src/main/java/forestry/factory/recipes/FermenterRecipe.java index cb3b387f9..9bb712762 100644 --- a/src/main/java/forestry/factory/recipes/FermenterRecipe.java +++ b/src/main/java/forestry/factory/recipes/FermenterRecipe.java @@ -11,14 +11,20 @@ package forestry.factory.recipes; import com.google.common.base.Preconditions; -import forestry.api.recipes.IFermenterRecipe; + +import javax.annotation.Nullable; + import net.minecraft.item.ItemStack; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import forestry.api.recipes.IFermenterRecipe; + public class FermenterRecipe implements IFermenterRecipe { private final ItemStack resource; + private final String resourceOreName; private final int fermentationValue; private final float modifier; private final Fluid output; @@ -31,17 +37,39 @@ public class FermenterRecipe implements IFermenterRecipe { Preconditions.checkNotNull(fluidResource, "Fermenter Liquid cannot be null!"); this.resource = resource; + this.resourceOreName = null; this.fermentationValue = fermentationValue; this.modifier = modifier; this.output = output; this.fluidResource = fluidResource; } + public FermenterRecipe(String resourceOreName, int fermentationValue, float modifier, Fluid output, FluidStack fluidResource) { + Preconditions.checkNotNull(resourceOreName, "Fermenter Resource cannot be null!"); + Preconditions.checkArgument(!resourceOreName.isEmpty(), "Fermenter Resource ore name cannot be empty!"); + Preconditions.checkNotNull(output, "Fermenter Output cannot be null!"); + Preconditions.checkNotNull(fluidResource, "Fermenter Liquid cannot be null!"); + + this.resource = ItemStack.EMPTY; + this.resourceOreName = resourceOreName; + this.fermentationValue = fermentationValue; + this.modifier = modifier; + this.output = output; + this.fluidResource = fluidResource; + } + + @Override public ItemStack getResource() { return resource; } + @Nullable + @Override + public String getResourceOreName() { + return resourceOreName; + } + @Override public FluidStack getFluidResource() { return fluidResource; @@ -61,4 +89,9 @@ public class FermenterRecipe implements IFermenterRecipe { public Fluid getOutput() { return output; } + + @Override + public int compareTo(IFermenterRecipe o) { + return resource.isEmpty() ? 1 : 0; + } } diff --git a/src/main/java/forestry/factory/recipes/FermenterRecipeManager.java b/src/main/java/forestry/factory/recipes/FermenterRecipeManager.java index 669cb4b82..efd1c3ffb 100644 --- a/src/main/java/forestry/factory/recipes/FermenterRecipeManager.java +++ b/src/main/java/forestry/factory/recipes/FermenterRecipeManager.java @@ -14,6 +14,7 @@ import javax.annotation.Nullable; import java.util.Collections; import java.util.HashSet; import java.util.Set; +import java.util.TreeSet; import net.minecraft.item.ItemStack; @@ -27,7 +28,7 @@ import forestry.core.utils.ItemStackUtil; public class FermenterRecipeManager implements IFermenterManager { - private static final Set recipes = new HashSet<>(); + private static final Set recipes = new TreeSet<>(); public static final Set recipeFluidInputs = new HashSet<>(); public static final Set recipeFluidOutputs = new HashSet<>(); @@ -42,6 +43,17 @@ public class FermenterRecipeManager implements IFermenterManager { addRecipe(resource, fermentationValue, modifier, output, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME)); } + @Override + public void addRecipe(String resourceOreName, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) { + IFermenterRecipe recipe = new FermenterRecipe(resourceOreName, fermentationValue, modifier, output.getFluid(), liquid); + addRecipe(recipe); + } + + @Override + public void addRecipe(String resourceOreName, int fermentationValue, float modifier, FluidStack output) { + addRecipe(resourceOreName, fermentationValue, modifier, output, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME)); + } + @Nullable public static IFermenterRecipe findMatchingRecipe(ItemStack res, FluidStack liqu) { if(res.isEmpty()){ @@ -57,7 +69,7 @@ public class FermenterRecipeManager implements IFermenterManager { public static boolean matches(IFermenterRecipe recipe, ItemStack res, FluidStack liqu) { ItemStack resource = recipe.getResource(); - if (!ItemStackUtil.isCraftingEquivalent(resource, res)) { + if (!ItemStackUtil.isCraftingEquivalent(resource, res, recipe.getResourceOreName(), false)) { return false; } @@ -71,7 +83,7 @@ public class FermenterRecipeManager implements IFermenterManager { } for (IFermenterRecipe recipe : recipes) { - if (ItemStackUtil.isCraftingEquivalent(recipe.getResource(), resource)) { + if (ItemStackUtil.isCraftingEquivalent(recipe.getResource(), resource, recipe.getResourceOreName(), false)) { return true; } } diff --git a/src/main/java/forestry/factory/recipes/jei/bottler/BottlerRecipeMaker.java b/src/main/java/forestry/factory/recipes/jei/bottler/BottlerRecipeMaker.java index 8b937230d..489eff11b 100644 --- a/src/main/java/forestry/factory/recipes/jei/bottler/BottlerRecipeMaker.java +++ b/src/main/java/forestry/factory/recipes/jei/bottler/BottlerRecipeMaker.java @@ -3,8 +3,8 @@ package forestry.factory.recipes.jei.bottler; import java.util.ArrayList; import java.util.List; -import mezz.jei.api.ingredients.IIngredientRegistry; import net.minecraft.item.ItemStack; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; @@ -13,6 +13,8 @@ import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.fluids.capability.IFluidTankProperties; +import mezz.jei.api.ingredients.IIngredientRegistry; + public class BottlerRecipeMaker { private BottlerRecipeMaker() { diff --git a/src/main/java/forestry/factory/recipes/jei/fermenter/FermenterRecipeMaker.java b/src/main/java/forestry/factory/recipes/jei/fermenter/FermenterRecipeMaker.java index 84d2087f1..3b22d3208 100644 --- a/src/main/java/forestry/factory/recipes/jei/fermenter/FermenterRecipeMaker.java +++ b/src/main/java/forestry/factory/recipes/jei/fermenter/FermenterRecipeMaker.java @@ -3,12 +3,17 @@ package forestry.factory.recipes.jei.fermenter; import java.util.ArrayList; import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; + +import net.minecraftforge.oredict.OreDictionary; + import forestry.api.recipes.IFermenterRecipe; import forestry.api.recipes.IVariableFermentable; import forestry.api.recipes.RecipeManagers; import forestry.core.utils.Log; + import mezz.jei.api.recipe.IStackHelper; -import net.minecraft.item.ItemStack; public class FermenterRecipeMaker { @@ -19,12 +24,13 @@ public class FermenterRecipeMaker { List recipes = new ArrayList<>(); for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) { if (!recipe.getResource().isEmpty()) { - if (recipe.getResource().getItem() instanceof IVariableFermentable) { - for (ItemStack stack : stackHelper.getSubtypes(recipe.getResource())) { - recipes.add(new FermenterRecipeWrapper(recipe, stack)); + addWrapperToList(stackHelper, recipe, recipe.getResource(), recipes); + }else if(recipe.getResourceOreName() != null){ + NonNullList itemStacks = OreDictionary.getOres(recipe.getResourceOreName()); + if(!itemStacks.isEmpty()){ + for(ItemStack resource : itemStacks){ + addWrapperToList(stackHelper, recipe, resource, recipes); } - } else { - recipes.add(new FermenterRecipeWrapper(recipe, recipe.getResource())); } } else { Log.error("Empty resource for recipe"); @@ -33,4 +39,14 @@ public class FermenterRecipeMaker { return recipes; } + private static void addWrapperToList(IStackHelper stackHelper, IFermenterRecipe recipe, ItemStack resource, List recipes){ + if (resource.getItem() instanceof IVariableFermentable) { + for (ItemStack stack : stackHelper.getSubtypes(resource)) { + recipes.add(new FermenterRecipeWrapper(recipe, stack)); + } + } else { + recipes.add(new FermenterRecipeWrapper(recipe, resource)); + } + } + } diff --git a/src/main/java/forestry/farming/DummyFarmRegistry.java b/src/main/java/forestry/farming/DummyFarmRegistry.java new file mode 100644 index 000000000..52b4930da --- /dev/null +++ b/src/main/java/forestry/farming/DummyFarmRegistry.java @@ -0,0 +1,37 @@ +package forestry.farming; + +import java.util.Collection; +import java.util.Collections; + +import net.minecraft.item.ItemStack; + +import forestry.api.farming.IFarmLogic; +import forestry.api.farming.IFarmRegistry; +import forestry.api.farming.IFarmable; +import forestry.api.farming.ISimpleFarmLogic; + +public class DummyFarmRegistry implements IFarmRegistry { + + @Override + public void registerFarmables(String identifier, IFarmable... farmable) { + } + + @Override + public Collection getFarmables(String identifier) { + return Collections.emptyList(); + } + + @Override + public IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic) { + return null; + } + + @Override + public void registerFertilizer(ItemStack itemStack, int value) { + } + + @Override + public int getFertilizeValue(ItemStack itemStack) { + return 0; + } +} diff --git a/src/main/java/forestry/farming/FarmRegistry.java b/src/main/java/forestry/farming/FarmRegistry.java index fd241b12f..7a3643cbf 100644 --- a/src/main/java/forestry/farming/FarmRegistry.java +++ b/src/main/java/forestry/farming/FarmRegistry.java @@ -19,7 +19,6 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.common.config.Property; import net.minecraftforge.oredict.OreDictionary; -import forestry.api.core.ForestryAPI; import forestry.api.farming.IFarmLogic; import forestry.api.farming.IFarmRegistry; import forestry.api.farming.IFarmable; @@ -36,10 +35,6 @@ public final class FarmRegistry implements IFarmRegistry { private final Multimap farmables = HashMultimap.create(); private final Map fertilizers = new LinkedHashMap<>(); - static { - ForestryAPI.farmRegistry = INSTANCE; - } - public static FarmRegistry getInstance() { return INSTANCE; } diff --git a/src/main/java/forestry/farming/PluginFarming.java b/src/main/java/forestry/farming/PluginFarming.java index f8a25fa03..2217aef23 100644 --- a/src/main/java/forestry/farming/PluginFarming.java +++ b/src/main/java/forestry/farming/PluginFarming.java @@ -11,10 +11,31 @@ package forestry.farming; +import com.google.common.base.Preconditions; + import javax.annotation.Nullable; import java.io.File; import java.util.List; -import com.google.common.base.Preconditions; + +import net.minecraft.block.BlockBeetroot; +import net.minecraft.block.BlockCrops; +import net.minecraft.block.BlockNetherWart; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; + +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.Forestry; import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.CircuitSocketType; @@ -63,22 +84,6 @@ import forestry.farming.triggers.FarmingTriggers; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; import forestry.plugins.ForestryPluginUids; -import net.minecraft.block.BlockBeetroot; -import net.minecraft.block.BlockCrops; -import net.minecraft.block.BlockNetherWart; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.registry.GameRegistry; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import net.minecraftforge.oredict.OreDictionary; @ForestryPlugin(pluginID = ForestryPluginUids.FARMING, name = "Farming", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.farming.description") public class PluginFarming extends BlankForestryPlugin { @@ -95,6 +100,16 @@ public class PluginFarming extends BlankForestryPlugin { return blocks; } + @Override + public void setupAPI() { + ForestryAPI.farmRegistry = FarmRegistry.getInstance(); + } + + @Override + public void disabledSetupAPI() { + ForestryAPI.farmRegistry = new DummyFarmRegistry(); + } + @Override public void registerItemsAndBlocks() { blocks = new BlockRegistryFarming(); @@ -106,7 +121,7 @@ public class PluginFarming extends BlankForestryPlugin { BlockRegistryFarming blocks = getBlocks(); MinecraftForge.EVENT_BUS.register(this); - IFarmRegistry registry = FarmRegistry.getInstance(); + IFarmRegistry registry = ForestryAPI.farmRegistry; registry.registerFarmables("farmArboreal", new FarmableVanillaSapling()); if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) { diff --git a/src/main/java/forestry/farming/items/ItemBlockFarm.java b/src/main/java/forestry/farming/items/ItemBlockFarm.java index 41be2021d..0dda1ac36 100755 --- a/src/main/java/forestry/farming/items/ItemBlockFarm.java +++ b/src/main/java/forestry/farming/items/ItemBlockFarm.java @@ -13,13 +13,21 @@ package forestry.farming.items; import javax.annotation.Nullable; import java.util.List; +import forestry.core.utils.Translator; +import forestry.farming.models.EnumFarmBlockTexture; import net.minecraft.block.Block; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.utils.ItemTooltipUtil; import forestry.core.utils.Translator; import forestry.farming.models.EnumFarmBlockTexture; @@ -35,15 +43,20 @@ public class ItemBlockFarm extends ItemBlock { return i; } + @SideOnly(Side.CLIENT) @Override - public void addInformation(ItemStack itemstack, @Nullable World world, List info, ITooltipFlag par4) { - info.add(Translator.translateToLocal("tile.for.ffarm.tooltip")); - if (itemstack.getTagCompound() == null) { - return; - } - EnumFarmBlockTexture texture = EnumFarmBlockTexture.getFromCompound(itemstack.getTagCompound()); + public void addInformation(ItemStack stack, @Nullable World world, List tooltip, ITooltipFlag flag) { + if(GuiScreen.isShiftKeyDown()){ + tooltip.add(Translator.translateToLocal("tile.for.ffarm.tooltip")); + if (stack.getTagCompound() == null) { + return; + } + EnumFarmBlockTexture texture = EnumFarmBlockTexture.getFromCompound(stack.getTagCompound()); - info.add(Translator.translateToLocal("tile.for.ffarm.material.tooltip") + texture.getFormatting() + TextFormatting.ITALIC + " "+ texture.getName()); + tooltip.add(Translator.translateToLocal("tile.for.ffarm.material.tooltip") + texture.getFormatting() + TextFormatting.ITALIC + " "+ texture.getName()); + }else{ + ItemTooltipUtil.addShiftInformation(stack, world, tooltip, flag); + } } @Override diff --git a/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java b/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java index ea0594d0d..198508d4d 100644 --- a/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java +++ b/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java @@ -1,9 +1,6 @@ package forestry.farming.logic; -import java.util.Collection; -import java.util.List; - import javax.annotation.Nonnull; import net.minecraft.item.ItemStack; diff --git a/src/main/java/forestry/farming/logic/CropDestroyDouble.java b/src/main/java/forestry/farming/logic/CropDestroyDouble.java new file mode 100644 index 000000000..d8a21ff52 --- /dev/null +++ b/src/main/java/forestry/farming/logic/CropDestroyDouble.java @@ -0,0 +1,60 @@ +package forestry.farming.logic; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.core.config.Constants; +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.utils.NetworkUtil; + +public class CropDestroyDouble extends Crop { + + protected final IBlockState blockState; + protected final IBlockState blockStateUp; + @Nullable + protected final IBlockState replantState; + + public CropDestroyDouble(World world, IBlockState blockState, IBlockState blockStateUp, BlockPos position, @Nullable IBlockState replantState) { + super(world, position); + this.blockState = blockState; + this.blockStateUp = blockStateUp; + this.replantState = replantState; + } + + @Override + protected boolean isCrop(World world, BlockPos pos) { + return world.getBlockState(pos) == blockState; + } + + @Override + protected NonNullList harvestBlock(World world, BlockPos pos) { + Block block = blockState.getBlock(); + Block blockUp = blockStateUp.getBlock(); + NonNullList harvested = NonNullList.create(); + harvested.addAll(block.getDrops(world, pos, blockState, 0)); + harvested.addAll(blockUp.getDrops(world, pos.up(), blockStateUp, 0)); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState); + NetworkUtil.sendNetworkPacket(packet, pos, world); + + world.setBlockToAir(pos.up()); + if (replantState != null) { + world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC); + } else { + world.setBlockToAir(pos); + } + + return harvested; + } + + @Override + public String toString() { + return String.format("CropDestroyDouble [ position: [ %s ]; block: %s ]", position.toString(), blockState); + } +} diff --git a/src/main/java/forestry/farming/logic/FarmLogicCereal.java b/src/main/java/forestry/farming/logic/FarmLogicCereal.java index 5a15f5495..3d148d0f3 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCereal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCereal.java @@ -13,12 +13,12 @@ package forestry.farming.logic; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; -import forestry.farming.FarmRegistry; +import forestry.api.core.ForestryAPI; public class FarmLogicCereal extends FarmLogicCrops { public FarmLogicCereal() { - super(FarmRegistry.getInstance().getFarmables("farmWheat")); + super(ForestryAPI.farmRegistry.getFarmables("farmWheat")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicEnder.java b/src/main/java/forestry/farming/logic/FarmLogicEnder.java index eb082e021..c2b2adac8 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicEnder.java +++ b/src/main/java/forestry/farming/logic/FarmLogicEnder.java @@ -13,12 +13,6 @@ package forestry.farming.logic; import java.util.Collection; import java.util.Stack; -import forestry.api.farming.FarmDirection; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmHousing; -import forestry.api.farming.IFarmable; -import forestry.core.utils.BlockUtil; -import forestry.farming.FarmRegistry; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -27,10 +21,17 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import forestry.api.core.ForestryAPI; +import forestry.api.farming.FarmDirection; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmHousing; +import forestry.api.farming.IFarmable; +import forestry.core.utils.BlockUtil; + public class FarmLogicEnder extends FarmLogicHomogeneous { public FarmLogicEnder() { - super(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmEnder")); + super(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState(), ForestryAPI.farmRegistry.getFarmables("farmEnder")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicMushroom.java b/src/main/java/forestry/farming/logic/FarmLogicMushroom.java index c2aad0803..93705fc16 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicMushroom.java +++ b/src/main/java/forestry/farming/logic/FarmLogicMushroom.java @@ -10,17 +10,18 @@ ******************************************************************************/ package forestry.farming.logic; -import forestry.api.farming.IFarmHousing; -import forestry.farming.FarmRegistry; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import net.minecraft.world.World; +import forestry.api.core.ForestryAPI; +import forestry.api.farming.IFarmHousing; + public class FarmLogicMushroom extends FarmLogicArboreal { public FarmLogicMushroom() { - super(new ItemStack(Blocks.MYCELIUM), Blocks.MYCELIUM.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmShroom")); + super(new ItemStack(Blocks.MYCELIUM), Blocks.MYCELIUM.getDefaultState(), ForestryAPI.farmRegistry.getFarmables("farmShroom")); addSoil(new ItemStack(Blocks.DIRT, 1, 2), Blocks.DIRT.getStateFromMeta(2), true); } diff --git a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java index 403666627..c83aa4268 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java +++ b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.farming.logic; +import com.google.common.collect.ImmutableList; + import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -19,7 +21,14 @@ import java.util.List; import java.util.Set; import java.util.Stack; -import com.google.common.collect.ImmutableList; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.core.ForestryAPI; import forestry.api.farming.FarmDirection; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; @@ -27,13 +36,6 @@ import forestry.api.farming.IFarmable; import forestry.api.genetics.IFruitBearer; import forestry.core.PluginCore; import forestry.core.tiles.TileUtil; -import forestry.farming.FarmRegistry; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; public class FarmLogicOrchard extends FarmLogic { @@ -42,7 +44,7 @@ public class FarmLogicOrchard extends FarmLogic { private final ImmutableList traversalBlocks; public FarmLogicOrchard() { - this.farmables = FarmRegistry.getInstance().getFarmables("farmOrchard"); + this.farmables = ForestryAPI.farmRegistry.getFarmables("farmOrchard"); ImmutableList.Builder traversalBlocksBuilder = ImmutableList.builder(); // if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.AGRICRAFT) || ForestryAPI.enabledPlugins.contains(ForestryPluginUids.INDUSTRIALCRAFT)) { diff --git a/src/main/java/forestry/farming/logic/FarmLogicReeds.java b/src/main/java/forestry/farming/logic/FarmLogicReeds.java index 9d20c2d77..089a9d304 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicReeds.java +++ b/src/main/java/forestry/farming/logic/FarmLogicReeds.java @@ -13,12 +13,6 @@ package forestry.farming.logic; import java.util.Collection; import java.util.Stack; -import forestry.api.farming.FarmDirection; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmHousing; -import forestry.api.farming.IFarmable; -import forestry.core.utils.ItemStackUtil; -import forestry.farming.FarmRegistry; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -27,8 +21,15 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import forestry.api.core.ForestryAPI; +import forestry.api.farming.FarmDirection; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmHousing; +import forestry.api.farming.IFarmable; +import forestry.core.utils.ItemStackUtil; + public class FarmLogicReeds extends FarmLogic { - private final Collection germlings = FarmRegistry.getInstance().getFarmables("farmPoales"); + private final Collection germlings = ForestryAPI.farmRegistry.getFarmables("farmPoales"); @Override public ItemStack getIconItemStack() { diff --git a/src/main/java/forestry/farming/logic/FarmableDoubleCrop.java b/src/main/java/forestry/farming/logic/FarmableDoubleCrop.java new file mode 100644 index 000000000..d524506ac --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmableDoubleCrop.java @@ -0,0 +1,33 @@ +package forestry.farming.logic; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.farming.ICrop; + +public class FarmableDoubleCrop extends FarmableBase { + private final IBlockState topMatureState; + + public FarmableDoubleCrop(ItemStack germling, IBlockState plantedState, IBlockState matureState, IBlockState topMatureState, boolean replant) { + super(germling, plantedState, matureState, replant); + this.topMatureState = topMatureState; + } + + @Override + public boolean isSaplingAt(World world, BlockPos pos) { + IBlockState blockState = world.getBlockState(pos); + return blockState.getBlock() == plantedState.getBlock() && blockState != topMatureState; + } + + @Override + public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { + BlockPos posUp = pos.up(); + IBlockState stateUp = world.getBlockState(posUp); + if (blockState != matureState || stateUp != topMatureState) { + return null; + } + return new CropDestroyDouble(world, blockState, stateUp, pos, replant ? plantedState : null); + } +} diff --git a/src/main/java/forestry/farming/logic/FarmableRusticGrape.java b/src/main/java/forestry/farming/logic/FarmableRusticGrape.java new file mode 100644 index 000000000..598103d91 --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmableRusticGrape.java @@ -0,0 +1,69 @@ +package forestry.farming.logic; + +import com.google.common.base.Preconditions; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.block.properties.PropertyBool; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; + +public class FarmableRusticGrape implements IFarmable { + public static final PropertyBool GRAPES = PropertyBool.create("grapes"); + + private final Block cropBlock; + + public FarmableRusticGrape(Block cropBlock) { + Preconditions.checkNotNull(cropBlock); + + this.cropBlock = cropBlock; + } + + @Override + public boolean isSaplingAt(World world, BlockPos pos) { + IBlockState blockState = world.getBlockState(pos); + return blockState.getBlock() == cropBlock; + } + + @Override + @Nullable + public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { + if (blockState.getBlock() != cropBlock) { + return null; + } + + if (!blockState.getValue(GRAPES)) { + return null; + } + + IBlockState replantState = getReplantState(blockState); + return new CropDestroy(world, blockState, pos, replantState); + } + + @Nullable + protected IBlockState getReplantState(IBlockState blockState) { + return blockState.withProperty(GRAPES, false); + } + + @Override + public boolean isGermling(ItemStack itemstack) { + return false; + } + + @Override + public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { + return false; + } + + @Override + public boolean isWindfall(ItemStack itemstack) { + return false; + } +} diff --git a/src/main/java/forestry/farming/logic/FarmableRusticSapling.java b/src/main/java/forestry/farming/logic/FarmableRusticSapling.java new file mode 100644 index 000000000..7ca0e7e33 --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmableRusticSapling.java @@ -0,0 +1,67 @@ +package forestry.farming.logic; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.utils.NetworkUtil; + +public class FarmableRusticSapling implements IFarmable { + + protected final Item germling; + protected final Block germlingBlock; + private final ItemStack[] windfall; + + public FarmableRusticSapling(Item germling, ItemStack[] windfall) { + this.germling = germling; + this.germlingBlock = Block.getBlockFromItem(germling); + this.windfall = windfall; + } + + @Override + public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { + if (world.setBlockState(pos, germlingBlock.getStateFromMeta(germling.getItemDamage()))) { + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, germlingBlock.getStateFromMeta(germling.getItemDamage())); + NetworkUtil.sendNetworkPacket(packet, pos, world); + return true; + } + return false; + } + + @Override + public boolean isSaplingAt(World world, BlockPos pos) { + return world.getBlockState(pos).getBlock() == germlingBlock; + } + + @Override + public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { + Block block = blockState.getBlock(); + if (!block.isWood(world, pos)) { + return null; + } + + return new CropDestroy(world, blockState, pos, null); + } + + @Override + public boolean isGermling(ItemStack itemstack) { + return germling == itemstack.getItem(); + } + + @Override + public boolean isWindfall(ItemStack itemstack) { + for (ItemStack drop : windfall) { + if (drop.isItemEqual(itemstack)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/forestry/farming/multiblock/InventoryFarm.java b/src/main/java/forestry/farming/multiblock/InventoryFarm.java index 904598585..fea22ccd5 100644 --- a/src/main/java/forestry/farming/multiblock/InventoryFarm.java +++ b/src/main/java/forestry/farming/multiblock/InventoryFarm.java @@ -12,6 +12,16 @@ package forestry.farming.multiblock; import java.util.Stack; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; + +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; + import forestry.api.core.ForestryAPI; import forestry.api.farming.FarmDirection; import forestry.api.farming.IFarmInventory; @@ -24,15 +34,6 @@ import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.utils.InventoryUtil; import forestry.core.utils.PlayerUtil; import forestry.core.utils.SlotUtil; -import forestry.farming.FarmRegistry; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidUtil; public class InventoryFarm extends InventoryAdapterRestricted implements IFarmInventory { public static final int SLOT_RESOURCES_1 = 0; @@ -136,8 +137,8 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn if (itemstack.isEmpty()) { return false; } - - return FarmRegistry.getInstance().getFertilizeValue(itemstack) > 0; + + return ForestryAPI.farmRegistry.getFertilizeValue(itemstack) > 0; } @Override @@ -213,7 +214,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn return 0; } - int fertilizerValue = FarmRegistry.getInstance().getFertilizeValue(fertilizerStack); + int fertilizerValue = ForestryAPI.farmRegistry.getFertilizeValue(fertilizerStack); if(fertilizerValue > 0){ return fertilizerValue * FERTILIZER_MODIFIER; } diff --git a/src/main/java/forestry/greenhouse/GreenhouseClimateSource.java b/src/main/java/forestry/greenhouse/GreenhouseClimateSource.java deleted file mode 100644 index e54dbb28a..000000000 --- a/src/main/java/forestry/greenhouse/GreenhouseClimateSource.java +++ /dev/null @@ -1,149 +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; - -import forestry.api.climate.EnumClimatiserModes; -import forestry.api.climate.EnumClimatiserTypes; -import forestry.api.climate.IClimateInfo; -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; - -public class GreenhouseClimateSource

extends ClimateSource

{ - - private static final int COOLDOWN = 10; - private int currentCooldown; - - public GreenhouseClimateSource(int ticksForChange) { - super(ticksForChange); - } - - @Override - public boolean changeClimate(int tickCount, IClimateRegion region) { - if (provider == null) { - return false; - } - if(currentCooldown > 0){ - currentCooldown--; - return false; - } - IClimatiserDefinition definition = provider.getDefinition(); - IMultiblockLogic logic = provider.getMultiblockLogic(); - IMultiblockController controller = logic.getController(); - Iterable positionsInRange = provider.getPositionsInRange(); - - boolean hasChange = false; - boolean isActive = false; - if (logic.isConnected() && controller.isAssembled() && controller instanceof IGreenhouseControllerInternal && positionsInRange.iterator().hasNext()) { - IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller; - IClimateInfo climateInfo = getClimateControl(greenhouseInternal); - float controlTemp = climateInfo.getTemperature(); - float controlHum = climateInfo.getHumidity(); - 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.getAverageTemperature() < controlTemp) { - if (!canChange(mode, EnumClimatiserModes.POSITIVE)) { - isActive = false; - } - } else if (region.getAverageTemperature() > controlTemp) { - if (!canChange(mode, EnumClimatiserModes.NEGATIVE)) { - isActive = false; - } - } - } - if (canChange(type, EnumClimatiserTypes.HUMIDITY)) { - if (region.getAverageTemperature() < controlHum) { - if (!canChange(mode, EnumClimatiserModes.POSITIVE)) { - isActive = false; - } - } else if (region.getAverageTemperature() > controlHum) { - if (!canChange(mode, EnumClimatiserModes.NEGATIVE)) { - isActive = false; - } - } - } - } - - if (isActive) { - for (BlockPos pos : positionsInRange) { - IClimatePosition position = region.getPosition(pos); - if (position != null) { - double distance = pos.distanceSq(provider.getCoordinates()); - double range = definition.getRange(); - 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())); - hasChange = true; - } - } else if (position.getTemperature() > controlTemp) { - if (canChange(mode, EnumClimatiserModes.NEGATIVE)) { - position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change)); - hasChange = true; - } - } - } - if (canChange(type, EnumClimatiserTypes.HUMIDITY)) { - if (position.getHumidity() < controlHum) { - if (canChange(mode, EnumClimatiserModes.POSITIVE)) { - position.addHumidity(Math.min(change, controlHum - position.getHumidity())); - hasChange = true; - } - } else if (position.getHumidity() > controlHum) { - if (canChange(mode, EnumClimatiserModes.NEGATIVE)) { - position.addHumidity(-Math.min(position.getHumidity() - controlHum, change)); - hasChange = true; - } - } - } - } - } - } - } - if(!hasChange){ - currentCooldown = COOLDOWN; - if(isActive){ - isActive = false; - } - } - if (provider.isActive() != isActive) { - provider.setActive(isActive); - } - return hasChange; - } - - protected boolean canChange(EnumClimatiserTypes climatiserType, EnumClimatiserTypes type) { - return type == climatiserType || climatiserType == EnumClimatiserTypes.BOTH; - } - - protected boolean canChange(EnumClimatiserModes climatiserMode, EnumClimatiserModes mode) { - return mode == climatiserMode || climatiserMode == EnumClimatiserModes.BOTH; - } - - protected IClimateInfo getClimateControl(IGreenhouseControllerInternal greenhouseInternal) { - return greenhouseInternal.getControlClimate(); - } - -} diff --git a/src/main/java/forestry/greenhouse/GreenhouseClimateWindow.java b/src/main/java/forestry/greenhouse/GreenhouseClimateWindow.java deleted file mode 100644 index 02d2ca841..000000000 --- a/src/main/java/forestry/greenhouse/GreenhouseClimateWindow.java +++ /dev/null @@ -1,122 +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; - -import javax.annotation.Nullable; - -import forestry.api.climate.EnumClimatiserModes; -import forestry.api.climate.EnumClimatiserTypes; -import forestry.api.climate.IClimateInfo; -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.BiomeClimateInfo; -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 { - @Nullable - private Biome biome; - - public GreenhouseClimateWindow(int ticksForChange) { - super(ticksForChange); - } - - @Override - public boolean changeClimate(int tickCount, IClimateRegion region) { - if (provider == null) { - return false; - } - World world = region.getWorld(); - IClimatiserDefinition definition = provider.getDefinition(); - IMultiblockLogic logic = provider.getMultiblockLogic(); - IMultiblockController controller = logic.getController(); - Iterable positionsInRange = provider.getPositionsInRange(); - - boolean hasChange = false; - WindowMode windowMode = provider.getMode(); - if (logic.isConnected() && controller.isAssembled() && controller instanceof IGreenhouseControllerInternal && positionsInRange.iterator().hasNext()) { - IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller; - IClimateInfo climateInfo = getClimateControl(greenhouseInternal); - float controlTemp = climateInfo.getTemperature(); - float controlHum = climateInfo.getHumidity(); - 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) { - EnumClimatiserTypes type = definition.getType(); - EnumClimatiserModes mode = definition.getMode(); - float maxChange = definition.getChange(); - - for (BlockPos pos : positionsInRange) { - IClimatePosition position = region.getPosition(pos); - if (position != null) { - double distance = pos.distanceSq(provider.getCoordinates()); - 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())); - hasChange = true; - } - } else if (position.getTemperature() > controlTemp) { - if (canChange(mode, EnumClimatiserModes.NEGATIVE)) { - position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change)); - hasChange = true; - } - } - } - if (canChange(type, EnumClimatiserTypes.HUMIDITY)) { - if (position.getHumidity() < controlHum) { - if (canChange(mode, EnumClimatiserModes.POSITIVE)) { - position.addHumidity(Math.min(change, controlHum - position.getHumidity())); - hasChange = true; - } - } else if (position.getHumidity() > controlHum) { - if (canChange(mode, EnumClimatiserModes.NEGATIVE)) { - position.addHumidity(-Math.min(position.getHumidity() - controlHum, change)); - hasChange = true; - } - } - } - } - } - } - } - return hasChange; - } - - @Override - protected IClimateInfo getClimateControl(IGreenhouseControllerInternal greenhouseInternal) { - if (biome == null) { - BlockPos pos = provider.getCoordinates(); - World world = provider.getWorld(); - biome = world.getBiome(pos); - } - return BiomeClimateInfo.getInfo(biome); - } - -} diff --git a/src/main/java/forestry/greenhouse/GreenhouseEventHandler.java b/src/main/java/forestry/greenhouse/GreenhouseEventHandler.java new file mode 100644 index 000000000..dd0ebd989 --- /dev/null +++ b/src/main/java/forestry/greenhouse/GreenhouseEventHandler.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * 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 java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.event.world.WorldEvent; + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.greenhouse.IGreenhouseLimits; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.greenhouse.Position2D; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.core.multiblock.MultiblockUtil; +import forestry.greenhouse.items.ItemGreenhouseScreen; +import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; + +@SideOnly(Side.CLIENT) +public class GreenhouseEventHandler { + + protected long previousCheckTick = 0; + protected Set greenhousePositions = new HashSet<>(); + + @SubscribeEvent + public void onWorldRenderLast(RenderWorldLastEvent event) { + try { + float partialTicks = event.getPartialTicks(); + EntityPlayer player = Minecraft.getMinecraft().player; + World world = player.world; + long tick = world.getTotalWorldTime(); + if (tick > previousCheckTick + 50) { + greenhousePositions.clear(); + for (ItemStack itemStack : getClimateScreen(player.inventory)) { + if (!itemStack.isEmpty()) { + BlockPos position = ItemGreenhouseScreen.getGreenhousePos(itemStack); + IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, position, IGreenhouseComponent.class); + if (controller == null || !controller.isAssembled()) { + return; + } + position = controller.getCenterCoordinates(); + double distance = MathHelper.sqrt(player.getDistanceSqToCenter(position)); + if (distance > 64F) { + return; + } + greenhousePositions.add(position); + } + } + previousCheckTick = tick; + } + for (BlockPos position : greenhousePositions) { + IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, position, IGreenhouseComponent.class); + if (controller == null || !controller.isAssembled()) { + return; + } + IGreenhouseProvider provider = controller.getProvider(); + position = controller.getCenterCoordinates(); + double distance = MathHelper.sqrt(player.getDistanceSqToCenter(position)); + if (distance > 64F) { + return; + } + double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks; + double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks; + double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks; + GlStateManager.pushMatrix(); + GlStateManager.translate(-playerX, -playerY, -playerZ); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.disableTexture2D(); + GlStateManager.glLineWidth(2.5F); + IGreenhouseLimits limits = provider.getUsedLimits(); + if (limits != null) { + BlockPos offset = provider.getCenterPos(); + Position2D minEdge = limits.getMinimumCoordinates(); + Position2D maxEdge = limits.getMaximumCoordinates(); + AxisAlignedBB greenhouseBB = new AxisAlignedBB(minEdge.getX(), limits.getDepth(), minEdge.getZ(), maxEdge.getX() + 1, limits.getHeight() + 1, maxEdge.getZ() + 1); + AxisAlignedBB testBlockBB = Block.FULL_BLOCK_AABB; + testBlockBB = testBlockBB.offset(offset); + RenderGlobal.drawSelectionBoundingBox(testBlockBB, 0.0F, 0.0F, 0.0F, 0.5F); + RenderGlobal.drawSelectionBoundingBox(greenhouseBB, 0.0F, 0.0F, 0.0F, 0.5F); + } + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) { + previousCheckTick = 0; + } + + private NonNullList getClimateScreen(InventoryPlayer inventoryPlayer) { + NonNullList climateScreens = NonNullList.create(); + List items = NonNullList.create(); + items.addAll(inventoryPlayer.mainInventory); + items.addAll(inventoryPlayer.offHandInventory); + for (ItemStack stack : items) { + if (stack.isEmpty()) { + continue; + } + if (stack.getItem() != PluginGreenhouse.getItems().greenhouseScreen) { + continue; + } + if (ItemGreenhouseScreen.isPreviewModeActive(stack) && ItemGreenhouseScreen.isValid(stack, inventoryPlayer.player.world)) { + climateScreens.add(stack); + } + } + return climateScreens; + } + +} diff --git a/src/main/java/forestry/greenhouse/GreenhouseHelper.java b/src/main/java/forestry/greenhouse/GreenhouseHelper.java index 8d0a186a0..2975b40ef 100644 --- a/src/main/java/forestry/greenhouse/GreenhouseHelper.java +++ b/src/main/java/forestry/greenhouse/GreenhouseHelper.java @@ -10,36 +10,94 @@ ******************************************************************************/ package forestry.greenhouse; -import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import net.minecraft.item.ItemStack; + +import forestry.api.climate.IClimateModifier; import forestry.api.greenhouse.IGreenhouseHelper; -import forestry.api.greenhouse.IInternalBlock; +import forestry.api.greenhouse.IGreenhouseLogic; +import forestry.api.greenhouse.IGreenhouseLogicFactory; import forestry.api.multiblock.IGreenhouseController; -import forestry.core.multiblock.IMultiblockControllerInternal; -import forestry.core.multiblock.MultiblockRegistry; -import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; -import forestry.greenhouse.multiblock.InternalBlockCheck; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; public class GreenhouseHelper implements IGreenhouseHelper { - @Override - @Nullable - public IGreenhouseController getGreenhouseController(World world, BlockPos pos) { - for (IMultiblockControllerInternal controllerInternal : MultiblockRegistry.getControllersFromWorld(world)) { - if (controllerInternal instanceof IGreenhouseControllerInternal && - controllerInternal.isAssembled() && - isPositionInGreenhouse((IGreenhouseControllerInternal) controllerInternal, pos)) { - return (IGreenhouseController) controllerInternal; - } - } - return null; + private final Set modifiers; + private List factories = new ArrayList<>(); + private Map windowGlasses = new HashMap<>(); + + public GreenhouseHelper() { + modifiers = new TreeSet((firstModifier, secondModifier) -> firstModifier.getPriority() > secondModifier.getPriority() ? 1 : -1); } - private static boolean isPositionInGreenhouse(IGreenhouseControllerInternal controller, BlockPos pos) { - IInternalBlock checkBlock = new InternalBlockCheck(pos); - return controller.getInternalBlocks().contains(checkBlock); + @Override + public void registerWindowGlass(String name, ItemStack item, String texture) { + windowGlasses.put(name, new GreenhouseWindowGlass(name, texture, item)); + } + + @Override + public ItemStack getGlassItem(String name) { + GreenhouseWindowGlass glass = windowGlasses.get(name); + if (glass == null) { + return ItemStack.EMPTY; + } + return glass.item.copy(); + } + + @Override + public String getGlassTexture(String name) { + GreenhouseWindowGlass glass = windowGlasses.get(name); + if (glass == null) { + return "minecraft:blocks/glass"; + } + return glass.texture; + } + + @Override + public Collection getWindowGlasses() { + return windowGlasses.keySet(); + } + + @Override + public void registerLogic(IGreenhouseLogicFactory logicFactory) { + factories.add(logicFactory); + } + + @Override + public Collection createLogics(IGreenhouseController controller) { + List logics = new ArrayList<>(); + for (IGreenhouseLogicFactory factory : factories) { + logics.add(factory.createLogic(controller)); + } + return logics; + } + + @Override + public void registerModifier(IClimateModifier modifier) { + modifiers.add(modifier); + } + + @Override + public Collection getModifiers() { + return modifiers; + } + + private final class GreenhouseWindowGlass { + ItemStack item; + String name; + String texture; + + public GreenhouseWindowGlass(String name, String texture, ItemStack item) { + this.name = name; + this.texture = texture; + this.item = item; + } } } diff --git a/src/main/java/forestry/greenhouse/PluginGreenhouse.java b/src/main/java/forestry/greenhouse/PluginGreenhouse.java index bfc619c63..bdd22a6dc 100644 --- a/src/main/java/forestry/greenhouse/PluginGreenhouse.java +++ b/src/main/java/forestry/greenhouse/PluginGreenhouse.java @@ -10,33 +10,65 @@ ******************************************************************************/ package forestry.greenhouse; +import com.google.common.base.Preconditions; + import javax.annotation.Nullable; -import com.google.common.base.Preconditions; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.common.MinecraftForge; + +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.registry.GameRegistry; + +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.CircuitSocketType; +import forestry.api.circuits.ICircuitLayout; +import forestry.api.climate.ClimateType; +import forestry.api.core.CamouflageManager; import forestry.api.core.ForestryAPI; +import forestry.api.core.Tabs; import forestry.api.greenhouse.GreenhouseManager; +import forestry.api.greenhouse.IGreenhouseHelper; +import forestry.core.CreativeTabForestry; import forestry.core.PluginCore; +import forestry.core.circuits.CircuitLayout; +import forestry.core.circuits.Circuits; import forestry.core.config.Constants; import forestry.core.items.EnumElectronTube; import forestry.core.items.ItemRegistryCore; +import forestry.core.network.IPacketRegistry; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.OreDictUtil; +import forestry.greenhouse.blocks.BlockClimatiserType; import forestry.greenhouse.blocks.BlockGreenhouseType; import forestry.greenhouse.blocks.BlockRegistryGreenhouse; +import forestry.greenhouse.camouflage.CamouflageAccess; +import forestry.greenhouse.camouflage.CamouflageHandlerBlock; +import forestry.greenhouse.circuits.CircuitClimateSource; +import forestry.greenhouse.climate.modifiers.AltitudeModifier; +import forestry.greenhouse.climate.modifiers.ClimateSourceModifier; +import forestry.greenhouse.climate.modifiers.TimeModifier; +import forestry.greenhouse.climate.modifiers.WeatherModifier; +import forestry.greenhouse.items.ItemRegistryGreenhouse; +import forestry.greenhouse.multiblock.GreenhouseController; +import forestry.greenhouse.multiblock.blocks.ChunkEvents; +import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; +import forestry.greenhouse.network.PacketRegistryGreenhouse; import forestry.greenhouse.proxy.ProxyGreenhouse; -import forestry.greenhouse.tiles.TileGreenhouseNursery; -import forestry.greenhouse.tiles.TileGreenhouseClimateControl; +import forestry.greenhouse.tiles.TileDehumidifier; +import forestry.greenhouse.tiles.TileFan; import forestry.greenhouse.tiles.TileGreenhouseControl; -import forestry.greenhouse.tiles.TileGreenhouseDoor; -import forestry.greenhouse.tiles.TileGreenhouseDryer; -import forestry.greenhouse.tiles.TileGreenhouseFan; import forestry.greenhouse.tiles.TileGreenhouseGearbox; -import forestry.greenhouse.tiles.TileGreenhouseHatch; -import forestry.greenhouse.tiles.TileGreenhouseHeater; import forestry.greenhouse.tiles.TileGreenhousePlain; -import forestry.greenhouse.tiles.TileGreenhouseHumidifier; -import forestry.greenhouse.tiles.TileGreenhouseValve; +import forestry.greenhouse.tiles.TileGreenhouseScreen; import forestry.greenhouse.tiles.TileGreenhouseWindow; +import forestry.greenhouse.tiles.TileHeater; +import forestry.greenhouse.tiles.TileHumidifier; +import forestry.greenhouse.tiles.TileHygroregulator; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; import forestry.plugins.ForestryPluginUids; @@ -55,200 +87,186 @@ public class PluginGreenhouse extends BlankForestryPlugin { @Nullable private static BlockRegistryGreenhouse blocks; + @Nullable + private static ItemRegistryGreenhouse items; public static BlockRegistryGreenhouse getBlocks() { Preconditions.checkState(blocks != null); return blocks; } + public static ItemRegistryGreenhouse getItems() { + Preconditions.checkArgument(items != null); + return items; + } + + public static CreativeTabs getGreenhouseTab() { + if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) { + return Tabs.tabAgriculture; + } + return CreativeTabForestry.tabForestry; + } + @Override public void setupAPI() { GreenhouseManager.greenhouseHelper = new GreenhouseHelper(); + GreenhouseManager.greenhouseBlockManager = GreenhouseBlockManager.getInstance(); + CamouflageManager.camouflageAccess = new CamouflageAccess(); } @Override public void registerItemsAndBlocks() { blocks = new BlockRegistryGreenhouse(); + items = new ItemRegistryGreenhouse(); } @Override public void preInit() { + proxy.preInti(); + MinecraftForge.EVENT_BUS.register(new ChunkEvents()); + CamouflageManager.camouflageAccess.registerItemHandler(new CamouflageHandlerBlock()); proxy.initializeModels(); + + ICircuitLayout layoutManaged = new CircuitLayout("greenhouse.climatiser", CircuitSocketType.GREENHOUSE_CLIMATISER); + ChipsetManager.circuitRegistry.registerLayout(layoutManaged); } @Override public void doInit() { super.doInit(); + IGreenhouseHelper helper = GreenhouseManager.greenhouseHelper; - GameRegistry.registerTileEntity(TileGreenhouseFan.class, "forestry.GreenhouseFan"); - GameRegistry.registerTileEntity(TileGreenhouseHeater.class, "forestry.GreenhouseHeater"); - GameRegistry.registerTileEntity(TileGreenhouseDryer.class, "forestry.GreenhouseDryer"); - GameRegistry.registerTileEntity(TileGreenhouseHumidifier.class, "forestry.GreenhouseSprinkler"); - GameRegistry.registerTileEntity(TileGreenhouseValve.class, "forestry.GreenhouseValve"); + GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.GreenhousePlain"); + GameRegistry.registerTileEntity(TileFan.class, "forestry.GreenhouseFan"); + GameRegistry.registerTileEntity(TileHeater.class, "forestry.GreenhouseHeater"); + GameRegistry.registerTileEntity(TileDehumidifier.class, "forestry.GreenhouseDryer"); + GameRegistry.registerTileEntity(TileHumidifier.class, "forestry.GreenhouseSprinkler"); + GameRegistry.registerTileEntity(TileHygroregulator.class, "forestry.ClimateSourceHygroregulator"); GameRegistry.registerTileEntity(TileGreenhouseGearbox.class, "forestry.GreenhouseGearbox"); GameRegistry.registerTileEntity(TileGreenhouseControl.class, "forestry.GreenhouseController"); - 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(TileGreenhouseNursery.class, "forestry.GreenhouseButterflyHatch"); + GameRegistry.registerTileEntity(TileGreenhouseWindow.class, "forestry.ClimateSourceWindow"); + GameRegistry.registerTileEntity(TileGreenhouseScreen.class, "forestry.GreenhouseScreen"); + + helper.registerWindowGlass("glass", new ItemStack(Blocks.GLASS), "blocks/glass"); + for (EnumDyeColor dye : EnumDyeColor.values()) { + helper.registerWindowGlass("glass" + dye.getName(), new ItemStack(Blocks.STAINED_GLASS, 1, dye.getMetadata()), "blocks/glass_" + dye.getName()); } + + helper.registerModifier(new WeatherModifier()); + helper.registerModifier(new TimeModifier()); + helper.registerModifier(new AltitudeModifier()); + helper.registerModifier(new ClimateSourceModifier()); + + Circuits.greenhouseClimatiserTemperature1 = new CircuitClimateSource("climatiser.temperature.1", ClimateType.TEMPERATURE, 0.125F, 0.125F); + Circuits.greenhouseClimatiserTemperature2 = new CircuitClimateSource("climatiser.temperature.2", ClimateType.TEMPERATURE, 0.25F, 0.25F); + Circuits.greenhouseClimatiserHumidity1 = new CircuitClimateSource("climatiser.humidity.1", ClimateType.HUMIDITY, 0.125F, 0.125F); + Circuits.greenhouseClimatiserHumidity2 = new CircuitClimateSource("climatiser.humidity.2", ClimateType.HUMIDITY, 0.25F, 0.25F); + proxy.inti(); } @Override public void registerRecipes() { ItemRegistryCore coreItems = PluginCore.getItems(); BlockRegistryGreenhouse blocks = getBlocks(); + ItemRegistryGreenhouse items = getItems(); - Block greenhousePlainBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN); - RecipeUtil.addRecipe("greenhouse_plain", new ItemStack(greenhousePlainBlock, 2), - "#X#", - "SIS", - 'I', OreDictUtil.INGOT_IRON, - 'S', OreDictUtil.SLAB_WOOD, - 'X', Blocks.BRICK_BLOCK, - '#', coreItems.craftingMaterial.getCamouflagedPaneling()); + // / CAMOUFLAGE SPRAY CAN + RecipeUtil.addRecipe("camouflage_spray_can", items.camouflageSprayCan, "TTT", "TCT", "TCT", 'T', OreDictUtil.INGOT_TIN, 'C', coreItems.craftingMaterial.getCamouflagedPaneling()); - Block greenhouseGlassBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS); - RecipeUtil.addRecipe("greenhouse_glass", new ItemStack(greenhouseGlassBlock, 2), - "#X#", - "PIP", - 'I', OreDictUtil.INGOT_IRON, - 'X', OreDictUtil.BLOCK_GLASS, - 'P', OreDictUtil.PANE_GLASS, - '#', coreItems.craftingMaterial.getCamouflagedPaneling()); + ItemStack greenhousePlainBlock = new ItemStack(blocks.greenhouseBlock, 2, BlockGreenhouseType.PLAIN.ordinal()); + RecipeUtil.addRecipe("greenhouse_plain", greenhousePlainBlock.copy(), + "#X#", + "SIS", + 'I', OreDictUtil.INGOT_IRON, + 'S', OreDictUtil.SLAB_WOOD, + 'X', GreenhouseController.createDefaultCamouflageBlock(), + '#', coreItems.craftingMaterial.getCamouflagedPaneling()); + greenhousePlainBlock.setCount(1); - Block greenhouseHatchInputBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HATCH_INPUT); - RecipeUtil.addRecipe("greenhouse_hatch_in", greenhouseHatchInputBlock, - "TXT", - "#H#", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - 'H', OreDictUtil.TRAPDOOR_WOOD, - '#', OreDictUtil.GEAR_TIN, - 'T', coreItems.tubes.get(EnumElectronTube.BRONZE, 1)); + RecipeUtil.addRecipe("greenhouse_control", new ItemStack(blocks.greenhouseBlock, 1, BlockGreenhouseType.CONTROL.ordinal()), + " X ", + "#T#", + 'X', greenhousePlainBlock.copy(), + '#', OreDictUtil.DUST_REDSTONE, + 'T', coreItems.tubes.get(EnumElectronTube.GOLD, 1)); - Block greenhouseHatchOutputBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HATCH_OUTPUT); - RecipeUtil.addRecipe("greenhouse_hatch_out", greenhouseHatchOutputBlock, - "#H#", - "TXT", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - 'H', OreDictUtil.TRAPDOOR_WOOD, - '#', OreDictUtil.GEAR_TIN, - 'T', coreItems.tubes.get(EnumElectronTube.BRONZE, 1)); + RecipeUtil.addRecipe("greenhouse_gearbox", new ItemStack(blocks.greenhouseBlock, 1, BlockGreenhouseType.GEARBOX.ordinal()), + " X ", + "###", + 'X', greenhousePlainBlock.copy(), + '#', OreDictUtil.GEAR_TIN); - Block greenhouseControlBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.CONTROL); - RecipeUtil.addRecipe("greenhouse_control", greenhouseControlBlock, - " X ", - "#T#", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - '#', OreDictUtil.DUST_REDSTONE, - 'T', coreItems.tubes.get(EnumElectronTube.GOLD, 1)); + RecipeUtil.addRecipe("greenhouse_hygro", new ItemStack(blocks.climatiserBlock, 1, BlockClimatiserType.HYGRO.ordinal()), + "GIG", + "GXG", + "GIG", + 'X', greenhousePlainBlock.copy(), + 'I', OreDictUtil.INGOT_IRON, + 'G', OreDictUtil.BLOCK_GLASS); - Block greenhouseGearBoxBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.GEARBOX); - RecipeUtil.addRecipe("greenhouse_gearbox", greenhouseGearBoxBlock, - " X ", - "###", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - '#', OreDictUtil.GEAR_TIN); + RecipeUtil.addRecipe("greenhouse_heater", new ItemStack(blocks.climatiserBlock, 1, BlockClimatiserType.HEATER.ordinal()), + "T#T", + "#X#", + "T#T", + 'X', greenhousePlainBlock.copy(), + '#', OreDictUtil.INGOT_TIN, + 'T', coreItems.tubes.get(EnumElectronTube.GOLD, 1)); - Block greenhouseValveBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.VALVE); - RecipeUtil.addRecipe("greenhouse_valve", greenhouseValveBlock, - " X ", - "#G#", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - '#', OreDictUtil.BLOCK_GLASS, - 'G', OreDictUtil.GEAR_TIN); + RecipeUtil.addRecipe("greenhouse_fan", new ItemStack(blocks.climatiserBlock, 1, BlockClimatiserType.FAN.ordinal()), + "T#T", + "#X#", + "T#T", + 'X', greenhousePlainBlock.copy(), + '#', OreDictUtil.INGOT_IRON, + 'T', coreItems.tubes.get(EnumElectronTube.TIN, 1)); - Block greenhouseHeaterBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HEATER); - RecipeUtil.addRecipe("greenhouse_heater", greenhouseHeaterBlock, - "T#T", - "#X#", - "T#T", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - '#', OreDictUtil.INGOT_TIN, - 'T', coreItems.tubes.get(EnumElectronTube.GOLD, 1)); + RecipeUtil.addRecipe("greenhouse_dehumidifier", new ItemStack(blocks.climatiserBlock, 1, BlockClimatiserType.DEHUMIDIFIER.ordinal()), + "T#T", + "#X#", + "T#T", + 'X', greenhousePlainBlock.copy(), + '#', OreDictUtil.INGOT_TIN, + 'T', coreItems.tubes.get(EnumElectronTube.BLAZE, 1)); - Block greenhouseFanlock = blocks.getGreenhouseBlock(BlockGreenhouseType.FAN); - RecipeUtil.addRecipe("greenhouse_fan", greenhouseFanlock, - "T#T", - "#X#", - "T#T", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - '#', OreDictUtil.INGOT_IRON, - 'T', coreItems.tubes.get(EnumElectronTube.TIN, 1)); + RecipeUtil.addRecipe("greenhouse_humidifier", new ItemStack(blocks.climatiserBlock, 1, BlockClimatiserType.HUMIDIFIER.ordinal()), + "T#T", + "#X#", + "T#T", + 'X', greenhousePlainBlock.copy(), + '#', OreDictUtil.INGOT_TIN, + 'T', coreItems.tubes.get(EnumElectronTube.LAPIS, 1)); - Block greenhouseDryerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.DEHUMIDIFIER); - RecipeUtil.addRecipe("greenhouse_dryer", greenhouseDryerBlock, - "T#T", - "#X#", - "T#T", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - '#', OreDictUtil.INGOT_TIN, - 'T', coreItems.tubes.get(EnumElectronTube.BLAZE, 1)); - - Block greenhouseSprinklerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HUMIDIFIER); - RecipeUtil.addRecipe("greenhouse_sprinkler", greenhouseSprinklerBlock, - "T#T", - "#X#", - "T#T", - 'X', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - '#', OreDictUtil.INGOT_TIN, - 'T', coreItems.tubes.get(EnumElectronTube.LAPIS, 1)); - - Block greenhouseDoorBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.DOOR); - RecipeUtil.addRecipe("greenhouse_door", greenhouseDoorBlock, - true, - "GG ", - "GG ", - "GG ", - 'G', blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS)); - - Block greenhouseWindowBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.WINDOW); - RecipeUtil.addRecipe("greenhouse_window", greenhouseWindowBlock, - true, - "GGS", - "GGG", - "GGS", - 'G', blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS), - 'S', OreDictUtil.STICK_WOOD); - - Block greenhouseWindowRoofBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.WINDOW_UP); - RecipeUtil.addRecipe("greenhouse_window_roof", greenhouseWindowRoofBlock, + for (String glassName : GreenhouseManager.greenhouseHelper.getWindowGlasses()) { + ItemStack glassItem = GreenhouseManager.greenhouseHelper.getGlassItem(glassName); + ItemStack window = blocks.window.getItem(glassName); + ItemStack roodWindow = blocks.roofWindow.getItem(glassName); + RecipeUtil.addRecipe("greenhouse_window_" + glassName, roodWindow, true, "SGS", "GGG", "GGG", - 'G', blocks.getGreenhouseBlock(BlockGreenhouseType.GLASS), + 'G', glassItem, 'S', OreDictUtil.STICK_WOOD); - Block greenhouseClimateControlBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.CLIMATE_CONTROL); - RecipeUtil.addRecipe("greenhouse_climate_control", greenhouseClimateControlBlock, + RecipeUtil.addRecipe("greenhouse_window_roof_" + glassName, window, true, - "IRG", - "EBT", - "GRI", - 'B', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - 'I', OreDictUtil.INGOT_BRONZE, - 'G', OreDictUtil.GEAR_TIN, - 'R', OreDictUtil.DUST_REDSTONE, - 'T', coreItems.tubes.get(EnumElectronTube.LAPIS, 1), - 'E', coreItems.tubes.get(EnumElectronTube.BLAZE, 1)); - - if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) { - Block greenhouseButterflyHatchBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.NURSERY); - RecipeUtil.addRecipe("greenhouse_butterfly_hatch", greenhouseButterflyHatchBlock, - true, - "IRG", - "SBS", - "GRI", - 'R', OreDictUtil.DUST_REDSTONE, - 'I', OreDictUtil.INGOT_IRON, - 'G', OreDictUtil.GEAR_COPPER, - 'B', blocks.getGreenhouseBlock(BlockGreenhouseType.PLAIN), - 'S', coreItems.craftingMaterial.getSilkWisp()); + "SGG", + "GGG", + "SGG", + 'G', glassItem, + 'S', OreDictUtil.STICK_WOOD); } + + ICircuitLayout layout = ChipsetManager.circuitRegistry.getLayout("forestry.greenhouse.climatiser"); + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.greenhouseClimatiserTemperature1); + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.BLAZE, 1), Circuits.greenhouseClimatiserTemperature2); + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.greenhouseClimatiserHumidity1); + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.greenhouseClimatiserHumidity2); + } + + @Override + public IPacketRegistry getPacketRegistry() { + return new PacketRegistryGreenhouse(); } } diff --git a/src/main/java/forestry/greenhouse/blocks/BlockClimatiser.java b/src/main/java/forestry/greenhouse/blocks/BlockClimatiser.java new file mode 100644 index 000000000..9f6d74afa --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/BlockClimatiser.java @@ -0,0 +1,291 @@ +/******************************************************************************* + * 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.blocks; + +import javax.annotation.Nullable; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +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.gui.GuiScreen; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.color.BlockColors; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +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.EnumHand; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.common.property.ExtendedBlockState; +import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.common.property.IUnlistedProperty; +import net.minecraftforge.fluids.FluidUtil; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.ICamouflageHandler; +import forestry.api.core.IItemModelRegister; +import forestry.api.core.IModelManager; +import forestry.api.core.ISpriteRegister; +import forestry.api.core.ITextureManager; +import forestry.core.blocks.IBlockWithMeta; +import forestry.core.blocks.IColoredBlock; +import forestry.core.blocks.properties.UnlistedBlockAccess; +import forestry.core.blocks.properties.UnlistedBlockPos; +import forestry.core.gui.GuiHandler; +import forestry.core.tiles.IActivatable; +import forestry.core.tiles.TileForestry; +import forestry.core.tiles.TileUtil; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.ItemTooltipUtil; +import forestry.core.utils.Translator; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.models.ModelCamouflaged; +import forestry.greenhouse.tiles.TileDehumidifier; +import forestry.greenhouse.tiles.TileFan; +import forestry.greenhouse.tiles.TileHeater; +import forestry.greenhouse.tiles.TileHumidifier; +import forestry.greenhouse.tiles.TileHygroregulator; + +public class BlockClimatiser extends Block implements IBlockWithMeta, ISpriteRegister, IItemModelRegister, IColoredBlock, IBlockCamouflaged, ITileEntityProvider { + public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockClimatiserType.class); + + public BlockClimatiser() { + super(Material.GLASS); + + setHardness(1.0f); + setHarvestLevel("pickaxe", 0); + setCreativeTab(PluginGreenhouse.getGreenhouseTab()); + this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, BlockClimatiserType.HUMIDIFIER)); + } + + @Override + public String getNameFromMeta(int meta) { + BlockClimatiserType type = BlockClimatiserType.VALUES[meta]; + return type.getName(); + } + + @SuppressWarnings("deprecation") + @Override + public IBlockState getStateFromMeta(int meta) { + return getDefaultState().withProperty(TYPE, BlockClimatiserType.VALUES[meta]); + } + + @Override + public int getMetaFromState(IBlockState state) { + return state.getValue(TYPE).ordinal(); + } + + @SuppressWarnings("deprecation") + @Override + public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { + TileEntity tile = TileUtil.getTile(worldIn, pos, TileEntity.class); + if (tile instanceof IActivatable) { + state = state.withProperty(State.PROPERTY, ((IActivatable) tile).isActive() ? State.ON : State.OFF); + } + return super.getActualState(state, worldIn, pos); + } + + @Override + public int damageDropped(IBlockState state) { + return getMetaFromState(state); + } + + /* MODELS */ + @Override + @SideOnly(Side.CLIENT) + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.SOLID; + } + + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + TileForestry tile = TileUtil.getTile(world, pos, TileForestry.class); + if (tile != null) { + if (TileUtil.isUsableByPlayer(player, tile)) { + + ItemStack heldItem = player.getHeldItem(hand); + if (!player.isSneaking()) { + if (FluidUtil.interactWithFluidHandler(player, hand, world, pos, facing)) { + return true; + } + } + + if (!world.isRemote) { + GuiHandler.openGui(player, tile); + } + return true; + } + } + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList list) { + for (int i = 0; i < BlockClimatiserType.VALUES.length; i++) { + list.add(new ItemStack(itemIn, 1, i)); + } + } + + @Override + protected BlockStateContainer createBlockState() { + return new ExtendedBlockState(this, new IProperty[]{TYPE, State.PROPERTY}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) { + if (GuiScreen.isShiftKeyDown()) { + tooltip.add(TextFormatting.GREEN.toString() + TextFormatting.ITALIC.toString() + Translator.translateToLocal("tile.for.greenhouse.camouflage.tooltip")); + } else { + ItemTooltipUtil.addShiftInformation(stack, player, tooltip, advanced); + } + } + + @Override + public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { + return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos) + .withProperty(UnlistedBlockAccess.BLOCKACCESS, world); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) { + return true; + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) { + BlockClimatiserType type = BlockClimatiserType.VALUES[meta]; + switch (type) { + case DEHUMIDIFIER: + return new TileDehumidifier(); + case HUMIDIFIER: + return new TileHumidifier(); + case HYGRO: + return new TileHygroregulator(); + case FAN: + return new TileFan(); + case HEATER: + return new TileHeater(); + } + return null; + } + + @Override + @SideOnly(Side.CLIENT) + @SuppressWarnings("deprecation") + public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex) { + if (pos == null || worldIn == null) { + return 0xffffff; + } + ItemStack camouflageStack = getCamouflageBlock(worldIn, pos); + + if (tintIndex < ModelCamouflaged.OVERLAY_COLOR_INDEX && !camouflageStack.isEmpty()) { + Block block = Block.getBlockFromItem(camouflageStack.getItem()); + if (block != Blocks.AIR) { + IBlockState camouflageState = block.getStateFromMeta(camouflageStack.getItemDamage()); + BlockColors blockColors = Minecraft.getMinecraft().getBlockColors(); + + int color = blockColors.colorMultiplier(camouflageState, worldIn, pos, tintIndex); + if (color != -1) { + return color; + } + } + } + + return 0xffffff; + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + for (int i = 0; i < BlockClimatiserType.VALUES.length; i++) { + ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation("forestry:climatiser", "inventory")); + } + } + + @SideOnly(Side.CLIENT) + @Override + public void registerSprites(ITextureManager manager) { + BlockClimatiserSprite.registerSprites(); + } + + @Override + public ItemStack getCamouflageBlock(IBlockAccess world, BlockPos pos) { + if (world == null || pos == null) { + return ItemStack.EMPTY; + } + ICamouflageHandler handler = getCamouflageHandler(world, pos); + if (handler != null) { + ItemStack camouflageStack = handler.getCamouflageBlock(); + ItemStack defaultCamouflageStack = handler.getDefaultCamouflageBlock(); + if (!ItemStackUtil.isIdenticalItem(camouflageStack, defaultCamouflageStack)) { + return camouflageStack; + } + } + return ItemStack.EMPTY; + } + + @Override + public ICamouflageHandler getCamouflageHandler(IBlockAccess world, BlockPos pos) { + if (world == null || pos == null) { + return null; + } + ICamouflageHandler handler = TileUtil.getTile(world, pos, ICamouflageHandler.class); + if (handler != null) { + return handler; + } + return null; + } + + @SideOnly(Side.CLIENT) + @Override + public boolean hasOverlaySprite(int meta, int layer) { + return true; + } + + @Override + public int getLayers() { + return 1; + } + + @SideOnly(Side.CLIENT) + @Override + public TextureAtlasSprite getDefaultSprite() { + return BlockGreenhouseSprite.getSprite(BlockGreenhouseType.PLAIN, null, null, -1); + } + + @SideOnly(Side.CLIENT) + @Override + public TextureAtlasSprite getOverlaySprite(EnumFacing facing, IBlockState state, int meta, int layer) { + return BlockClimatiserSprite.getSprite(BlockClimatiserType.VALUES[meta], facing, state); + } +} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockClimatiserSprite.java b/src/main/java/forestry/greenhouse/blocks/BlockClimatiserSprite.java new file mode 100644 index 000000000..9c0ed8571 --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/BlockClimatiserSprite.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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.blocks; + +import javax.annotation.Nullable; +import java.util.EnumMap; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.config.Constants; + +@SideOnly(Side.CLIENT) +public enum BlockClimatiserSprite { + HYGRO("hygroregulator"), + HEATER_OFF("heater.off"), HEATER_ON("heater.on"), + FAN_OFF("fan.off"), FAN_ON("fan.on"), + HUMIDIFIER_OFF("humidifier.off"), HUMIDIFIER_ON("humidifier.on"), + DEHUMIDIFIER_OFF("dehumidifier.off"), DEHUMIDIFIER_ON("dehumidifier.on"); + + public static final BlockClimatiserSprite[] VALUES = values(); + private static EnumMap sprites; + private static TextureAtlasSprite missingImage; + + private final String spriteName; + + BlockClimatiserSprite(String spriteName) { + this.spriteName = spriteName; + } + + public static void registerSprites() { + sprites = new EnumMap<>(BlockClimatiserSprite.class); + TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); + + for (BlockClimatiserSprite sprite : BlockClimatiserSprite.VALUES) { + ResourceLocation location = new ResourceLocation(Constants.MOD_ID, "blocks/greenhouse/" + sprite.spriteName); + TextureAtlasSprite textureAtlasSprite = map.registerSprite(location); + sprites.put(sprite, textureAtlasSprite); + } + missingImage = map.missingImage; + } + + /** + * @return The texture sprite from the type and the {@link IBlockState} of the greenhouse block + */ + public static TextureAtlasSprite getSprite(BlockClimatiserType type, @Nullable EnumFacing facing, @Nullable IBlockState state) { + TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); + switch (type) { + case HYGRO: + return sprites.get(BlockClimatiserSprite.HYGRO); + case HEATER: + if (state == null || state.getValue(State.PROPERTY) == State.OFF) { + return sprites.get(BlockClimatiserSprite.HEATER_OFF); + } else { + return sprites.get(BlockClimatiserSprite.HEATER_ON); + } + case FAN: + if (state == null || state.getValue(State.PROPERTY) == State.OFF) { + return sprites.get(BlockClimatiserSprite.FAN_OFF); + } else { + return sprites.get(BlockClimatiserSprite.FAN_ON); + } + case HUMIDIFIER: + if (state == null || state.getValue(State.PROPERTY) == State.OFF) { + return sprites.get(BlockClimatiserSprite.HUMIDIFIER_OFF); + } else { + return sprites.get(BlockClimatiserSprite.HUMIDIFIER_ON); + } + case DEHUMIDIFIER: + if (state == null || state.getValue(State.PROPERTY) == State.OFF) { + return sprites.get(BlockClimatiserSprite.DEHUMIDIFIER_OFF); + } else { + return sprites.get(BlockClimatiserSprite.DEHUMIDIFIER_ON); + } + } + return missingImage; + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDryer.java b/src/main/java/forestry/greenhouse/blocks/BlockClimatiserType.java similarity index 53% rename from src/main/java/forestry/greenhouse/tiles/TileGreenhouseDryer.java rename to src/main/java/forestry/greenhouse/blocks/BlockClimatiserType.java index 45926a445..e82f5e5b0 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDryer.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockClimatiserType.java @@ -8,19 +8,29 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.greenhouse.tiles; +package forestry.greenhouse.blocks; -import forestry.api.climate.EnumClimatiserModes; -import forestry.api.climate.EnumClimatiserTypes; -import forestry.api.climate.IClimatiserDefinition; -import forestry.core.climate.ClimatiserDefinition; +import java.util.Locale; -public class TileGreenhouseDryer extends TileGreenhouseClimatiser { +import net.minecraft.util.IStringSerializable; - private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5F, EnumClimatiserTypes.HUMIDITY); +public enum BlockClimatiserType implements IStringSerializable { + HYGRO, + //temperature + HEATER, FAN, + //humidity + HUMIDIFIER, DEHUMIDIFIER; - public TileGreenhouseDryer() { - super(DEFINITION); + public static final BlockClimatiserType[] VALUES = values(); + + @Override + public String toString() { + return getName(); + } + + @Override + public String getName() { + return name().toLowerCase(Locale.ENGLISH); } } diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java index f052405af..f0e61ba1c 100755 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java @@ -11,24 +11,20 @@ package forestry.greenhouse.blocks; import javax.annotation.Nullable; -import java.util.EnumMap; import java.util.List; -import java.util.Locale; -import java.util.Map; 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.gui.GuiScreen; import net.minecraft.client.renderer.block.model.ModelResourceLocation; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.client.renderer.color.BlockColors; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; @@ -36,11 +32,8 @@ 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.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; @@ -51,109 +44,68 @@ import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import forestry.api.core.ForestryAPI; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateState; +import forestry.api.core.EnumTemperature; +import forestry.api.core.ICamouflageHandler; import forestry.api.core.ICamouflagedTile; import forestry.api.core.IModelManager; import forestry.api.core.ISpriteRegister; import forestry.api.core.ITextureManager; -import forestry.api.core.Tabs; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IMultiblockComponent; import forestry.api.multiblock.IMultiblockController; -import forestry.core.CreativeTabForestry; import forestry.core.blocks.BlockStructure; -import forestry.core.blocks.IBlockRotatable; +import forestry.core.blocks.IBlockWithMeta; import forestry.core.blocks.IColoredBlock; import forestry.core.blocks.properties.UnlistedBlockAccess; import forestry.core.blocks.properties.UnlistedBlockPos; import forestry.core.multiblock.MultiblockTileEntityForestry; -import forestry.core.tiles.IActivatable; +import forestry.core.multiblock.MultiblockUtil; import forestry.core.tiles.TileUtil; -import forestry.core.utils.CamouflageUtil; +import forestry.core.utils.ClimateUtil; import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.Log; +import forestry.core.utils.ItemTooltipUtil; import forestry.core.utils.Translator; -import forestry.greenhouse.tiles.TileGreenhouseClimateControl; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.models.ModelCamouflaged; +import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; import forestry.greenhouse.tiles.TileGreenhouseControl; -import forestry.greenhouse.tiles.TileGreenhouseDoor; -import forestry.greenhouse.tiles.TileGreenhouseDryer; -import forestry.greenhouse.tiles.TileGreenhouseFan; import forestry.greenhouse.tiles.TileGreenhouseGearbox; -import forestry.greenhouse.tiles.TileGreenhouseHatch; -import forestry.greenhouse.tiles.TileGreenhouseHeater; -import forestry.greenhouse.tiles.TileGreenhouseHumidifier; -import forestry.greenhouse.tiles.TileGreenhouseNursery; import forestry.greenhouse.tiles.TileGreenhousePlain; -import forestry.greenhouse.tiles.TileGreenhouseValve; -import forestry.greenhouse.tiles.TileGreenhouseWindow; -import forestry.greenhouse.tiles.TileGreenhouseWindow.WindowMode; -import forestry.plugins.ForestryPluginUids; +import forestry.greenhouse.tiles.TileGreenhouseScreen; -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 = PropertyEnum.create("state", State.class); - public static final PropertyBool BLOCKED = PropertyBool.create("blocked"); - public static final PropertyDirection FACING = PropertyDirection.create("facing", Plane.HORIZONTAL); +public class BlockGreenhouse extends BlockStructure implements ISpriteRegister, IBlockWithMeta, IColoredBlock, IBlockCamouflaged { + public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockGreenhouseType.class); - public enum State implements IStringSerializable { - ON, OFF; - - @Override - public String getName() { - return name().toLowerCase(Locale.ENGLISH); - } - } - - public static Map create() { - Map blockMap = new EnumMap<>(BlockGreenhouseType.class); - for (final BlockGreenhouseType type : BlockGreenhouseType.VALUES) { - if (type == BlockGreenhouseType.NURSERY) { - if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) { - continue; - } - } - - BlockGreenhouse block; - if (type == BlockGreenhouseType.DOOR) { - block = new BlockGreenhouseDoor(); - } else { - block = new BlockGreenhouse(type) { - - @Override - public BlockGreenhouseType getGreenhouseType() { - return type; - } - - - @Override - public SoundType getSoundType() { - if (hasGlass()) { - return SoundType.GLASS; - } - return super.getSoundType(); - } - }; - } - blockMap.put(type, block); - } - return blockMap; - } - - public BlockGreenhouse(BlockGreenhouseType type) { + public BlockGreenhouse() { super(Material.ROCK); - IBlockState defaultState = this.blockState.getBaseState(); - if (type == BlockGreenhouseType.WINDOW || type == BlockGreenhouseType.WINDOW_UP) { - defaultState = defaultState.withProperty(FACING, EnumFacing.NORTH); - } - setDefaultState(defaultState); setHardness(1.0f); setHarvestLevel("pickaxe", 0); - if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) { - setCreativeTab(Tabs.tabAgriculture); - } else { - setCreativeTab(CreativeTabForestry.tabForestry); + setCreativeTab(PluginGreenhouse.getGreenhouseTab()); + this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, BlockGreenhouseType.PLAIN)); + } + + @Override + public String getNameFromMeta(int meta) { + BlockGreenhouseType type = BlockGreenhouseType.VALUES[meta]; + return type.getName(); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + for (int i = 0; i < BlockGreenhouseType.VALUES.length; i++) { + if (i == 1 || i == 2) { + continue; + } + ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation("forestry:greenhouse", "inventory")); } } @@ -169,24 +121,8 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR } IMultiblockController controller = part.getMultiblockLogic().getController(); - if (playerIn.getHeldItemMainhand().isEmpty()) { - if (part instanceof TileGreenhouseWindow) { - TileGreenhouseWindow window = (TileGreenhouseWindow) part; - 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(playerIn, getPlaySound(!window.isActive()), pos, 0); - return true; - } - } - + ItemStack mainHand = playerIn.getHeldItemMainhand(); + if (mainHand.isEmpty()) { if (playerIn.getHeldItemOffhand().isEmpty()) { // 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. @@ -208,125 +144,94 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR if (!controller.isAssembled()) { return false; } - + if (!worldIn.isRemote) { part.openGui(playerIn); } return true; } - protected int getPlaySound(boolean open) { - if (open) { - return 1007; - } else { - return 1013; - } - } - - @Override - public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { - if (getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP) { - return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos) - .withProperty(UnlistedBlockAccess.BLOCKACCESS, world); - } - return super.getExtendedState(state, world, pos); - } - - @Override - protected BlockStateContainer createBlockState() { - 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}); - } - } - - @Override - public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { - TileEntity tile = TileUtil.getTile(worldIn, pos, TileEntity.class); - 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)); - } - + @SuppressWarnings("deprecation") @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); + return getDefaultState().withProperty(TYPE, BlockGreenhouseType.VALUES[meta]); } @Override public int getMetaFromState(IBlockState state) { - if (getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP) { - return state.getValue(FACING).ordinal() - 2; - } - return 0; + return state.getValue(TYPE).ordinal(); } @Override - public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) { - IBlockState state = world.getBlockState(pos); + public int damageDropped(IBlockState state) { + int meta = getMetaFromState(state); + if (meta == 1 || meta == 2) { + meta = 0; + } + return meta; + } - if (state.getProperties().containsKey(FACING)) { - world.setBlockState(pos, state.withProperty(FACING, player.getHorizontalFacing().getOpposite())); + /* MODELS */ + @Override + @SideOnly(Side.CLIENT) + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.SOLID; + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList list) { + for (int i = 0; i < BlockGreenhouseType.VALUES.length; i++) { + if (i == 1 || i == 2) { + continue; + } + list.add(new ItemStack(itemIn, 1, i)); } } @Override - @Deprecated - public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { - try { - TileUtil.actOnTile(worldIn, pos, TileGreenhouseWindow.class, TileGreenhouseWindow::onNeighborBlockChange); - } catch (StackOverflowError error) { - Log.error("Stack Overflow Error in BlockMachine.onNeighborBlockChange()", error); - throw error; + protected BlockStateContainer createBlockState() { + return new ExtendedBlockState(this, new IProperty[]{TYPE}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) { + if (GuiScreen.isShiftKeyDown()) { + tooltip.add(Translator.translateToLocal("tile.for.greenhouse.tooltip")); + tooltip.add(TextFormatting.GREEN.toString() + TextFormatting.ITALIC.toString() + Translator.translateToLocal("tile.for.greenhouse.camouflage.tooltip")); + } else { + ItemTooltipUtil.addShiftInformation(stack, player, tooltip, advanced); } } + @Override + public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable EnumFacing side) { + return getGreenhouseType(state) == BlockGreenhouseType.CONTROL; + } + + @Override + public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { + return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos) + .withProperty(UnlistedBlockAccess.BLOCKACCESS, world); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) { + return true; + } + @Override public TileEntity createNewTileEntity(World world, int meta) { - BlockGreenhouseType type = getGreenhouseType(); + BlockGreenhouseType type = getGreenhouseType(getStateFromMeta(meta)); switch (type) { case GEARBOX: return new TileGreenhouseGearbox(); - case DEHUMIDIFIER: - return new TileGreenhouseDryer(); - case HUMIDIFIER: - return new TileGreenhouseHumidifier(); - case VALVE: - return new TileGreenhouseValve(); - case FAN: - return new TileGreenhouseFan(); - case HEATER: - return new TileGreenhouseHeater(); - case DOOR: - 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(); - case NURSERY: - return new TileGreenhouseNursery(); + case SCREEN: + return new TileGreenhouseScreen(); default: return new TileGreenhousePlain(); } @@ -334,127 +239,136 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR @Override @SideOnly(Side.CLIENT) - public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex) { - if (pos == null || worldIn == null) { - return 0xffffff; + @SuppressWarnings("deprecation") + public int colorMultiplier(IBlockState blockState, @Nullable IBlockAccess world, @Nullable BlockPos pos, int tintIndex) { + if (pos == null || world == null) { + return 16777215; } + ItemStack camouflageStack = getCamouflageBlock(world, pos); + if (tintIndex == ModelCamouflaged.OVERLAY_COLOR_INDEX + 1) { + BlockGreenhouseType type = getGreenhouseType(blockState); + if (type == BlockGreenhouseType.SCREEN) { + IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class); + if (controller == null || !controller.isAssembled()) { + return 16777215; + } + IClimateContainer container = controller.getClimateContainer(); + IClimateState state = container.getState(); + return ClimateUtil.getColor(EnumTemperature.getFromValue(state.getTemperature())); + } else if (type == BlockGreenhouseType.BORDER_CENTER) { + boolean isClosed = true; + IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class); + if (controller == null || !controller.isAssembled()) { + isClosed = false; + } else { + IGreenhouseProvider manager = controller.getProvider(); + isClosed = manager.isClosed(); + } + return isClosed ? 1356406 : 12197655; + } + } else if (tintIndex < ModelCamouflaged.OVERLAY_COLOR_INDEX && !camouflageStack.isEmpty()) { + Block block = Block.getBlockFromItem(camouflageStack.getItem()); + if (block != Blocks.AIR) { + IBlockState camouflageState = block.getStateFromMeta(camouflageStack.getItemDamage()); + BlockColors blockColors = Minecraft.getMinecraft().getBlockColors(); - ICamouflagedTile tile = TileUtil.getTile(worldIn, pos, ICamouflagedTile.class); - if (tile != null) { - ItemStack camouflageStack = CamouflageUtil.getCamouflageBlock(worldIn, pos); - - if (tintIndex < 100 && !camouflageStack.isEmpty()) { - Block block = Block.getBlockFromItem(camouflageStack.getItem()); - if (block != Blocks.AIR) { - IBlockState camouflageState = block.getStateFromMeta(camouflageStack.getItemDamage()); - - int color = Minecraft.getMinecraft().getBlockColors().colorMultiplier(camouflageState, worldIn, pos, tintIndex); - if (color != -1) { - return color; - } + int color = blockColors.colorMultiplier(camouflageState, world, pos, tintIndex); + if (color != -1) { + return color; } } } - return 0xffffff; - } - - /* MODELS */ - @Override - @SideOnly(Side.CLIENT) - public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) { - if (hasGlass()) { - return layer == BlockRenderLayer.TRANSLUCENT; - } - return layer != BlockRenderLayer.TRANSLUCENT && layer != BlockRenderLayer.CUTOUT_MIPPED; - } - - @Override - public boolean isFullCube(IBlockState state) { - return !hasGlass(); - } - - @Override - public boolean isOpaqueCube(IBlockState state) { - return !hasGlass(); - } - - protected boolean hasGlass(){ - BlockGreenhouseType type = getGreenhouseType(); - return type == BlockGreenhouseType.GLASS || type == BlockGreenhouseType.WINDOW || type == BlockGreenhouseType.WINDOW_UP; - } - - @Override - public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { - super.onBlockPlacedBy(world, pos, state, placer, stack); - TileUtil.actOnTile(world, pos, TileGreenhouseWindow.class, window -> { - if (!window.getWorld().isRemote) { - window.setMode(window.isBlocked()); - } - }); - } - - @Override - @SideOnly(Side.CLIENT) - public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { - IBlockState iblockstate = blockAccess.getBlockState(pos); - Block block = iblockstate.getBlock(); - - if (getGreenhouseType() == BlockGreenhouseType.GLASS) { - BlockPos posSide = pos.offset(side); - if (blockAccess.getBlockState(posSide) != iblockstate) { - return true; - } - TileEntity tile = TileUtil.getTile(blockAccess, pos); - TileEntity tileSide = TileUtil.getTile(blockAccess, posSide); - if (tile instanceof TileGreenhousePlain && tileSide instanceof TileGreenhousePlain) { - if (((TileGreenhousePlain) tile).getCamouflageType().equals(((TileGreenhousePlain) tileSide).getCamouflageType())) { - ItemStack camouflage = CamouflageUtil.getCamouflageBlock(blockAccess, pos); - ItemStack camouflageSide = CamouflageUtil.getCamouflageBlock(blockAccess, posSide); - if (!camouflage.isEmpty() && !camouflageSide.isEmpty()) { - return !ItemStackUtil.isIdenticalItem(camouflage, camouflageSide); - } - } - } - return block != this && super.shouldSideBeRendered(blockState, blockAccess, pos, side); - } else if (getGreenhouseType() == BlockGreenhouseType.DOOR) { - return super.shouldSideBeRendered(blockState, blockAccess, pos, side); - } - - return super.shouldSideBeRendered(blockState, blockAccess, pos, side); - } - - @SideOnly(Side.CLIENT) - @Override - public void registerModel(Item item, IModelManager manager) { - BlockGreenhouseType type = getGreenhouseType(); - if (type == BlockGreenhouseType.WINDOW) { - ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.window", "inventory")); - } else if (type == BlockGreenhouseType.WINDOW_UP) { - ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.window_up", "inventory")); - } else { - ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse", "inventory")); - } + return 16777215; } @SideOnly(Side.CLIENT) @Override public void registerSprites(ITextureManager manager) { - BlockGreenhouseType.registerSprites(); + BlockGreenhouseSprite.registerSprites(); + } + + public BlockGreenhouseType getGreenhouseType(IBlockState state) { + return state.getValue(TYPE); } @Override - public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable EnumFacing side) { - return getGreenhouseType() == BlockGreenhouseType.CONTROL; + public ItemStack getCamouflageBlock(IBlockAccess world, BlockPos pos) { + if (world == null || pos == null) { + return ItemStack.EMPTY; + } + TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class); + if (tile instanceof ICamouflagedTile) { + ICamouflagedTile block = (ICamouflagedTile) tile; + ItemStack camouflageStack = ItemStack.EMPTY; + + if (tile instanceof ICamouflageHandler) { + ICamouflageHandler tileHandler = (ICamouflageHandler) tile; + ItemStack tileCamouflageStack = tileHandler.getCamouflageBlock(); + ItemStack defaultCamouflageStack = tileHandler.getDefaultCamouflageBlock(); + if (!ItemStackUtil.isIdenticalItem(tileCamouflageStack, defaultCamouflageStack)) { + camouflageStack = tileCamouflageStack; + } + } + if (camouflageStack.isEmpty() && tile instanceof IMultiblockComponent) { + IMultiblockComponent component = (IMultiblockComponent) tile; + IMultiblockController controller = component.getMultiblockLogic().getController(); + if (controller instanceof ICamouflageHandler) { + ICamouflageHandler multiblockHandler = (ICamouflageHandler) controller; + camouflageStack = multiblockHandler.getCamouflageBlock(); + } + if (!controller.isAssembled()) { + camouflageStack = ItemStack.EMPTY; + } + } + + return camouflageStack; + } + return ItemStack.EMPTY; } + @Override + public ICamouflageHandler getCamouflageHandler(IBlockAccess world, BlockPos pos) { + TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class); + if (tile instanceof ICamouflagedTile) { + ICamouflagedTile block = (ICamouflagedTile) tile; + ICamouflageHandler handler = null; + if (tile instanceof ICamouflageHandler) { + handler = (ICamouflageHandler) tile; + } + if ((handler == null || handler.getCamouflageBlock().isEmpty()) && tile instanceof IMultiblockComponent) { + IMultiblockComponent component = (IMultiblockComponent) tile; + IMultiblockController controller = component.getMultiblockLogic().getController(); + if (controller instanceof ICamouflageHandler) { + handler = (ICamouflageHandler) controller; + } + } + return handler; + } + return null; + } - public abstract BlockGreenhouseType getGreenhouseType(); - @SideOnly(Side.CLIENT) @Override - public void addInformation(ItemStack stack, @Nullable World world, List tooltip, ITooltipFlag advanced) { - tooltip.add(Translator.translateToLocal("tile.for.greenhouse.tooltip")); - tooltip.add(TextFormatting.GREEN.toString() + TextFormatting.ITALIC.toString() + Translator.translateToLocal("tile.for.greenhouse.camouflage.tooltip")); + public boolean hasOverlaySprite(int meta, int layer) { + BlockGreenhouseType type = BlockGreenhouseType.VALUES[meta]; + return layer == 0 || type.twoLayers; + } + + @Override + public int getLayers() { + return 2; + } + + @SideOnly(Side.CLIENT) + @Override + public TextureAtlasSprite getDefaultSprite() { + return BlockGreenhouseSprite.getSprite(BlockGreenhouseType.PLAIN, null, null, -1); + } + + @SideOnly(Side.CLIENT) + @Override + public TextureAtlasSprite getOverlaySprite(EnumFacing facing, IBlockState state, int meta, int layer) { + return BlockGreenhouseSprite.getSprite(BlockGreenhouseType.VALUES[meta], facing, state, layer); } } diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseDoor.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseDoor.java deleted file mode 100644 index ab38849e0..000000000 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseDoor.java +++ /dev/null @@ -1,341 +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.blocks; - -import java.util.Random; - -import forestry.api.core.IModelManager; -import forestry.api.core.IStateMapperRegister; -import forestry.core.blocks.properties.UnlistedBlockAccess; -import forestry.core.blocks.properties.UnlistedBlockPos; -import forestry.core.tiles.TileUtil; -import forestry.core.utils.CamouflageUtil; -import forestry.core.utils.Translator; -import forestry.greenhouse.models.GreenhouseDoorStateMapper; -import forestry.greenhouse.tiles.TileGreenhouse; -import net.minecraft.block.Block; -import net.minecraft.block.BlockDoor; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.EnumPushReaction; -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.renderer.block.model.ModelResourceLocation; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.util.BlockRenderLayer; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.common.property.ExtendedBlockState; -import net.minecraftforge.common.property.IUnlistedProperty; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMapperRegister { - - //The door properties - private static final PropertyDirection FACING = BlockDoor.FACING; - private static final PropertyBool OPEN = BlockDoor.OPEN; - private static final PropertyEnum HINGE = BlockDoor.HINGE; - private static final PropertyBool POWERED = BlockDoor.POWERED; - private static final PropertyEnum HALF = BlockDoor.HALF; - public static final PropertyBool CAMOUFLAGED = PropertyBool.create("camouflaged"); - - protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.1875D); - protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.8125D, 1.0D, 1.0D, 1.0D); - protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.8125D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); - protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.1875D, 1.0D, 1.0D); - - public BlockGreenhouseDoor() { - super(BlockGreenhouseType.DOOR); - setSoundType(SoundType.GLASS); - setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, false).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, false).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(CAMOUFLAGED, false)); - } - - @Override - public String getLocalizedName() { - return Translator.translateToLocal((this.getUnlocalizedName() + ".name").replaceAll("tile", "item")); - } - - @Override - public boolean isOpaqueCube(IBlockState state) { - return false; - } - - @Override - public boolean isPassable(IBlockAccess worldIn, BlockPos pos) { - return isOpen(combineMetadata(worldIn, pos)); - } - - @Override - public boolean isFullCube(IBlockState state) { - return false; - } - - @Override - public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { - state = state.getActualState(source, pos); - EnumFacing enumfacing = state.getValue(FACING); - boolean flag = !state.getValue(OPEN); - boolean flag1 = state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT; - - switch (enumfacing) { - case EAST: - default: - return flag ? EAST_AABB : (flag1 ? NORTH_AABB : SOUTH_AABB); - case SOUTH: - return flag ? SOUTH_AABB : (flag1 ? EAST_AABB : WEST_AABB); - case WEST: - return flag ? WEST_AABB : (flag1 ? SOUTH_AABB : NORTH_AABB); - case NORTH: - return flag ? NORTH_AABB : (flag1 ? WEST_AABB : EAST_AABB); - } - } - - @Override - public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { - TileGreenhouse door = TileUtil.getTile(worldIn, pos, TileGreenhouse.class); - if (door == null) { - return false; - } - - if (playerIn.isSneaking() && playerIn.getHeldItem(hand).isEmpty()) { - if (!worldIn.isRemote) { - door.openGui(playerIn); - } - return true; - } - - BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down(); - IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos); - - if (iblockstate.getBlock() != this) { - return false; - } else { - state = iblockstate.cycleProperty(OPEN); - worldIn.setBlockState(blockpos, state, 2); - worldIn.markBlockRangeForRenderUpdate(blockpos, pos); - worldIn.playEvent(playerIn, state.getValue(OPEN) ? 1005 : 1011, pos, 0); - return true; - } - } - - @Override - @Deprecated - public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { - if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) { - BlockPos blockpos = pos.down(); - IBlockState iblockstate = worldIn.getBlockState(blockpos); - - if (iblockstate.getBlock() != this) { - worldIn.setBlockToAir(pos); - } else if (blockIn != this) { - iblockstate.neighborChanged(worldIn, blockpos, blockIn, fromPos); - } - } else { - boolean flag1 = false; - BlockPos blockpos1 = pos.up(); - IBlockState iblockstate1 = worldIn.getBlockState(blockpos1); - - if (iblockstate1.getBlock() != this) { - worldIn.setBlockToAir(pos); - flag1 = true; - } - - if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP)) { - worldIn.setBlockToAir(pos); - flag1 = true; - - if (iblockstate1.getBlock() == this) { - worldIn.setBlockToAir(blockpos1); - } - } - - if (flag1) { - if (!worldIn.isRemote) { - this.dropBlockAsItem(worldIn, pos, state, 0); - } - } else { - boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1); - - if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != iblockstate1.getValue(POWERED)) { - worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, flag), 2); - - if (flag != state.getValue(OPEN)) { - worldIn.setBlockState(pos, state.withProperty(OPEN, flag), 2); - worldIn.markBlockRangeForRenderUpdate(pos, pos); - worldIn.playEvent(null, flag ? 1006 : 1012, pos, 0); - } - } - } - } - } - - @Override - public Item getItemDropped(IBlockState state, Random rand, int fortune) { - return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : Item.getItemFromBlock(state.getBlock()); - } - - @Override - public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { - return pos.getY() < worldIn.getHeight() - 1 && (worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up())); - } - - @Override - public EnumPushReaction getMobilityFlag(IBlockState state) { - return EnumPushReaction.DESTROY; - } - - private static int combineMetadata(IBlockAccess worldIn, BlockPos pos) { - IBlockState iblockstate = worldIn.getBlockState(pos); - int i = iblockstate.getBlock().getMetaFromState(iblockstate); - boolean flag = isTop(i); - IBlockState iblockstate1 = worldIn.getBlockState(pos.down()); - int j = iblockstate1.getBlock().getMetaFromState(iblockstate1); - int k = flag ? j : i; - IBlockState iblockstate2 = worldIn.getBlockState(pos.up()); - int l = iblockstate2.getBlock().getMetaFromState(iblockstate2); - int i1 = flag ? i : l; - boolean flag1 = (i1 & 1) != 0; - boolean flag2 = (i1 & 2) != 0; - return removeHalfBit(k) | (flag ? 8 : 0) | (flag1 ? 16 : 0) | (flag2 ? 32 : 0); - } - - @Override - public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) { - BlockPos blockpos = pos.down(); - - if (player.capabilities.isCreativeMode && state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this) { - worldIn.setBlockToAir(blockpos); - } - } - - @Override - public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { - if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER) { - IBlockState iblockstate = worldIn.getBlockState(pos.up()); - - if (iblockstate.getBlock() == this) { - state = state.withProperty(HINGE, iblockstate.getValue(HINGE)).withProperty(POWERED, iblockstate.getValue(POWERED)); - } - } else { - IBlockState iblockstate1 = worldIn.getBlockState(pos.down()); - - if (iblockstate1.getBlock() == this) { - state = state.withProperty(FACING, iblockstate1.getValue(FACING)).withProperty(OPEN, iblockstate1.getValue(OPEN)); - } - } - state = state.withProperty(CAMOUFLAGED, !CamouflageUtil.getCamouflageBlock(worldIn, pos).isEmpty()); - - return state; - } - - @Override - public IBlockState getStateFromMeta(int meta) { - return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.UPPER).withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, (meta & 2) > 0) : this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW()).withProperty(OPEN, (meta & 4) > 0); - } - - @SideOnly(Side.CLIENT) - @Override - public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) { - return layer == BlockRenderLayer.TRANSLUCENT; - } - - @Override - @SideOnly(Side.CLIENT) - public BlockRenderLayer getBlockLayer() { - return BlockRenderLayer.TRANSLUCENT; - } - - @Override - public int getMetaFromState(IBlockState state) { - int i = 0; - - if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) { - i = i | 8; - - if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT) { - i |= 1; - } - - if (state.getValue(POWERED)) { - i |= 2; - } - } else { - i = i | state.getValue(FACING).rotateY().getHorizontalIndex(); - - if (state.getValue(OPEN)) { - i |= 4; - } - } - - return i; - } - - @SideOnly(Side.CLIENT) - @Override - public void registerModel(Item item, IModelManager manager) { - ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.door", "inventory")); - } - - @SideOnly(Side.CLIENT) - @Override - public void registerStateMapper() { - ModelLoader.setCustomStateMapper(this, new GreenhouseDoorStateMapper()); - } - - protected static int removeHalfBit(int meta) { - return meta & 7; - } - - public static boolean isOpen(IBlockAccess worldIn, BlockPos pos) { - return isOpen(combineMetadata(worldIn, pos)); - } - - public static EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos) { - return getFacing(combineMetadata(worldIn, pos)); - } - - public static EnumFacing getFacing(int combinedMeta) { - return EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW(); - } - - protected static boolean isOpen(int combinedMeta) { - return (combinedMeta & 4) != 0; - } - - protected static boolean isTop(int meta) { - return (meta & 8) != 0; - } - - protected static boolean isHingeLeft(int combinedMeta) { - return (combinedMeta & 16) != 0; - } - - @Override - protected BlockStateContainer createBlockState() { - return new ExtendedBlockState(this, new IProperty[]{HALF, FACING, OPEN, HINGE, POWERED, CAMOUFLAGED}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); - } - - @Override - public BlockGreenhouseType getGreenhouseType() { - return BlockGreenhouseType.DOOR; - } - -} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseSprite.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseSprite.java new file mode 100644 index 000000000..1d028beb3 --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseSprite.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * 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.blocks; + +import javax.annotation.Nullable; +import java.util.EnumMap; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.config.Constants; + +@SideOnly(Side.CLIENT) +public enum BlockGreenhouseSprite { + TOP("top"), + GEARS("gears"), + BORDER("border"), + BORDER_TOP("border_top"), + BORDER_TOP_CENTER("border_top_center"), + HYGRO("hygroregulator"), + CONTROL("control"), + GREENHOUSE_SCREEN_0("greenhouse_screen_0"), + GREENHOUSE_SCREEN_1("greenhouse_screen_1"); + + public static final BlockGreenhouseSprite[] VALUES = values(); + private static EnumMap sprites; + private static TextureAtlasSprite missingImage; + + private final String spriteName; + + BlockGreenhouseSprite(String spriteName) { + this.spriteName = spriteName; + } + + public static void registerSprites() { + sprites = new EnumMap<>(BlockGreenhouseSprite.class); + TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); + + for (BlockGreenhouseSprite sprite : BlockGreenhouseSprite.VALUES) { + ResourceLocation location = new ResourceLocation(Constants.MOD_ID, "blocks/greenhouse/" + sprite.spriteName); + TextureAtlasSprite textureAtlasSprite = map.registerSprite(location); + sprites.put(sprite, textureAtlasSprite); + } + missingImage = map.missingImage; + } + + /** + * @return The texture sprite from the type and the {@link IBlockState} of the greenhouse block + */ + public static TextureAtlasSprite getSprite(BlockGreenhouseType type, @Nullable EnumFacing facing, @Nullable IBlockState state, int layer) { + TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); + switch (type) { + case BORDER: + if (facing == EnumFacing.UP) { + return sprites.get(BlockGreenhouseSprite.BORDER_TOP); + } else if (facing == EnumFacing.DOWN) { + return sprites.get(BlockGreenhouseSprite.TOP); + } + return sprites.get(BlockGreenhouseSprite.BORDER); + case BORDER_CENTER: + if (facing == EnumFacing.UP) { + if (layer == 0) { + return sprites.get(BlockGreenhouseSprite.BORDER_TOP_CENTER); + } + return sprites.get(BlockGreenhouseSprite.GREENHOUSE_SCREEN_1); + } + return sprites.get(BlockGreenhouseSprite.BORDER); + case GEARBOX: + if (facing == EnumFacing.UP || facing == EnumFacing.DOWN) { + return sprites.get(BlockGreenhouseSprite.TOP); + } + return sprites.get(BlockGreenhouseSprite.GEARS); + case CONTROL: + if (facing == EnumFacing.UP || facing == EnumFacing.DOWN) { + return sprites.get(BlockGreenhouseSprite.TOP); + } + return sprites.get(BlockGreenhouseSprite.CONTROL); + case SCREEN: + if (facing == EnumFacing.UP || facing == EnumFacing.DOWN) { + return sprites.get(BlockGreenhouseSprite.TOP); + } + if (layer == 0) { + return sprites.get(BlockGreenhouseSprite.GREENHOUSE_SCREEN_0); + } + return sprites.get(BlockGreenhouseSprite.GREENHOUSE_SCREEN_1); + case PLAIN: + if (facing == EnumFacing.UP || facing == EnumFacing.DOWN) { + return sprites.get(BlockGreenhouseSprite.TOP); + } + if (layer == 0) { + return missingImage; + } + default: + return map.getAtlasSprite("forestry:blocks/ash_brick"); + } + } + +} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java index d4193b86d..96ef10d69 100644 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java @@ -1,200 +1,47 @@ +/******************************************************************************* + * 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.blocks; -import javax.annotation.Nullable; -import java.util.EnumMap; import java.util.Locale; -import forestry.core.config.Constants; -import forestry.core.tiles.TileUtil; -import forestry.greenhouse.blocks.BlockGreenhouse.State; -import forestry.greenhouse.tiles.TileGreenhouseHatch; -import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraft.util.IStringSerializable; -public enum BlockGreenhouseType { +public enum BlockGreenhouseType implements IStringSerializable { PLAIN, - GLASS(Material.GLASS), - //item, energy / fluid - HATCH_INPUT(true), - HATCH_OUTPUT(true), - //energy - GEARBOX(true), - //water - VALVE(true), - //temperature - HEATER(true, true), FAN(true, true), - //humidity - HUMIDIFIER(true, true), DEHUMIDIFIER(true, true), - //temperature and humidity - WINDOW(Material.GLASS, false, true), - //temperature and humidity - WINDOW_UP(Material.GLASS, false, true), - CONTROL(true), - DOOR, - CLIMATE_CONTROL(true), - NURSERY(true); + BORDER, + BORDER_CENTER(true), + //Item Name = Energy Distributor, to have a deference between the farm gearbox and this one + GEARBOX, + CONTROL, + SCREEN(true); public static final BlockGreenhouseType[] VALUES = values(); - public final boolean hasOverlaySprite; - public final boolean activatable; - public final Material material; + public final boolean twoLayers; - BlockGreenhouseType(Material material, boolean hasOverlaySprite, boolean activatable) { - this.hasOverlaySprite = hasOverlaySprite; - this.activatable = activatable; - this.material = material; - } - - BlockGreenhouseType(Material material, boolean hasOverlaySprite) { - this(material, hasOverlaySprite, false); - } - - BlockGreenhouseType(Material material) { - this(material, false, false); - } - - BlockGreenhouseType(boolean hasOverlaySprite, boolean activatable) { - this(Material.ROCK, hasOverlaySprite, activatable); - } - - BlockGreenhouseType(boolean hasOverlaySprite) { - this(Material.ROCK, hasOverlaySprite); + BlockGreenhouseType(boolean twoLayers) { + this.twoLayers = twoLayers; } BlockGreenhouseType() { - this(Material.ROCK); - } - - @SideOnly(Side.CLIENT) - private static EnumMap sprites; - - private enum BlockGreenhouseSprites { - GEARS("gears"), - VALVE("valve"), - HEATER_OFF("heater.off"), HEATER_ON("heater.on"), - FAN_OFF("fan.off"), FAN_ON("fan.on"), - HUMIDIFIER_OFF("humidifier.off"), HUMIDIFIER_ON("humidifier.on"), - DEHUMIDIFIER_OFF("dehumidifier.off"), DEHUMIDIFIER_ON("dehumidifier.on"), - 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(); - - private final String spriteName; - - BlockGreenhouseSprites(String spriteName) { - this.spriteName = spriteName; - } - } - - @SideOnly(Side.CLIENT) - public static void registerSprites() { - sprites = new EnumMap<>(BlockGreenhouseSprites.class); - TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); - - for (BlockGreenhouseSprites sprite : BlockGreenhouseSprites.VALUES) { - ResourceLocation location = new ResourceLocation(Constants.MOD_ID, "blocks/greenhouse/" + sprite.spriteName); - TextureAtlasSprite textureAtlasSprite = map.registerSprite(location); - sprites.put(sprite, textureAtlasSprite); - } - } - - /** - * @return The texture sprite from the type and the {@link IBlockState} of the greenhouse block - */ - @SideOnly(Side.CLIENT) - public static TextureAtlasSprite getSprite(BlockGreenhouseType type, @Nullable EnumFacing facing, @Nullable IBlockState state, @Nullable IBlockAccess world, @Nullable BlockPos pos) { - TileEntity tile = null; - if (world != null && pos != null) { - tile = TileUtil.getTile(world, pos); - } - TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); - switch (type) { - case PLAIN: - return map.getAtlasSprite("minecraft:blocks/brick"); - case GLASS: - return map.getAtlasSprite("minecraft:blocks/glass_green"); - case GEARBOX: - return sprites.get(BlockGreenhouseSprites.GEARS); - case VALVE: - return sprites.get(BlockGreenhouseSprites.VALVE); - case HEATER: - if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) { - return sprites.get(BlockGreenhouseSprites.HEATER_OFF); - } else { - return sprites.get(BlockGreenhouseSprites.HEATER_ON); - } - case FAN: - if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) { - return sprites.get(BlockGreenhouseSprites.FAN_OFF); - } else { - return sprites.get(BlockGreenhouseSprites.FAN_ON); - } - case HUMIDIFIER: - if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) { - return sprites.get(BlockGreenhouseSprites.HUMIDIFIER_OFF); - } else { - return sprites.get(BlockGreenhouseSprites.HUMIDIFIER_ON); - } - case DEHUMIDIFIER: - if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) { - return sprites.get(BlockGreenhouseSprites.DEHUMIDIFIER_OFF); - } else { - return sprites.get(BlockGreenhouseSprites.DEHUMIDIFIER_ON); - } - case CONTROL: - return sprites.get(BlockGreenhouseSprites.CONTROL); - case HATCH_OUTPUT: - case HATCH_INPUT: - if (tile == null || facing == null || !(tile instanceof TileGreenhouseHatch)) { - return sprites.get(BlockGreenhouseSprites.HATCH_DEFAULT); - } - TileGreenhouseHatch hatch = (TileGreenhouseHatch) tile; - if (hatch.getOutwardsDir() == null) { - return sprites.get(BlockGreenhouseSprites.HATCH_DEFAULT); - } - if (hatch.getOutwardsDir() == facing) { - return sprites.get(BlockGreenhouseSprites.HATCH_OUTPUT); - } else if (hatch.getOutwardsDir().getOpposite() == facing) { - return sprites.get(BlockGreenhouseSprites.HATCH_INPUT); - } - return Minecraft.getMinecraft().getTextureMapBlocks().missingImage; - case CLIMATE_CONTROL: - if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) { - return Minecraft.getMinecraft().getTextureMapBlocks().missingImage; - } - return sprites.get(BlockGreenhouseSprites.CLIMATE_CONTROL); - case NURSERY: - if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) { - return Minecraft.getMinecraft().getTextureMapBlocks().missingImage; - } - return sprites.get(BlockGreenhouseSprites.BUTTERFLY_HATCH); - default: - return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite(); - } - } - - @SideOnly(Side.CLIENT) - public static EnumMap getSprites() { - return sprites; + this(false); } @Override public String toString() { - return name().toLowerCase(Locale.ENGLISH); + return getName(); } + @Override + public String getName() { + return name().toLowerCase(Locale.ENGLISH); + } } diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseWindow.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseWindow.java new file mode 100644 index 000000000..ff31a3ad9 --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseWindow.java @@ -0,0 +1,267 @@ +/******************************************************************************* + * 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.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +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.nbt.NBTTagCompound; +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.NonNullList; +import net.minecraft.util.Rotation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.common.property.ExtendedBlockState; +import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.common.property.IUnlistedProperty; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.IItemModelRegister; +import forestry.api.core.IModelManager; +import forestry.api.greenhouse.GreenhouseManager; +import forestry.core.blocks.IBlockRotatable; +import forestry.core.blocks.properties.UnlistedBlockAccess; +import forestry.core.blocks.properties.UnlistedBlockPos; +import forestry.core.tiles.IActivatable; +import forestry.core.tiles.TileUtil; +import forestry.core.utils.Log; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.tiles.TileGreenhouseWindow; +import forestry.greenhouse.tiles.TileGreenhouseWindow.WindowMode; + +public class BlockGreenhouseWindow extends Block implements IBlockRotatable, ITileEntityProvider, IItemModelRegister { + public static final PropertyDirection FACING = PropertyDirection.create("facing", Plane.HORIZONTAL); + + private boolean roofWindow; + + public BlockGreenhouseWindow(boolean roofWindow) { + super(Material.ROCK); + IBlockState defaultState = this.blockState.getBaseState(); + setDefaultState(defaultState.withProperty(FACING, EnumFacing.NORTH)); + + setHardness(1.0f); + setHarvestLevel("pickaxe", 0); + setCreativeTab(PluginGreenhouse.getGreenhouseTab()); + setSoundType(SoundType.GLASS); + this.roofWindow = roofWindow; + } + + public ItemStack getItem(String glass) { + ItemStack stack = new ItemStack(this); + NBTTagCompound tagCompound = new NBTTagCompound(); + tagCompound.setString("Glass", glass); + stack.setTagCompound(tagCompound); + return stack; + } + + protected int getPlaySound(boolean open) { + if (open) { + return 1007; + } else { + return 1013; + } + } + + @SuppressWarnings("deprecation") + @Override + public IBlockState getStateFromMeta(int meta) { + return getDefaultState().withProperty(FACING, EnumFacing.VALUES[meta + 2]); + } + + @Override + public int getMetaFromState(IBlockState state) { + return state.getValue(FACING).ordinal() - 2; + } + + @SuppressWarnings("deprecation") + @Override + public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { + TileEntity tile = TileUtil.getTile(worldIn, pos, TileEntity.class); + if (tile instanceof IActivatable) { + state = state.withProperty(State.PROPERTY, ((IActivatable) tile).isActive() ? State.ON : State.OFF); + } + return super.getActualState(state, worldIn, pos); + } + + @SuppressWarnings("deprecation") + @Override + public IBlockState withRotation(IBlockState state, Rotation rot) { + EnumFacing facing = state.getValue(FACING); + return state.withProperty(FACING, rot.rotate(facing)); + } + + @SuppressWarnings("deprecation") + @Override + public boolean isFullCube(IBlockState state) { + return false; + } + + @SuppressWarnings("deprecation") + @Override + public boolean isOpaqueCube(IBlockState state) { + return false; + } + + @Override + @Deprecated + public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { + try { + TileUtil.actOnTile(worldIn, pos, TileGreenhouseWindow.class, TileGreenhouseWindow::onNeighborBlockChange); + } catch (StackOverflowError error) { + Log.error("Stack Overflow Error in BlockMachine.onNeighborBlockChange()", error); + throw error; + } + } + + /* MODELS */ + @Override + @SideOnly(Side.CLIENT) + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.TRANSLUCENT; + } + + @Override + public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + if (playerIn.isSneaking()) { + return false; + } + + TileGreenhouseWindow window = TileUtil.getTile(worldIn, pos, TileGreenhouseWindow.class); + if (window == null) { + return false; + } + + if (playerIn.getHeldItemMainhand().isEmpty()) { + 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(playerIn, getPlaySound(!window.isActive()), pos, 0); + return true; + } + } + + return false; + } + + @Override + public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { + super.onBlockPlacedBy(world, pos, state, placer, stack); + TileUtil.actOnTile(world, pos, TileGreenhouseWindow.class, window -> { + if (!window.getWorld().isRemote) { + window.setMode(window.isBlocked()); + } + NBTTagCompound itemTag = stack.getTagCompound(); + if (itemTag != null) { + window.setGlass(itemTag.getString("Glass")); + } + }); + } + + @Override + public void getSubBlocks(Item item, CreativeTabs tab, NonNullList list) { + for (String glass : GreenhouseManager.greenhouseHelper.getWindowGlasses()) { + list.add(getItem(glass)); + } + } + + @Override + protected BlockStateContainer createBlockState() { + return new ExtendedBlockState(this, new IProperty[]{State.PROPERTY, FACING}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); + } + + @Override + public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { + List ret = new java.util.ArrayList(); + String glass = "glass"; + TileGreenhouseWindow window = TileUtil.getTile(world, pos, TileGreenhouseWindow.class); + if (window != null) { + glass = window.getGlass(); + } + ret.add(getItem(glass)); + return ret; + } + + @Override + public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) { + return true; + } + + @Override + public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { + List drops = getDrops(world, pos, world.getBlockState(pos), 0); + if (drops.isEmpty()) { + return super.getPickBlock(state, target, world, pos, player); + } + return drops.get(0); + } + + @Override + public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { + return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos) + .withProperty(UnlistedBlockAccess.BLOCKACCESS, world); + } + + @Override + public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) { + IBlockState state = world.getBlockState(pos); + world.setBlockState(pos, state.withProperty(FACING, player.getHorizontalFacing().getOpposite())); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileGreenhouseWindow(); + } + + public boolean isRoofWindow() { + return roofWindow; + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + if (roofWindow) { + ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse_window_up", "inventory")); + } else { + ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse_window", "inventory")); + } + } + +} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockRegistryGreenhouse.java b/src/main/java/forestry/greenhouse/blocks/BlockRegistryGreenhouse.java index 21702ecb4..9a3896c92 100644 --- a/src/main/java/forestry/greenhouse/blocks/BlockRegistryGreenhouse.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockRegistryGreenhouse.java @@ -1,29 +1,26 @@ package forestry.greenhouse.blocks; -import java.util.Map; - import forestry.core.blocks.BlockRegistry; import forestry.core.items.ItemBlockForestry; -import forestry.greenhouse.items.ItemBlockGreenhouseDoor; -import net.minecraft.item.ItemBlock; public class BlockRegistryGreenhouse extends BlockRegistry { - private final Map greenhouseBlockMap; + public final BlockGreenhouse greenhouseBlock; + public final BlockClimatiser climatiserBlock; + public final BlockGreenhouseWindow window; + public final BlockGreenhouseWindow roofWindow; public BlockRegistryGreenhouse() { - greenhouseBlockMap = BlockGreenhouse.create(); - for (BlockGreenhouse block : greenhouseBlockMap.values()) { - ItemBlock itemBlock = new ItemBlockForestry(block); - if (block instanceof BlockGreenhouseDoor) { - itemBlock = new ItemBlockGreenhouseDoor(block); - } - registerBlock(block, itemBlock, "greenhouse." + block.getGreenhouseType()); - } - } + greenhouseBlock = new BlockGreenhouse(); + registerBlock(greenhouseBlock, new ItemBlockForestry(greenhouseBlock), "greenhouse"); + climatiserBlock = new BlockClimatiser(); + registerBlock(climatiserBlock, new ItemBlockForestry(climatiserBlock), "climatiser"); - public BlockGreenhouse getGreenhouseBlock(BlockGreenhouseType type) { - return greenhouseBlockMap.get(type); + window = new BlockGreenhouseWindow(false); + registerBlock(window, new ItemBlockForestry(window), "greenhouse.window"); + + roofWindow = new BlockGreenhouseWindow(true); + registerBlock(roofWindow, new ItemBlockForestry(roofWindow), "greenhouse.window_up"); } } diff --git a/src/main/java/forestry/greenhouse/blocks/IBlockCamouflaged.java b/src/main/java/forestry/greenhouse/blocks/IBlockCamouflaged.java new file mode 100644 index 000000000..216ca7358 --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/IBlockCamouflaged.java @@ -0,0 +1,35 @@ +package forestry.greenhouse.blocks; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.ICamouflageHandler; + +public interface IBlockCamouflaged> { + + ItemStack getCamouflageBlock(@Nullable IBlockAccess world, @Nullable BlockPos pos); + + @Nullable + ICamouflageHandler getCamouflageHandler(@Nullable IBlockAccess world, @Nullable BlockPos pos); + + @SideOnly(Side.CLIENT) + boolean hasOverlaySprite(int meta, int layer); + + int getLayers(); + + @SideOnly(Side.CLIENT) + TextureAtlasSprite getDefaultSprite(); + + @SideOnly(Side.CLIENT) + TextureAtlasSprite getOverlaySprite(@Nullable EnumFacing facing, @Nullable IBlockState state, int meta, int layer); +} diff --git a/src/main/java/forestry/greenhouse/blocks/State.java b/src/main/java/forestry/greenhouse/blocks/State.java new file mode 100644 index 000000000..6d1d97606 --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/State.java @@ -0,0 +1,17 @@ +package forestry.greenhouse.blocks; + +import java.util.Locale; + +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.util.IStringSerializable; + +public enum State implements IStringSerializable { + ON, OFF; + + public static final PropertyEnum PROPERTY = PropertyEnum.create("state", State.class); + + @Override + public String getName() { + return name().toLowerCase(Locale.ENGLISH); + } +} diff --git a/src/main/java/forestry/greenhouse/blocks/package-info.java b/src/main/java/forestry/greenhouse/blocks/package-info.java index b9cf96ae9..9b490c4c3 100644 --- a/src/main/java/forestry/greenhouse/blocks/package-info.java +++ b/src/main/java/forestry/greenhouse/blocks/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse.blocks; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/core/CamouflageAccess.java b/src/main/java/forestry/greenhouse/camouflage/CamouflageAccess.java similarity index 52% rename from src/main/java/forestry/core/CamouflageAccess.java rename to src/main/java/forestry/greenhouse/camouflage/CamouflageAccess.java index 31b41db9c..18be1cdd1 100644 --- a/src/main/java/forestry/core/CamouflageAccess.java +++ b/src/main/java/forestry/greenhouse/camouflage/CamouflageAccess.java @@ -8,93 +8,76 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core; +package forestry.greenhouse.camouflage; + +import com.google.common.collect.Lists; -import java.util.ArrayList; import java.util.List; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageAccess; -import forestry.api.core.ICamouflageItemHandler; -import forestry.core.utils.Log; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; + import net.minecraftforge.fml.common.Loader; +import forestry.api.core.ICamouflageAccess; +import forestry.api.core.ICamouflageItemHandler; +import forestry.core.utils.Log; + public class CamouflageAccess implements ICamouflageAccess { - private static final ListMultimap camouflageItemHandlers = ArrayListMultimap.create(); - private static final ListMultimap camouflageItemBlacklist = ArrayListMultimap.create(); - private static final ListMultimap blacklistedMods = ArrayListMultimap.create(); - public static final ICamouflageItemHandler NONE = new CamouflageHandlerNone(); + private static final List camouflageItemHandlers = Lists.newArrayList(); + private static final List camouflageItemBlacklist = Lists.newArrayList(); + private static final List blacklistedMods = Lists.newArrayList(); @Override - public void registerCamouflageItemHandler(ICamouflageItemHandler itemHandler) { - String type = itemHandler.getType(); - - List handlers = camouflageItemHandlers.get(type); - if (!handlers.contains(itemHandler)) { - handlers.add(itemHandler); + public void registerItemHandler(ICamouflageItemHandler itemHandler) { + if (!camouflageItemHandlers.contains(itemHandler)) { + camouflageItemHandlers.add(itemHandler); } else { Log.error("Fail to register a camouflage item handler, because the handler is already registered. The handler is form the mod with the ID: " + Loader.instance().activeModContainer().getModId() + "."); } } @Override - public List getCamouflageItemHandler(String type) { - if (type.equals(CamouflageManager.NONE)) { - List handlers = new ArrayList<>(); - handlers.addAll(camouflageItemHandlers.values()); - return handlers; - } - - return camouflageItemHandlers.get(type); + public List getItemHandlers() { + return camouflageItemHandlers; } @Override - public void addModIdToBlackList(String type, String modID) { - if (!blacklistedMods.get(type).contains(modID)) { - blacklistedMods.put(type, modID); - } - } - - @Override - public void addItemToBlackList(String type, ItemStack camouflageBlock) { + public void addItemToBlackList(ItemStack camouflageBlock) { Block block = Block.getBlockFromItem(camouflageBlock.getItem()); if (block == Blocks.AIR) { Log.error("Fail to add camouflage block item to the black list: because it has no block."); return; } - for (ItemStack camouflageBlacklisted : camouflageItemBlacklist.get(type)) { + for (ItemStack camouflageBlacklisted : camouflageItemBlacklist) { if (camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)) { Log.error("Fail to add camouflage block item to the black list, because it is already registered: " + camouflageBlock + "."); return; } } - camouflageItemBlacklist.put(type, camouflageBlock); + camouflageItemBlacklist.add(camouflageBlock); } @Override - public boolean isItemBlackListed(String type, ItemStack camouflageBlock) { - if (camouflageBlock.isEmpty() || Block.getBlockFromItem(camouflageBlock.getItem()) == Blocks.AIR || !type.equals(CamouflageManager.NONE) && !camouflageItemBlacklist.containsKey(type)) { + public void addModIdToBlackList(String modID) { + if (!blacklistedMods.contains(modID)) { + blacklistedMods.add(modID); + } + } + + @Override + public boolean isItemBlackListed(ItemStack camouflageBlock) { + if (camouflageBlock.isEmpty() || Block.getBlockFromItem(camouflageBlock.getItem()) == Blocks.AIR) { return false; } String modId = camouflageBlock.getItem().getRegistryName().getResourceDomain(); - if (blacklistedMods.get(type) != null && blacklistedMods.get(type).contains(modId)) { + if (blacklistedMods.contains(modId)) { return true; } - List camouflageItemBlacklisted; - if (type.equals(CamouflageManager.NONE)) { - camouflageItemBlacklisted = new ArrayList<>(); - camouflageItemBlacklisted.addAll(camouflageItemBlacklist.values()); - } else { - camouflageItemBlacklisted = camouflageItemBlacklist.get(type); - } - for (ItemStack camouflageBlacklisted : camouflageItemBlacklisted) { + for (ItemStack camouflageBlacklisted : camouflageItemBlacklist) { if (camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)) { return true; } @@ -104,21 +87,16 @@ public class CamouflageAccess implements ICamouflageAccess { } @Override - public ICamouflageItemHandler getNoneItemHandler() { - return NONE; - } - - @Override - public ICamouflageItemHandler getHandlerFromItem(ItemStack stack) { + public ICamouflageItemHandler getHandler(ItemStack stack) { if (stack.isEmpty()) { - return NONE; + return null; } - for (ICamouflageItemHandler handler : camouflageItemHandlers.values()) { + for (ICamouflageItemHandler handler : camouflageItemHandlers) { if (handler.canHandle(stack)) { return handler; } } - return NONE; + return null; } } diff --git a/src/main/java/forestry/core/CamouflageHandlerBlock.java b/src/main/java/forestry/greenhouse/camouflage/CamouflageHandlerBlock.java similarity index 86% rename from src/main/java/forestry/core/CamouflageHandlerBlock.java rename to src/main/java/forestry/greenhouse/camouflage/CamouflageHandlerBlock.java index d18dffa5a..e17426fc6 100644 --- a/src/main/java/forestry/core/CamouflageHandlerBlock.java +++ b/src/main/java/forestry/greenhouse/camouflage/CamouflageHandlerBlock.java @@ -8,27 +8,30 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core; +package forestry.greenhouse.camouflage; import com.google.common.base.Preconditions; -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.core.ICamouflageItemHandler; -import forestry.api.core.ICamouflagedTile; + +import org.apache.commons.lang3.tuple.Pair; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelShapes; +import net.minecraft.client.renderer.BlockRendererDispatcher; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; + +import forestry.api.core.ICamouflageHandler; +import forestry.api.core.ICamouflageItemHandler; +import forestry.api.core.ICamouflagedTile; public class CamouflageHandlerBlock implements ICamouflageItemHandler { - @Override public boolean canHandle(ItemStack stack) { if (stack.isEmpty() || Block.getBlockFromItem(stack.getItem()) == Blocks.AIR) { @@ -40,23 +43,14 @@ public class CamouflageHandlerBlock implements ICamouflageItemHandler { return stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && stateFromMeta.isNormalCube() && stateFromMeta.isFullCube() && stateFromMeta.isBlockNormalCube(); } - @Override - public String getType() { - return CamouflageManager.BLOCK; - } - - @Override - public float getLightTransmittance(ItemStack stack, ICamouflageHandler camouflageHandler) { - return 0F; - } - @SideOnly(Side.CLIENT) @Override public Pair getModel(ItemStack stack, ICamouflageHandler camouflageHandler, ICamouflagedTile camouflageTile) { Preconditions.checkNotNull(camouflageHandler); Preconditions.checkArgument(!stack.isEmpty(), "Stack cannot be empty"); - BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); + BlockRendererDispatcher rendererDispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher(); + BlockModelShapes modelShapes = rendererDispatcher.getBlockModelShapes(); Block block = Block.getBlockFromItem(stack.getItem()); Preconditions.checkArgument(block != Blocks.AIR, "Block cannot be AIR"); diff --git a/src/main/java/forestry/greenhouse/camouflage/CamouflageHandlerType.java b/src/main/java/forestry/greenhouse/camouflage/CamouflageHandlerType.java new file mode 100644 index 000000000..7d5f8a061 --- /dev/null +++ b/src/main/java/forestry/greenhouse/camouflage/CamouflageHandlerType.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * 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.camouflage; + +public enum CamouflageHandlerType { + TILE, STRUCTURE, ITEM; + + public static final CamouflageHandlerType[] VALUES = values(); + +} diff --git a/src/main/java/forestry/greenhouse/camouflage/package-info.java b/src/main/java/forestry/greenhouse/camouflage/package-info.java new file mode 100644 index 000000000..dd243b5c9 --- /dev/null +++ b/src/main/java/forestry/greenhouse/camouflage/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.camouflage; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/circuits/CircuitClimateSource.java b/src/main/java/forestry/greenhouse/circuits/CircuitClimateSource.java new file mode 100644 index 000000000..defa5cb60 --- /dev/null +++ b/src/main/java/forestry/greenhouse/circuits/CircuitClimateSource.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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.circuits; + +import javax.annotation.Nullable; + +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateSource; +import forestry.api.climate.IClimateSourceCircuitable; +import forestry.api.climate.IClimateSourceOwner; +import forestry.core.circuits.Circuit; + +public class CircuitClimateSource extends Circuit { + private ClimateType type; + private float changeChange; + private float rangeChange; + + public CircuitClimateSource(String uid, ClimateType type, float changeChange, float rangeChange) { + super(uid); + this.type = type; + this.changeChange = changeChange; + this.rangeChange = rangeChange; + } + + @Override + public boolean isCircuitable(Object tile) { + return tile instanceof IClimateSourceOwner && ((IClimateSourceOwner) tile).isCircuitable(); + } + + @Override + public void onInsertion(int slot, Object tile) { + IClimateSourceOwner owner = getCircuitable(tile); + if (owner == null) { + return; + } + IClimateSource source = owner.getClimateSource(); + if (!(source instanceof IClimateSourceCircuitable)) { + return; + } + ((IClimateSourceCircuitable) source).changeSourceConfig(type, changeChange, rangeChange); + } + + @Override + public void onLoad(int slot, Object tile) { + onInsertion(slot, tile); + } + + @Override + public void onRemoval(int slot, Object tile) { + IClimateSourceOwner owner = getCircuitable(tile); + if (owner == null) { + return; + } + IClimateSource source = owner.getClimateSource(); + if (!(source instanceof IClimateSourceCircuitable)) { + return; + } + ((IClimateSourceCircuitable) source).changeSourceConfig(type, -changeChange, -rangeChange); + } + + @Override + public void onTick(int slot, Object tile) { + + } + + @Nullable + private IClimateSourceOwner getCircuitable(Object tile) { + if (!isCircuitable(tile)) { + return null; + } + return (IClimateSourceOwner) tile; + } +} diff --git a/src/main/java/forestry/greenhouse/circuits/package-info.java b/src/main/java/forestry/greenhouse/circuits/package-info.java new file mode 100644 index 000000000..37c4491a9 --- /dev/null +++ b/src/main/java/forestry/greenhouse/circuits/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.circuits; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/climate/ClimateSourceCircuitable.java b/src/main/java/forestry/greenhouse/climate/ClimateSourceCircuitable.java new file mode 100644 index 000000000..b2b71202b --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/ClimateSourceCircuitable.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.climate; + +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateSourceCircuitable; +import forestry.api.climate.IClimateSourceOwner; +import forestry.core.climate.ClimateSource; +import forestry.core.climate.ClimateSourceType; + +public abstract class ClimateSourceCircuitable extends ClimateSource implements IClimateSourceCircuitable { + protected float changeMultiplierTemperature = 1.0f; + protected float rangeMultiplierTemperature = 1.0f; + protected float changeMultiplierHumidity = 1.0f; + protected float rangeMultiplierHumidity = 1.0f; + + public ClimateSourceCircuitable(float change, float range, ClimateSourceType sourceType) { + super(change, range, sourceType); + } + + @Override + public void changeSourceConfig(ClimateType type, float changeChange, float rangeChange) { + if (type == ClimateType.TEMPERATURE) { + changeMultiplierTemperature += changeChange; + rangeMultiplierTemperature += rangeChange; + } else { + changeMultiplierHumidity += changeChange; + rangeMultiplierHumidity += rangeChange; + } + } + + public float getChangeMultiplier(ClimateType type) { + float changeMultiplier; + if (type == ClimateType.TEMPERATURE) { + changeMultiplier = changeMultiplierTemperature; + } else { + changeMultiplier = changeMultiplierHumidity; + } + return changeMultiplier; + } + + @Override + protected float getRange(ClimateType type) { + float rangeMultiplier; + if (type == ClimateType.TEMPERATURE) { + rangeMultiplier = rangeMultiplierTemperature; + } else { + rangeMultiplier = rangeMultiplierHumidity; + } + return super.getRange(type) * rangeMultiplier; + } + + @Override + protected float getChange(ClimateType type) { + return super.getChange(type) * getChangeMultiplier(type); + } +} diff --git a/src/main/java/forestry/greenhouse/climate/ClimateSourceClimatiser.java b/src/main/java/forestry/greenhouse/climate/ClimateSourceClimatiser.java new file mode 100644 index 000000000..1ef55911b --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/ClimateSourceClimatiser.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * 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.climate; + +import forestry.api.climate.ClimateChange; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateHousing; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.core.IErrorLogic; +import forestry.core.climate.ClimateSourceMode; +import forestry.core.climate.ClimateSourceType; +import forestry.core.errors.EnumErrorCode; +import forestry.energy.EnergyManager; +import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; +import forestry.greenhouse.tiles.TileClimatiser; + +public class ClimateSourceClimatiser extends ClimateSourceCircuitable { + + protected static final int ENERGY_PER_OPERATION = 150; + + public ClimateSourceClimatiser(ClimateSourceType type, float change, float range) { + super(change, range, type); + if (type.canChangeTemperature()) { + setTemperatureMode(change > 0 ? ClimateSourceMode.POSITIVE : ClimateSourceMode.NEGATIVE); + } else { + setHumidityMode(change > 0 ? ClimateSourceMode.POSITIVE : ClimateSourceMode.NEGATIVE); + } + } + + @Override + public void onRemoved(IClimateContainer container) { + super.onRemoved(container); + owner.setActive(false); + } + + @Override + protected void isNotValid() { + owner.setActive(false); + } + + @Override + public boolean canWork(IClimateState state, ImmutableClimateState target) { + IClimateHousing region = container.getParent(); + if (region instanceof IGreenhouseControllerInternal) { + IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region; + IErrorLogic errorLogic = owner.getErrorLogic(); + EnergyManager energyManager = controller.getEnergyManager(); + + if (energyManager.extractEnergy(ENERGY_PER_OPERATION, true) > 0) { + owner.setActive(true); + errorLogic.setCondition(false, EnumErrorCode.NO_POWER); + return true; + } else { + owner.setActive(false); + errorLogic.setCondition(true, EnumErrorCode.NO_POWER); + return false; + } + } + if (owner.isActive()) { + owner.setActive(false); + } + return false; + } + + @Override + protected void removeResources(IClimateState state, ImmutableClimateState target) { + IClimateHousing region = container.getParent(); + if (region instanceof IGreenhouseControllerInternal) { + IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region; + + EnergyManager energyManager = controller.getEnergyManager(); + + energyManager.extractEnergy(ENERGY_PER_OPERATION, false); + } + } + + @Override + protected ClimateChange getChange(ClimateSourceType type, IClimateState state, ImmutableClimateState target) { + float temperature = 0.0F; + float humidity = 0.0F; + if (type.canChangeHumidity()) { + humidity += getChange(ClimateType.HUMIDITY); + } + if (type.canChangeTemperature()) { + temperature += getChange(ClimateType.TEMPERATURE); + } + return new ClimateChange(temperature, humidity); + } + +} diff --git a/src/main/java/forestry/greenhouse/climate/ClimateSourceHygroregulator.java b/src/main/java/forestry/greenhouse/climate/ClimateSourceHygroregulator.java new file mode 100644 index 000000000..c6b5348f5 --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/ClimateSourceHygroregulator.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * 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.climate; + +import net.minecraftforge.fluids.FluidStack; + +import forestry.api.climate.ClimateChange; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.core.IErrorLogic; +import forestry.core.climate.ClimateSourceMode; +import forestry.core.climate.ClimateSourceType; +import forestry.core.errors.EnumErrorCode; +import forestry.core.fluids.FilteredTank; +import forestry.core.recipes.HygroregulatorRecipe; +import forestry.greenhouse.tiles.TileHygroregulator; + +public class ClimateSourceHygroregulator extends ClimateSourceCircuitable { + + private HygroregulatorRecipe currentRecipe; + + public ClimateSourceHygroregulator(float range) { + super(0.0F, range, ClimateSourceType.BOTH); + } + + @Override + protected void beforeWork() { + currentRecipe = null; + createRecipe(); + if (currentRecipe != null) { + float tempChange = currentRecipe.tempChange; + float humidChange = currentRecipe.humidChange; + if (tempChange > 0) { + setTemperatureMode(ClimateSourceMode.POSITIVE); + } else if (tempChange < 0) { + setTemperatureMode(ClimateSourceMode.NEGATIVE); + } else { + setTemperatureMode(ClimateSourceMode.NONE); + } + if (humidChange > 0) { + setHumidityMode(ClimateSourceMode.POSITIVE); + } else if (humidChange < 0) { + setHumidityMode(ClimateSourceMode.NEGATIVE); + } else { + setHumidityMode(ClimateSourceMode.NONE); + } + } else { + setTemperatureMode(ClimateSourceMode.NONE); + setHumidityMode(ClimateSourceMode.NONE); + } + } + + @Override + public boolean canWork(IClimateState state, ImmutableClimateState target) { + createRecipe(); + FilteredTank liquidTank = owner.getLiquidTank(); + IErrorLogic errorLogic = owner.getErrorLogic(); + if (currentRecipe != null && liquidTank.drainInternal(currentRecipe.liquid.amount, false) != null) { + errorLogic.setCondition(false, EnumErrorCode.NO_RESOURCE_LIQUID); + return true; + } + errorLogic.setCondition(true, EnumErrorCode.NO_RESOURCE_LIQUID); + return false; + } + + @Override + protected void removeResources(IClimateState state, ImmutableClimateState target) { + FilteredTank liquidTank = owner.getLiquidTank(); + liquidTank.drainInternal(currentRecipe.liquid.amount, true); + } + + @Override + protected ClimateChange getChange(ClimateSourceType type, IClimateState state, ImmutableClimateState target) { + float temperature = 0.0F; + float humidity = 0.0F; + if (type.canChangeHumidity()) { + humidity += currentRecipe.humidChange * getChangeMultiplier(ClimateType.HUMIDITY); + } + if (type.canChangeTemperature()) { + temperature += currentRecipe.tempChange * getChangeMultiplier(ClimateType.TEMPERATURE); + } + return new ClimateChange(temperature, humidity); + } + + private void createRecipe() { + if (currentRecipe == null) { + FilteredTank liquidTank = owner.getLiquidTank(); + FluidStack fluid = liquidTank.getFluid(); + if (fluid != null && fluid.amount > 0) { + currentRecipe = owner.getRecipe(fluid); + } else { + currentRecipe = null; + } + } + } + +} diff --git a/src/main/java/forestry/greenhouse/climate/ClimateSourceWindow.java b/src/main/java/forestry/greenhouse/climate/ClimateSourceWindow.java new file mode 100644 index 000000000..e885a8581 --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/ClimateSourceWindow.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.climate; + +import forestry.api.climate.ClimateChange; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.core.ForestryAPI; +import forestry.core.climate.ClimateSource; +import forestry.core.climate.ClimateSourceMode; +import forestry.core.climate.ClimateSourceType; +import forestry.greenhouse.tiles.TileGreenhouseWindow; +import forestry.greenhouse.tiles.TileGreenhouseWindow.WindowMode; + +public class ClimateSourceWindow extends ClimateSource { + + public ClimateSourceWindow(float change, float range) { + super(change, range, ClimateSourceType.BOTH); + } + + @Override + protected void beforeWork() { + IClimateState currentState = container.getState(); + IClimateState biomeState = ForestryAPI.climateManager.getBiomeState(owner.getWorld(), owner.getPos()); + if (biomeState.getTemperature() > currentState.getTemperature()) { + setTemperatureMode(ClimateSourceMode.POSITIVE); + } else if (biomeState.getTemperature() < currentState.getTemperature()) { + setTemperatureMode(ClimateSourceMode.NEGATIVE); + } else { + setTemperatureMode(ClimateSourceMode.NONE); + } + if (biomeState.getHumidity() > currentState.getHumidity()) { + setHumidityMode(ClimateSourceMode.POSITIVE); + } else if (biomeState.getHumidity() < currentState.getHumidity()) { + setHumidityMode(ClimateSourceMode.NEGATIVE); + } else { + setHumidityMode(ClimateSourceMode.NONE); + } + } + + @Override + public boolean canWork(IClimateState state, ImmutableClimateState target) { + return owner.getMode() == WindowMode.OPEN; + } + + @Override + protected void removeResources(IClimateState state, ImmutableClimateState target) { + } + + @Override + protected ClimateChange getChange(ClimateSourceType type, IClimateState state, ImmutableClimateState target) { + float temperature = 0.0F; + float humidity = 0.0F; + if (type.canChangeHumidity()) { + if (humidityMode == ClimateSourceMode.NEGATIVE) { + humidity -= change; + } else { + humidity += change; + } + } + if (type.canChangeTemperature()) { + if (temperatureMode == ClimateSourceMode.NEGATIVE) { + temperature -= change; + } else { + temperature += change; + } + } + return new ClimateChange(temperature, humidity); + } + +} diff --git a/src/main/java/forestry/greenhouse/climate/modifiers/AltitudeModifier.java b/src/main/java/forestry/greenhouse/climate/modifiers/AltitudeModifier.java new file mode 100644 index 000000000..c1f1fdbf6 --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/modifiers/AltitudeModifier.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * 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.climate.modifiers; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.BlankClimateModifier; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateData; +import forestry.api.climate.IClimateHousing; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.core.utils.Translator; + +public class AltitudeModifier extends BlankClimateModifier { + + private static final float TEMPERATURE_CHANGE = 0.01F; + + @Override + public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, ImmutableClimateState oldState, NBTTagCompound data) { + World world = container.getWorld(); + IClimateHousing parent = container.getParent(); + if (world.provider.isSurfaceWorld()) { + BlockPos position = parent.getCoordinates(); + float modifier = (64 - position.getY()) / 64F; + float altitudeChange = modifier * TEMPERATURE_CHANGE; + data.setFloat("altitudeChange", altitudeChange); + newState = newState.addTemperature(altitudeChange); + } + return newState; + } + + @Override + @SideOnly(Side.CLIENT) + public void addData(IClimateContainer container, IClimateState climateState, NBTTagCompound nbtData, IClimateData data) { + data.addData(ClimateType.TEMPERATURE, Translator.translateToLocal("for.gui.modifier.altitude"), nbtData.getFloat("altitudeChange")); + } + +} diff --git a/src/main/java/forestry/greenhouse/climate/modifiers/ClimateSourceModifier.java b/src/main/java/forestry/greenhouse/climate/modifiers/ClimateSourceModifier.java new file mode 100644 index 000000000..58b53488c --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/modifiers/ClimateSourceModifier.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * 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.climate.modifiers; + +import java.util.Collection; + +import net.minecraft.nbt.NBTTagCompound; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.BlankClimateModifier; +import forestry.api.climate.ClimateChange; +import forestry.api.climate.ClimateState; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateData; +import forestry.api.climate.IClimateHousing; +import forestry.api.climate.IClimateSource; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.core.config.Config; +import forestry.core.utils.Translator; + +public class ClimateSourceModifier extends BlankClimateModifier { + + @Override + public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, ImmutableClimateState oldState, NBTTagCompound data) { + Collection sources = container.getClimateSources(); + if (sources.isEmpty()) { + data.removeTag("rangeUp"); + data.removeTag("rangeDown"); + data.removeTag("change"); + return newState; + } + IClimateHousing housing = container.getParent(); + double sizeModifier = housing.getSize() / Config.climateSourceRange; + double size = sizeModifier * 0.2D; + sizeModifier = Math.max(sizeModifier, 1.0D); + + container.recalculateBoundaries(sizeModifier); + + IClimateState boundaryUp = container.getBoundaryUp(); + IClimateState boundaryDown = container.getBoundaryDown(); + + data.setTag("rangeUp", boundaryUp.writeToNBT(new NBTTagCompound())); + data.setTag("rangeDown", boundaryDown.writeToNBT(new NBTTagCompound())); + + int workedSources = 0; + ImmutableClimateState target = getTargetOrBound(oldState, container.getBoundaryDown(), container.getBoundaryUp(), container.getTargetedState()); + ClimateChange changeState = new ClimateChange(data.getCompoundTag("change")); + + for (IClimateSource source : container.getClimateSources()) { + ClimateChange state = source.work(oldState, target); + if (state != null) { + boolean hasChange = false; + double temperatureChange = state.getTemperature(); + double humidityChange = state.getHumidity(); + if (temperatureChange != 0) { + temperatureChange /= sizeModifier; + hasChange = true; + } + if (humidityChange != 0) { + humidityChange /= sizeModifier; + hasChange = true; + } + if (hasChange) { + changeState = changeState.addTemperature((float) temperatureChange); + changeState = changeState.addHumidity((float) humidityChange); + workedSources++; + } + } + } + if (workedSources == 0) { + return newState.add(changeState); + } + data.setTag("change", changeState.writeToNBT(new NBTTagCompound())); + return newState.add(changeState); + } + + @Override + @SideOnly(Side.CLIENT) + public void addData(IClimateContainer container, IClimateState climateState, NBTTagCompound nbtData, IClimateData data) { + IClimateState rangeDown = new ClimateState(nbtData.getCompoundTag("rangeDown")); + IClimateState rangeUp = new ClimateState(nbtData.getCompoundTag("rangeUp")); + IClimateState change = new ClimateState(nbtData.getCompoundTag("change")); + + data.addData(ClimateType.HUMIDITY, Translator.translateToLocal("for.gui.modifier.sources.range.up"), rangeUp.getHumidity()) + .addData(ClimateType.HUMIDITY, Translator.translateToLocal("for.gui.modifier.sources.range.down"), rangeDown.getHumidity()) + .addData(ClimateType.HUMIDITY, Translator.translateToLocal("for.gui.modifier.sources.change"), change.getHumidity()); + + data.addData(ClimateType.TEMPERATURE, Translator.translateToLocal("for.gui.modifier.sources.range.up"), rangeUp.getTemperature()) + .addData(ClimateType.TEMPERATURE, Translator.translateToLocal("for.gui.modifier.sources.range.down"), rangeDown.getTemperature()) + .addData(ClimateType.TEMPERATURE, Translator.translateToLocal("for.gui.modifier.sources.change"), change.getTemperature()); + } + + @Override + public int getPriority() { + return -1; + } + + private ImmutableClimateState getTargetOrBound(IClimateState climateState, IClimateState boundaryDown, IClimateState boundaryUp, IClimateState targetedState) { + float temperature = climateState.getTemperature(); + float humidity = climateState.getHumidity(); + float targetTemperature = targetedState.getTemperature(); + float targetHumidity = targetedState.getHumidity(); + float humidityBoundaryUp = boundaryUp.getHumidity(); + float humidityBoundaryDown = boundaryDown.getHumidity(); + float temperatureBoundaryUp = boundaryUp.getTemperature(); + float temperatureBoundaryDown = boundaryDown.getTemperature(); + if (targetTemperature > temperature) { + temperature = Math.min(targetTemperature, temperatureBoundaryUp); + } else if (targetTemperature < temperature) { + temperature = Math.max(targetTemperature, temperatureBoundaryDown); + } + if (targetHumidity > humidity) { + humidity = Math.min(targetHumidity, humidityBoundaryUp); + } else if (targetHumidity < humidity) { + humidity = Math.max(targetHumidity, humidityBoundaryDown); + } + return new ImmutableClimateState(temperature, humidity); + } +} diff --git a/src/main/java/forestry/greenhouse/climate/modifiers/TimeModifier.java b/src/main/java/forestry/greenhouse/climate/modifiers/TimeModifier.java new file mode 100644 index 000000000..58156e88e --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/modifiers/TimeModifier.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.climate.modifiers; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.EnumSkyBlock; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.BlankClimateModifier; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateData; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.core.utils.Translator; + +public class TimeModifier extends BlankClimateModifier { + + private static final float TEMPERATURE_CHANGE = 0.01F; + + public static float calculateLightRatio(World world) { + int lightValue = EnumSkyBlock.SKY.defaultLightValue - world.getSkylightSubtracted(); + float sunAngle = world.getCelestialAngleRadians(1.0F); + + if (sunAngle < (float) Math.PI) { + sunAngle -= sunAngle * 0.2F; + } else { + sunAngle += (((float) Math.PI * 2F) - sunAngle) * 0.2F; + } + + lightValue = Math.round(lightValue * MathHelper.cos(sunAngle)); + + lightValue = MathHelper.clamp(lightValue, 0, 15); + return lightValue / 15f; + } + + @Override + public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, ImmutableClimateState oldState, NBTTagCompound data) { + World world = container.getWorld(); + float lightRatio = calculateLightRatio(world); + float temperatureChange = lightRatio * TEMPERATURE_CHANGE; + data.setFloat("timeTemperatureChange", temperatureChange); + return newState.addTemperature(temperatureChange); + } + + @Override + @SideOnly(Side.CLIENT) + public void addData(IClimateContainer container, IClimateState climateState, NBTTagCompound nbtData, IClimateData data) { + data.addData(ClimateType.TEMPERATURE, Translator.translateToLocal("for.gui.modifier.time"), nbtData.getFloat("timeTemperatureChange")); + } + +} diff --git a/src/main/java/forestry/greenhouse/climate/modifiers/WeatherModifier.java b/src/main/java/forestry/greenhouse/climate/modifiers/WeatherModifier.java new file mode 100644 index 000000000..f3caeef18 --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/modifiers/WeatherModifier.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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.climate.modifiers; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.BlankClimateModifier; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateData; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.core.utils.Translator; + +public class WeatherModifier extends BlankClimateModifier { + + private static final int RAIN_TIME = 600; + private static final float RAIN_HUMIDITY_CHANGE = 0.15F; + private static final float RAIN_TEMPERATURE_CHANGE = -0.10F; + private static final int SNOW_MODIFIER = 2; + + @Override + public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, ImmutableClimateState oldState, NBTTagCompound data) { + World world = container.getWorld(); + IClimateState defaultClimate = container.getParent().getDefaultClimate(); + int rainTime = data.getInteger("raintime"); + if (world.isRaining()) { + if (rainTime < RAIN_TIME) { + rainTime++; + } + } else { + if (rainTime > 0) { + rainTime--; + } + } + if (rainTime > 0) { + float rainModifier = (float) rainTime / (float) RAIN_TIME; + float temperatureChange = rainModifier * RAIN_TEMPERATURE_CHANGE; + if (defaultClimate.getTemperature() <= 0.35F) { + temperatureChange *= SNOW_MODIFIER; + } + float humidityChange = rainModifier * RAIN_HUMIDITY_CHANGE; + data.setFloat("rainTemperatureChange", temperatureChange); + data.setFloat("rainHumidityChange", humidityChange); + newState = newState.addHumidity(humidityChange); + newState = newState.addTemperature(temperatureChange); + } + data.setInteger("raintime", rainTime); + return newState; + } + + @Override + @SideOnly(Side.CLIENT) + public void addData(IClimateContainer container, IClimateState climateState, NBTTagCompound nbtData, IClimateData data) { + data.addData(ClimateType.HUMIDITY, Translator.translateToLocal("for.gui.modifier.rain"), nbtData.getFloat("rainHumidityChange")) + .addData(ClimateType.TEMPERATURE, Translator.translateToLocal("for.gui.modifier.rain"), nbtData.getFloat("rainTemperatureChange")); + } + +} diff --git a/src/main/java/forestry/greenhouse/climate/modifiers/package-info.java b/src/main/java/forestry/greenhouse/climate/modifiers/package-info.java new file mode 100644 index 000000000..83b27df03 --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/modifiers/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.climate.modifiers; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/climate/package-info.java b/src/main/java/forestry/greenhouse/climate/package-info.java new file mode 100644 index 000000000..d2a543318 --- /dev/null +++ b/src/main/java/forestry/greenhouse/climate/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.climate; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/entities/SprinklerWater.java b/src/main/java/forestry/greenhouse/entities/SprinklerWater.java deleted file mode 100755 index 0c39c8536..000000000 --- a/src/main/java/forestry/greenhouse/entities/SprinklerWater.java +++ /dev/null @@ -1,60 +0,0 @@ -package forestry.greenhouse.entities; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.texture.TextureManager; -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.x; - this.motionY = vector.y; - this.motionZ = vector.z; - this.particleMaxAge = 15; - this.setSize(0.2f, 0.2f); - } - - @Override - public int getFXLayer() { - return 1; - } - - @Override - public void renderParticle(BufferBuilder buffer, Entity entity, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) { - 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) * rotationX - interpPosX); - float f12 = (float) (this.prevPosY + (this.posY - this.prevPosY) * rotationX - interpPosY); - float f13 = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * rotationX - interpPosZ); - TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); - textureManager.bindTexture(FluidRegistry.WATER.getStill()); - int i = this.getBrightnessForRender(partialTicks); - int j = i >> 16 & 65535; - int k = i & 65535; - buffer.pos((f11 - rotationZ * f10 - rotationXZ * f10), (f12 - rotationYZ * f10), (f13 - rotationXY * f10 - f6 * f10)).color(1F, 1F, 1F, 0.5F).tex(f7, f9).lightmap(j, k).endVertex(); - buffer.pos((f11 - rotationZ * f10 + rotationXZ * f10), (f12 + rotationYZ * f10), (f13 - rotationXY * f10 + f6 * f10)).color(1F, 1F, 1F, 0.5F).tex(f7, f8).lightmap(j, k).endVertex(); - buffer.pos((f11 + rotationZ * f10 + rotationXZ * f10), (f12 + rotationYZ * f10), (f13 + rotationXY * f10 + f6 * f10)).color(1F, 1F, 1F, 0.5F).tex(f6, f8).lightmap(j, k).endVertex(); - buffer.pos((f11 + rotationZ * f10 - rotationXZ * f10), (f12 - rotationYZ * f10), (f13 + rotationXY * 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; - } -} \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/gui/ClimateTextFields.java b/src/main/java/forestry/greenhouse/gui/ClimateTextFields.java deleted file mode 100644 index 2e44cc090..000000000 --- a/src/main/java/forestry/greenhouse/gui/ClimateTextFields.java +++ /dev/null @@ -1,117 +0,0 @@ -package forestry.greenhouse.gui; - -import com.google.common.base.Predicate; -import com.google.common.primitives.Floats; - -import forestry.api.climate.IClimateControlProvider; -import forestry.api.climate.IClimateInfo; -import forestry.api.multiblock.IGreenhouseController; -import forestry.core.climate.ClimateInfo; -import forestry.core.gui.TextLayoutHelper; -import forestry.core.network.packets.PacketUpdateClimateControl; -import forestry.core.render.ColourProperties; -import forestry.core.utils.NetworkUtil; -import forestry.core.utils.Translator; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiTextField; - -public class ClimateTextFields { - - private final GuiTextField humidityField; - private final GuiTextField temperatureField; - private final IClimateControlProvider provider; - - public ClimateTextFields(IGreenhouseController controller, FontRenderer fontRenderer, int guiLeft, int guiTop) { - this.provider = controller; - IClimateInfo info = controller.getControlClimate(); - - temperatureField = new GuiTextField(0, fontRenderer, guiLeft + 64, guiTop + 31, 50, 10); - temperatureField.setValidator(NUMBER_FILTER); - temperatureField.setEnableBackgroundDrawing(false); - temperatureField.setText(Float.toString(info.getTemperature())); - - humidityField = new GuiTextField(1, fontRenderer, guiLeft + 64, guiTop + 61, 50, 10); - humidityField.setValidator(NUMBER_FILTER); - humidityField.setEnableBackgroundDrawing(false); - humidityField.setText(Float.toString(info.getHumidity())); - - } - - protected boolean keyTyped(char typedChar, int keyCode) { - return humidityField.textboxKeyTyped(typedChar, keyCode) || temperatureField.textboxKeyTyped(typedChar, keyCode); - } - - public void mouseClicked(int mouseX, int mouseY, int mouseButton){ - boolean temperatureWasFocused = temperatureField.isFocused(); - boolean humidityWasFocused = humidityField.isFocused(); - - temperatureField.mouseClicked(mouseX, mouseY, mouseButton); - humidityField.mouseClicked(mouseX, mouseY, mouseButton); - - if (temperatureWasFocused && !temperatureField.isFocused() || humidityWasFocused && !humidityField.isFocused()) { - float temp = parseField(temperatureField); - float hum = parseField(humidityField); - setClimate(provider, temp, hum); - } - NetworkUtil.sendToServer(new PacketUpdateClimateControl(provider)); - } - - public void draw(GuiGreenhouse gui, int guiLeft, int guiTop){ - TextLayoutHelper textLayout = gui.getTextLayout(); - - gui.drawTexturedModalRect(guiLeft + 62, guiTop + 29, 204, 115, 52, 12); - gui.drawTexturedModalRect(guiLeft + 62, guiTop + 59, 204, 127, 52, 12); - - textLayout.line = 20; - textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.temperature"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.temperature.text")); - temperatureField.drawTextBox(); - - textLayout.line = 50; - textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.humidity"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.humidity.text")); - humidityField.drawTextBox(); - } - - public void setClimate(float temp){ - IClimateInfo info = provider.getControlClimate(); - setClimate(provider, temp, info.getHumidity()); - } - - public void setClimate(IClimateControlProvider provider, float temp, float hum){ - temperatureField.setText(Float.toString(temp)); - humidityField.setText(Float.toString(hum)); - provider.setControlClimate(new ClimateInfo(temp, hum)); - } - - private static float parseField(GuiTextField field) { - String text = field.getText(); - if (text.isEmpty()) { - return 2.0F; - } - try { - float f = Float.parseFloat(text); - if (f >= 2) { - f = 2.0F; - } - return f; - } catch (NumberFormatException var5) { - return 2.0F; - } - } - - protected static final Predicate NUMBER_FILTER = text -> { - if (text == null) { - return false; - } - if (!text.isEmpty() && text.length() > 1) { - if (!text.contains(".")) { - return false; - } - } - if (text.length() > 7) { - return false; - } - Float f = Floats.tryParse(text); - return text.isEmpty() || f != null && Floats.isFinite(f) && f >= 0.0F; - }; - -} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHeater.java b/src/main/java/forestry/greenhouse/gui/ContainerCamouflageSprayCan.java similarity index 53% rename from src/main/java/forestry/greenhouse/tiles/TileGreenhouseHeater.java rename to src/main/java/forestry/greenhouse/gui/ContainerCamouflageSprayCan.java index 1e4cab4df..6b7cabacd 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHeater.java +++ b/src/main/java/forestry/greenhouse/gui/ContainerCamouflageSprayCan.java @@ -8,19 +8,17 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.greenhouse.tiles; +package forestry.greenhouse.gui; -import forestry.api.climate.EnumClimatiserModes; -import forestry.api.climate.EnumClimatiserTypes; -import forestry.api.climate.IClimatiserDefinition; -import forestry.core.climate.ClimatiserDefinition; +import net.minecraft.entity.player.InventoryPlayer; -public class TileGreenhouseHeater extends TileGreenhouseClimatiser { +import forestry.core.gui.ContainerItemInventory; +import forestry.greenhouse.inventory.ItemInventoryCamouflageSprayCan; - private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.POSITIVE, 5F, EnumClimatiserTypes.TEMPERATURE); +public class ContainerCamouflageSprayCan extends ContainerItemInventory { - public TileGreenhouseHeater() { - super(DEFINITION); + public ContainerCamouflageSprayCan(ItemInventoryCamouflageSprayCan inventory, InventoryPlayer playerInventory) { + super(inventory, playerInventory, 8, 84); } } diff --git a/src/main/java/forestry/greenhouse/gui/ContainerClimatiser.java b/src/main/java/forestry/greenhouse/gui/ContainerClimatiser.java new file mode 100644 index 000000000..53c5925f8 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/ContainerClimatiser.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; + +import forestry.core.gui.ContainerSocketed; +import forestry.core.network.packets.PacketGuiUpdate; +import forestry.greenhouse.tiles.TileClimatiser; + +public class ContainerClimatiser extends ContainerSocketed { + + private ItemStack socket = ItemStack.EMPTY; + + public ContainerClimatiser(InventoryPlayer playerInventory, TileClimatiser tile) { + super(tile, playerInventory, 8, 84); + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + ItemStack socket = tile.getSocket(0); + if (socket.isEmpty() && !this.socket.isEmpty() || !socket.isEmpty() && this.socket.isEmpty()) { + PacketGuiUpdate packet = new PacketGuiUpdate(tile); + sendPacketToListeners(packet); + } + } + +} diff --git a/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java b/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java index 0b700a30a..0265447e1 100644 --- a/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java +++ b/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java @@ -10,19 +10,16 @@ ******************************************************************************/ package forestry.greenhouse.gui; +import net.minecraft.entity.player.InventoryPlayer; + import forestry.core.gui.ContainerTile; -import forestry.core.gui.slots.SlotLiquidIn; import forestry.core.network.packets.PacketGuiUpdate; import forestry.greenhouse.tiles.TileGreenhouse; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraftforge.fluids.IFluidTank; public class ContainerGreenhouse extends ContainerTile { public ContainerGreenhouse(InventoryPlayer playerInventory, TileGreenhouse tile) { - super(tile, playerInventory, 8, 84); - - addSlotToContainer(new SlotLiquidIn(tile, 0, 125, 37)); + super(tile, playerInventory, 18, 120); } @Override @@ -32,8 +29,4 @@ public class ContainerGreenhouse extends ContainerTile { sendPacketToListeners(packet); } - public IFluidTank getTank(int slot) { - return tile.getMultiblockLogic().getController().getTankManager().getTank(slot); - } - } diff --git a/src/main/java/forestry/greenhouse/gui/ContainerGreenhouseNursery.java b/src/main/java/forestry/greenhouse/gui/ContainerGreenhouseNursery.java deleted file mode 100644 index a4e6eb094..000000000 --- a/src/main/java/forestry/greenhouse/gui/ContainerGreenhouseNursery.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse.gui; - -import forestry.core.gui.ContainerTile; -import forestry.core.gui.slots.SlotFiltered; -import forestry.core.gui.slots.SlotOutput; -import forestry.core.gui.slots.SlotWorking; -import forestry.core.network.packets.PacketGuiUpdate; -import forestry.greenhouse.inventory.InventoryNursery; -import forestry.greenhouse.tiles.TileGreenhouseNursery; -import net.minecraft.entity.player.InventoryPlayer; - -public class ContainerGreenhouseNursery extends ContainerTile { - - public ContainerGreenhouseNursery(InventoryPlayer playerInventory, TileGreenhouseNursery tile) { - super(tile, playerInventory, 8, 94); - - // Input buffer - for (int i = 0; i < 3; i++) { - for (int k = 0; k < 2; k++) { - addSlotToContainer(new SlotFiltered(tile, InventoryNursery.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18).setBackgroundTexture("slots/cocoon")); - } - } - - // Cocoon slot - addSlotToContainer(new SlotWorking(tile, InventoryNursery.SLOT_WORK, 84, 45)); - - // Output buffer - for (int i = 0; i < 3; i++) { - for (int k = 0; k < 2; k++) { - addSlotToContainer(new SlotOutput(tile, InventoryNursery.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 28 + i * 18)); - } - } - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - PacketGuiUpdate packet = new PacketGuiUpdate(tile); - sendPacketToListeners(packet); - } - -} diff --git a/src/main/java/forestry/greenhouse/gui/ContainerHygroregulator.java b/src/main/java/forestry/greenhouse/gui/ContainerHygroregulator.java new file mode 100644 index 000000000..7d184d9e3 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/ContainerHygroregulator.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui; + +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotLiquidIn; +import forestry.greenhouse.inventory.InventoryHygroregulator; +import forestry.greenhouse.tiles.TileHygroregulator; + +public class ContainerHygroregulator extends ContainerLiquidTanks { + + public ContainerHygroregulator(InventoryPlayer playerInventory, TileHygroregulator tile) { + super(tile, playerInventory, 8, 84); + + this.addSlotToContainer(new SlotLiquidIn(tile, InventoryHygroregulator.SLOT_INPUT, 56, 38)); + } + +} diff --git a/src/main/java/forestry/greenhouse/gui/GreenhouseEnergyLedger.java b/src/main/java/forestry/greenhouse/gui/GreenhouseEnergyLedger.java index fdb5d3fbf..9f7f9890b 100644 --- a/src/main/java/forestry/greenhouse/gui/GreenhouseEnergyLedger.java +++ b/src/main/java/forestry/greenhouse/gui/GreenhouseEnergyLedger.java @@ -9,7 +9,7 @@ import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; public class GreenhouseEnergyLedger extends Ledger { final IGreenhouseControllerInternal controller; - + public GreenhouseEnergyLedger(LedgerManager ledgerManager, IGreenhouseControllerInternal controller) { super(ledgerManager, "power"); maxHeight = 48; diff --git a/src/main/java/forestry/greenhouse/gui/GuiCamouflageSprayCan.java b/src/main/java/forestry/greenhouse/gui/GuiCamouflageSprayCan.java new file mode 100644 index 000000000..08c9672cd --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/GuiCamouflageSprayCan.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui; + +import net.minecraft.entity.player.EntityPlayer; + +import forestry.core.config.Constants; +import forestry.core.gui.GuiForestryTitled; +import forestry.greenhouse.gui.widgets.WidgetCamouflageSlot; +import forestry.greenhouse.inventory.ItemInventoryCamouflageSprayCan; + +public class GuiCamouflageSprayCan extends GuiForestryTitled { + + public GuiCamouflageSprayCan(EntityPlayer player, ItemInventoryCamouflageSprayCan inventory) { + super(Constants.TEXTURE_PATH_GUI + "/camouflage_spray_can.png", new ContainerCamouflageSprayCan(inventory, player.inventory), inventory); + + //Add the camouflage slot + widgetManager.add(new WidgetCamouflageSlot(widgetManager, 80, 39, inventory)); + } + + @Override + protected void addLedgers() { + } + +} diff --git a/src/main/java/forestry/greenhouse/gui/GuiClimatiser.java b/src/main/java/forestry/greenhouse/gui/GuiClimatiser.java new file mode 100644 index 000000000..42ef853f8 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/GuiClimatiser.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui; + +import net.minecraft.entity.player.EntityPlayer; + +import forestry.core.config.Constants; +import forestry.core.gui.GuiForestryTitled; +import forestry.core.gui.widgets.SocketWidget; +import forestry.greenhouse.gui.widgets.WidgetCamouflageSlot; +import forestry.greenhouse.tiles.TileClimatiser; + +public class GuiClimatiser extends GuiForestryTitled { + + private final TileClimatiser tile; + + public GuiClimatiser(EntityPlayer player, TileClimatiser tile) { + super(Constants.TEXTURE_PATH_GUI + "/climatiser.png", new ContainerClimatiser(player.inventory, tile), tile); + + this.tile = tile; + + //Add the camouflage slot + widgetManager.add(new WidgetCamouflageSlot(widgetManager, guiLeft + 71, guiTop + 35, tile)); + widgetManager.add(new SocketWidget(widgetManager, guiLeft + 93, guiTop + 35, tile, 0)); + } + + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger("climatiser"); + } +} diff --git a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java index 98854d785..a51ebd1fd 100755 --- a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java +++ b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java @@ -13,91 +13,76 @@ package forestry.greenhouse.gui; import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; -import forestry.api.core.CamouflageManager; -import forestry.core.climate.ClimateInfo; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateData; +import forestry.api.climate.ImmutableClimateState; import forestry.core.config.Constants; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.TextLayoutHelper; -import forestry.core.gui.widgets.TankWidget; -import forestry.core.owner.IOwnedTile; +import forestry.core.utils.NetworkUtil; +import forestry.greenhouse.gui.widgets.WidgetCamouflageTab; +import forestry.greenhouse.gui.widgets.WidgetClimatePanel; +import forestry.greenhouse.gui.widgets.WidgetClimatePillar; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; +import forestry.greenhouse.network.packets.PacketSelectClimateTargeted; import forestry.greenhouse.tiles.TileGreenhouse; public class GuiGreenhouse extends GuiForestryTitled { + //The space between the top of the gui and the inventory. + private static final int GUI_HEIGHT = 119; + private final IGreenhouseControllerInternal controller; - private final IOwnedTile tile; - private ClimateTextFields fields; + private final TileGreenhouse tile; + public WidgetClimatePanel temperaturePanel; + public WidgetClimatePanel humidityPanel; + public IClimateContainer container; public GuiGreenhouse(EntityPlayer player, TileGreenhouse tile) { super(Constants.TEXTURE_PATH_GUI + "/greenhouse.png", new ContainerGreenhouse(player.inventory, tile), tile); this.controller = tile.getMultiblockLogic().getController(); + this.container = controller.getClimateContainer(); this.tile = tile; + this.xSize = 196; + this.ySize = 202; - //Add the water tank - widgetManager.add(new TankWidget(widgetManager, 152, 16, 0).setOverlayOrigin(176, 0)); - //Add the multiblock camouflage tabs - WidgetCamouflageTab previous; - int x = 3; - widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.BLOCK)); - x+=50 + (previous.getHandlerSlot() != null ? 20 : 0); - widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.GLASS)); - x+=50 + (previous.getHandlerSlot() != null ? 20 : 0); - widgetManager.add(new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.DOOR)); - - if(hasFields()){ - widgetManager.add(new WidgetClimatePillar(widgetManager, guiLeft- 23, guiTop + 5)); - } - } - - public boolean hasFields(){ - return controller != null && controller.getControlClimate() != ClimateInfo.MAX; + IClimateData data = container.getData(); + + //Add the camouflage tab + widgetManager.add(new WidgetCamouflageTab(widgetManager, xSize / 2 - WidgetCamouflageTab.WIDTH / 2, -WidgetCamouflageTab.HEIGHT, controller, tile)); + widgetManager.add(new WidgetClimatePillar(widgetManager, -WidgetClimatePillar.WIDTH, GUI_HEIGHT / 2 - WidgetClimatePillar.HEIGHT / 2)); + widgetManager.add(temperaturePanel = new WidgetClimatePanel(widgetManager, this, 9, 18, ClimateType.TEMPERATURE, data)); + widgetManager.add(humidityPanel = new WidgetClimatePanel(widgetManager, this, 102, 18, ClimateType.HUMIDITY, data)); } - @Override - public void initGui() { - super.initGui(); - - if(hasFields()){ - fields = new ClimateTextFields(controller, fontRenderer, guiLeft, guiTop); - }else{ - fields = null; - } + public void sendNetworkUpdate() { + BlockPos pos = controller.getCoordinates(); + float temp = temperaturePanel.parseValue(); + float hum = humidityPanel.parseValue(); + setClimate(container, temp, hum); + NetworkUtil.sendToServer(new PacketSelectClimateTargeted(pos, container.getTargetedState())); } - - public ClimateTextFields getFields() { - return fields; + + public void setClimate(IClimateContainer container, float temp, float hum) { + temperaturePanel.setValue(temp); + humidityPanel.setValue(hum); + container.setTargetedState(new ImmutableClimateState(temp, hum)); } @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { - if (fields == null || !fields.keyTyped(typedChar, keyCode)) { + if (!temperaturePanel.keyTyped(typedChar, keyCode) && !humidityPanel.keyTyped(typedChar, keyCode)) { super.keyTyped(typedChar, keyCode); } } - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); - if (fields != null) { - fields.mouseClicked(mouseX, mouseY, mouseButton); - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); - - if (fields != null) { - fields.draw(this, mouseX, mouseY); - } - } - TextLayoutHelper getTextLayout() { return textLayout; } - + @Override protected void addLedgers() { addErrorLedger(controller); diff --git a/src/main/java/forestry/greenhouse/gui/GuiGreenhouseNursery.java b/src/main/java/forestry/greenhouse/gui/GuiGreenhouseNursery.java deleted file mode 100644 index 989d15dc5..000000000 --- a/src/main/java/forestry/greenhouse/gui/GuiGreenhouseNursery.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse.gui; - -import forestry.api.core.CamouflageManager; -import forestry.core.config.Constants; -import forestry.core.gui.GuiForestryTitled; -import forestry.core.render.EnumTankLevel; -import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; -import forestry.greenhouse.tiles.TileGreenhouseNursery; -import net.minecraft.entity.player.EntityPlayer; - -public class GuiGreenhouseNursery extends GuiForestryTitled { - private final TileGreenhouseNursery tile; - - public GuiGreenhouseNursery(EntityPlayer player, TileGreenhouseNursery tile) { - super(Constants.TEXTURE_PATH_GUI + "/greenhouse_nursery.png", new ContainerGreenhouseNursery(player.inventory, tile), tile); - - this.tile = tile; - this.ySize = 176; - - IGreenhouseControllerInternal controller = tile.getMultiblockLogic().getController(); - WidgetCamouflageTab previous; - int x = 3; - widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.BLOCK)); - x+=50 + (previous.getHandlerSlot() != null ? 20 : 0); - widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.GLASS)); - x+=50 + (previous.getHandlerSlot() != null ? 20 : 0); - widgetManager.add(new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, controller, tile, CamouflageManager.DOOR)); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - drawMeter(guiLeft + 75, guiTop + 30, tile.getProgressScaled(46), EnumTankLevel.rateTankLevel(tile.getProgressScaled(100))); - } - - private void drawMeter(int x, int y, int height, EnumTankLevel rated) { - int i = 176 + rated.getLevelScaled(16); - - drawTexturedModalRect(x, y + 46 - height, i, 46 - height, 4, height); - } - - @Override - protected void addLedgers() { - IGreenhouseControllerInternal controller = tile.getMultiblockLogic().getController(); - - addErrorLedger(tile); - addClimateLedger(tile); - ledgerManager.add(new GreenhouseEnergyLedger(ledgerManager, controller)); - addHintLedger("greenhouse"); - addOwnerLedger(tile); - } -} diff --git a/src/main/java/forestry/greenhouse/gui/GuiHygroregulator.java b/src/main/java/forestry/greenhouse/gui/GuiHygroregulator.java new file mode 100644 index 000000000..e6f157a5a --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/GuiHygroregulator.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.config.Constants; +import forestry.core.gui.ContainerSocketedHelper; +import forestry.core.gui.GuiForestryTitled; +import forestry.core.gui.IContainerSocketed; +import forestry.core.gui.widgets.SocketWidget; +import forestry.core.gui.widgets.TankWidget; +import forestry.greenhouse.gui.widgets.WidgetCamouflageSlot; +import forestry.greenhouse.tiles.TileHygroregulator; + +public class GuiHygroregulator extends GuiForestryTitled implements IContainerSocketed { + private final TileHygroregulator tile; + private final ContainerSocketedHelper helper; + + public GuiHygroregulator(InventoryPlayer inventory, TileHygroregulator tile) { + super(Constants.TEXTURE_PATH_GUI + "/greenhouse_hygroregulator.png", new ContainerHygroregulator(inventory, tile), tile); + this.tile = tile; + + widgetManager.add(new TankWidget(this.widgetManager, 104, 17, 0)); + //Add the camouflage slot + widgetManager.add(new WidgetCamouflageSlot(widgetManager, guiLeft + 152, guiTop + 38, tile)); + + widgetManager.add(new SocketWidget(widgetManager, guiLeft + 9, guiTop + 38, tile, 0)); + this.helper = new ContainerSocketedHelper<>(tile); + } + + /** + * {@link net.minecraft.block.Block#isFullBlock(IBlockState)} + * + * @param slot + */ + @Override + @SideOnly(Side.CLIENT) + public void handleChipsetClick(int slot) { + helper.handleChipsetClick(slot); + } + + @Override + public void handleChipsetClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { + helper.handleChipsetClickServer(slot, player, itemstack); + } + + @Override + @SideOnly(Side.CLIENT) + public void handleSolderingIronClick(int slot) { + helper.handleSolderingIronClick(slot); + } + + @Override + public void handleSolderingIronClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { + helper.handleSolderingIronClickServer(slot, player, itemstack); + } + + @Override + protected void addLedgers() { + addErrorLedger(tile); + } +} diff --git a/src/main/java/forestry/greenhouse/gui/GuiTextFieldAdvanced.java b/src/main/java/forestry/greenhouse/gui/GuiTextFieldAdvanced.java new file mode 100644 index 000000000..ea3c7e963 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/GuiTextFieldAdvanced.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; + +public class GuiTextFieldAdvanced extends GuiTextField { + + public ITextFieldListener listener; + + public GuiTextFieldAdvanced(int componentId, FontRenderer fontrendererObj, int x, int y, int par5Width, int par6Height) { + super(componentId, fontrendererObj, x, y, par5Width, par6Height); + } + + public void setListener(ITextFieldListener listener) { + this.listener = listener; + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + boolean wasFocused = isFocused(); + super.mouseClicked(mouseX, mouseY, mouseButton); + if (wasFocused && !isFocused()) { + if (listener != null) { + setText(listener.parseValue(getText())); + } + } + } + + public interface ITextFieldListener { + String parseValue(String value); + } +} diff --git a/src/main/java/forestry/greenhouse/gui/package-info.java b/src/main/java/forestry/greenhouse/gui/package-info.java index 11eccc55d..8433b5abc 100644 --- a/src/main/java/forestry/greenhouse/gui/package-info.java +++ b/src/main/java/forestry/greenhouse/gui/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse.gui; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/core/gui/widgets/WidgetCamouflageSlot.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java similarity index 80% rename from src/main/java/forestry/core/gui/widgets/WidgetCamouflageSlot.java rename to src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java index 98f2e2f0d..83ef7fe75 100755 --- a/src/main/java/forestry/core/gui/widgets/WidgetCamouflageSlot.java +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java @@ -8,14 +8,15 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui.widgets; +package forestry.greenhouse.gui.widgets; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.text.TextFormatting; @@ -28,49 +29,54 @@ 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.utils.Translator; public class WidgetCamouflageSlot extends Widget { private final ICamouflageHandler camouflageHandler; - private final String type; + protected final ToolTip toolTip = new ToolTip(250) { + @Override + @SideOnly(Side.CLIENT) + public void refresh() { + toolTip.clear(); + if (camouflageHandler instanceof IMultiblockController) { + toolTip.add(Translator.translateToLocal("for.gui.empty.slot.camouflage.multiblock") + ": "); + } else { + toolTip.add(Translator.translateToLocal("for.gui.empty.slot.camouflage") + ": "); + } + ItemStack camouflageBlock = camouflageHandler.getCamouflageBlock(); - public WidgetCamouflageSlot(WidgetManager manager, int xPos, int yPos, ICamouflageHandler camouflageHandler, String type) { + if (camouflageBlock.isEmpty()) { + toolTip.add(TextFormatting.ITALIC.toString() + Translator.translateToLocal("for.gui.empty")); + } else { + Minecraft minecraft = Minecraft.getMinecraft(); + toolTip.add(TextFormatting.ITALIC.toString() + camouflageBlock.getTooltip(minecraft.player, minecraft.gameSettings.advancedItemTooltips)); + } + } + }; + + public WidgetCamouflageSlot(WidgetManager manager, int xPos, int yPos, ICamouflageHandler camouflageHandler) { super(manager, xPos, yPos); this.camouflageHandler = camouflageHandler; - this.type = type; } @Override @SideOnly(Side.CLIENT) public void draw(int startX, int startY) { - ItemStack camouflageBlock = camouflageHandler.getCamouflageBlock(type); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + ItemStack camouflageBlock = camouflageHandler.getCamouflageBlock(); if (!camouflageBlock.isEmpty()) { Minecraft minecraft = Minecraft.getMinecraft(); TextureManager textureManager = minecraft.getTextureManager(); textureManager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); + GlStateManager.enableRescaleNormal(); + RenderHelper.enableGUIStandardItemLighting(); RenderItem renderItem = minecraft.getRenderItem(); renderItem.renderItemIntoGUI(camouflageBlock, startX + xPos, startY + yPos); - } - } - - @Override - public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { - super.handleMouseClick(mouseX, mouseY, mouseButton); - if (GuiScreen.isShiftKeyDown()) { - camouflageHandler.setCamouflageBlock(type, camouflageHandler.getDefaultCamouflageBlock(type), true); - } else { - EntityPlayer player = Minecraft.getMinecraft().player; - ItemStack stack = player.inventory.getItemStack(); - if (!stack.isEmpty()) { - if (!CamouflageManager.camouflageAccess.isItemBlackListed(type, stack)) { - for (ICamouflageItemHandler handler : CamouflageManager.camouflageAccess.getCamouflageItemHandler(type)) { - if (handler != null && handler.canHandle(stack)) { - camouflageHandler.setCamouflageBlock(handler.getType(), stack.copy(), true); - } - } - } - } + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableRescaleNormal(); } } @@ -83,25 +89,24 @@ public class WidgetCamouflageSlot extends Widget { } } - protected final ToolTip toolTip = new ToolTip(250) { - @Override - @SideOnly(Side.CLIENT) - public void refresh() { - toolTip.clear(); - if (camouflageHandler instanceof IMultiblockController) { - toolTip.add(Translator.translateToLocal("for.gui.empty.slot.camouflage.multiblock." + type) + ": "); - } else { - toolTip.add(Translator.translateToLocal("for.gui.empty.slot.camouflage") + ": "); - } - ItemStack camouflageBlock = camouflageHandler.getCamouflageBlock(type); - - if (camouflageBlock.isEmpty()) { - toolTip.add(TextFormatting.ITALIC.toString() + Translator.translateToLocal("for.gui.empty")); - } else { - Minecraft minecraft = Minecraft.getMinecraft(); - toolTip.add(TextFormatting.ITALIC.toString() + camouflageBlock.getTooltip(minecraft.player, minecraft.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL)); + @Override + public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { + super.handleMouseClick(mouseX, mouseY, mouseButton); + if (GuiScreen.isShiftKeyDown()) { + camouflageHandler.setCamouflageBlock(camouflageHandler.getDefaultCamouflageBlock(), true); + } else { + EntityPlayer player = Minecraft.getMinecraft().player; + ItemStack stack = player.inventory.getItemStack(); + if (!stack.isEmpty()) { + if (!CamouflageManager.camouflageAccess.isItemBlackListed(stack)) { + for (ICamouflageItemHandler handler : CamouflageManager.camouflageAccess.getItemHandlers()) { + if (handler != null && handler.canHandle(stack)) { + camouflageHandler.setCamouflageBlock(stack.copy(), true); + } + } + } } } - }; + } } diff --git a/src/main/java/forestry/greenhouse/gui/WidgetCamouflageTab.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageTab.java similarity index 73% rename from src/main/java/forestry/greenhouse/gui/WidgetCamouflageTab.java rename to src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageTab.java index dc0e271fb..145627178 100644 --- a/src/main/java/forestry/greenhouse/gui/WidgetCamouflageTab.java +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageTab.java @@ -1,55 +1,48 @@ -package forestry.greenhouse.gui; +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui.widgets; import javax.annotation.Nullable; -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.multiblock.IGreenhouseController; -import forestry.core.gui.tooltips.ToolTip; -import forestry.core.gui.widgets.Widget; -import forestry.core.gui.widgets.WidgetCamouflageSlot; -import forestry.core.gui.widgets.WidgetManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import forestry.api.core.ICamouflageHandler; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.gui.tooltips.ToolTip; +import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; +import forestry.greenhouse.multiblock.GreenhouseController; + public class WidgetCamouflageTab extends Widget { + public static final int WIDTH = 68; + public static final int HEIGHT = 25; + private final WidgetCamouflageSlot greenhouseSlot; @Nullable private final WidgetCamouflageSlot handlerSlot; private final ItemStack typeStack; - public WidgetCamouflageTab(WidgetManager manager, int xPos, int yPos, IGreenhouseController controller, ICamouflageHandler camouflageHandler, String type) { + public WidgetCamouflageTab(WidgetManager manager, int xPos, int yPos, IGreenhouseController controller, ICamouflageHandler camouflageHandler) { super(manager, xPos, yPos); - this.width = 48; - this.height = 25; - greenhouseSlot = new WidgetCamouflageSlot(manager, xPos + 26, yPos + 6, controller, type); - if (camouflageHandler.canHandleType(type)) { - handlerSlot = new WidgetCamouflageSlot(manager, xPos + 46, yPos + 6, camouflageHandler, type); - width += 20; - } else { - handlerSlot = null; - } - switch (type) { - case CamouflageManager.BLOCK: - typeStack = new ItemStack(Blocks.BRICK_BLOCK); - break; - case CamouflageManager.GLASS: - typeStack = new ItemStack(Blocks.GLASS); - break; - case CamouflageManager.DOOR: - typeStack = new ItemStack(Items.OAK_DOOR); - break; - default: - typeStack = ItemStack.EMPTY; - break; - } + this.width = WIDTH; + this.height = HEIGHT; + greenhouseSlot = new WidgetCamouflageSlot(manager, xPos + 26, yPos + 6, controller); + handlerSlot = new WidgetCamouflageSlot(manager, xPos + 46, yPos + 6, camouflageHandler); + typeStack = GreenhouseController.createDefaultCamouflageBlock(); } @Override @@ -73,6 +66,17 @@ public class WidgetCamouflageTab extends Widget { } } + @Override + public ToolTip getToolTip(int mouseX, int mouseY) { + if (greenhouseSlot.isMouseOver(mouseX, mouseY)) { + return greenhouseSlot.getToolTip(mouseX, mouseY); + } else if (handlerSlot != null && handlerSlot.isMouseOver(mouseX, mouseY)) { + return handlerSlot.getToolTip(mouseX, mouseY); + } else { + return null; + } + } + @Override public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { mouseX -= manager.gui.getGuiLeft(); @@ -93,15 +97,4 @@ public class WidgetCamouflageTab extends Widget { public WidgetCamouflageSlot getHandlerSlot() { return handlerSlot; } - - @Override - public ToolTip getToolTip(int mouseX, int mouseY) { - if (greenhouseSlot.isMouseOver(mouseX, mouseY)) { - return greenhouseSlot.getToolTip(mouseX, mouseY); - } else if (handlerSlot != null && handlerSlot.isMouseOver(mouseX, mouseY)) { - return handlerSlot.getToolTip(mouseX, mouseY); - } else { - return null; - } - } } diff --git a/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePanel.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePanel.java new file mode 100644 index 000000000..20691d442 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePanel.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui.widgets; + +import com.google.common.base.Predicate; +import com.google.common.primitives.Floats; + +import java.util.Map; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.renderer.GlStateManager; + +import org.lwjgl.input.Keyboard; + +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateData; +import forestry.core.gui.tables.Table; +import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; +import forestry.core.render.ColourProperties; +import forestry.core.utils.StringUtil; +import forestry.core.utils.Translator; +import forestry.greenhouse.gui.GuiGreenhouse; + +public class WidgetClimatePanel extends Widget { + + protected static final Predicate NUMBER_FILTER = text -> { + if (text == null) { + return false; + } + if (text.isEmpty()) { + return true; + } + if (text.length() > 1) { + if (!text.contains(".")) { + return false; + } + } + if (text.length() > 7) { + return false; + } + Float value = Floats.tryParse(text); + return value != null && Floats.isFinite(value) && value >= 0.0F; + }; + private final GuiGreenhouse gui; + private final ClimateType type; + private final Table table; + private final GuiTextField textField; + + public WidgetClimatePanel(WidgetManager manager, GuiGreenhouse gui, int xPos, int yPos, ClimateType type, IClimateData data) { + super(manager, xPos, yPos); + this.width = 85; + this.height = 98; + this.type = type; + this.gui = gui; + int textFieldLength = 50; + textField = new GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, xPos + width / 2 - textFieldLength / 2, yPos + 14, textFieldLength, 10); + textField.setValidator(NUMBER_FILTER); + textField.setEnableBackgroundDrawing(false); + textField.setText(Float.toString(gui.container.getTargetedState().get(type))); + table = new Table(); + for (Map.Entry entry : data.getData(type).entrySet()) { + table.addValueEntry(entry.getKey(), StringUtil.floatAsPercent(entry.getValue())); + } + } + + @Override + public void draw(int startX, int startY) { + GlStateManager.color(1.0f, 1.0f, 1.0f); + Minecraft mc = Minecraft.getMinecraft(); + mc.getTextureManager().bindTexture(gui.textureFile); + gui.drawTexturedModalRect(startX + textField.xPosition - 2, startY + textField.yPosition - 2, 204, 115, 52, 12); + + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + String title = Translator.translateToLocal("for.gui." + type.getName()); + fontRenderer.drawString(title, xPos + startX + width / 2 - fontRenderer.getStringWidth(title) / 2, startY + yPos + 2, ColourProperties.INSTANCE.get("gui.greenhouse." + type.getName() + ".header")); + + GlStateManager.color(1.0f, 1.0f, 1.0f); + textField.drawTextBox(); + + table.draw(xPos + startX - 2, yPos + startY + 26, 14737632, false); + } + + @Override + public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { + boolean wasFocused = textField.isFocused(); + textField.mouseClicked(mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop(), mouseButton); + if (wasFocused && !textField.isFocused()) { + gui.sendNetworkUpdate(); + } + } + + public void setValue(float value) { + textField.setText(Float.toString(value)); + } + + public float parseValue() { + String text = textField.getText(); + if (text.isEmpty()) { + return 2.0F; + } + try { + float value = Float.parseFloat(text); + return Math.max(0.0F, Math.min(value, 2.0F)); + } catch (NumberFormatException e) { + return 2.0F; + } + } + + public boolean keyTyped(char typedChar, int keyCode) { + if (keyCode == Keyboard.KEY_RETURN && textField.isFocused()) { + textField.setFocused(false); + gui.sendNetworkUpdate(); + return true; + } + return textField.textboxKeyTyped(typedChar, keyCode); + } +} diff --git a/src/main/java/forestry/greenhouse/gui/WidgetClimatePillar.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePillar.java similarity index 63% rename from src/main/java/forestry/greenhouse/gui/WidgetClimatePillar.java rename to src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePillar.java index 9ff36b301..33a21ffef 100644 --- a/src/main/java/forestry/greenhouse/gui/WidgetClimatePillar.java +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePillar.java @@ -1,48 +1,64 @@ -package forestry.greenhouse.gui; +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.gui.widgets; import java.util.ArrayList; import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureManager; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.api.core.EnumTemperature; import forestry.api.genetics.AlleleManager; import forestry.core.gui.tooltips.ToolTip; import forestry.core.gui.widgets.Widget; import forestry.core.gui.widgets.WidgetManager; import forestry.core.render.TextureManagerForestry; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.greenhouse.gui.GuiGreenhouse; public class WidgetClimatePillar extends Widget { + public static final int WIDTH = 23; + public static final int HEIGHT = 90; + private final List buttons = new ArrayList<>(); - + public WidgetClimatePillar(WidgetManager manager, int xPos, int yPos) { super(manager, xPos, yPos); - this.width = 23; - this.height = 90; - for(int i = 1;i < 6;i++){ + this.width = WIDTH; + this.height = HEIGHT; + for (int i = 1; i < 6; i++) { EnumTemperature temp = EnumTemperature.VALUES[i]; float value; switch (temp) { - case ICY: - value = 0.0F; - break; - case COLD: - value = 0.2F; - break; - case WARM: - value = 0.9F; - break; - case HOT: - value = 1.2F; - break; - default: - value = 0.5F; - break; + case ICY: + value = 0.0F; + break; + case COLD: + value = 0.2F; + break; + case WARM: + value = 0.9F; + break; + case HOT: + value = 1.2F; + break; + default: + value = 0.5F; + break; } buttons.add(new ClimateButton(this, temp, value, xPos + 5, yPos + 5 + (i - 1) * 16)); } @@ -53,68 +69,49 @@ public class WidgetClimatePillar extends Widget { TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); textureManager.bindTexture(manager.gui.textureFile); manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, 220, 25, width, height); - for(ClimateButton button : buttons){ + for (ClimateButton button : buttons) { button.draw(startX, startY); } } - + @Override public ToolTip getToolTip(int mouseX, int mouseY) { - for(ClimateButton button : buttons){ - if(button.isMouseOver(mouseX, mouseY)){ + for (ClimateButton button : buttons) { + if (button.isMouseOver(mouseX, mouseY)) { return button.getToolTip(); } } return null; } - - @Override - public boolean handleMouseRelease(int mouseX, int mouseY, int eventType) { - mouseX-=manager.gui.getGuiLeft(); - mouseY-=manager.gui.getGuiTop(); - if(isMouseOver(mouseX, mouseY)){ - return true; - } - return false; - } - + @Override public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { - mouseX-=manager.gui.getGuiLeft(); - mouseY-=manager.gui.getGuiTop(); - for(ClimateButton button : buttons){ - if(button.isMouseOver(mouseX, mouseY)){ - ((GuiGreenhouse)manager.gui).getFields().setClimate(button.value); + mouseX -= manager.gui.getGuiLeft(); + mouseY -= manager.gui.getGuiTop(); + for (ClimateButton button : buttons) { + if (button.isMouseOver(mouseX, mouseY)) { + ((GuiGreenhouse) manager.gui).temperaturePanel.setValue(button.value); } } } - - private static class ClimateButton{ + + @Override + public boolean handleMouseRelease(int mouseX, int mouseY, int eventType) { + mouseX -= manager.gui.getGuiLeft(); + mouseY -= manager.gui.getGuiTop(); + return isMouseOver(mouseX, mouseY); + } + + protected void drawSprite(TextureAtlasSprite sprite, int x, int y) { + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0F); + TextureManagerForestry.getInstance().bindGuiTextureMap(); + manager.gui.drawTexturedModalRect(x, y, sprite, 16, 16); + } + + private static class ClimateButton { final WidgetClimatePillar parent; - final EnumTemperature temperature; + final EnumTemperature temperature; final float value; - final int xPos, yPos; - - public ClimateButton(WidgetClimatePillar parent, EnumTemperature temperature, float value, int xPos, int yPos) { - this.parent = parent; - this.temperature = temperature; - this.value = value; - this.xPos = xPos; - this.yPos = yPos; - } - - public void draw(int startX, int startY) { - parent.drawSprite(temperature.getSprite(), startX + xPos, startY + yPos); - } - - public ToolTip getToolTip() { - return toolTip; - } - - public boolean isMouseOver(int mouseX, int mouseY) { - return mouseX >= xPos && mouseX <= xPos + 16 && mouseY >= yPos && mouseY <= yPos + 16; - } - protected final ToolTip toolTip = new ToolTip(250) { @Override @SideOnly(Side.CLIENT) @@ -124,11 +121,26 @@ public class WidgetClimatePillar extends Widget { toolTip.add("V: " + value); } }; - } - - protected void drawSprite(TextureAtlasSprite sprite, int x, int y) { - GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0F); - TextureManagerForestry.getInstance().bindGuiTextureMap(); - manager.gui.drawTexturedModalRect(x, y, sprite, 16, 16); + final int xPos, yPos; + + public ClimateButton(WidgetClimatePillar parent, EnumTemperature temperature, float value, int xPos, int yPos) { + this.parent = parent; + this.temperature = temperature; + this.value = value; + this.xPos = xPos; + this.yPos = yPos; + } + + public void draw(int startX, int startY) { + parent.drawSprite(temperature.getSprite(), startX + xPos, startY + yPos); + } + + public ToolTip getToolTip() { + return toolTip; + } + + public boolean isMouseOver(int mouseX, int mouseY) { + return mouseX >= xPos && mouseX <= xPos + 16 && mouseY >= yPos && mouseY <= yPos + 16; + } } } diff --git a/src/main/java/forestry/greenhouse/gui/widgets/package-info.java b/src/main/java/forestry/greenhouse/gui/widgets/package-info.java new file mode 100644 index 000000000..d4d9ad814 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/widgets/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.gui.widgets; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/inventory/InventoryGreenhouse.java b/src/main/java/forestry/greenhouse/inventory/InventoryHygroregulator.java similarity index 53% rename from src/main/java/forestry/greenhouse/inventory/InventoryGreenhouse.java rename to src/main/java/forestry/greenhouse/inventory/InventoryHygroregulator.java index 505e2adde..00bcd80f6 100644 --- a/src/main/java/forestry/greenhouse/inventory/InventoryGreenhouse.java +++ b/src/main/java/forestry/greenhouse/inventory/InventoryHygroregulator.java @@ -10,31 +10,27 @@ ******************************************************************************/ package forestry.greenhouse.inventory; -import forestry.core.fluids.FluidHelper; -import forestry.core.fluids.TankManager; -import forestry.core.inventory.InventoryAdapterRestricted; -import forestry.greenhouse.multiblock.GreenhouseController; import net.minecraft.item.ItemStack; + import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; -public class InventoryGreenhouse extends InventoryAdapterRestricted { +import forestry.core.inventory.InventoryAdapterTile; +import forestry.greenhouse.tiles.TileHygroregulator; - private final GreenhouseController greenhouseController; +public class InventoryHygroregulator extends InventoryAdapterTile { + public static final short SLOT_INPUT = 0; - public InventoryGreenhouse(GreenhouseController greenhouseController) { - super(1, "Items"); - this.greenhouseController = greenhouseController; + public InventoryHygroregulator(TileHygroregulator alvearyHygroregulator) { + super(alvearyHygroregulator, 1, "CanInv"); } @Override public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - FluidStack fluid = FluidUtil.getFluidContained(itemStack); - return fluid != null && greenhouseController.getTankManager().canFillFluidType(fluid); + if (slotIndex == SLOT_INPUT) { + FluidStack fluid = FluidUtil.getFluidContained(itemStack); + return fluid != null && tile.getTankManager().canFillFluidType(fluid); + } + return false; } - - public void drainCan(TankManager tankManager) { - FluidHelper.drainContainers(tankManager, this, 0); - } - } diff --git a/src/main/java/forestry/greenhouse/inventory/InventoryNursery.java b/src/main/java/forestry/greenhouse/inventory/InventoryNursery.java deleted file mode 100644 index 3df47e37b..000000000 --- a/src/main/java/forestry/greenhouse/inventory/InventoryNursery.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse.inventory; - -import forestry.core.inventory.InventoryAdapterTile; -import forestry.core.utils.SlotUtil; -import forestry.greenhouse.tiles.TileGreenhouseNursery; -import forestry.lepidopterology.PluginLepidopterology; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; - -public class InventoryNursery extends InventoryAdapterTile { - - public static final short SLOT_WORK = 0; - public static final short SLOT_OUTPUT_1 = 1; - public static final short SLOT_OUTPUT_COUNT = 6; - public static final short SLOT_INPUT_1 = 7; - public static final short SLOT_INPUT_COUNT = 6; - public static final short SLOTS = 13; - - public InventoryNursery(TileGreenhouseNursery tile) { - super(tile, SLOTS, "Items", 64); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if(SlotUtil.isSlotInRange(slotIndex, SLOT_INPUT_1, SLOT_INPUT_COUNT)){ - return itemStack.getItem() == PluginLepidopterology.getItems().cocoonGE; - } - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack stack, EnumFacing side) { - return SlotUtil.isSlotInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT); - } - -} diff --git a/src/main/java/forestry/greenhouse/inventory/ItemInventoryCamouflageSprayCan.java b/src/main/java/forestry/greenhouse/inventory/ItemInventoryCamouflageSprayCan.java new file mode 100644 index 000000000..3e08e0c8b --- /dev/null +++ b/src/main/java/forestry/greenhouse/inventory/ItemInventoryCamouflageSprayCan.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.core.ICamouflageHandler; +import forestry.core.inventory.ItemInventory; +import forestry.core.tiles.ITitled; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.NetworkUtil; +import forestry.greenhouse.camouflage.CamouflageHandlerType; +import forestry.greenhouse.network.packets.PacketCamouflageSelectionServer; + +public class ItemInventoryCamouflageSprayCan extends ItemInventory implements ICamouflageHandler, ITitled { + + public ItemInventoryCamouflageSprayCan(EntityPlayer player, ItemStack parent) { + super(player, 1, parent); + } + + @Override + public ItemStack getCamouflageBlock() { + return getStackInSlot(0); + } + + @Override + public ItemStack getDefaultCamouflageBlock() { + return ItemStack.EMPTY; + } + + @Override + public boolean setCamouflageBlock(ItemStack camouflageBlock, boolean sendClientUpdate) { + if (!ItemStackUtil.isIdenticalItem(camouflageBlock, getStackInSlot(0))) { + setInventorySlotContents(0, camouflageBlock); + + World world = player.world; + if (sendClientUpdate && world != null && world.isRemote) { + NetworkUtil.sendToServer(new PacketCamouflageSelectionServer(this, CamouflageHandlerType.ITEM)); + } + return true; + } + return false; + } + + @Override + public String getUnlocalizedTitle() { + return "for.gui.camouflage_spray_can"; + } + + @Override + public BlockPos getCoordinates() { + return new BlockPos(player); + } + + @Override + public World getWorldObj() { + return null; + } +} diff --git a/src/main/java/forestry/greenhouse/inventory/package-info.java b/src/main/java/forestry/greenhouse/inventory/package-info.java index 6594e95f5..bd1224df5 100644 --- a/src/main/java/forestry/greenhouse/inventory/package-info.java +++ b/src/main/java/forestry/greenhouse/inventory/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse.inventory; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/items/ItemBlockGreenhouseDoor.java b/src/main/java/forestry/greenhouse/items/ItemBlockGreenhouseDoor.java deleted file mode 100644 index 9fde96b0a..000000000 --- a/src/main/java/forestry/greenhouse/items/ItemBlockGreenhouseDoor.java +++ /dev/null @@ -1,66 +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.items; - -import forestry.core.items.ItemBlockForestry; -import forestry.greenhouse.blocks.BlockGreenhouseDoor; -import net.minecraft.block.Block; -import net.minecraft.block.SoundType; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemDoor; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -public class ItemBlockGreenhouseDoor extends ItemBlockForestry { - - public ItemBlockGreenhouseDoor(Block block) { - super(block); - } - - /** - * Copied from {@link ItemDoor#onItemUse(EntityPlayer, World, BlockPos, EnumHand, EnumFacing, float, float, float)} - */ - @Override - public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { - if (facing != EnumFacing.UP) { - return EnumActionResult.FAIL; - } else { - IBlockState iblockstate = worldIn.getBlockState(pos); - Block block = iblockstate.getBlock(); - - if (!block.isReplaceable(worldIn, pos)) { - pos = pos.offset(facing); - } - - ItemStack itemstack = player.getHeldItem(hand); - - if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) { - EnumFacing enumfacing = EnumFacing.fromAngle(player.rotationYaw); - int i = enumfacing.getFrontOffsetX(); - int j = enumfacing.getFrontOffsetZ(); - boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F; - ItemDoor.placeDoor(worldIn, pos, enumfacing, this.block, flag); - SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player); - worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); - itemstack.shrink(1); - return EnumActionResult.SUCCESS; - } else { - return EnumActionResult.FAIL; - } - } - } -} diff --git a/src/main/java/forestry/core/items/ItemCamouflageSprayCan.java b/src/main/java/forestry/greenhouse/items/ItemCamouflageSprayCan.java similarity index 53% rename from src/main/java/forestry/core/items/ItemCamouflageSprayCan.java rename to src/main/java/forestry/greenhouse/items/ItemCamouflageSprayCan.java index aae0cd0b5..678217856 100644 --- a/src/main/java/forestry/core/items/ItemCamouflageSprayCan.java +++ b/src/main/java/forestry/greenhouse/items/ItemCamouflageSprayCan.java @@ -1,12 +1,15 @@ -package forestry.core.items; +/******************************************************************************* + * 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.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 forestry.core.tiles.TileUtil; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.entity.player.EntityPlayer; @@ -20,11 +23,25 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.api.core.ICamouflageHandler; +import forestry.api.core.IModelManager; +import forestry.core.items.ItemWithGui; +import forestry.core.tiles.TileUtil; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.gui.ContainerCamouflageSprayCan; +import forestry.greenhouse.gui.GuiCamouflageSprayCan; +import forestry.greenhouse.inventory.ItemInventoryCamouflageSprayCan; + public class ItemCamouflageSprayCan extends ItemWithGui { + public ItemCamouflageSprayCan() { + setCreativeTab(PluginGreenhouse.getGreenhouseTab()); + } + @Override @SideOnly(Side.CLIENT) public GuiContainer getGui(EntityPlayer player, ItemStack heldItem, int data) { @@ -42,34 +59,35 @@ public class ItemCamouflageSprayCan extends ItemWithGui { super.registerModel(item, manager); ModelBakery.registerItemVariants(item, new ResourceLocation("forestry:camouflage_spray_can_filled")); } - + @Override - public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, - float hitY, float hitZ, EnumHand hand) { + public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { + if (player.isSneaking()) { + return EnumActionResult.PASS; + } ItemStack heldItem = player.getHeldItem(hand); ItemInventoryCamouflageSprayCan inventory = new ItemInventoryCamouflageSprayCan(player, heldItem); ItemStack camouflage = inventory.getStackInSlot(0); ICamouflageHandler handler = TileUtil.getTile(world, pos, ICamouflageHandler.class); - if (handler != null) { - String type = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflage).getType(); - if (handler.canHandleType(type)) { - if(world.isRemote){ - handler.setCamouflageBlock(type, camouflage, true); - } - return EnumActionResult.SUCCESS; + if (handler != null && !camouflage.isEmpty()) { + if (world.isRemote) { + handler.setCamouflageBlock(camouflage, true); } + return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; } @Override - public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { - if (!worldIn.isRemote && playerIn.isSneaking()) { - openGui(playerIn); + public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { + ItemStack stack = player.getHeldItem(hand); + if (player.isSneaking()) { + if (!world.isRemote) { + openGui(player); + } + return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } - - ItemStack heldItem = playerIn.getHeldItem(handIn); - return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem); + return ActionResult.newResult(EnumActionResult.PASS, stack); } } diff --git a/src/main/java/forestry/greenhouse/items/ItemGreenhouseScreen.java b/src/main/java/forestry/greenhouse/items/ItemGreenhouseScreen.java new file mode 100644 index 000000000..a9154dae2 --- /dev/null +++ b/src/main/java/forestry/greenhouse/items/ItemGreenhouseScreen.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * 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.items; + +import javax.annotation.Nullable; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagByte; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateState; +import forestry.api.core.EnumTemperature; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.items.IColoredItem; +import forestry.core.items.ItemForestry; +import forestry.core.multiblock.MultiblockUtil; +import forestry.core.utils.ClimateUtil; +import forestry.core.utils.Translator; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; + +public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem { + + public static final String GREENHOUSE_KEY = "greenhouse"; + public static final String PREVIEW_KEY = "preview"; + + public ItemGreenhouseScreen() { + setCreativeTab(PluginGreenhouse.getGreenhouseTab()); + } + + public static boolean isPreviewModeActive(ItemStack itemStack) { + NBTTagCompound nbtTagCompound = itemStack.getTagCompound(); + if (nbtTagCompound == null || !nbtTagCompound.hasKey(PREVIEW_KEY)) { + return false; + } + return nbtTagCompound.getBoolean(PREVIEW_KEY); + } + + public static void setPreviewMode(ItemStack itemStack, boolean preview) { + itemStack.setTagInfo(PREVIEW_KEY, new NBTTagByte((byte) (preview ? 1 : 0))); + } + + @Nullable + public static BlockPos getGreenhousePos(ItemStack itemStack) { + NBTTagCompound nbtTagCompound = itemStack.getTagCompound(); + if (nbtTagCompound == null || !nbtTagCompound.hasKey(GREENHOUSE_KEY)) { + return null; + } + NBTTagCompound compound = nbtTagCompound.getCompoundTag(GREENHOUSE_KEY); + if (compound.hasNoTags()) { + return null; + } + return NBTUtil.getPosFromTag(compound); + } + + public static boolean hasGreenhousePos(ItemStack itemStack) { + return getGreenhousePos(itemStack) != null; + } + + public static boolean isValid(ItemStack stack, World world) { + BlockPos pos = getGreenhousePos(stack); + boolean isValid = true; + if (pos == null || !world.isBlockLoaded(pos)) { + isValid = false; + } else { + IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class); + if (controller == null || !controller.isAssembled()) { + isValid = false; + } + } + return isValid; + } + + @Override + public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { + ItemStack itemStack = player.getHeldItem(hand); + if (!player.isSneaking()) { + boolean previewModeActive = isPreviewModeActive(itemStack); + setPreviewMode(itemStack, !previewModeActive); + + if (world.isRemote) { + player.sendStatusMessage(!previewModeActive ? new TextComponentTranslation("for.message.greenhouse_screen.preview.active") : new TextComponentTranslation("for.message.greenhouse_screen.preview.inactive"), true); + } + } + + return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack); + } + + @Override + public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { + if (!player.isSneaking()) { + return EnumActionResult.PASS; + } + ItemStack itemStack = player.getHeldItem(hand); + IGreenhouseComponent component = MultiblockUtil.getComponent(world, pos, IGreenhouseComponent.class); + if (component != null) { + IGreenhouseController controller = component.getMultiblockLogic().getController(); + if (!controller.isAssembled()) { + if (!world.isRemote) { + player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.notassembled"), true); + } + return EnumActionResult.PASS; + } + itemStack.setTagInfo(GREENHOUSE_KEY, NBTUtil.createPosTag(pos)); + if (!world.isRemote) { + player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.position"), true); + } + } else { + BlockPos itemPos = getGreenhousePos(itemStack); + if (itemPos == null) { + if (!world.isRemote) { + player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.fail"), true); + } + return EnumActionResult.PASS; + } + if (!world.isBlockLoaded(pos)) { + if (!world.isRemote) { + player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.away"), true); + } + return EnumActionResult.PASS; + } + IGreenhouseController controller = MultiblockUtil.getController(world, itemPos, IGreenhouseComponent.class); + if (controller == null || !controller.isAssembled()) { + return EnumActionResult.PASS; + } + controller.setCenterCoordinates(pos); + if (!world.isRemote) { + player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.center", pos), true); + } + } + return EnumActionResult.PASS; + } + + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) { + super.addInformation(stack, playerIn, tooltip, advanced); + boolean previewModeActive = isPreviewModeActive(stack); + tooltip.add(Translator.translateToLocal(Translator.translateToLocal("for.greenhouse_screen.mode.name") + ": " + (previewModeActive ? "Active" : "Inactive"))); + } + + @Override + @SideOnly(Side.CLIENT) + public int getColorFromItemstack(ItemStack stack, int tintIndex) { + if (tintIndex == 2) { + return isValid(stack, Minecraft.getMinecraft().world) ? 1356406 : 12197655; + } else if (tintIndex == 1) { + World world = Minecraft.getMinecraft().world; + if (!isValid(stack, world)) { + return 16777215; + } + BlockPos pos = getGreenhousePos(stack); + IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class); + IClimateContainer container = controller.getClimateContainer(); + IClimateState state = container.getState(); + return ClimateUtil.getColor(EnumTemperature.getFromValue(state.getTemperature())); + } + return 16777215; + } +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHumidifier.java b/src/main/java/forestry/greenhouse/items/ItemRegistryGreenhouse.java similarity index 53% rename from src/main/java/forestry/greenhouse/tiles/TileGreenhouseHumidifier.java rename to src/main/java/forestry/greenhouse/items/ItemRegistryGreenhouse.java index be901ba44..daef68eb8 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHumidifier.java +++ b/src/main/java/forestry/greenhouse/items/ItemRegistryGreenhouse.java @@ -8,19 +8,22 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.greenhouse.tiles; +package forestry.greenhouse.items; -import forestry.api.climate.EnumClimatiserModes; -import forestry.api.climate.EnumClimatiserTypes; -import forestry.api.climate.IClimatiserDefinition; -import forestry.core.climate.ClimatiserDefinition; +import forestry.core.items.ItemRegistry; -public class TileGreenhouseHumidifier extends TileGreenhouseClimatiser { +public class ItemRegistryGreenhouse extends ItemRegistry { - private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.POSITIVE, 5F, EnumClimatiserTypes.HUMIDITY); + /* MISC */ + public final ItemGreenhouseScreen greenhouseScreen; - public TileGreenhouseHumidifier() { - super(DEFINITION); + /* Camouflage */ + public final ItemCamouflageSprayCan camouflageSprayCan; + + public ItemRegistryGreenhouse() { + // SCREEN + greenhouseScreen = registerItem(new ItemGreenhouseScreen(), "greenhouse_screen"); + // CAMOUFLAGE + camouflageSprayCan = registerItem(new ItemCamouflageSprayCan(), "camouflage_spray_can"); } - } diff --git a/src/main/java/forestry/greenhouse/items/package-info.java b/src/main/java/forestry/greenhouse/items/package-info.java index c51910d37..d8ff24eef 100644 --- a/src/main/java/forestry/greenhouse/items/package-info.java +++ b/src/main/java/forestry/greenhouse/items/package-info.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ @ParametersAreNonnullByDefault @FieldsAreNonnullByDefault @MethodsReturnNonnullByDefault @@ -6,4 +16,5 @@ package forestry.greenhouse.items; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/models/GreenhouseDoorStateMapper.java b/src/main/java/forestry/greenhouse/models/GreenhouseDoorStateMapper.java deleted file mode 100644 index 556efe5d2..000000000 --- a/src/main/java/forestry/greenhouse/models/GreenhouseDoorStateMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package forestry.greenhouse.models; - -import java.util.LinkedHashMap; -import java.util.Map; - -import com.google.common.collect.Maps; -import forestry.core.render.ForestryStateMapper; -import forestry.greenhouse.blocks.BlockGreenhouseDoor; -import net.minecraft.block.Block; -import net.minecraft.block.BlockDoor; -import net.minecraft.block.properties.IProperty; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.renderer.block.model.ModelResourceLocation; - -public class GreenhouseDoorStateMapper extends ForestryStateMapper { - - @Override - public Map putStateModelLocations(Block block) { - for (IBlockState state : block.getBlockState().getValidStates()) { - if (state.getValue(BlockGreenhouseDoor.CAMOUFLAGED)) { - mapStateModelLocations.put(state, new ModelResourceLocation(block.getRegistryName(), "camouflage")); - } else { - LinkedHashMap, Comparable> linkedhashmap = Maps.newLinkedHashMap(state.getProperties()); - linkedhashmap.remove(BlockGreenhouseDoor.CAMOUFLAGED); - linkedhashmap.remove(BlockDoor.POWERED); - mapStateModelLocations.put(state, new ModelResourceLocation(block.getRegistryName(), getPropertyString(linkedhashmap))); - } - } - return mapStateModelLocations; - } - -} diff --git a/src/main/java/forestry/core/models/ModelCamouflageSprayCan.java b/src/main/java/forestry/greenhouse/models/ModelCamouflageSprayCan.java similarity index 92% rename from src/main/java/forestry/core/models/ModelCamouflageSprayCan.java rename to src/main/java/forestry/greenhouse/models/ModelCamouflageSprayCan.java index 063e933e9..206b72d28 100755 --- a/src/main/java/forestry/core/models/ModelCamouflageSprayCan.java +++ b/src/main/java/forestry/greenhouse/models/ModelCamouflageSprayCan.java @@ -1,4 +1,4 @@ -package forestry.core.models; +package forestry.greenhouse.models; import javax.annotation.Nullable; import javax.vecmath.Matrix4f; @@ -26,17 +26,20 @@ import net.minecraftforge.client.model.IModel; import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.PerspectiveMapWrapper; import net.minecraftforge.common.model.IModelState; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import forestry.core.inventory.ItemInventoryCamouflageSprayCan; +import forestry.core.models.BlankModel; +import forestry.core.models.DefaultTextureGetter; +import forestry.core.models.ModelManager; +import forestry.core.models.TRSRBakedModel; +import forestry.greenhouse.inventory.ItemInventoryCamouflageSprayCan; @SideOnly(Side.CLIENT) public class ModelCamouflageSprayCan extends BlankModel { - @Override - protected ItemOverrideList createOverrides() { - return new SprayCanOverrideList(); + public ModelCamouflageSprayCan() { } private class SprayCanOverrideList extends ItemOverrideList { @@ -66,7 +69,7 @@ public class ModelCamouflageSprayCan extends BlankModel { } } - + private class SprayCanModel extends BlankModel { private final IBakedModel originalModel; @@ -100,6 +103,9 @@ public class ModelCamouflageSprayCan extends BlankModel { return PerspectiveMapWrapper.handlePerspective(originalModel, state, cameraTransformType); } + } @Override + protected ItemOverrideList createOverrides() { + return new SprayCanOverrideList(); } } diff --git a/src/main/java/forestry/greenhouse/models/ModelCamouflaged.java b/src/main/java/forestry/greenhouse/models/ModelCamouflaged.java new file mode 100644 index 000000000..30f410758 --- /dev/null +++ b/src/main/java/forestry/greenhouse/models/ModelCamouflaged.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.models; + +import javax.annotation.Nullable; + +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; + +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.common.property.IExtendedBlockState; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +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.blocks.properties.UnlistedBlockAccess; +import forestry.core.blocks.properties.UnlistedBlockPos; +import forestry.core.models.ModelBlockDefault; +import forestry.core.tiles.TileUtil; +import forestry.greenhouse.blocks.BlockGreenhouseSprite; +import forestry.greenhouse.blocks.BlockGreenhouseType; +import forestry.greenhouse.blocks.IBlockCamouflaged; +import forestry.greenhouse.multiblock.GreenhouseController; + +// DO NOT CACHE THIS. PLEASE. I BEG YOU. NOT IN THE CURRENT STATE. +@SideOnly(Side.CLIENT) +public class ModelCamouflaged extends ModelBlockDefault { + public static final int DEFAULT_COLOR_INDEX = 100; + public static final int OVERLAY_COLOR_INDEX = 101; + public final ModelOverlay overlayModel; + + public ModelCamouflaged(Class blockClass) { + super(blockClass); + overlayModel = new ModelOverlay(blockClass); + } + + @Override + public TextureAtlasSprite getParticleTexture() { + return BlockGreenhouseSprite.getSprite(BlockGreenhouseType.PLAIN, null, null, -1); + } + + @Override + protected Key getInventoryKey(ItemStack stack) { + return new Key(stack, stack.getItemDamage()); + } + + @Override + protected Key getWorldKey(IBlockState state) { + IExtendedBlockState stateExtended = (IExtendedBlockState) state; + IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS); + BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS); + return new Key(stateExtended, world, pos, state.getBlock().getMetaFromState(state)); + } + + @Override + protected void bakeBlock(B block, Key key, IModelBaker baker, boolean inventory) { + IBlockAccess world = key.world; + BlockPos pos = key.pos; + BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer(); + addCamouflageModel(block, baker, layer, world, pos); + /*if (layer == BlockRenderLayer.CUTOUT || layer == null) { + for (int overlayLayer = 0; overlayLayer < block.getLayers(); overlayLayer++) { + addOverlaySprite(block, baker, world, pos, key.state, key.meta, overlayLayer); + } + }*/ + IBakedModel model; + if (key.state != null) { + model = overlayModel.getModel(key.state); + } else { + model = overlayModel.getModel(key.itemStack, Minecraft.getMinecraft().world); + } + baker.addBakedModelPost(key.state, model); + } + + /*private void addOverlaySprite(B block, IModelBaker baker, IBlockAccess world, BlockPos pos, IBlockState state, int meta, int layer) { + if (block.hasOverlaySprite(world, pos, meta, layer)) { + TextureAtlasSprite[] sprite = new TextureAtlasSprite[6]; + for (EnumFacing facing : EnumFacing.VALUES) { + sprite[facing.ordinal()] = block.getOverlaySprite(facing, state, meta, layer); + } + baker.addBlockModel(pos, sprite, OVERLAY_COLOR_INDEX + layer); + } + }*/ + + private void addCamouflageModel(B block, IModelBaker baker, BlockRenderLayer layer, IBlockAccess world, BlockPos pos) { + if (world == null || pos == null) { + TextureAtlasSprite defaultSprite = block.getDefaultSprite(); + + baker.addBlockModel(pos, defaultSprite, DEFAULT_COLOR_INDEX); + baker.setParticleSprite(defaultSprite); + ItemStack camouflageStack = GreenhouseController.createDefaultCamouflageBlock(); + } else { + ItemStack camouflageStack = block.getCamouflageBlock(world, pos); + Block camouflageBlock = Block.getBlockFromItem(camouflageStack.getItem()); + if (camouflageStack.isEmpty() || camouflageBlock == Blocks.AIR) { + camouflageStack = GreenhouseController.createDefaultCamouflageBlock(); + } + ICamouflageItemHandler itemHandler = CamouflageManager.camouflageAccess.getHandler(camouflageStack); + if (itemHandler != null) { + ICamouflageHandler camouflageHandler = block.getCamouflageHandler(world, pos); + if (camouflageHandler != null) { + ICamouflagedTile camouflageTile = TileUtil.getTile(world, pos, ICamouflagedTile.class); + if (camouflageTile != null) { + Pair modelPair = itemHandler.getModel(camouflageStack, camouflageHandler, camouflageTile); + IBlockState blockState = modelPair.getLeft(); + if (camouflageBlock.canRenderInLayer(blockState, layer)) { + IBakedModel bakedModel = modelPair.getRight(); + baker.addBakedModel(blockState, bakedModel); + baker.setParticleSprite(bakedModel.getParticleTexture()); + } + } + } + } + } + } + + public static class Key { + @Nullable + public final IExtendedBlockState state; + @Nullable + public final IBlockAccess world; + @Nullable + public final BlockPos pos; + public final ItemStack itemStack; + public final int meta; + + public Key(@Nullable IExtendedBlockState state, @Nullable IBlockAccess world, @Nullable BlockPos pos, int meta) { + this.state = state; + this.world = world; + this.pos = pos; + this.meta = meta; + this.itemStack = ItemStack.EMPTY; + } + + public Key(ItemStack itemStack, int meta) { + this.state = null; + this.world = null; + this.pos = null; + this.meta = meta; + this.itemStack = itemStack; + } + } +} diff --git a/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java b/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java deleted file mode 100644 index 5ce56f946..000000000 --- a/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java +++ /dev/null @@ -1,129 +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.models; - -import javax.annotation.Nullable; - -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.blocks.properties.UnlistedBlockAccess; -import forestry.core.blocks.properties.UnlistedBlockPos; -import forestry.core.models.ModelBlockDefault; -import forestry.core.tiles.TileUtil; -import forestry.core.utils.CamouflageUtil; -import forestry.greenhouse.blocks.BlockGreenhouse; -import forestry.greenhouse.blocks.BlockGreenhouseType; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockRenderLayer; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.MinecraftForgeClient; -import net.minecraftforge.common.property.IExtendedBlockState; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.apache.commons.lang3.tuple.Pair; - -// DO NOT CACHE THIS. PLEASE. I BEG YOU. NOT IN THE CURRENT STATE. -@SideOnly(Side.CLIENT) -public class ModelGreenhouse extends ModelBlockDefault { - public static class Key { - @Nullable - public final IExtendedBlockState state; - @Nullable - public final IBlockAccess world; - @Nullable - public final BlockPos pos; - - public Key(@Nullable IExtendedBlockState state, @Nullable IBlockAccess world, @Nullable BlockPos pos) { - this.state = state; - this.world = world; - this.pos = pos; - } - } - - public ModelGreenhouse() { - super(BlockGreenhouse.class); - } - - @Override - protected Key getInventoryKey(ItemStack stack) { - return new Key(null, null, null); - } - - @Override - protected Key getWorldKey(IBlockState state) { - IExtendedBlockState stateExtended = (IExtendedBlockState) state; - IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS); - BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS); - return new Key(stateExtended, world, pos); - } - - @Override - protected void bakeBlock(BlockGreenhouse block, Key key, IModelBaker baker, boolean inventory) { - ItemStack camouflageStack = key.world != null ? CamouflageUtil.getCamouflageBlock(key.world, key.pos) : ItemStack.EMPTY; - IBlockAccess world = key.world; - BlockPos pos = key.pos; - - BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer(); - if(layer != BlockRenderLayer.CUTOUT){ - if (!camouflageStack.isEmpty()) { - ICamouflageHandler camouflageHandler = CamouflageUtil.getCamouflageHandler(world, pos); - ICamouflagedTile camouflageTile = (ICamouflagedTile) TileUtil.getTile(world, pos, TileEntity.class); - ICamouflageItemHandler itemHandler = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflageStack); - if (itemHandler != null && camouflageHandler != null && camouflageTile != null) { - Pair model = itemHandler.getModel(camouflageStack, camouflageHandler, camouflageTile); - - baker.addBakedModel(model.getLeft(), model.getRight()); - baker.setParticleSprite(model.getRight().getParticleTexture()); - } - } - - //Bake the default blocks - else if (block.getGreenhouseType() == BlockGreenhouseType.GLASS) { - TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos); - - baker.addBlockModel(pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos), 100); - baker.setParticleSprite(glassSprite); - } else { - TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos); - - baker.addBlockModel(pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos), 100); - baker.setParticleSprite(plainSprite); - } - //Only item model - if(key.pos == null || key.state == null || key.world == null){ - if (block.getGreenhouseType().hasOverlaySprite) { - TextureAtlasSprite[] sprite = new TextureAtlasSprite[6]; - for (EnumFacing facing : EnumFacing.VALUES) { - sprite[facing.ordinal()] = BlockGreenhouseType.getSprite(block.getGreenhouseType(), facing, key.state, world, pos); - } - baker.addBlockModel(pos, sprite, 101); - } - } - } else { - if (block.getGreenhouseType().hasOverlaySprite) { - TextureAtlasSprite[] sprite = new TextureAtlasSprite[6]; - for (EnumFacing facing : EnumFacing.VALUES) { - sprite[facing.ordinal()] = BlockGreenhouseType.getSprite(block.getGreenhouseType(), facing, key.state, world, pos); - } - baker.addBlockModel(pos, sprite, 101); - } - } - } -} diff --git a/src/main/java/forestry/greenhouse/models/ModelGreenhouseWindow.java b/src/main/java/forestry/greenhouse/models/ModelGreenhouseWindow.java new file mode 100644 index 000000000..f7aeb46db --- /dev/null +++ b/src/main/java/forestry/greenhouse/models/ModelGreenhouseWindow.java @@ -0,0 +1,134 @@ +package forestry.greenhouse.models; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; + +import javax.annotation.Nullable; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ModelRotation; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; + +import net.minecraftforge.client.model.IModel; +import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.client.model.ModelProcessingHelper; +import net.minecraftforge.client.model.ModelStateComposition; +import net.minecraftforge.common.model.IModelState; +import net.minecraftforge.common.property.IExtendedBlockState; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.greenhouse.GreenhouseManager; +import forestry.core.blocks.properties.UnlistedBlockAccess; +import forestry.core.blocks.properties.UnlistedBlockPos; +import forestry.core.models.DefaultTextureGetter; +import forestry.core.models.ModelBlockCustomCached; +import forestry.core.tiles.TileUtil; +import forestry.core.utils.ModelUtil; +import forestry.greenhouse.blocks.BlockGreenhouseWindow; +import forestry.greenhouse.blocks.State; +import forestry.greenhouse.tiles.TileGreenhouseWindow; + +@SideOnly(Side.CLIENT) +public class ModelGreenhouseWindow extends ModelBlockCustomCached { + public ModelGreenhouseWindow() { + super(BlockGreenhouseWindow.class); + } + + @Override + protected Key getInventoryKey(ItemStack stack) { + NBTTagCompound tagCompound = stack.getTagCompound(); + String glassName = "glass"; + if (tagCompound != null) { + glassName = tagCompound.getString("Glass"); + } + return new Key(glassName, true, true, null); + } + + @Override + protected Key getWorldKey(IBlockState state) { + IExtendedBlockState stateExtended = (IExtendedBlockState) state; + IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS); + BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS); + TileGreenhouseWindow window = TileUtil.getTile(world, pos, TileGreenhouseWindow.class); + String glassName = "glass"; + if (window != null) { + glassName = window.getGlass(); + } + return new Key(glassName, state.getValue(State.PROPERTY) == State.ON, false, state.getValue(BlockGreenhouseWindow.FACING)); + } + + @Override + protected IBakedModel bakeBlock(BlockGreenhouseWindow block, Key key, boolean inventory) { + ImmutableMap.Builder textures = ImmutableMap.builder(); + String texture = GreenhouseManager.greenhouseHelper.getGlassTexture(key.glassName); + textures.put("texture", texture); + textures.put("particle", texture); + + IModel model = null; + IModelState state = null; + String stateName = "forestry:models/item/greenhouse_window"; + String modelName = "forestry:block/greenhouse_window_"; + if (block.isRoofWindow()) { + stateName += "_up"; + modelName += "up_"; + } + modelName += key.isOpen ? "open" : "closed"; + try { + model = ModelLoaderRegistry.getModel(new ResourceLocation(modelName)); + state = ModelUtil.loadModelState(new ResourceLocation(stateName)); + } catch (Exception e) { + Throwables.propagate(e); + } + if (model == null || state == null) { + throw new IllegalArgumentException("Could not bake greenhouse window model"); + } + EnumFacing facing = key.facing; + if (facing == EnumFacing.EAST) { + state = new ModelStateComposition(state, ModelRotation.X0_Y270); + } else if (facing == EnumFacing.WEST) { + state = new ModelStateComposition(state, ModelRotation.X0_Y90); + } else if (facing == EnumFacing.NORTH) { + state = new ModelStateComposition(state, ModelRotation.X0_Y180); + } + IModel retexturedModel = ModelProcessingHelper.retexture(model, textures.build()); + return retexturedModel.bake(state, key.inventory ? DefaultVertexFormats.ITEM : DefaultVertexFormats.BLOCK, DefaultTextureGetter.INSTANCE); + } + + public static class Key { + public final boolean inventory; + public final String glassName; + public final boolean isOpen; + @Nullable + public final EnumFacing facing; + + public Key(String glassName, boolean isOpen, boolean inventory, EnumFacing facing) { + this.glassName = glassName; + this.isOpen = isOpen; + this.inventory = inventory; + this.facing = facing; + } + + @Override + public int hashCode() { + return Boolean.hashCode(inventory) + Boolean.hashCode(isOpen) + glassName.hashCode() + (facing != null ? facing.hashCode() : 0); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Key)) { + return false; + } + Key key = (Key) obj; + return key.inventory == inventory && key.isOpen == isOpen && facing == key.facing && key.glassName.equals(glassName); + } + } +} diff --git a/src/main/java/forestry/greenhouse/models/ModelOverlay.java b/src/main/java/forestry/greenhouse/models/ModelOverlay.java new file mode 100644 index 000000000..aa137f7d6 --- /dev/null +++ b/src/main/java/forestry/greenhouse/models/ModelOverlay.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.models; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +import net.minecraftforge.client.MinecraftForgeClient; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.IModelBaker; +import forestry.core.models.ModelBlockCached; +import forestry.greenhouse.blocks.BlockGreenhouseSprite; +import forestry.greenhouse.blocks.BlockGreenhouseType; +import forestry.greenhouse.blocks.IBlockCamouflaged; + +@SideOnly(Side.CLIENT) +public class ModelOverlay extends ModelBlockCached { + public static final int OVERLAY_COLOR_INDEX = 101; + + public ModelOverlay(Class blockClass) { + super(blockClass); + } + + @Override + public TextureAtlasSprite getParticleTexture() { + return BlockGreenhouseSprite.getSprite(BlockGreenhouseType.PLAIN, null, null, -1); + } + + @Override + protected Key getInventoryKey(ItemStack stack) { + return new Key(null, stack.getItemDamage()); + } + + @Override + protected Key getWorldKey(IBlockState state) { + int meta = state.getBlock().getMetaFromState(state); + return new Key(state, meta); + } + + @Override + protected void bakeBlock(B block, Key key, IModelBaker baker, boolean inventory) { + BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer(); + if (layer == BlockRenderLayer.CUTOUT || layer == null) { + for (int overlayLayer = 0; overlayLayer < block.getLayers(); overlayLayer++) { + addOverlaySprite(block, baker, key.state, key.meta, overlayLayer); + } + } + } + + @Override + public IBakedModel getModel(IBlockState state) { + return super.getModel(state); + } + + @Override + public IBakedModel getModel(ItemStack stack, World world) { + return super.getModel(stack, world); + } + + private void addOverlaySprite(B block, IModelBaker baker, IBlockState state, int meta, int layer) { + if (block.hasOverlaySprite(meta, layer)) { + TextureAtlasSprite[] sprite = new TextureAtlasSprite[6]; + for (EnumFacing facing : EnumFacing.VALUES) { + sprite[facing.ordinal()] = block.getOverlaySprite(facing, state, meta, layer); + } + baker.addBlockModel(null, sprite, OVERLAY_COLOR_INDEX + layer); + } + } + + public static class Key { + @Nullable + public final IBlockState state; + public final int meta; + + public Key(@Nullable IBlockState state, int meta) { + this.state = state; + this.meta = meta; + } + + @Override + public int hashCode() { + return Integer.hashCode(meta) * 31 + (state == null ? 0 : state.hashCode()); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Key)) { + return false; + } + Key k = (Key) obj; + return k.meta == meta && k.state == state; + } + } +} diff --git a/src/main/java/forestry/greenhouse/models/package-info.java b/src/main/java/forestry/greenhouse/models/package-info.java index 5645d19ce..742d920de 100644 --- a/src/main/java/forestry/greenhouse/models/package-info.java +++ b/src/main/java/forestry/greenhouse/models/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse.models; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java index 2a9f076fe..a5e99c149 100644 --- a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java @@ -10,118 +10,104 @@ ******************************************************************************/ package forestry.greenhouse.multiblock; +import javax.annotation.Nullable; import java.util.Collections; import java.util.Set; -import forestry.api.climate.IClimateInfo; -import forestry.api.climate.IClimateRegion; -import forestry.api.greenhouse.IInternalBlock; -import forestry.api.lepidopterology.IButterfly; -import forestry.api.multiblock.IGreenhouseComponent.Nursery; -import forestry.api.multiblock.IGreenhouseComponent.Listener; -import forestry.core.climate.ClimateInfo; -import forestry.core.fluids.FakeTankManager; -import forestry.core.fluids.ITankManager; -import forestry.core.inventory.FakeInventoryAdapter; -import forestry.core.inventory.IInventoryAdapter; -import forestry.core.multiblock.FakeMultiblockController; -import forestry.energy.EnergyManager; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.greenhouse.IGreenhouseLimits; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.multiblock.IGreenhouseComponent.Listener; +import forestry.core.multiblock.FakeMultiblockController; +import forestry.energy.EnergyManager; + public class FakeGreenhouseController extends FakeMultiblockController implements IGreenhouseControllerInternal { public static final FakeGreenhouseController instance = new FakeGreenhouseController(); private FakeGreenhouseController() { } - @Override - public IInventoryAdapter getInternalInventory() { - return FakeInventoryAdapter.instance(); - } - - @Override - public ITankManager getTankManager() { - return FakeTankManager.instance; - } - @Override public EnergyManager getEnergyManager() { return null; } - @Override - public ItemStack getCamouflageBlock(String type) { - return ItemStack.EMPTY; - } - - @Override - public ItemStack getDefaultCamouflageBlock(String type) { - return ItemStack.EMPTY; - } - - @Override - public boolean setCamouflageBlock(String type, ItemStack camouflageBlock, boolean sendClientUpdate) { - return false; - } - - @Override - public boolean canHandleType(String type) { - return false; - } - - @Override - public BlockPos getCoordinates() { - return BlockPos.ORIGIN; - } - - @Override - public Set getInternalBlocks() { - return Collections.emptySet(); - } - - @Override - public String getUnlocalizedType() { - return "for.multiblock.greenhouse.type"; - } - - @Override - public IClimateRegion getRegion() { - return null; - } - - @Override - public Set getListenerComponents() { - return Collections.emptySet(); - } - - @Override - public Set getButterflyNurserys() { - return Collections.emptySet(); - } - @Override public boolean canWork() { return false; } @Override - public IClimateInfo getControlClimate() { - return ClimateInfo.MAX; + public Set getListenerComponents() { + return Collections.emptySet(); } - + @Override - public void setControlClimate(IClimateInfo climateControl) { - + public ItemStack getCamouflageBlock() { + return ItemStack.EMPTY; } - + @Override - public boolean spawnButterfly(Nursery nursery) { + public ItemStack getDefaultCamouflageBlock() { + return ItemStack.EMPTY; + } + + @Override + public boolean setCamouflageBlock(ItemStack camouflageBlock, boolean sendClientUpdate) { return false; } @Override - public boolean spawnButterfly(IButterfly butterfly) { - return false; + public String getUnlocalizedType() { + return GreenhouseController.TYPE; + } + + @Override + public IClimateContainer getClimateContainer() { + return null; + } + + @Override + public int getSize() { + return 0; + } + + @Override + public void onUpdateClimate() { + } + + @Override + public ImmutableClimateState getDefaultClimate() { + return null; + } + + @Override + public BlockPos getCoordinates() { + return BlockPos.ORIGIN; + } + + @Override + public IGreenhouseProvider getProvider() { + return null; + } + + @Nullable + @Override + public IGreenhouseLimits getLimits() { + return null; + } + + @Override + public BlockPos getCenterCoordinates() { + return null; + } + + @Override + public void setCenterCoordinates(BlockPos cordinates) { + } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index f35102f99..ad656cd84 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -12,104 +12,122 @@ package forestry.greenhouse.multiblock; import javax.annotation.Nullable; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; -import java.util.Stack; -import forestry.api.climate.IClimateInfo; -import forestry.api.climate.IClimatePosition; -import forestry.api.climate.IClimateRegion; -import forestry.api.climate.IClimateSourceProvider; -import forestry.api.core.CamouflageManager; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.GreenhouseState; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateContainerListener; +import forestry.api.climate.ImmutableClimateState; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.api.core.ForestryAPI; import forestry.api.core.ICamouflagedTile; -import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent; -import forestry.api.greenhouse.GreenhouseEvents.CreateInternalBlockEvent; -import forestry.api.lepidopterology.IButterfly; -import forestry.api.greenhouse.IInternalBlock; -import forestry.api.greenhouse.IInternalBlockFace; +import forestry.api.greenhouse.GreenhouseManager; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseLimits; +import forestry.api.greenhouse.IGreenhouseListener; +import forestry.api.greenhouse.IGreenhouseLogic; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.greenhouse.IGreenhouseProviderListener; +import forestry.api.greenhouse.Position2D; import forestry.api.multiblock.IGreenhouseComponent; -import forestry.api.multiblock.IGreenhouseComponent.Nursery; -import forestry.api.multiblock.IGreenhouseComponent.ClimateControl; -import forestry.api.multiblock.IGreenhouseComponent.Climatiser; +import forestry.api.multiblock.IGreenhouseComponent.Active; +import forestry.api.multiblock.IGreenhouseComponent.Listener; import forestry.api.multiblock.IMultiblockComponent; -import forestry.core.climate.ClimateInfo; -import forestry.core.climate.ClimatePosition; -import forestry.core.climate.ClimateRegion; -import forestry.core.config.Constants; -import forestry.core.fluids.FilteredTank; -import forestry.core.fluids.StandardTank; -import forestry.core.fluids.TankManager; -import forestry.core.inventory.FakeInventoryAdapter; -import forestry.core.inventory.IInventoryAdapter; +import forestry.core.PluginCore; +import forestry.core.climate.ClimateContainer; +import forestry.core.config.Config; import forestry.core.multiblock.IMultiblockControllerInternal; import forestry.core.multiblock.MultiblockValidationException; import forestry.core.multiblock.RectangularMultiblockControllerBase; import forestry.core.network.PacketBufferForestry; -import forestry.core.network.packets.CamouflageSelectionType; -import forestry.core.network.packets.PacketCamouflageSelectServer; -import forestry.core.tiles.ILiquidTankTile; -import forestry.core.tiles.TileUtil; -import forestry.core.utils.CamouflageUtil; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.NetworkUtil; import forestry.core.utils.Translator; import forestry.energy.EnergyManager; -import forestry.greenhouse.inventory.InventoryGreenhouse; -import forestry.greenhouse.tiles.TileGreenhouseHumidifier; -import forestry.lepidopterology.ButterflyUtils; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fluids.FluidRegistry; +import forestry.greenhouse.camouflage.CamouflageHandlerType; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProvider; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderClient; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderServer; +import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; +import forestry.greenhouse.network.packets.PacketCamouflageSelectionServer; +import forestry.greenhouse.network.packets.PacketGreenhouseDataRequest; +import forestry.greenhouse.tiles.TileGreenhousePlain; -public class GreenhouseController extends RectangularMultiblockControllerBase implements IGreenhouseControllerInternal, ILiquidTankTile { +public class GreenhouseController extends RectangularMultiblockControllerBase implements IGreenhouseControllerInternal, IClimateContainerListener, IGreenhouseProviderListener { - private final Set internalBlocks = new HashSet<>(); - private final Set listenerComponents = new HashSet<>(); - private final Set activeComponents = new HashSet<>(); - private final Set climatiserComponents = new HashSet<>(); - private final Set butterflyNurserys = new HashSet<>(); - @Nullable - protected ClimateControl climateControl; - - private final TankManager tankManager; + public static final String TYPE = "for.multiblock.greenhouse.type"; + public static final int CENTER_HEIGHT = 3; + public static final int REGION_DEPTH = 6; + private static final String CAMOUFLAGE_NBT_KEY = "Camouflage"; + private static final String CONTAINER_NBT_KEY = "Container"; + private static final String CENTER_POSITION_NBT_KEY = "Center"; + private final Set listenerComponents = new HashSet<>(); + private final Set activeComponents = new HashSet<>(); + private final Collection logics; private final EnergyManager energyManager; - private final InventoryGreenhouse inventory; - private final boolean needRenderUpdate = false; - + //Provider + private final GreenhouseProvider provider; + @Nullable + private IGreenhouseLimits limits; //Camouflage blocks - private ItemStack camouflagePlainBlock; - private ItemStack camouflageGlassBlock; - private ItemStack camouflageDoorBlock; - private ClimateRegion region; + private ItemStack camouflage; + //Climate + private ClimateContainer climateContainer; + private ImmutableClimateState defaultState = ImmutableClimateState.MIN; + private BlockPos centerPos; + private int assembleTickCount; + @SideOnly(Side.CLIENT) + private boolean requestedData; public GreenhouseController(World world) { super(world, GreenhouseMultiblockSizeLimits.instance); - StandardTank resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY).setFilters(FluidRegistry.WATER); - this.tankManager = new TankManager(this, resourceTank); this.energyManager = new EnergyManager(200, 100000); - this.inventory = new InventoryGreenhouse(this); - this.camouflagePlainBlock = getDefaultCamouflageBlock(CamouflageManager.BLOCK); - this.camouflageGlassBlock = getDefaultCamouflageBlock(CamouflageManager.GLASS); - this.camouflageDoorBlock = getDefaultCamouflageBlock(CamouflageManager.DOOR); - this.region = new ClimateRegion(this); + this.camouflage = getDefaultCamouflageBlock(); + this.climateContainer = new ClimateContainer(this); + this.climateContainer.addListaner(this); + this.centerPos = BlockPos.ORIGIN; + if (world.isRemote) { + provider = new GreenhouseProviderClient(world, climateContainer); + } else { + provider = new GreenhouseProviderServer(world, climateContainer); + } + provider.addListener(this); + this.logics = GreenhouseManager.greenhouseHelper.createLogics(this); + for (IGreenhouseLogic logic : logics) { + if (logic instanceof IGreenhouseProviderListener) { + this.provider.addListener((IGreenhouseProviderListener) logic); + } + } + } + + /** + * The default camouflage block {@link ItemStack} for every greenhouse block. + */ + public static ItemStack createDefaultCamouflageBlock() { + return new ItemStack(PluginCore.getBlocks().ashBrick); + } + + /* IClimateHousing */ + @Override + public BlockPos getCoordinates() { + return getReferenceCoord(); } - /* CLIMATE */ @Override public EnumTemperature getTemperature() { return EnumTemperature.getFromValue(getExactTemperature()); @@ -122,62 +140,54 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im @Override public float getExactTemperature() { - return region.getAverageTemperature(); + return climateContainer.getState().getTemperature(); } @Override public float getExactHumidity() { - return region.getAverageHumidity(); + return climateContainer.getState().getHumidity(); } @Override - public String getUnlocalizedType() { - return "for.multiblock.greenhouse.type"; + public IClimateContainer getClimateContainer() { + return climateContainer; + } + + /* IGreenhouseHousing */ + @Override + public int getSize() { + return provider.getSize(); } @Override - public BlockPos getCoordinates() { - return getReferenceCoord(); - } - - /* SAVING & LOADING */ - @Override - public NBTTagCompound writeToNBT(NBTTagCompound data) { - data = super.writeToNBT(data); - - tankManager.writeToNBT(data); - energyManager.writeToNBT(data); - inventory.writeToNBT(data); - - CamouflageUtil.writeCamouflageBlockToNBT(data, this, CamouflageManager.BLOCK); - CamouflageUtil.writeCamouflageBlockToNBT(data, this, CamouflageManager.GLASS); - CamouflageUtil.writeCamouflageBlockToNBT(data, this, CamouflageManager.DOOR); - - data.setTag("Region", region.writeToNBT(new NBTTagCompound())); - - return data; - } - - @Override - public void readFromNBT(NBTTagCompound data) { - super.readFromNBT(data); - - tankManager.readFromNBT(data); - energyManager.readFromNBT(data); - inventory.readFromNBT(data); - - CamouflageUtil.readCamouflageBlockFromNBT(data, this, CamouflageManager.BLOCK); - CamouflageUtil.readCamouflageBlockFromNBT(data, this, CamouflageManager.GLASS); - CamouflageUtil.readCamouflageBlockFromNBT(data, this, CamouflageManager.DOOR); - - if (data.hasKey("Region")) { - NBTTagCompound nbtTag = data.getCompoundTag("Region"); - if (region != null) { - region.readFromNBT(nbtTag); - } + public void onUpdateClimate() { + if (provider instanceof GreenhouseProviderClient) { + GreenhouseProviderClient providerClient = (GreenhouseProviderClient) provider; + providerClient.markBlockForRenderUpdate(); } } + @Override + public ImmutableClimateState getDefaultClimate() { + return defaultState; + } + + @Override + public IGreenhouseProvider getProvider() { + return provider; + } + + @Override + public IGreenhouseLimits getLimits() { + return limits; + } + + @Override + public boolean isClosed(IClimateContainer container) { + return provider.isClosed(); + } + + /* IMultiblockControllerInternal */ @Override public void formatDescriptionPacket(NBTTagCompound data) { writeToNBT(data); @@ -188,556 +198,321 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im readFromNBT(data); } + @Override + public String getUnlocalizedType() { + return TYPE; + } + + /* MultiblockControllerBase */ @Override protected void onAttachedPartWithMultiblockData(IMultiblockComponent part, NBTTagCompound data) { readFromNBT(data); } - /* GUI DATA */ @Override - public void writeGuiData(PacketBufferForestry data) { - tankManager.writeData(data); - energyManager.writeData(data); - inventory.writeData(data); - CamouflageUtil.writeCamouflageBlockToData(data, this, CamouflageManager.BLOCK); - CamouflageUtil.writeCamouflageBlockToData(data, this, CamouflageManager.GLASS); - CamouflageUtil.writeCamouflageBlockToData(data, this, CamouflageManager.DOOR); - region.writeData(data); - } - - @Override - public void readGuiData(PacketBufferForestry data) throws IOException { - tankManager.readData(data); - energyManager.readData(data); - inventory.readData(data); - CamouflageUtil.readCamouflageBlockFromData(data, this); - CamouflageUtil.readCamouflageBlockFromData(data, this); - CamouflageUtil.readCamouflageBlockFromData(data, this); - region.readData(data); - } - - @Override - public boolean canHandleType(String type) { - return type.equals(CamouflageManager.BLOCK) || type.equals(CamouflageManager.GLASS) || type.equals(CamouflageManager.DOOR); - } - - /* CAMOUFLAGE */ - @Override - public boolean setCamouflageBlock(String type, ItemStack camouflageBlock, boolean sendClientUpdate) { - ItemStack oldCamouflageBlock; - switch (type) { - case CamouflageManager.BLOCK: - oldCamouflageBlock = camouflagePlainBlock; - break; - case CamouflageManager.GLASS: - oldCamouflageBlock = camouflageGlassBlock; - break; - case CamouflageManager.DOOR: - oldCamouflageBlock = camouflageDoorBlock; - break; - default: - return false; + protected void onBlockAdded(IMultiblockComponent newPart) { + if (newPart instanceof Active) { + activeComponents.add((Active) newPart); } - - if (!ItemStackUtil.isIdenticalItem(camouflageBlock, oldCamouflageBlock)) { - switch (type) { - case CamouflageManager.BLOCK: - camouflagePlainBlock = camouflageBlock; - break; - case CamouflageManager.GLASS: - camouflageGlassBlock = camouflageBlock; - break; - case CamouflageManager.DOOR: - camouflageDoorBlock = camouflageBlock; - break; - default: - return false; - } - if (sendClientUpdate && world.isRemote) { - for (IMultiblockComponent comp : connectedParts) { - if (comp instanceof ICamouflagedTile) { - ICamouflagedTile camBlock = (ICamouflagedTile) comp; - if (camBlock.getCamouflageType().equals(type)) { - world.markBlockRangeForRenderUpdate(camBlock.getCoordinates(), camBlock.getCoordinates()); - } - } - } - NetworkUtil.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.MULTIBLOCK)); - } - return true; - } - return false; - } - - @Override - public ItemStack getCamouflageBlock(String type) { - switch (type) { - case CamouflageManager.BLOCK: - return camouflagePlainBlock; - case CamouflageManager.GLASS: - return camouflageGlassBlock; - case CamouflageManager.DOOR: - return camouflageDoorBlock; - default: - return ItemStack.EMPTY; + if (newPart instanceof Listener) { + listenerComponents.add((Listener) newPart); } } @Override - public ItemStack getDefaultCamouflageBlock(String type) { - switch (type) { - case CamouflageManager.BLOCK: - return new ItemStack(Blocks.BRICK_BLOCK); - case CamouflageManager.GLASS: - return new ItemStack(Blocks.STAINED_GLASS, 1, 13); - case CamouflageManager.DOOR: - return ItemStack.EMPTY; - default: - return ItemStack.EMPTY; + protected void onBlockRemoved(IMultiblockComponent oldPart) { + if (oldPart instanceof Active) { + activeComponents.remove(oldPart); + } + if (oldPart instanceof Listener) { + listenerComponents.remove(oldPart); } - } - - /* MANAGERS */ - @Override - public TankManager getTankManager() { - return tankManager; } @Override - public EnergyManager getEnergyManager() { - return energyManager; + protected void onMachineRestored() { + super.onMachineRestored(); } @Override - public IInventoryAdapter getInternalInventory() { - if (isAssembled()) { - return inventory; - } else { - return FakeInventoryAdapter.instance(); - } - } - - private void addNewPositions(Collection newPositions){ - for (IClimatePosition position : newPositions) { - BlockPos pos = position.getPos(); - IClimatePosition oldPosition = region.getPosition(pos); - float temperature = position.getTemperature(); - float humidity = position.getHumidity(); - if (oldPosition != null) { - temperature = oldPosition.getTemperature(); - humidity = oldPosition.getHumidity(); - } - region.setPosition(pos, temperature, humidity); - } - region.calculateAverageClimate(); - } - - /* CONTROLLER */ - @Override - protected void onMachineAssembled() { - super.onMachineAssembled(); - - Set internalPositions = new HashSet<>(); - for (IInternalBlock block : internalBlocks) { - if (block != null) { - internalPositions.add(new ClimatePosition(region, block.getPos())); - } - } - addNewPositions(internalPositions); - ForestryAPI.climateManager.addRegion(region); - - for (IClimateSourceProvider source : climatiserComponents) { - region.addSource(source.getClimateSource()); - } - - for (IMultiblockComponent comp : connectedParts) { - if (comp instanceof ICamouflagedTile) { - world.markBlockRangeForRenderUpdate(comp.getCoordinates(), comp.getCoordinates()); - } - } + protected void onMachinePaused() { + provider.clear(true); + this.centerPos = BlockPos.ORIGIN; } @Override protected void onMachineDisassembled() { super.onMachineDisassembled(); - internalBlocks.clear(); - - ForestryAPI.climateManager.removeRegion(region); + provider.clear(false); - for (IClimateSourceProvider source : climatiserComponents) { - region.removeSource(source.getClimateSource()); - } + this.centerPos = BlockPos.ORIGIN; for (IMultiblockComponent comp : connectedParts) { if (comp instanceof ICamouflagedTile) { world.markBlockRangeForRenderUpdate(comp.getCoordinates(), comp.getCoordinates()); } } + limits = null; } @Override - protected void onBlockAdded(IMultiblockComponent newPart) { - if (newPart instanceof IGreenhouseComponent.Listener) { - listenerComponents.add((IGreenhouseComponent.Listener) newPart); - } else if (newPart instanceof IGreenhouseComponent.Climatiser) { - climatiserComponents.add((Climatiser) newPart); - } else if (newPart instanceof IGreenhouseComponent.Active) { - activeComponents.add((IGreenhouseComponent.Active) newPart); - } else if (newPart instanceof IGreenhouseComponent.Nursery) { - butterflyNurserys.add((IGreenhouseComponent.Nursery) newPart); + public BlockPos getLastValidationErrorPosition() { + BlockPos pos = super.getLastValidationErrorPosition(); + if (pos != null) { + return pos; } - } - - @Override - protected void onBlockRemoved(IMultiblockComponent oldPart) { - if (oldPart instanceof IGreenhouseComponent.Listener) { - listenerComponents.remove(oldPart); - } else if (oldPart instanceof IGreenhouseComponent.Climatiser) { - climatiserComponents.remove(oldPart); - ForestryAPI.climateManager.removeSource((IClimateSourceProvider) oldPart); - } else if (oldPart instanceof IGreenhouseComponent.Active) { - activeComponents.remove(oldPart); - } else if (oldPart instanceof IGreenhouseComponent.Nursery) { - butterflyNurserys.remove(oldPart); + GreenhouseException exception = provider.getLastNotClosedException(); + if (exception == null) { + return null; } + return exception.pos; } @Override protected void onAssimilate(IMultiblockControllerInternal assimilated) { - IGreenhouseControllerInternal internal = (IGreenhouseControllerInternal) assimilated; - addNewPositions(internal.getRegion().getPositions()); } @Override public void onAssimilated(IMultiblockControllerInternal assimilator) { - if(isAssembled()){ - ForestryAPI.climateManager.removeRegion(region); - } } + /* UPDATES */ @Override protected boolean updateServer(int tickCount) { - if (updateOnInterval(20)) { - inventory.drainCan(tankManager); - } + if (provider.getState() == GreenhouseState.UNLOADED) { + if (assembleTickCount + 20 <= tickCount) { + provider.create(); + } + } else { + if (canWork()) { + climateContainer.updateClimate(tickCount); + } - for (IGreenhouseComponent.Active activeComponent : activeComponents) { - activeComponent.updateServer(tickCount); + for (Active activeComponent : activeComponents) { + activeComponent.updateServer(tickCount); + } + + for (IGreenhouseLogic logic : logics) { + logic.work(tickCount); + } } return false; } - @Override - protected void isMachineWhole() throws MultiblockValidationException { - int minX = getSizeLimits().getMinimumXSize(); - int minY = getSizeLimits().getMinimumYSize(); - int minZ = getSizeLimits().getMinimumZSize(); - - if (connectedParts.size() < getSizeLimits().getMinimumNumberOfBlocksForAssembledMachine()) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.small", minX, minY, minZ)); - } - - BlockPos maximumCoord = getMaximumCoord(); - BlockPos minimumCoord = getMinimumCoord(); - - // Quickly check for exceeded dimensions - int deltaX = maximumCoord.getX() - minimumCoord.getX() + 1; - int deltaY = maximumCoord.getY() - minimumCoord.getY() + 1; - int deltaZ = maximumCoord.getZ() - minimumCoord.getZ() + 1; - - int maxX = getSizeLimits().getMaximumXSize(); - int maxY = getSizeLimits().getMaximumYSize(); - int maxZ = getSizeLimits().getMaximumZSize(); - - if (maxX > 0 && deltaX > maxX) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.large.x", maxX)); - } - if (maxY > 0 && deltaY > maxY) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.large.y", maxY)); - } - if (maxZ > 0 && deltaZ > maxZ) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.large.z", maxZ)); - } - if (deltaX < minX) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.small.x", minX)); - } - if (deltaY < minY) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.small.y", minY)); - } - if (deltaZ < minZ) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.small.z", minZ)); - } - - // Now we run a simple check on each block within that volume. - // Any block deviating = NO DEAL SIR - TileEntity te; - IMultiblockComponent part; - boolean isNextRoof = false; - Class myClass = this.getClass(); - - for (int y = minimumCoord.getY(); y <= maximumCoord.getY() && !isNextRoof; y++) { - for (int x = minimumCoord.getX(); x <= maximumCoord.getX(); x++) { - for (int z = minimumCoord.getZ(); z <= maximumCoord.getZ(); z++) { - // Okay, figure out what sort of block this should be. - BlockPos pos = new BlockPos(x, y, z); - te = TileUtil.getTile(world, pos); - if (te instanceof IMultiblockComponent) { - part = (IMultiblockComponent) te; - } else { - // This is permitted so that we can incorporate certain non-multiblock parts inside interiors - part = null; - } - - // Validate block type against both part-level and material-level validators. - int extremes = 0; - int sides = 0; - - if (x == minimumCoord.getX()) { - extremes++; - sides++; - } - if (y == minimumCoord.getY()) { - extremes++; - } - if (z == minimumCoord.getZ()) { - extremes++; - sides++; - } - - if (x == maximumCoord.getX()) { - extremes++; - sides++; - } - if (z == maximumCoord.getZ()) { - extremes++; - sides++; - } - - - if (extremes >= 1) { - // Side - - int exteriorLevel = y - minimumCoord.getY(); - if (part != null) { - // Ensure this part should actually be allowed within a cube of this controller's type - if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.part", Translator.translateToLocal(getUnlocalizedType())), part.getCoordinates()); - } - isGoodForExteriorLevel(part, exteriorLevel); - } else { - isBlockGoodForExteriorLevel(exteriorLevel, this.world, pos); - } - } else { - if (part != null) { - IBlockState state = world.getBlockState(part.getCoordinates()); - if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) { - isGoodForInterior(part); - } else { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.part", Translator.translateToLocal(getUnlocalizedType())), part.getCoordinates()); - } - } else { - isBlockGoodForInterior(this.world, pos); - } - } - - BlockPos posUp = pos.up(2); - TileEntity tileUp = TileUtil.getTile(world, posUp); - if (sides >= 1 && !(tileUp instanceof IGreenhouseComponent)) { - int delta = y - minimumCoord.getY(); - if (delta + 2 >= minY) { - isNextRoof = true; - } - } - } - } - } - internalBlocks.clear(); - - if (isNextRoof) { - checkInternalBlocks(); - } - - if (internalBlocks.isEmpty()) { - throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.space.closed")); - } - - Set controls = new HashSet<>(); - for (IMultiblockComponent comp : connectedParts) { - if (comp instanceof ClimateControl) { - controls.add((ClimateControl) comp); - } - } - if (controls.size() > 1) { - throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.climatecontrol.toomany")); - } - if (controls.iterator().hasNext()) { - climateControl = controls.iterator().next(); - } - } - @Override protected void updateClient(int tickCount) { - } - - /** - * Check all internal blocks. - */ - private void checkInternalBlocks() throws MultiblockValidationException { - Stack blocksToCheck = new Stack<>(); - IInternalBlock internalBlock = createInternalBlock(new InternalBlock(getMinimumCoord().add(1, 1, 1))); - blocksToCheck.add(internalBlock); - while (!blocksToCheck.isEmpty()) { - IInternalBlock blockToCheck = blocksToCheck.pop(); - List newBlocksToCheck = checkInternalBlock(blockToCheck); - blocksToCheck.addAll(newBlocksToCheck); + if (!requestedData && provider.getState() == GreenhouseState.UNLOADED) { + NetworkUtil.sendToServer(new PacketGreenhouseDataRequest(getReferenceCoord())); + requestedData = true; } } - /** - * Returns a list of more internal blocks to check. - */ - private List checkInternalBlock(IInternalBlock blockToCheck) throws MultiblockValidationException { - List newBlocksToCheck = new ArrayList<>(); + /* IStreamableGui */ + @Override + public void writeGuiData(PacketBufferForestry data) { + energyManager.writeData(data); + data.writeItemStack(camouflage); + climateContainer.writeData(data); + } - internalBlocks.add(blockToCheck); - BlockPos posRoot = blockToCheck.getPos(); + @Override + public void readGuiData(PacketBufferForestry data) throws IOException { + energyManager.readData(data); + camouflage = data.readItemStack(); + climateContainer.readData(data); + } - isBlockGoodForInterior(world, posRoot); - for (IInternalBlockFace faceToCheck : blockToCheck.getFaces()) { - CheckInternalBlockFaceEvent checkEvent = new CheckInternalBlockFaceEvent(this, blockToCheck, faceToCheck); - MinecraftForge.EVENT_BUS.post(checkEvent); + /* ICamouflageHandler */ + @Override + public ItemStack getCamouflageBlock() { + return camouflage; + } - if (!faceToCheck.isTested()) { - EnumFacing face = faceToCheck.getFace(); - BlockPos posFacing = posRoot.offset(face); + @Override + public ItemStack getDefaultCamouflageBlock() { + return createDefaultCamouflageBlock(); + } - BlockPos minPos = getMinimumCoord(); - BlockPos maxPos = getMaximumCoord(); + @Override + public boolean setCamouflageBlock(ItemStack camouflageBlock, boolean sendClientUpdate) { + if (!ItemStackUtil.isIdenticalItem(camouflageBlock, camouflage)) { + camouflage = camouflageBlock; + if (sendClientUpdate && world.isRemote) { + for (IMultiblockComponent comp : connectedParts) { + if (comp instanceof ICamouflagedTile) { + ICamouflagedTile camBlock = (ICamouflagedTile) comp; - if (minPos.getX() > posFacing.getX() || minPos.getY() > posFacing.getY() || minPos.getZ() > posFacing.getZ() || maxPos.getX() < posFacing.getX() || maxPos.getY() < posFacing.getY() || maxPos.getZ() < posFacing.getZ()) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.closed"), posRoot); - } - - TileEntity tileFace = TileUtil.getTile(world, posFacing); - - if (tileFace instanceof IGreenhouseComponent) { - if (((IGreenhouseComponent) tileFace).getMultiblockLogic().getController() != this) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.not.connected.part"), posRoot); - } else if (!(tileFace instanceof TileGreenhouseHumidifier)) { - faceToCheck.setTested(true); - } - } else { - IInternalBlock internalBlock = createInternalBlock(new InternalBlock(posFacing, face.getOpposite(), blockToCheck)); - - // Check is the internal block in the list - if (internalBlocks.contains(internalBlock)) { - faceToCheck.setTested(true); - } else { - newBlocksToCheck.add(internalBlock); + BlockPos coordinates = camBlock.getCoordinates(); + world.markBlockRangeForRenderUpdate(coordinates, coordinates); } } + NetworkUtil.sendToServer(new PacketCamouflageSelectionServer(this, CamouflageHandlerType.STRUCTURE)); } + return true; } - return newBlocksToCheck; - } - - private IInternalBlock createInternalBlock(IInternalBlock internalBlock) { - CreateInternalBlockEvent createEvent = new CreateInternalBlockEvent(this, internalBlock); - - MinecraftForge.EVENT_BUS.post(createEvent); - - return createEvent.internalBlock; - + return false; } + /* IGreenhouseControllerInternal */ @Override - public Set getInternalBlocks() { - return internalBlocks; - } - - @Override - public IClimateInfo getControlClimate() { - if (climateControl == null) { - return ClimateInfo.MAX; - } - return climateControl.getControlClimate(); - } - - @Override - public void setControlClimate(IClimateInfo climateControl) { - if (this.climateControl != null) { - this.climateControl.setControlClimate(climateControl); - } - } - - @Override - public Set getButterflyNurserys() { - return butterflyNurserys; - } - - @Override - protected void isGoodForExteriorLevel(IMultiblockComponent part, int level) throws MultiblockValidationException { - - } - - @Override - protected void isGoodForInterior(IMultiblockComponent part) throws MultiblockValidationException { - - } - - @Override - protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException { - } - - @Override - public IClimateRegion getRegion() { - return region; - } - - @Override - public Set getListenerComponents() { - return listenerComponents; + public EnergyManager getEnergyManager() { + return energyManager; } @Override public boolean canWork() { boolean canWork = true; for (IGreenhouseComponent.Listener listenerComponent : listenerComponents) { - canWork = listenerComponent.getGreenhouseListener().canWork(this, canWork); + IGreenhouseListener listener = listenerComponent.getGreenhouseListener(); + canWork = listener.canWork(this, canWork); } return canWork; } - + @Override - public boolean spawnButterfly(IGreenhouseComponent.Nursery nursery) { - for(IInternalBlock block : internalBlocks){ - BlockPos pos = block.getPos(); - if(world.isAirBlock(pos)){ - if(ButterflyUtils.spawnButterflyWithoutCheck(nursery.getCaterpillar(), world, pos)){ - return true; - } - } - } - return false; - } - - /** - * TODO: remove in 5.4 or 5.3.4 - */ - @Override - @Deprecated - public boolean spawnButterfly(IButterfly butterfly) { - for(IInternalBlock block : internalBlocks){ - BlockPos pos = block.getPos(); - if(world.isAirBlock(pos)){ - if(ButterflyUtils.spawnButterflyWithoutCheck(butterfly, world, pos)){ - return true; - } - } - } - return false; + public Set getListenerComponents() { + return listenerComponents; } + /* IGreenhouseController */ + @Override + public BlockPos getCenterCoordinates() { + return getTopCenterCoord(); + } + + @Override + public void setCenterCoordinates(BlockPos coordinates) { + if (!coordinates.equals(centerPos) && isAssembled()) { + centerPos = coordinates; + provider.init(centerPos, limits); + if (!world.isRemote) { + assembleTickCount = getTickCount(); + } + } + } + + /* MultiblockControllerForestry */ + @Override + protected void onMachineAssembled() { + super.onMachineAssembled(); + + BlockPos centerTop = getTopCenterCoord(); + centerPos = centerTop.up(CENTER_HEIGHT); + + createDefaultState(); + limits = createLimits(); + climateContainer.setState(getDefaultClimate().toMutable()); + + provider.init(centerPos, limits); + assembleTickCount = getTickCount(); + } + + /* SAVING & LOADING */ + @Override + public NBTTagCompound writeToNBT(NBTTagCompound data) { + data = super.writeToNBT(data); + + energyManager.writeToNBT(data); + + data.setTag(CAMOUFLAGE_NBT_KEY, camouflage.serializeNBT()); + + data.setTag(CONTAINER_NBT_KEY, climateContainer.writeToNBT(new NBTTagCompound())); + + data.setTag(CENTER_POSITION_NBT_KEY, NBTUtil.createPosTag(centerPos)); + + for (IGreenhouseLogic logic : logics) { + data.setTag(logic.getUID(), logic.writeToNBT(new NBTTagCompound())); + } + + return data; + } + + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + + energyManager.readFromNBT(data); + + if (data.hasKey(CAMOUFLAGE_NBT_KEY)) { + NBTTagCompound nbtTag = data.getCompoundTag(CAMOUFLAGE_NBT_KEY); + camouflage = new ItemStack(nbtTag); + } + + if (data.hasKey(CONTAINER_NBT_KEY)) { + NBTTagCompound nbtTag = data.getCompoundTag(CONTAINER_NBT_KEY); + climateContainer.readFromNBT(nbtTag); + } + + if (data.hasKey(CENTER_POSITION_NBT_KEY)) { + centerPos = NBTUtil.getPosFromTag(data.getCompoundTag(CENTER_POSITION_NBT_KEY)); + } + + for (IGreenhouseLogic logic : logics) { + logic.readFromNBT(data.getCompoundTag(logic.getUID())); + } + } + + private void createDefaultState() { + BlockPos maximumCoord = getMaximumCoord(); + BlockPos minimumCoord = getMinimumCoord(); + + double biomes = 0; + double temperature = 0; + double humidity = 0; + for (int x = minimumCoord.getX(); x <= maximumCoord.getX(); x++) { + for (int z = minimumCoord.getZ(); z <= maximumCoord.getZ(); z++) { + Biome biome = world.getBiome(new BlockPos(x, 0, z)); + temperature += biome.getTemperature(); + humidity += biome.getRainfall(); + biomes++; + } + } + defaultState = new ImmutableClimateState((float) (temperature / biomes), (float) (humidity / biomes)); + } + + /* RectangularMultiblockControllerBase */ + @Override + public void isGoodForExteriorLevel(IMultiblockComponent part, int level) throws MultiblockValidationException { + int maxLevel = getMaximumCoord().getY() - getMinimumCoord().getY(); + if (level == maxLevel && !(part instanceof TileGreenhousePlain)) { + throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.needPlainOnTop")); + } + IGreenhouseBlock logicBlock = GreenhouseBlockManager.getInstance().getBlock(world, part.getCoordinates()); + if (logicBlock != null && logicBlock.getProvider() != getProvider()) { + throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.needSpace")); + } + } + + @Override + public void isGoodForInterior(IMultiblockComponent part) throws MultiblockValidationException { + if (!(part instanceof TileGreenhousePlain)) { + throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.needPlainInterior")); + } + IGreenhouseBlock logicBlock = GreenhouseBlockManager.getInstance().getBlock(world, ((TileGreenhousePlain) part).getPos()); + if (logicBlock != null && logicBlock.getProvider() != getProvider()) { + throw new MultiblockValidationException(Translator.translateToLocal("for.multiblock.greenhouse.error.needSpace")); + } + } + + /* IGreenhouseProviderListener */ + @Override + public void onCheckPosition(BlockPos pos) { + } + + private IGreenhouseLimits createLimits() { + BlockPos centerTop = getTopCenterCoord(); + centerPos = centerTop.up(CENTER_HEIGHT); + BlockPos max = getMaximumCoord(); + BlockPos min = getMinimumCoord(); + + int sizeNorthSouth = Math.abs(max.getZ() - min.getZ()) + 1; + int sizeEastWest = Math.abs(max.getX() - min.getX()) + 1; + + int height = (Math.abs(max.getY() - min.getY()) + 2) * Config.greenhouseSize; + int lengthEastWest = sizeEastWest * Config.greenhouseSize; + int lengthNorthSouth = sizeNorthSouth * Config.greenhouseSize; + return new GreenhouseLimits(new Position2D(lengthEastWest, lengthNorthSouth), new Position2D(-lengthEastWest, -lengthNorthSouth), height, REGION_DEPTH); + } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseLimits.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseLimits.java new file mode 100644 index 000000000..4b744a292 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseLimits.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock; + +import java.io.IOException; + +import net.minecraft.nbt.NBTTagCompound; + +import forestry.api.greenhouse.IGreenhouseLimits; +import forestry.api.greenhouse.Position2D; +import forestry.core.network.PacketBufferForestry; + +public class GreenhouseLimits implements IGreenhouseLimits { + private final Position2D maximumCoordinates; + private final Position2D minimumCoordinates; + private final int height; + private final int depth; + + public GreenhouseLimits(Position2D maximumCoordinates, Position2D minimumCoordinates, int height, int depth) { + this.maximumCoordinates = maximumCoordinates; + this.minimumCoordinates = minimumCoordinates; + this.height = height; + this.depth = depth; + } + + public GreenhouseLimits(NBTTagCompound compound) { + minimumCoordinates = new Position2D(compound.getCompoundTag("minimumCoordinates")); + maximumCoordinates = new Position2D(compound.getCompoundTag("maximumCoordinates")); + depth = compound.getInteger("depth"); + height = compound.getInteger("height"); + } + + public GreenhouseLimits(PacketBufferForestry data) throws IOException { + minimumCoordinates = data.readPosition(); + maximumCoordinates = data.readPosition(); + depth = data.readInt(); + height = data.readInt(); + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + nbt.setTag("minimumCoordinates", minimumCoordinates.writeToNBT(new NBTTagCompound())); + nbt.setTag("maximumCoordinates", maximumCoordinates.writeToNBT(new NBTTagCompound())); + nbt.setInteger("depth", depth); + nbt.setInteger("height", height); + return nbt; + } + + public void writeData(PacketBufferForestry data) { + data.writePosition(minimumCoordinates); + data.writePosition(maximumCoordinates); + data.writeInt(depth); + data.writeInt(height); + } + + @Override + public Position2D getMaximumCoordinates() { + return maximumCoordinates; + } + + @Override + public Position2D getMinimumCoordinates() { + return minimumCoordinates; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public int getDepth() { + return depth; + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseLimitsBuilder.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseLimitsBuilder.java new file mode 100644 index 000000000..a01504a86 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseLimitsBuilder.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock; + +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.Position2D; + +public class GreenhouseLimitsBuilder { + public BlockPos.MutableBlockPos maximumCoordinates; + public BlockPos.MutableBlockPos minimumCoordinates; + + public GreenhouseLimitsBuilder() { + this.maximumCoordinates = new BlockPos.MutableBlockPos(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); + this.minimumCoordinates = new BlockPos.MutableBlockPos(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + } + + public void recalculate(BlockPos position) { + if (position.getX() < minimumCoordinates.getX()) { + minimumCoordinates.setPos(position.getX(), minimumCoordinates.getY(), minimumCoordinates.getZ()); + } + if (position.getX() > maximumCoordinates.getX()) { + maximumCoordinates.setPos(position.getX(), maximumCoordinates.getY(), maximumCoordinates.getZ()); + } + if (position.getY() < minimumCoordinates.getY()) { + minimumCoordinates.setPos(minimumCoordinates.getX(), position.getY(), minimumCoordinates.getZ()); + } + if (position.getY() > maximumCoordinates.getY()) { + maximumCoordinates.setPos(maximumCoordinates.getX(), position.getY(), maximumCoordinates.getZ()); + } + if (position.getZ() < minimumCoordinates.getZ()) { + minimumCoordinates.setPos(minimumCoordinates.getX(), minimumCoordinates.getY(), position.getZ()); + } + if (position.getZ() > maximumCoordinates.getZ()) { + maximumCoordinates.setPos(maximumCoordinates.getX(), maximumCoordinates.getY(), position.getZ()); + } + } + + public GreenhouseLimits build(int height, int depth) { + return new GreenhouseLimits(new Position2D(maximumCoordinates), new Position2D(minimumCoordinates), height, depth); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java index 74f1242e7..8efaf89a8 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java @@ -21,36 +21,36 @@ class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits { @Override public int getMinimumNumberOfBlocksForAssembledMachine() { - return 0; + return 18; } @Override public int getMaximumXSize() { - return 64; + return 5; } @Override public int getMaximumZSize() { - return 64; + return 5; } @Override public int getMaximumYSize() { - return 150; + return 5; } @Override public int getMinimumXSize() { - return 5; - } - - @Override - public int getMinimumZSize() { - return 5; + return 3; } @Override public int getMinimumYSize() { - return 5; + return 2; + } + + @Override + public int getMinimumZSize() { + return 3; } } diff --git a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java index fbafa06e2..6fb326624 100644 --- a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java +++ b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java @@ -10,13 +10,10 @@ ******************************************************************************/ package forestry.greenhouse.multiblock; -import javax.annotation.Nullable; import java.util.Set; import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IGreenhouseController; -import forestry.core.fluids.ITankManager; -import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.IMultiblockControllerInternal; import forestry.core.network.IStreamableGui; import forestry.core.owner.IOwnedTile; @@ -24,16 +21,6 @@ import forestry.energy.EnergyManager; public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IOwnedTile, IStreamableGui { - /** - * @return The inventory of the controller. - */ - IInventoryAdapter getInternalInventory(); - - /** - * @return The tank manager of the controller. - */ - ITankManager getTankManager(); - /** * @return The energy manager of the controller. */ @@ -48,10 +35,4 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM * @return A Set with listener componets. */ Set getListenerComponents(); - - /** - * @return A Set of butterfly nurserys. - */ - @Nullable - Set getButterflyNurserys(); } diff --git a/src/main/java/forestry/greenhouse/multiblock/InternalBlock.java b/src/main/java/forestry/greenhouse/multiblock/InternalBlock.java deleted file mode 100644 index 3ab02462c..000000000 --- a/src/main/java/forestry/greenhouse/multiblock/InternalBlock.java +++ /dev/null @@ -1,76 +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.multiblock; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import forestry.api.greenhouse.IInternalBlock; -import forestry.api.greenhouse.IInternalBlockFace; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; - -public class InternalBlock implements IInternalBlock { - private final BlockPos pos; - private final List faces = new ArrayList<>(6); - @Nullable - private final IInternalBlock root; - - public InternalBlock(BlockPos pos) { - this.pos = pos; - this.root = null; - - for (EnumFacing facing : EnumFacing.VALUES) { - this.faces.add(new InternalBlockFace(facing, getPos().offset(facing), false)); - } - } - - public InternalBlock(BlockPos pos, EnumFacing rootFace, IInternalBlock root) { - this.pos = pos; - this.root = root; - - for (EnumFacing face : EnumFacing.VALUES) { - this.faces.add(new InternalBlockFace(face, getPos().offset(face), face == rootFace)); - } - } - - @Override - public BlockPos getPos() { - return pos; - } - - @Override - public Collection getFaces() { - return faces; - } - - @Nullable - @Override - public IInternalBlock getRoot() { - return root; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof IInternalBlock)) { - return false; - } - IInternalBlock internalBlock = (IInternalBlock) obj; - return getPos().equals(internalBlock.getPos()); - } - - @Override - public int hashCode() { - return pos.hashCode(); - } -} diff --git a/src/main/java/forestry/greenhouse/multiblock/InternalBlockCheck.java b/src/main/java/forestry/greenhouse/multiblock/InternalBlockCheck.java deleted file mode 100644 index ea47c8109..000000000 --- a/src/main/java/forestry/greenhouse/multiblock/InternalBlockCheck.java +++ /dev/null @@ -1,50 +0,0 @@ -package forestry.greenhouse.multiblock; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; - -import forestry.api.greenhouse.IInternalBlock; -import forestry.api.greenhouse.IInternalBlockFace; -import net.minecraft.util.math.BlockPos; - -/** - * Used to check if a blockPos is in a collection of IInternalBlock - */ -public class InternalBlockCheck implements IInternalBlock { - private final BlockPos pos; - - public InternalBlockCheck(BlockPos pos) { - this.pos = pos; - } - - @Override - public BlockPos getPos() { - return pos; - } - - @Nullable - @Override - public IInternalBlock getRoot() { - return null; - } - - @Override - public Collection getFaces() { - return Collections.emptyList(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof IInternalBlock)) { - return false; - } - IInternalBlock internalBlock = (IInternalBlock) obj; - return internalBlock.getPos().equals(getPos()); - } - - @Override - public int hashCode() { - return pos.hashCode(); - } -} diff --git a/src/main/java/forestry/greenhouse/multiblock/InternalBlockFace.java b/src/main/java/forestry/greenhouse/multiblock/InternalBlockFace.java deleted file mode 100644 index 32fbe358f..000000000 --- a/src/main/java/forestry/greenhouse/multiblock/InternalBlockFace.java +++ /dev/null @@ -1,50 +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.multiblock; - -import forestry.api.greenhouse.IInternalBlockFace; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; - -public class InternalBlockFace implements IInternalBlockFace { - - private final EnumFacing face; - private final BlockPos pos; - private boolean isTested; - - public InternalBlockFace(EnumFacing face, BlockPos pos, boolean isTested) { - this.face = face; - this.pos = pos; - this.isTested = isTested; - } - - @Override - public boolean isTested() { - return isTested; - } - - @Override - public void setTested(boolean tested) { - this.isTested = tested; - } - - - @Override - public EnumFacing getFace() { - return face; - } - - @Override - public BlockPos getPos() { - return pos; - } - -} diff --git a/src/main/java/forestry/greenhouse/multiblock/MultiblockLogicGreenhouse.java b/src/main/java/forestry/greenhouse/multiblock/MultiblockLogicGreenhouse.java index fe203fff2..34379bff1 100644 --- a/src/main/java/forestry/greenhouse/multiblock/MultiblockLogicGreenhouse.java +++ b/src/main/java/forestry/greenhouse/multiblock/MultiblockLogicGreenhouse.java @@ -10,9 +10,10 @@ ******************************************************************************/ package forestry.greenhouse.multiblock; +import net.minecraft.world.World; + import forestry.api.multiblock.IMultiblockLogicGreenhouse; import forestry.core.multiblock.MultiblockLogic; -import net.minecraft.world.World; public class MultiblockLogicGreenhouse extends MultiblockLogic implements IMultiblockLogicGreenhouse { diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/ChunkEvents.java b/src/main/java/forestry/greenhouse/multiblock/blocks/ChunkEvents.java new file mode 100644 index 000000000..21064cde4 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/ChunkEvents.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +import net.minecraftforge.common.util.BlockSnapshot; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; +import net.minecraftforge.event.world.BlockEvent.MultiPlaceEvent; +import net.minecraftforge.event.world.BlockEvent.PlaceEvent; +import net.minecraftforge.event.world.ChunkEvent; + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import forestry.greenhouse.multiblock.blocks.world.ChunkThread; +import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; + +public class ChunkEvents { + + @SubscribeEvent + public void onWorldTick(TickEvent.WorldTickEvent event) { + if (event.phase != TickEvent.Phase.END) { + return; + } + + if (GreenhouseBlockManager.getThread() == null || !GreenhouseBlockManager.getThread().isAlive()) { + Thread climateThread = new Thread(new ChunkThread(false), "Forestry Greenhouse"); + GreenhouseBlockManager.setThread(climateThread, false); + climateThread.start(); + } + } + + @SubscribeEvent + public void onWorldTick(TickEvent.ClientTickEvent event) { + if (event.phase != TickEvent.Phase.END) { + return; + } + + if (GreenhouseBlockManager.getClientThread() == null || !GreenhouseBlockManager.getClientThread().isAlive()) { + Thread climateThread = new Thread(new ChunkThread(true), "Forestry Greenhouse Client"); + GreenhouseBlockManager.setThread(climateThread, true); + climateThread.start(); + } + } + + @SubscribeEvent + public void loadChunk(ChunkEvent.Load event) { + Chunk chunk = event.getChunk(); + World world = event.getWorld(); + GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + manager.loadChunk(world, chunk.xPosition, chunk.zPosition); + } + + @SubscribeEvent + public void unloadChunk(ChunkEvent.Unload event) { + Chunk chunk = event.getChunk(); + World world = event.getWorld(); + GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + manager.unloadChunk(world, chunk.xPosition, chunk.zPosition); + } + + @SubscribeEvent + public void breakBlock(BreakEvent event) { + GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + World world = event.getWorld(); + BlockPos pos = event.getPos(); + manager.markBlockDirty(world, pos); + } + + @SubscribeEvent + public void placeBlock(PlaceEvent event) { + GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + World world = event.getWorld(); + BlockPos pos = event.getPos(); + manager.markBlockDirty(world, pos); + } + + @SubscribeEvent + public void multiPlaceBlock(MultiPlaceEvent event) { + GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + World world = event.getWorld(); + for (BlockSnapshot snapshot : event.getReplacedBlockSnapshots()) { + BlockPos pos = snapshot.getPos(); + manager.markBlockDirty(world, pos); + } + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseBlock.java b/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseBlock.java new file mode 100644 index 000000000..d463262b5 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseBlock.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks; + +import com.google.common.base.Objects; + +import javax.annotation.Nullable; +import java.util.Set; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IBlankBlock; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseBlockStorage; +import forestry.api.greenhouse.IGreenhouseProvider; + +public abstract class GreenhouseBlock

implements IGreenhouseBlock { + protected final BlockPos pos; + protected final IGreenhouseProvider provider; + protected final IGreenhouseBlockStorage storage; + @Nullable + protected P root; + @Nullable + protected EnumFacing rootFace; + + public GreenhouseBlock(IGreenhouseProvider provider, BlockPos pos) { + this.provider = provider; + this.storage = provider.getStorage(); + this.pos = pos; + this.root = null; + this.rootFace = null; + } + + public GreenhouseBlock(IGreenhouseProvider provider, BlockPos pos, @Nullable EnumFacing rootFace, @Nullable P root) { + this.provider = provider; + this.storage = provider.getStorage(); + this.pos = pos; + this.root = root; + this.rootFace = rootFace; + } + + @Override + public BlockPos getPos() { + return pos; + } + + @Nullable + @Override + public P getRoot() { + return root; + } + + public void setRoot(@Nullable P root) { + this.root = root; + } + + @Nullable + @Override + public EnumFacing getRootFace() { + return rootFace; + } + + @Override + public IGreenhouseProvider getProvider() { + return provider; + } + + @Override + public void onNeighborRemoved(IBlankBlock changedBlock, EnumFacing facing, boolean forcedRemove, @Nullable Set blocksToCheck) { + } + + public void setRootFace(@Nullable EnumFacing rootFace) { + this.rootFace = rootFace; + } + + @Override + public int hashCode() { + return pos.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof IGreenhouseBlock)) { + return false; + } + IGreenhouseBlock logicBlock = (IGreenhouseBlock) obj; + BlockPos blockPos = logicBlock.getPos(); + return pos.equals(blockPos); + } + + public String toString() { + return Objects.toStringHelper(this).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseBlockCache.java b/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseBlockCache.java new file mode 100644 index 000000000..af3c12a47 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseBlockCache.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks; + +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.core.network.IStreamable; +import forestry.core.network.PacketBufferForestry; +import forestry.greenhouse.network.packets.PacketGreenhouseData; + +/** + * A cache that caches every block that is removed or added to a {@link IGreenhouseProvider} + * to send it later to the client with the {@link PacketGreenhouseData}. + */ +public class GreenhouseBlockCache implements IStreamable { + + private HashMap> positions; + + public GreenhouseBlockCache() { + positions = new HashMap<>(); + } + + public void add(Long chunkPos, BlockPos position) { + positions.computeIfAbsent(chunkPos, k -> new HashSet<>()).add(position); + } + + @Override + public void writeData(PacketBufferForestry data) { + data.writeInt(positions.size()); + for (Map.Entry> entry : positions.entrySet()) { + data.writeLong(entry.getKey()); + Set chunkPositions = entry.getValue(); + data.writeInt(chunkPositions.size()); + for (BlockPos pos : chunkPositions) { + data.writeBlockPos(pos); + } + } + } + + @Override + public void readData(PacketBufferForestry data) throws IOException { + positions.clear(); + int size = data.readInt(); + for (int i = 0; i < size; i++) { + long chunkPosition = data.readLong(); + int chunkSize = data.readInt(); + Set chunkPositions = new HashSet<>(); + for (int p = 0; p < chunkSize; p++) { + chunkPositions.add(data.readBlockPos()); + } + positions.put(chunkPosition, chunkPositions); + } + } + + public HashMap> getPositions() { + return positions; + } + + public void clear() { + positions.clear(); + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseException.java b/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseException.java new file mode 100644 index 000000000..a0a29d35d --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/GreenhouseException.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks; + +import net.minecraft.util.math.BlockPos; + +public class GreenhouseException extends Exception { + + public BlockPos pos; + + public GreenhouseException(String reason) { + super(reason); + } + + public GreenhouseException setPos(BlockPos pos) { + this.pos = pos; + return this; + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlock.java b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlock.java new file mode 100644 index 000000000..f9e7ad7ea --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlock.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.blank; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IBlankBlock; +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.greenhouse.multiblock.blocks.GreenhouseBlock; + +public class BlankBlock extends GreenhouseBlock implements IBlankBlock { + private final boolean[] faces; + private boolean hasWall; + private boolean isValid; + + public BlankBlock(IGreenhouseProvider provider, BlockPos pos, EnumFacing rootFace, IBlankBlock root) { + super(provider, pos, rootFace, root); + this.faces = new boolean[6]; + if (rootFace != null) { + this.faces[rootFace.ordinal()] = true; + } + } + + @Override + public boolean isFaceTested(EnumFacing face) { + return faces[face.ordinal()]; + } + + @Override + public void setFaceTested(EnumFacing face, boolean isTested) { + faces[face.ordinal()] = isTested; + } + + @Override + public boolean isNearWall() { + return hasWall; + } + + @Override + public void setNearWall(boolean hasWall) { + this.hasWall = hasWall; + } + + @Override + public void validate() { + isValid = true; + } + + @Override + public void invalidate(boolean chunkUnloading) { + isValid = false; + } + + @Override + public boolean isValid() { + return isValid; + } + + @Override + public IGreenhouseBlockHandler getHandler() { + return BlankBlockHandler.getInstance(); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlockHandler.java b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlockHandler.java new file mode 100644 index 000000000..233040008 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlockHandler.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.blank; + +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IBlankBlock; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.IGreenhouseBlockStorage; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; + +public class BlankBlockHandler implements IGreenhouseBlockHandler { + + private static final BlankBlockHandler INSTANCE = new BlankBlockHandler(); + + public static BlankBlockHandler getInstance() { + return INSTANCE; + } + + @Override + public void onRemoveBlock(IGreenhouseBlockStorage storage, IBlankBlock blockToRemove) { + BlockPos pos = blockToRemove.getPos(); + blockToRemove.invalidate(false); + } + + @Override + public IBlankBlock createBlock(IGreenhouseBlockStorage storage, IBlankBlock root, EnumFacing rootFacing, BlockPos position) { + IBlankBlock blankBlock = new BlankBlock(storage.getProvider(), position, rootFacing, root); + blankBlock.validate(); + return blankBlock; + } + + @Override + public IBlankBlock getBlock(IGreenhouseBlockStorage storage, BlockPos position) { + IGreenhouseBlock logicBlock = storage.getBlock(position); + if (logicBlock instanceof IBlankBlock) { + return (IBlankBlock) logicBlock; + } + return null; + } + + @Override + public List checkNeighborBlocks(IGreenhouseBlockStorage storage, IBlankBlock blockToCheck) throws GreenhouseException { + List newBlocksToCheck = new LinkedList<>(); + BlockPos position = blockToCheck.getPos(); + if (storage.setBlock(position, blockToCheck)) { + for (EnumFacing facing : EnumFacing.HORIZONTALS) { + checkBlockFacing(storage, blockToCheck, position, facing, newBlocksToCheck); + } + } + return newBlocksToCheck; + } + + @Override + public boolean onCheckPosition(IGreenhouseBlockStorage storage, IBlankBlock rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck) { + if (block == null) { + newBlocksToCheck.add(createBlock(storage, rootBlock, facing.getOpposite(), position)); + } else if (block instanceof IBlankBlock) { + // Check is the internal block in the list + IBlankBlock faceBlock = (IBlankBlock) block; + faceBlock.setFaceTested(facing.getOpposite(), true); + rootBlock.setFaceTested(facing, true); + } + return false; + } + + @Override + public Class getBlockClass() { + return IBlankBlock.class; + } + + private void checkBlockFacing(IGreenhouseBlockStorage storage, IBlankBlock blockToCheck, BlockPos rootPos, EnumFacing facing, List newBlocksToCheck) throws GreenhouseException { + if (!blockToCheck.isFaceTested(facing)) { + BlockPos facingPosition = rootPos.offset(facing); + IGreenhouseProvider provider = storage.getProvider(); + + provider.checkPosition(facingPosition); + + IGreenhouseBlock logicBlock = storage.getBlock(facingPosition); + for (IGreenhouseBlockHandler handler : provider.getHandlers()) { + if (handler.onCheckPosition(storage, blockToCheck, facingPosition, facing, logicBlock, newBlocksToCheck)) { + break; + } + } + } + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/blank/package-info.java b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/package-info.java new file mode 100644 index 000000000..51141d285 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.multiblock.blocks.blank; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlock.java b/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlock.java new file mode 100644 index 000000000..76ff5b89d --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlock.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.client; + +import net.minecraft.util.math.BlockPos; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.greenhouse.multiblock.blocks.GreenhouseBlock; + +/** + * Only a small logic block for the client. Because he has to know which blocks are inside a greenhouse and which not. + */ +@SideOnly(Side.CLIENT) +public class ClientBlock extends GreenhouseBlock { + + public ClientBlock(IGreenhouseProvider manager, BlockPos pos) { + super(manager, pos); + } + + @Override + public IGreenhouseBlockHandler getHandler() { + return ClientBlockHandler.getInstance(); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlockHandler.java b/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlockHandler.java new file mode 100644 index 000000000..74f5f8aaf --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlockHandler.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.client; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.IGreenhouseBlockStorage; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; + +public class ClientBlockHandler implements IGreenhouseBlockHandler { + + private static final ClientBlockHandler INSTANCE = new ClientBlockHandler(); + + public static ClientBlockHandler getInstance() { + return INSTANCE; + } + + @Override + public void onRemoveBlock(IGreenhouseBlockStorage storage, ClientBlock blockToRemove) { + } + + @Override + public ClientBlock createBlock(IGreenhouseBlockStorage storage, @Nullable ClientBlock root, @Nullable EnumFacing rootFacing, @Nullable BlockPos position) { + return new ClientBlock(storage.getProvider(), position); + } + + @Override + public ClientBlock getBlock(IGreenhouseBlockStorage storage, BlockPos position) { + IGreenhouseBlock logicBlock = storage.getBlock(position); + if (logicBlock instanceof ClientBlock) { + return (ClientBlock) logicBlock; + } + return null; + } + + @Override + public List checkNeighborBlocks(IGreenhouseBlockStorage storage, ClientBlock blockToCheck) throws GreenhouseException { + return Collections.emptyList(); + } + + @Override + public boolean onCheckPosition(IGreenhouseBlockStorage storage, ClientBlock rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck) throws GreenhouseException { + return false; + } + + @Override + public Class getBlockClass() { + return ClientBlock.class; + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/client/package-info.java b/src/main/java/forestry/greenhouse/multiblock/blocks/client/package-info.java new file mode 100644 index 000000000..a259c3b32 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/client/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.multiblock.blocks.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/package-info.java b/src/main/java/forestry/greenhouse/multiblock/blocks/package-info.java new file mode 100644 index 000000000..b07a375dc --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.multiblock.blocks; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseBlockStorage.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseBlockStorage.java new file mode 100644 index 000000000..52d7bc6d7 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseBlockStorage.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.storage; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.greenhouse.IBlankBlock; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseBlockStorage; +import forestry.api.greenhouse.IGreenhouseChunk; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.greenhouse.Position2D; +import forestry.core.network.IStreamable; +import forestry.core.network.PacketBufferForestry; +import forestry.greenhouse.multiblock.blocks.GreenhouseBlockCache; +import forestry.greenhouse.multiblock.blocks.client.ClientBlock; +import forestry.greenhouse.multiblock.blocks.client.ClientBlockHandler; +import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; + +public class GreenhouseBlockStorage implements IGreenhouseBlockStorage, IStreamable { + protected final HashMap> blocks; + protected final IGreenhouseProvider provider; + protected final World world; + protected final GreenhouseBlockCache cache; + + protected int blockCount; + + public GreenhouseBlockStorage(IGreenhouseProvider provider, World world) { + this.blocks = new HashMap<>(); + this.world = world; + this.provider = provider; + this.cache = new GreenhouseBlockCache(); + } + + public void addProviderToChunks() { + for (long chunkPos : blocks.keySet()) { + IGreenhouseChunk chunk = getChunk(chunkPos); + chunk.add(provider); + } + } + + public void removeProviderFromChunks() { + for (long chunkPos : blocks.keySet()) { + IGreenhouseChunk chunk = getChunk(chunkPos); + chunk.remove(provider); + } + } + + @SideOnly(Side.CLIENT) + public void createBlocksFromCache() { + ClientBlockHandler blockHandler = ClientBlockHandler.getInstance(); + for (Set positions : cache.getPositions().values()) { + for (BlockPos position : positions) { + ClientBlock block = blockHandler.createBlock(this, null, EnumFacing.DOWN, position); + setBlock(position, block); + } + } + } + + @SideOnly(Side.CLIENT) + public void createChunksFromCache() { + removeProviderFromChunks(); + for (long chunkPos : cache.getPositions().keySet()) { + IGreenhouseChunk chunk = getChunk(chunkPos); + chunk.add(provider); + } + } + + public void clearBlocks(boolean chunkUnloading) { + for (HashMap blocks : this.blocks.values()) { + Iterator blockIterator = blocks.values().iterator(); + while (blockIterator.hasNext()) { + IGreenhouseBlock block = blockIterator.next(); + if (block != null) { + removeBlock(block); + blockIterator.remove(); + } + } + } + blockCount = 0; + } + + protected IGreenhouseChunk getChunk(BlockPos pos) { + int xChunk = pos.getX() >> 4; + int zChunk = pos.getZ() >> 4; + return getChunk(ChunkPos.asLong(xChunk, zChunk)); + } + + protected IGreenhouseChunk getChunk(long chunkPos) { + GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + return manager.getOrCreateChunk(world, chunkPos); + } + + @Nullable + @Override + public IGreenhouseBlock getBlock(BlockPos pos) { + long chunkPos = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4); + HashMap chunkBlocks = getChunkBlocks(chunkPos); + return chunkBlocks.get(new Position2D(pos)); + } + + public boolean setBlock(BlockPos pos, @Nullable IGreenhouseBlock newBlock) { + IGreenhouseChunk chunk = getChunk(pos); + if (chunk != null) { + IGreenhouseBlock oldBlock; + Long chunkPos = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4); + HashMap chunkBlocks = getChunkBlocks(chunkPos); + if (newBlock == null) { + oldBlock = chunkBlocks.remove(new Position2D(pos)); + } else { + oldBlock = chunkBlocks.put(new Position2D(pos), newBlock); + } + //Only count block on the server side + if (!world.isRemote) { + if (newBlock == null) { + if (oldBlock instanceof IBlankBlock) { + blockCount--; + } + } else if (newBlock != null) { + cache.add(chunkPos, pos); + if (newBlock instanceof IBlankBlock) { + blockCount++; + } + } + } + return true; + } + return false; + } + + @Override + public int getBlockCount() { + return blockCount; + } + + public void removeBlock(IGreenhouseBlock blockToRemove) { + blockToRemove.getHandler().onRemoveBlock(this, blockToRemove); + } + + @Override + public IGreenhouseProvider getProvider() { + return provider; + } + + protected HashMap getChunkBlocks(long chunkPos) { + return blocks.computeIfAbsent(chunkPos, k -> new HashMap()); + } + + @Override + public void writeData(PacketBufferForestry data) { + cache.writeData(data); + cache.clear(); + data.writeInt(blockCount); + } + + @Override + public void readData(PacketBufferForestry data) throws IOException { + cache.readData(data); + blockCount = data.readInt(); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseChunk.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseChunk.java new file mode 100644 index 000000000..9ebc55198 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseChunk.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.storage; + +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseChunk; +import forestry.api.greenhouse.IGreenhouseProvider; + +public class GreenhouseChunk implements IGreenhouseChunk { + + /** + * The greenhouse managers of the greenhouses that are located in the world chunk on this chunk position. + */ + public final Set providers; + /** + * The managers that were modified in the last tick. + */ + public final Set dirtyProviders; + + public GreenhouseChunk() { + this.providers = new HashSet<>(); + this.dirtyProviders = new HashSet<>(); + } + + public Set getProviders() { + return providers; + } + + public synchronized void markProviderDirty(BlockPos pos) { + IGreenhouseBlock block = get(pos); + if (block != null) { + dirtyProviders.add(block.getProvider()); + } + } + + public synchronized Collection getDirtyProviders() { + return dirtyProviders; + } + + @Nullable + public IGreenhouseBlock get(BlockPos pos) { + IGreenhouseBlock block = null; + for (IGreenhouseProvider provider : providers) { + block = provider.getStorage().getBlock(pos); + if (block != null) { + break; + } + } + return block; + } + + public void add(IGreenhouseProvider manager) { + providers.add(manager); + } + + public void remove(IGreenhouseProvider manager) { + providers.remove(manager); + } + + public synchronized void markProviderDirty(IGreenhouseProvider dirtyProvider) { + if (dirtyProvider != null) { + dirtyProviders.add(dirtyProvider); + } + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProvider.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProvider.java new file mode 100644 index 000000000..5a25b5543 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProvider.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.storage; + +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.climate.GreenhouseState; +import forestry.api.climate.IClimateContainer; +import forestry.api.greenhouse.IGreenhouseLimits; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.greenhouse.IGreenhouseProviderListener; +import forestry.core.network.IStreamable; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; + +public abstract class GreenhouseProvider implements IGreenhouseProvider, IStreamable { + + protected final Set listeners; + protected final GreenhouseBlockStorage storage; + protected final World world; + protected final IClimateContainer container; + + @Nullable + protected GreenhouseException lastNotClosedException; + protected BlockPos centerPos; + protected boolean ready; + protected GreenhouseState state; + protected IGreenhouseLimits limits; + protected IGreenhouseLimits usedLimits; + protected int size; + + public GreenhouseProvider(World world, IClimateContainer container) { + this.listeners = new HashSet<>(); + this.centerPos = BlockPos.ORIGIN; + this.world = world; + this.container = container; + this.state = GreenhouseState.UNREADY; + this.storage = new GreenhouseBlockStorage(this, world); + } + + public abstract void create(); + + public GreenhouseException getLastNotClosedException() { + return lastNotClosedException; + } + + @Override + public IClimateContainer getClimateContainer() { + return container; + } + + @Override + public void addListener(IGreenhouseProviderListener listener) { + listeners.add(listener); + } + + public Collection getListeners() { + return listeners; + } + + @Override + public void init(BlockPos centerPos, IGreenhouseLimits limits) { + this.centerPos = centerPos; + this.limits = limits; + ready = true; + state = GreenhouseState.UNLOADED; + } + + @Override + public void clear(boolean chunkUnloading) { + storage.clearBlocks(chunkUnloading); + this.centerPos = BlockPos.ORIGIN; + ready = false; + } + + @Override + public String getLastNotClosedError() { + if (lastNotClosedException == null) { + return null; + } + return lastNotClosedException.getMessage(); + } + + @Override + public boolean hasUnloadedChunks() { + return state == GreenhouseState.UNLOADED_CHUNK; + } + + @Override + public BlockPos getCenterPos() { + return centerPos; + } + + @Override + public IGreenhouseLimits getLimits() { + return limits; + } + + @Nullable + @Override + public IGreenhouseLimits getUsedLimits() { + return usedLimits; + } + + @Override + public GreenhouseState getState() { + return state; + } + + @Override + public World getWorld() { + return world; + } + + @Override + public boolean isClosed() { + return state == GreenhouseState.CLOSED; + } + + @Override + public int getSize() { + return size; + } + + @Override + public GreenhouseBlockStorage getStorage() { + return storage; + } + + @Override + public int hashCode() { + return container.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GreenhouseProvider)) { + return false; + } + GreenhouseProvider provider = (GreenhouseProvider) obj; + return provider.getClimateContainer().equals(container); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderClient.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderClient.java new file mode 100644 index 000000000..aae945ff6 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderClient.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.storage; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.climate.GreenhouseState; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateHousing; +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.Position2D; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.network.PacketBufferForestry; +import forestry.greenhouse.multiblock.GreenhouseLimits; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; +import forestry.greenhouse.multiblock.blocks.client.ClientBlockHandler; + +public class GreenhouseProviderClient extends GreenhouseProvider { + boolean reloadChunks; + + public GreenhouseProviderClient(World world, IClimateContainer container) { + super(world, container); + } + + @Override + public void create() { + //Server side only + } + + @Override + public void writeData(PacketBufferForestry data) { + // Only write on the server side + } + + @Override + public void readData(PacketBufferForestry data) throws IOException { + storage.readData(data); + storage.createChunksFromCache(); + state = GreenhouseState.values()[data.readByte()]; + reloadChunks = data.readBoolean(); + size = data.readInt(); + centerPos = data.readBlockPos(); + if (data.readBoolean()) { + limits = new GreenhouseLimits(data); + } + if (data.readBoolean()) { + usedLimits = new GreenhouseLimits(data); + } + } + + @Override + public synchronized void recreate() { + storage.clearBlocks(false); + storage.createBlocksFromCache(); + Minecraft mc = Minecraft.getMinecraft(); + mc.addScheduledTask(() -> markBlockForRenderUpdate()); + } + + /* CHUNK LOADING */ + @Override + public void onUnloadChunk(long chunkPos) { + //Server side only + } + + @Override + public void onLoadChunk(long chunkPos) { + //Server side only + } + + @Override + public void checkPosition(BlockPos position) throws GreenhouseException { + } + + @Override + public Collection getHandlers() { + return Collections.singleton(ClientBlockHandler.getInstance()); + } + + @Override + public void onBlockChange() { + //Server side only + } + + @Override + public void scheduledUpdate() { + //Server side only + } + + public void markBlockForRenderUpdate() { + IClimateHousing housing = container.getParent(); + if (housing instanceof IGreenhouseController) { + IGreenhouseController controller = (IGreenhouseController) housing; + if (!controller.isAssembled()) { + return; + } + BlockPos position = controller.getCenterCoordinates(); + Position2D minEdge = limits.getMinimumCoordinates(); + Position2D maxEdge = limits.getMaximumCoordinates(); + BlockPos minPos = new BlockPos(minEdge.getX(), -limits.getDepth(), minEdge.getZ()); + BlockPos maxPos = new BlockPos(maxEdge.getX() + 1, limits.getHeight(), maxEdge.getZ() + 1); + minPos = minPos.add(position); + maxPos = maxPos.add(position); + world.markBlockRangeForRenderUpdate(minPos, maxPos); + } + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderServer.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderServer.java new file mode 100644 index 000000000..94a838cc1 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderServer.java @@ -0,0 +1,317 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.storage; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.Stack; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.world.World; + +import forestry.api.climate.GreenhouseState; +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateHousing; +import forestry.api.greenhouse.IBlankBlock; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.IGreenhouseLimits; +import forestry.api.greenhouse.Position2D; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.network.PacketBufferForestry; +import forestry.core.utils.NetworkUtil; +import forestry.core.utils.Translator; +import forestry.greenhouse.multiblock.GreenhouseLimits; +import forestry.greenhouse.multiblock.GreenhouseLimitsBuilder; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; +import forestry.greenhouse.multiblock.blocks.blank.BlankBlockHandler; +import forestry.greenhouse.multiblock.blocks.wall.WallBlockHandler; +import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; +import forestry.greenhouse.network.packets.PacketGreenhouseData; + +public class GreenhouseProviderServer extends GreenhouseProvider { + private static final List HANDLERS = new ArrayList<>(); + private static final int TIME_BETWEEN_UPDATES = 100; + private static final int UPDATE_DELAY = 35; + + private final Set unloadedChunks; + + private Position2D maxSize; + private Position2D minSize; + private boolean needReload; + private boolean needUpdate; + private long previousUpdateTick; + + public GreenhouseProviderServer(World world, IClimateContainer container) { + super(world, container); + this.unloadedChunks = new HashSet<>(); + this.maxSize = Position2D.NULL_POSITION; + this.minSize = Position2D.NULL_POSITION; + } + + public void create() { + if (ready) { + GreenhouseState oldState = this.state; + + storage.removeProviderFromChunks(); + storage.clearBlocks(false); + createBlocks(); + storage.addProviderToChunks(); + if (!world.isRemote) { + IClimateHousing region = container.getParent(); + BlockPos pos = region.getCoordinates(); + if (pos != null) { + needReload = oldState != state; + NetworkUtil.sendNetworkPacket(new PacketGreenhouseData(pos, this), pos, world); + } + } + } + } + + @Override + public void init(BlockPos centerPos, IGreenhouseLimits limits) { + super.init(centerPos, limits); + } + + @Override + public void clear(boolean chunkUnloading) { + super.clear(chunkUnloading); + this.maxSize = Position2D.NULL_POSITION; + this.minSize = Position2D.NULL_POSITION; + this.unloadedChunks.clear(); + } + + @Override + public void writeData(PacketBufferForestry data) { + storage.writeData(data); + data.writeByte(state.ordinal()); + data.writeBoolean(needReload); + data.writeInt(size); + data.writeBlockPos(centerPos); + if (limits != null && limits instanceof GreenhouseLimits) { + data.writeBoolean(true); + ((GreenhouseLimits) limits).writeData(data); + } else { + data.writeBoolean(false); + } + if (usedLimits != null && usedLimits instanceof GreenhouseLimits) { + data.writeBoolean(true); + ((GreenhouseLimits) usedLimits).writeData(data); + } else { + data.writeBoolean(false); + } + } + + @Override + public void readData(PacketBufferForestry data) throws IOException { + // Only read on the client side + } + + @Override + public synchronized void recreate() { + create(); + } + + /* CHUNK LOADING */ + @Override + public void onUnloadChunk(long chunkPos) { + unloadedChunks.add(chunkPos); + lastNotClosedException = new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.unloaded")); + state = GreenhouseState.UNLOADED_CHUNK; + } + + @Override + public void onLoadChunk(long chunkPos) { + unloadedChunks.remove(chunkPos); + if (unloadedChunks.isEmpty() && hasUnloadedChunks()) { + state = GreenhouseState.OPEN; + create(); + } + } + + public void checkPosition(BlockPos position) throws GreenhouseException { + if (maxSize.getX() < position.getX() + || maxSize.getZ() < position.getZ() + || minSize.getX() > position.getX() + || minSize.getZ() > position.getZ()) { + throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.notclosed", position.getX(), position.getZ())).setPos(position); + } + + if (!world.isBlockLoaded(position)) { + unloadedChunks.add(ChunkPos.asLong(position.getX() >> 4, position.getZ() >> 4)); + throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.unloaded", position.getX(), position.getZ())); + } + } + + @Override + public Collection getHandlers() { + if (HANDLERS.isEmpty()) { + HANDLERS.add(WallBlockHandler.getInstance()); + HANDLERS.add(BlankBlockHandler.getInstance()); + } + return HANDLERS; + } + + @Override + public void onBlockChange() { + long totalWorldTime = world.getTotalWorldTime(); + if (totalWorldTime >= previousUpdateTick + TIME_BETWEEN_UPDATES) { + GreenhouseBlockManager.getInstance().scheduleUpdate(world, container.getParent().getCoordinates(), this, UPDATE_DELAY); + previousUpdateTick = totalWorldTime; + } + } + + @Override + public void scheduledUpdate() { + create(); + } + + /** + * Check all internal blocks. + */ + private void createBlocks() { + Stack blocksToCheck = new Stack(); + blocksToCheck.add(BlankBlockHandler.getInstance().createBlock(storage, null, null, centerPos)); + checkState(checkBlocks(blocksToCheck)); + EntityPlayer player = world.getClosestPlayer(centerPos.getX(), centerPos.getY(), centerPos.getZ(), 100000.0D, false); + if (!world.isRemote && lastNotClosedException != null && player != null) { + player.sendMessage(new TextComponentString(lastNotClosedException.getMessage())); + } + } + + private void checkState(GreenhouseState state) { + this.state = state; + } + + /** + * Check all internal blocks. + */ + private GreenhouseState checkBlocks(Collection blocks) { + try { + if (minSize == null || maxSize == null || minSize == Position2D.NULL_POSITION || maxSize == Position2D.NULL_POSITION) { + checkMinMax(); + } + int greenhouseHeight = centerPos.getY(); + int greenhouseDepth = centerPos.getY(); + int height = 0; + int depth = 0; + int maximalHeight = ((IGreenhouseController) container.getParent()).getCenterCoordinates().getY() + limits.getHeight(); + GreenhouseLimitsBuilder builder = new GreenhouseLimitsBuilder(); + Stack blocksToCheck = new Stack(); + blocksToCheck.addAll(blocks); + while (!blocksToCheck.isEmpty()) { + IGreenhouseBlock blockToCheck = blocksToCheck.pop(); + if (blockToCheck != null) { + BlockPos position = blockToCheck.getPos(); + IGreenhouseBlockHandler handler = blockToCheck.getHandler(); + builder.recalculate(position); + List newBlocksToCheck = handler.checkNeighborBlocks(storage, blockToCheck); + blocksToCheck.addAll(newBlocksToCheck); + if (blockToCheck instanceof IBlankBlock) { + int positionHeight = getHeight(position, maximalHeight); + int positionDepth = getDepth(position); + if (positionHeight == -1) { + throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.roof.notclosed", position.getX(), position.getY(), position.getZ())).setPos(position); + } + if (positionHeight > greenhouseHeight) { + greenhouseHeight = positionHeight; + } + height += positionHeight - centerPos.getY(); + if (positionDepth < greenhouseDepth) { + greenhouseDepth = positionDepth; + } + depth += centerPos.getY() - positionDepth; + } + } + } + this.size = height + depth + storage.getBlockCount(); + lastNotClosedException = null; + usedLimits = builder.build(greenhouseHeight, greenhouseDepth); + return GreenhouseState.CLOSED; + } catch (GreenhouseException exception) { + lastNotClosedException = exception; + if (!unloadedChunks.isEmpty()) { + return GreenhouseState.UNLOADED_CHUNK; + } + return GreenhouseState.OPEN; + } + } + + private void checkMinMax() throws GreenhouseException { + if (limits == null) { + minSize = maxSize = null; + throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.edges")); + } + if (limits.getMaximumCoordinates() != null) { + Position2D edge = limits.getMaximumCoordinates(); + maxSize = edge.add(1, 1).add(centerPos.getX(), centerPos.getZ()); + } else { + maxSize = null; + throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.edge")); + } + if (limits.getMinimumCoordinates() != null) { + Position2D edge = limits.getMinimumCoordinates(); + minSize = edge.add(-1, -1).add(centerPos.getX(), centerPos.getZ()); + } else { + minSize = null; + throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.edge")); + } + } + + public int getHeight(BlockPos pos, int maximalHeight) { + int worldHeight = world.getHeight(); + BlockPos.MutableBlockPos position = new BlockPos.MutableBlockPos(pos); + int height = -1; + + while (position.getY() <= worldHeight && position.getY() <= maximalHeight && height == -1) { + IBlockState blockState = world.getBlockState(position); + AxisAlignedBB collisionBB = blockState.getCollisionBoundingBox(world, pos); + + if (collisionBB == null || collisionBB.equals(Block.NULL_AABB) || blockState.getBlock().isLeaves(blockState, world, pos)) { + position.move(EnumFacing.UP); + } else { + height = position.down().getY(); + } + } + + return height; + } + + public int getDepth(BlockPos pos) { + int worldDepth = 0; + BlockPos.MutableBlockPos position = new BlockPos.MutableBlockPos(pos); + int depth = -1; + + while (position.getY() > worldDepth && depth == -1) { + IBlockState blockState = world.getBlockState(position); + AxisAlignedBB collisionBB = blockState.getCollisionBoundingBox(world, pos); + + if (collisionBB == null || collisionBB.equals(Block.NULL_AABB) || blockState.getBlock().isLeaves(blockState, world, pos)) { + position.move(EnumFacing.DOWN); + } else { + depth = position.up().getY(); + } + } + + return depth; + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/package-info.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/package-info.java new file mode 100644 index 000000000..631483457 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.multiblock.blocks.storage; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlock.java b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlock.java new file mode 100644 index 000000000..f86919d24 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlock.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.wall; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.util.math.BlockPos; + +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateSource; +import forestry.api.climate.IClimateSourceOwner; +import forestry.api.core.ForestryAPI; +import forestry.api.greenhouse.IBlankBlock; +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.greenhouse.IWallBlock; +import forestry.api.greenhouse.Position2D; +import forestry.greenhouse.multiblock.blocks.GreenhouseBlock; + +public class WallBlock extends GreenhouseBlock implements IWallBlock { + + private final List sources; + + public WallBlock(IGreenhouseProvider manager, BlockPos pos) { + super(manager, pos); + this.sources = new ArrayList<>(); + } + + @Override + public void setRoot(IBlankBlock parent) { + this.root = parent; + } + + @Override + public void onCreate() { + IClimateContainer container = provider.getClimateContainer(); + for (IClimateSourceOwner sourceOwner : ForestryAPI.climateManager.getSources(provider.getWorld(), new Position2D(pos))) { + IClimateSource source = sourceOwner.getClimateSource(); + sources.add(source); + container.addClimateSource(source); + source.onAdded(container); + } + } + + @Override + public void onRemove() { + IClimateContainer container = provider.getClimateContainer(); + Iterator iterator = sources.iterator(); + while (iterator.hasNext()) { + IClimateSource source = iterator.next(); + source.onRemoved(container); + container.removeClimateSource(source); + iterator.remove(); + } + } + + @Override + public void add(IClimateSource source) { + sources.add(source); + } + + @Override + public IGreenhouseBlockHandler getHandler() { + return WallBlockHandler.getInstance(); + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlockHandler.java b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlockHandler.java new file mode 100644 index 000000000..f1aef109c --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlockHandler.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.wall; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.greenhouse.IBlankBlock; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseBlockHandler; +import forestry.api.greenhouse.IGreenhouseBlockStorage; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.greenhouse.IGreenhouseProviderListener; +import forestry.api.greenhouse.IWallBlock; +import forestry.greenhouse.multiblock.blocks.GreenhouseException; + +public class WallBlockHandler implements IGreenhouseBlockHandler { + + private static final WallBlockHandler INSTANCE = new WallBlockHandler(); + + public static WallBlockHandler getInstance() { + return INSTANCE; + } + + @Override + public void onRemoveBlock(IGreenhouseBlockStorage storage, IWallBlock blockToRemove) { + BlockPos pos = blockToRemove.getPos(); + blockToRemove.onRemove(); + } + + @Override + public IWallBlock createBlock(IGreenhouseBlockStorage storage, @Nullable IBlankBlock root, @Nullable EnumFacing rootFacing, @Nullable BlockPos position) { + IWallBlock wallBlock = new WallBlock(storage.getProvider(), position); + wallBlock.setRoot(root); + wallBlock.setRootFace(rootFacing); + wallBlock.onCreate(); + return wallBlock; + } + + @Override + public IWallBlock getBlock(IGreenhouseBlockStorage storage, BlockPos position) { + IGreenhouseBlock logicBlock = storage.getBlock(position); + if (logicBlock instanceof IWallBlock) { + return (IWallBlock) logicBlock; + } + return null; + } + + @Override + public List checkNeighborBlocks(IGreenhouseBlockStorage storage, IWallBlock blockToCheck) throws GreenhouseException { + return Collections.emptyList(); + } + + @Override + public boolean onCheckPosition(IGreenhouseBlockStorage storage, IBlankBlock rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck) { + IGreenhouseProvider provider = storage.getProvider(); + if (block == null && isValidWallBlock(provider.getWorld(), position)) { + for (IGreenhouseProviderListener listener : provider.getListeners()) { + listener.onCheckPosition(position); + } + IWallBlock wallBlock = createBlock(storage, rootBlock, facing, position); + storage.setBlock(position, wallBlock); + + rootBlock.setFaceTested(facing, true); + rootBlock.setNearWall(true); + return true; + } + return false; + } + + @Override + public Class getBlockClass() { + return IWallBlock.class; + } + + private boolean isValidWallBlock(World world, BlockPos pos) { + return !isAirBlock(world, pos); + } + + /** + * Same as {@link World#isAirBlock(BlockPos)} but faster + */ + private boolean isAirBlock(World world, BlockPos pos) { + IBlockState blockState = world.getBlockState(pos); + AxisAlignedBB collisionBB = blockState.getCollisionBoundingBox(world, pos); + return collisionBB == null || collisionBB.equals(Block.NULL_AABB) || blockState.getBlock().isLeaves(blockState, world, pos); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/wall/package-info.java b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/package-info.java new file mode 100644 index 000000000..def9c05fc --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.multiblock.blocks.wall; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/world/ChunkManager.java b/src/main/java/forestry/greenhouse/multiblock/blocks/world/ChunkManager.java new file mode 100644 index 000000000..d5494c7f5 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/world/ChunkManager.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.world; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; + +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk; + +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; + +class ChunkManager { + public final Map id2ChunkMap = new Long2ObjectOpenHashMap(8192); + public final List dirtyChunks = new ArrayList<>(); + private final Set pendingTickEntries = Sets.newHashSet(); + private final TreeSet pendingTickEntriesSorted = new TreeSet(); + private final List pendingTickEntriesThisTick = Lists.newArrayList(); + private final World world; + + public ChunkManager(World world) { + this.world = world; + } + + public void markChunkDirty(long pos) { + dirtyChunks.add(pos); + } + + public List getDirtyChunks() { + return dirtyChunks; + } + + public GreenhouseChunk createChunk(long pos) { + GreenhouseChunk chunk = new GreenhouseChunk(); + id2ChunkMap.put(pos, chunk); + return chunk; + } + + public GreenhouseChunk getOrCreateChunk(long pos) { + GreenhouseChunk chunk = getChunk(pos); + if (chunk == null) { + chunk = createChunk(pos); + } + return chunk; + } + + public GreenhouseChunk getChunk(long pos) { + return id2ChunkMap.get(pos); + } + + public void load(int x, int z) { + long chunkPos = ChunkPos.asLong(x, z); + updateChunk(x + 1, z, chunkPos); + updateChunk(x - 1, z, chunkPos); + updateChunk(x, z + 1, chunkPos); + updateChunk(x, z - 1, chunkPos); + } + + public void unload(int x, int z) { + long pos = ChunkPos.asLong(x, z); + GreenhouseChunk chunk = id2ChunkMap.remove(pos); + if (chunk != null) { + for (IGreenhouseProvider manager : chunk.getProviders()) { + manager.onUnloadChunk(pos); + } + } + } + + private void updateChunk(int x, int z, long updatedChunk) { + GreenhouseChunk chunk = getChunk(ChunkPos.asLong(x, z)); + if (chunk != null) { + for (IGreenhouseProvider manager : chunk.getProviders()) { + if (manager.hasUnloadedChunks()) { + manager.onLoadChunk(updatedChunk); + } + } + } + } + + public void scheduleUpdate(BlockPos pos, IGreenhouseProvider provider, int delay) { + NextTickEntry entry = new NextTickEntry(pos, provider); + + entry.setScheduledTime((long) delay + getWorldTotalTime()); + + if (!this.pendingTickEntries.contains(entry)) { + this.pendingTickEntries.add(entry); + this.pendingTickEntriesSorted.add(entry); + } + } + + public void tickUpdates() { + int entriesCount = this.pendingTickEntriesSorted.size(); + + if (entriesCount != this.pendingTickEntries.size()) { + throw new IllegalStateException("TickNextTick list out of synch"); + } else { + + for (int entryCount = 0; entryCount < entriesCount; ++entryCount) { + NextTickEntry entry = pendingTickEntriesSorted.first(); + + if (entry.scheduledTime > getWorldTotalTime()) { + break; + } + + this.pendingTickEntriesSorted.remove(entry); + this.pendingTickEntries.remove(entry); + this.pendingTickEntriesThisTick.add(entry); + } + + Iterator iterator = this.pendingTickEntriesThisTick.iterator(); + + while (iterator.hasNext()) { + NextTickEntry entry = iterator.next(); + iterator.remove(); + + if (world.isBlockLoaded(entry.getPosition())) { + entry.getProvider().scheduledUpdate(); + } else { + scheduleUpdate(entry.getPosition(), entry.getProvider(), 0); + } + } + + this.pendingTickEntriesThisTick.clear(); + } + } + + private long getWorldTotalTime() { + return world.getWorldInfo().getWorldTotalTime(); + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/world/ChunkThread.java b/src/main/java/forestry/greenhouse/multiblock/blocks/world/ChunkThread.java new file mode 100644 index 000000000..ea4ad7f48 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/world/ChunkThread.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.world; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.crash.CrashReport; +import net.minecraft.util.ReportedException; +import net.minecraft.world.World; + +import net.minecraftforge.common.DimensionManager; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.core.utils.Log; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk; + +public class ChunkThread implements Runnable { + + private final long INTERVAL = 250L; + private boolean stop = false; + private boolean isClient; + + public ChunkThread(boolean isClient) { + this.isClient = isClient; + } + + @SideOnly(Side.CLIENT) + private static void handleClientWorld() { + handleDirtyChunks(Minecraft.getMinecraft().world); + } + + private static void handleDirtyChunks(World world) { + if (world == null || world.provider == null) { + return; + } + GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + synchronized (manager) { + List dirtyChunks = manager.getDirtyChunks(world); + Iterator dirtyChunksIterator = dirtyChunks.iterator(); + + while (dirtyChunksIterator.hasNext()) { + Long chunkPos = dirtyChunksIterator.next(); + GreenhouseChunk chunk = manager.getChunk(world, chunkPos); + if (chunk != null) { + synchronized (chunk) { + Collection providers = chunk.getDirtyProviders(); + Iterator dirtyProviders = providers.iterator(); + while (dirtyProviders.hasNext()) { + IGreenhouseProvider provider = dirtyProviders.next(); + provider.recreate(); + + dirtyProviders.remove(); + } + } + } + dirtyChunksIterator.remove(); + } + manager.tickUpdates(world); + } + } + + @Override + public void run() { + Log.info("Starting greenhouse thread"); + while (!this.stop) { + try { + long startTime = System.currentTimeMillis(); + if (isClient) { + handleClientWorld(); + } else { + for (World world : DimensionManager.getWorlds()) { + handleDirtyChunks(world); + } + } + long executionTime = System.currentTimeMillis() - startTime; + try { + if (executionTime > INTERVAL) { + Log.warning("GREENHOUSE TAKING " + (executionTime - INTERVAL) + " ms LONGER THAN NORMAL"); + } + Thread.sleep(Math.max(1L, INTERVAL - executionTime)); + } catch (InterruptedException e) { + } + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Update Greenhouse change"); + throw new ReportedException(crashreport); + } + } + Log.info("Stopping climate thread"); + GreenhouseBlockManager.setThread(null, isClient); + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/world/GreenhouseBlockManager.java b/src/main/java/forestry/greenhouse/multiblock/blocks/world/GreenhouseBlockManager.java new file mode 100644 index 000000000..67f280807 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/world/GreenhouseBlockManager.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.world; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; + +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.api.greenhouse.IGreenhouseBlockManager; +import forestry.api.greenhouse.IGreenhouseChunk; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.core.utils.World2ObjectMap; +import forestry.greenhouse.multiblock.blocks.blank.BlankBlockHandler; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk; +import forestry.greenhouse.multiblock.blocks.wall.WallBlockHandler; + +public class GreenhouseBlockManager implements IGreenhouseBlockManager { + private static final GreenhouseBlockManager INSTANCE = new GreenhouseBlockManager(); + private static Thread thread; + private static Thread clientThread; + + private World2ObjectMap managers; + + private GreenhouseBlockManager() { + managers = new World2ObjectMap(world -> new ChunkManager(world)); + } + + public static GreenhouseBlockManager getInstance() { + return INSTANCE; + } + + public static void setThread(Thread thread, boolean isClient) { + if (isClient) { + GreenhouseBlockManager.clientThread = thread; + } else { + GreenhouseBlockManager.thread = thread; + } + } + + public static Thread getClientThread() { + return clientThread; + } + + public static Thread getThread() { + return thread; + } + + @Override + public BlankBlockHandler getBlankBlockHandler() { + return BlankBlockHandler.getInstance(); + } + + @Override + public WallBlockHandler getWallBlockHandler() { + return WallBlockHandler.getInstance(); + } + + @Override + @Nullable + public IGreenhouseBlock getBlock(World world, BlockPos pos) { + IGreenhouseChunk chunk = getChunk(world, pos.getX() >> 4, pos.getZ() >> 4); + if (chunk != null) { + return chunk.get(pos); + } + return null; + } + + @Nullable + public GreenhouseChunk getChunk(World world, long pos) { + ChunkManager manager = managers.get(world); + if (manager == null) { + return null; + } + return manager.getChunk(pos); + } + + @Override + public IGreenhouseChunk getOrCreateChunk(World world, long chunkPos) { + ChunkManager manager = managers.get(world); + if (manager == null) { + return null; + } + return manager.getOrCreateChunk(chunkPos); + } + + @Nullable + public GreenhouseChunk createChunk(World world, long pos) { + ChunkManager manager = managers.get(world); + if (manager == null) { + return null; + } + return manager.createChunk(pos); + } + + @Nullable + public void markChunkDirty(World world, long pos) { + ChunkManager manager = managers.get(world); + if (manager != null) { + manager.markChunkDirty(pos); + } + } + + @Nullable + public synchronized List getDirtyChunks(World world) { + ChunkManager manager = managers.get(world); + if (manager == null) { + return Collections.emptyList(); + } + return manager.getDirtyChunks(); + } + + @Nullable + public synchronized void markBlockDirty(World world, BlockPos pos) { + long position = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4); + GreenhouseChunk chunk = getChunk(world, position); + if (chunk != null) { + IGreenhouseBlock block = chunk.get(pos); + if (block != null) { + IGreenhouseProvider provider = block.getProvider(); + provider.onBlockChange(); + //markChunkDirty(world, position); + //chunk.markProviderDirty(pos); + + } + } + } + + @Nullable + public synchronized void markProviderDirty(World world, BlockPos pos, IGreenhouseProvider provider) { + if (provider != null) { + long position = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4); + GreenhouseChunk chunk = getChunk(world, position); + if (chunk != null) { + markChunkDirty(world, position); + chunk.markProviderDirty(provider); + } + } + } + + @Nullable + public void unloadChunk(World world, int x, int z) { + ChunkManager manager = managers.get(world); + if (manager != null) { + manager.unload(x, z); + } + } + + @Nullable + public void loadChunk(World world, int x, int z) { + ChunkManager manager = managers.get(world); + if (manager != null) { + manager.load(x, z); + } + } + + public void scheduleUpdate(World world, BlockPos pos, IGreenhouseProvider provider, int delay) { + ChunkManager manager = managers.get(world); + if (manager != null) { + manager.scheduleUpdate(pos, provider, delay); + } + } + + public void tickUpdates(World world) { + ChunkManager manager = managers.get(world); + if (manager != null) { + manager.tickUpdates(); + } + } +} \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/world/NextTickEntry.java b/src/main/java/forestry/greenhouse/multiblock/blocks/world/NextTickEntry.java new file mode 100644 index 000000000..9a5ea49f9 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/world/NextTickEntry.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.multiblock.blocks.world; + +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IGreenhouseProvider; + +class NextTickEntry implements Comparable { + private final IGreenhouseProvider provider; + private final BlockPos position; + public long scheduledTime; + + public NextTickEntry(BlockPos position, IGreenhouseProvider provider) { + this.position = position; + this.provider = provider; + } + + @Override + public int hashCode() { + return this.position.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof NextTickEntry)) { + return false; + } else { + NextTickEntry nextticklistentry = (NextTickEntry) o; + return this.position.equals(nextticklistentry.position) && provider.equals(provider); + } + } + + @Override + public String toString() { + return provider + ": " + this.position + ", " + this.scheduledTime; + } + + public NextTickEntry setScheduledTime(long scheduledTime) { + this.scheduledTime = scheduledTime; + return this; + } + + @Override + public int compareTo(NextTickEntry o) { + return this.scheduledTime < o.scheduledTime ? -1 : (this.scheduledTime > o.scheduledTime ? 1 : 0); + } + + public BlockPos getPosition() { + return position; + } + + public IGreenhouseProvider getProvider() { + return provider; + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/world/package-info.java b/src/main/java/forestry/greenhouse/multiblock/blocks/world/package-info.java new file mode 100644 index 000000000..7ac56c678 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/world/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.multiblock.blocks.world; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/multiblock/package-info.java b/src/main/java/forestry/greenhouse/multiblock/package-info.java index 6819eb459..854a0abb4 100644 --- a/src/main/java/forestry/greenhouse/multiblock/package-info.java +++ b/src/main/java/forestry/greenhouse/multiblock/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse.multiblock; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/network/PacketRegistryGreenhouse.java b/src/main/java/forestry/greenhouse/network/PacketRegistryGreenhouse.java new file mode 100644 index 000000000..c0f3fd509 --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/PacketRegistryGreenhouse.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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 net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.network.IPacketRegistry; +import forestry.core.network.PacketIdClient; +import forestry.core.network.PacketIdServer; +import forestry.greenhouse.network.packets.PacketCamouflageSelectionClient; +import forestry.greenhouse.network.packets.PacketCamouflageSelectionServer; +import forestry.greenhouse.network.packets.PacketGreenhouseData; +import forestry.greenhouse.network.packets.PacketGreenhouseDataRequest; +import forestry.greenhouse.network.packets.PacketSelectClimateTargeted; + +public class PacketRegistryGreenhouse implements IPacketRegistry { + @Override + public void registerPacketsServer() { + PacketIdServer.CAMOUFLAGE_SELECTION.setPacketHandler(new PacketCamouflageSelectionServer.Handler()); + PacketIdServer.SELECT_CLIMATE_TARGETED.setPacketHandler(new PacketSelectClimateTargeted.Handler()); + PacketIdServer.GREENHOUSE_DATA_REQUEST.setPacketHandler(new PacketGreenhouseDataRequest.Handler()); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerPacketsClient() { + PacketIdClient.CAMOUFLAGE_SELECTION.setPacketHandler(new PacketCamouflageSelectionClient.Handler()); + PacketIdClient.GREENHOUSE_DATA.setPacketHandler(new PacketGreenhouseData.Handler()); + } +} diff --git a/src/main/java/forestry/greenhouse/entities/package-info.java b/src/main/java/forestry/greenhouse/network/package-info.java similarity index 86% rename from src/main/java/forestry/greenhouse/entities/package-info.java rename to src/main/java/forestry/greenhouse/network/package-info.java index add00cfff..bd00d3cd5 100644 --- a/src/main/java/forestry/greenhouse/entities/package-info.java +++ b/src/main/java/forestry/greenhouse/network/package-info.java @@ -1,9 +1,10 @@ @ParametersAreNonnullByDefault @FieldsAreNonnullByDefault @MethodsReturnNonnullByDefault -package forestry.greenhouse.entities; +package forestry.greenhouse.network; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelection.java b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelection.java new file mode 100644 index 000000000..571835cbd --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelection.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.item.ItemStack; +import net.minecraft.util.math.BlockPos; + +import forestry.api.core.ICamouflageHandler; +import forestry.core.network.ForestryPacket; +import forestry.core.network.PacketBufferForestry; +import forestry.greenhouse.camouflage.CamouflageHandlerType; + +public abstract class PacketCamouflageSelection extends ForestryPacket { + protected final BlockPos pos; + protected final ItemStack camouflageStack; + protected final CamouflageHandlerType handlerType; + + public PacketCamouflageSelection(ICamouflageHandler handler, CamouflageHandlerType handlerType) { + this.pos = handler.getCoordinates(); + this.camouflageStack = handler.getCamouflageBlock(); + this.handlerType = handlerType; + } + + @Override + protected void writeData(PacketBufferForestry data) throws IOException { + data.writeBlockPos(pos); + data.writeShort(handlerType.ordinal()); + data.writeItemStack(camouflageStack); + } +} diff --git a/src/main/java/forestry/core/network/packets/PacketCamouflageSelectClient.java b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelectionClient.java similarity index 51% rename from src/main/java/forestry/core/network/packets/PacketCamouflageSelectClient.java rename to src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelectionClient.java index 3ada600f6..80c9b5889 100644 --- a/src/main/java/forestry/core/network/packets/PacketCamouflageSelectClient.java +++ b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelectionClient.java @@ -8,38 +8,33 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.network.packets; +package forestry.greenhouse.network.packets; import java.io.IOException; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.api.core.ICamouflageHandler; import forestry.api.core.ICamouflagedTile; import forestry.api.multiblock.IMultiblockComponent; import forestry.api.multiblock.IMultiblockController; -import forestry.core.network.ForestryPacket; import forestry.core.network.IForestryPacketClient; import forestry.core.network.IForestryPacketHandlerClient; import forestry.core.network.PacketBufferForestry; import forestry.core.network.PacketIdClient; import forestry.core.tiles.TileUtil; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.greenhouse.camouflage.CamouflageHandlerType; -public class PacketCamouflageSelectClient extends ForestryPacket implements IForestryPacketClient { - private final BlockPos pos; - private final ItemStack camouflageStack; - private final String camouflageType; - private final CamouflageSelectionType selectionType; - - public PacketCamouflageSelectClient(ICamouflageHandler handler, String camouflageType, CamouflageSelectionType selectionType) { - this.pos = handler.getCoordinates(); - this.camouflageStack = handler.getCamouflageBlock(camouflageType); - this.selectionType = selectionType; - this.camouflageType = camouflageType; +public class PacketCamouflageSelectionClient extends PacketCamouflageSelection implements IForestryPacketClient { + public PacketCamouflageSelectionClient(ICamouflageHandler handler, CamouflageHandlerType handlerType) { + super(handler, handlerType); } @Override @@ -47,50 +42,50 @@ public class PacketCamouflageSelectClient extends ForestryPacket implements IFor return PacketIdClient.CAMOUFLAGE_SELECTION; } - @Override - protected void writeData(PacketBufferForestry data) throws IOException { - data.writeBlockPos(pos); - data.writeShort(selectionType.ordinal()); - data.writeString(camouflageType); - data.writeItemStack(camouflageStack); - } - @SideOnly(Side.CLIENT) public static class Handler implements IForestryPacketHandlerClient { - @Override public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { BlockPos pos = data.readBlockPos(); - CamouflageSelectionType selectionType = CamouflageSelectionType.values()[data.readShort()]; - String camouflageType = data.readString(); + CamouflageHandlerType handlerType = CamouflageHandlerType.values()[data.readShort()]; ItemStack camouflageStack = data.readItemStack(); TileEntity tile = TileUtil.getTile(player.world, pos); ICamouflageHandler handler; - if (selectionType == CamouflageSelectionType.MULTIBLOCK) { - if (tile instanceof IMultiblockComponent) { - IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController(); + switch (handlerType) { + case STRUCTURE: { + if (!(tile instanceof IMultiblockComponent)) { + return; + } - if (controller instanceof ICamouflageHandler) { - handler = (ICamouflageHandler) controller; - if (handler.setCamouflageBlock(camouflageType, camouflageStack, false)) { - for (IMultiblockComponent comp : controller.getComponents()) { - if (comp instanceof ICamouflagedTile) { - ICamouflagedTile camBlock = (ICamouflagedTile) comp; - if (camBlock.getCamouflageType().equals(camouflageType)) { - player.world.markBlockRangeForRenderUpdate(camBlock.getCoordinates(), camBlock.getCoordinates()); - } - } - } + IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController(); + if (!(controller instanceof ICamouflageHandler)) { + return; + } + handler = (ICamouflageHandler) controller; + if (!handler.setCamouflageBlock(camouflageStack, false)) { + return; + } + for (IMultiblockComponent comp : controller.getComponents()) { + if (comp instanceof ICamouflagedTile) { + ICamouflagedTile camBlock = (ICamouflagedTile) comp; + BlockPos coordinates = camBlock.getCoordinates(); + World world = camBlock.getWorldObj(); + + world.markBlockRangeForRenderUpdate(coordinates, coordinates); } } + break; } - } else if (selectionType == CamouflageSelectionType.TILE) { - if (tile instanceof ICamouflageHandler) { - handler = (ICamouflageHandler) tile; - if (handler.setCamouflageBlock(camouflageType, camouflageStack, false)) { + case TILE: { + if (tile instanceof ICamouflageHandler) { + handler = (ICamouflageHandler) tile; + if (!handler.setCamouflageBlock(camouflageStack, false)) { + return; + } player.world.markBlockRangeForRenderUpdate(pos, pos); } + break; } } } diff --git a/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelectionServer.java b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelectionServer.java new file mode 100644 index 000000000..b99f92382 --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageSelectionServer.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * 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.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; + +import forestry.api.core.ICamouflageHandler; +import forestry.api.multiblock.IMultiblockComponent; +import forestry.api.multiblock.IMultiblockController; +import forestry.core.network.IForestryPacketHandlerServer; +import forestry.core.network.IForestryPacketServer; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.PacketIdServer; +import forestry.core.tiles.TileUtil; +import forestry.core.utils.NetworkUtil; +import forestry.greenhouse.camouflage.CamouflageHandlerType; +import forestry.greenhouse.gui.ContainerCamouflageSprayCan; +import forestry.greenhouse.inventory.ItemInventoryCamouflageSprayCan; + +public class PacketCamouflageSelectionServer extends PacketCamouflageSelection implements IForestryPacketServer { + + public PacketCamouflageSelectionServer(ICamouflageHandler handler, CamouflageHandlerType handlerType) { + super(handler, handlerType); + } + + @Override + public PacketIdServer getPacketId() { + return PacketIdServer.CAMOUFLAGE_SELECTION; + } + + public static class Handler implements IForestryPacketHandlerServer { + @Override + public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException { + BlockPos pos = data.readBlockPos(); + CamouflageHandlerType handlerType = CamouflageHandlerType.values()[data.readShort()]; + ItemStack camouflageStack = data.readItemStack(); + + TileEntity tile = TileUtil.getTile(player.world, pos); + ICamouflageHandler handler = null; + switch (handlerType) { + case STRUCTURE: { + if (tile instanceof IMultiblockComponent) { + IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController(); + + if (controller instanceof ICamouflageHandler) { + handler = (ICamouflageHandler) controller; + } + } + break; + } + case TILE: { + if (tile instanceof IMultiblockComponent) { + IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController(); + + if (controller instanceof ICamouflageHandler) { + handler = (ICamouflageHandler) controller; + } + } + break; + } + case ITEM: { + Container openContainer = player.openContainer; + if (openContainer instanceof ContainerCamouflageSprayCan) { + ContainerCamouflageSprayCan container = (ContainerCamouflageSprayCan) openContainer; + ItemInventoryCamouflageSprayCan sprayCanInv = container.getItemInventory(); + if (!sprayCanInv.isEmpty()) { + handler = sprayCanInv; + } + } + break; + } + } + + if (handler != null) { + if (handler.setCamouflageBlock(camouflageStack, true) && handlerType != CamouflageHandlerType.ITEM) { + NetworkUtil.sendNetworkPacket(new PacketCamouflageSelectionClient(handler, handlerType), pos, player.world); + } + } + } + } +} diff --git a/src/main/java/forestry/greenhouse/network/packets/PacketGreenhouseData.java b/src/main/java/forestry/greenhouse/network/packets/PacketGreenhouseData.java new file mode 100644 index 000000000..a1ce6ecea --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/packets/PacketGreenhouseData.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * 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.EntityPlayer; +import net.minecraft.util.math.BlockPos; + +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.multiblock.MultiblockUtil; +import forestry.core.network.ForestryPacket; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.IForestryPacketHandlerClient; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.PacketIdClient; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProvider; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderClient; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderServer; + +public class PacketGreenhouseData extends ForestryPacket implements IForestryPacketClient { + + BlockPos pos; + GreenhouseProviderServer provider; + + public PacketGreenhouseData(BlockPos pos, GreenhouseProviderServer provider) { + this.pos = pos; + this.provider = provider; + } + + @Override + public PacketIdClient getPacketId() { + return PacketIdClient.GREENHOUSE_DATA; + } + + @Override + protected void writeData(PacketBufferForestry data) throws IOException { + data.writeBlockPos(pos); + provider.writeData(data); + } + + public static class Handler implements IForestryPacketHandlerClient { + + public Handler() { + } + + @Override + public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { + BlockPos pos = data.readBlockPos(); + IGreenhouseController controller = MultiblockUtil.getController(player.world, pos, IGreenhouseComponent.class); + if (controller == null) { + return; + } + IGreenhouseProvider provider = controller.getProvider(); + if (provider instanceof GreenhouseProvider) { + GreenhouseProviderClient providerClient = (GreenhouseProviderClient) provider; + providerClient.readData(data); + } + //GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance(); + provider.onBlockChange(); + //manager.markProviderDirty(player.world, controller.getProvider().getCenterPos(), provider); + } + } +} diff --git a/src/main/java/forestry/greenhouse/network/packets/PacketGreenhouseDataRequest.java b/src/main/java/forestry/greenhouse/network/packets/PacketGreenhouseDataRequest.java new file mode 100644 index 000000000..62adfec2f --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/packets/PacketGreenhouseDataRequest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.multiblock.MultiblockUtil; +import forestry.core.network.ForestryPacket; +import forestry.core.network.IForestryPacketHandlerServer; +import forestry.core.network.IForestryPacketServer; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.PacketIdServer; +import forestry.core.utils.NetworkUtil; +import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderServer; + +public class PacketGreenhouseDataRequest extends ForestryPacket implements IForestryPacketServer { + + private BlockPos position; + + public PacketGreenhouseDataRequest(BlockPos position) { + this.position = position; + } + + @Override + protected void writeData(PacketBufferForestry data) throws IOException { + data.writeBlockPos(position); + } + + @Override + public PacketIdServer getPacketId() { + return PacketIdServer.GREENHOUSE_DATA_REQUEST; + } + + public static class Handler implements IForestryPacketHandlerServer { + @Override + public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException { + BlockPos position = data.readBlockPos(); + World world = player.world; + IGreenhouseController controller = MultiblockUtil.getController(world, position, IGreenhouseComponent.class); + if (controller != null) { + NetworkUtil.sendToPlayer(new PacketGreenhouseData(position, (GreenhouseProviderServer) controller.getProvider()), player); + } + } + } +} diff --git a/src/main/java/forestry/greenhouse/network/packets/PacketSelectClimateTargeted.java b/src/main/java/forestry/greenhouse/network/packets/PacketSelectClimateTargeted.java new file mode 100644 index 000000000..eae3acc5b --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/packets/PacketSelectClimateTargeted.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.util.math.BlockPos; + +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateState; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.multiblock.MultiblockUtil; +import forestry.core.network.ForestryPacket; +import forestry.core.network.IForestryPacketHandlerServer; +import forestry.core.network.IForestryPacketServer; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.PacketIdServer; + +public class PacketSelectClimateTargeted extends ForestryPacket implements IForestryPacketServer { + private final BlockPos pos; + private final IClimateState climateState; + + public PacketSelectClimateTargeted(BlockPos pos, IClimateState climateState) { + this.pos = pos; + this.climateState = climateState; + } + + @Override + public PacketIdServer getPacketId() { + return PacketIdServer.SELECT_CLIMATE_TARGETED; + } + + @Override + protected void writeData(PacketBufferForestry data) throws IOException { + data.writeBlockPos(pos); + data.writeFloat(climateState.getTemperature()); + data.writeFloat(climateState.getHumidity()); + } + + public static class Handler implements IForestryPacketHandlerServer { + @Override + public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException { + BlockPos pos = data.readBlockPos(); + float temperature = data.readFloat(); + float humidity = data.readFloat(); + + IGreenhouseController controller = MultiblockUtil.getController(player.world, pos, IGreenhouseComponent.class); + if (controller != null) { + IClimateContainer container = controller.getClimateContainer(); + container.setTargetedState(new ImmutableClimateState(temperature, humidity)); + } + } + } +} diff --git a/src/main/java/forestry/greenhouse/network/packets/package-info.java b/src/main/java/forestry/greenhouse/network/packets/package-info.java new file mode 100644 index 000000000..1d35adeac --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/packets/package-info.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.greenhouse.network.packets; + +import javax.annotation.ParametersAreNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/package-info.java b/src/main/java/forestry/greenhouse/package-info.java index 87627b614..1b16be01a 100644 --- a/src/main/java/forestry/greenhouse/package-info.java +++ b/src/main/java/forestry/greenhouse/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouse.java b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouse.java index 877c17fa2..9e36843c9 100644 --- a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouse.java +++ b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouse.java @@ -14,4 +14,12 @@ public class ProxyGreenhouse { public void initializeModels() { } + + public void preInti() { + + } + + public void inti() { + + } } diff --git a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java index 654ddc30d..b90d395ae 100644 --- a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java +++ b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java @@ -11,50 +11,142 @@ package forestry.greenhouse.proxy; import com.google.common.base.Preconditions; -import forestry.api.core.ForestryAPI; -import forestry.core.models.BlockModelEntry; -import forestry.core.models.ModelManager; -import forestry.greenhouse.PluginGreenhouse; -import forestry.greenhouse.blocks.BlockGreenhouseType; -import forestry.greenhouse.blocks.BlockRegistryGreenhouse; -import forestry.greenhouse.models.ModelGreenhouse; -import forestry.plugins.ForestryPluginUids; + import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.ColorizerGrass; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeColorHelper; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.terraingen.BiomeEvent; + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -@SuppressWarnings("unused") +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.IClimateState; +import forestry.api.greenhouse.IGreenhouseBlock; +import forestry.core.models.BlockModelEntry; +import forestry.core.models.ModelEntry; +import forestry.core.models.ModelManager; +import forestry.greenhouse.GreenhouseEventHandler; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockClimatiser; +import forestry.greenhouse.blocks.BlockGreenhouse; +import forestry.greenhouse.blocks.BlockRegistryGreenhouse; +import forestry.greenhouse.models.ModelCamouflageSprayCan; +import forestry.greenhouse.models.ModelCamouflaged; +import forestry.greenhouse.models.ModelGreenhouseWindow; +import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; + @SideOnly(Side.CLIENT) public class ProxyGreenhouseClient extends ProxyGreenhouse { + private static BlockPos COLOR_BLOCK_POSITION; + private static BiomeColorHelper.ColorResolver ORIGINAL_GRASS_COLOR; + private static BiomeColorHelper.ColorResolver ORIGINAL_FOLIAGE_COLOR; + @Override public void initializeModels() { BlockRegistryGreenhouse blocks = PluginGreenhouse.getBlocks(); Preconditions.checkState(blocks != null); - for (BlockGreenhouseType greenhouseType : BlockGreenhouseType.VALUES) { - Block greenhouseBlock = blocks.getGreenhouseBlock(greenhouseType); + ModelManager modelManager = ModelManager.getInstance(); + Block greenhouseBlock = blocks.greenhouseBlock; - if (greenhouseType == BlockGreenhouseType.DOOR) { - ModelManager.getInstance().registerCustomBlockModel(new BlockModelEntry(new ModelResourceLocation("forestry:greenhouse." + greenhouseType, "camouflage"), - null, new ModelGreenhouse(), - greenhouseBlock, false)); - continue; - } else if (greenhouseType == BlockGreenhouseType.NURSERY) { - if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) { - continue; - } - } else if (greenhouseType == BlockGreenhouseType.WINDOW || greenhouseType == BlockGreenhouseType.WINDOW_UP) { - continue; + if (greenhouseBlock != null) { + ModelResourceLocation blockModelLocation = new ModelResourceLocation("forestry:greenhouse"); + ModelResourceLocation itemModelLocation = new ModelResourceLocation("forestry:greenhouse", "inventory"); + BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModelLocation, new ModelCamouflaged(BlockGreenhouse.class), greenhouseBlock); + modelManager.registerCustomBlockModel(blockModelIndex); + } + Block climatiserBlock = blocks.climatiserBlock; + + if (climatiserBlock != null) { + ModelResourceLocation blockModelLocation = new ModelResourceLocation("forestry:climatiser"); + ModelResourceLocation itemModelLocation = new ModelResourceLocation("forestry:climatiser", "inventory"); + BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModelLocation, new ModelCamouflaged(BlockClimatiser.class), climatiserBlock); + modelManager.registerCustomBlockModel(blockModelIndex); + } + { + ModelResourceLocation blockModelLocation = new ModelResourceLocation("forestry:greenhouse.window"); + ModelResourceLocation itemModelLocation = new ModelResourceLocation("forestry:greenhouse_window", "inventory"); + BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModelLocation, new ModelGreenhouseWindow(), PluginGreenhouse.getBlocks().window); + modelManager.registerCustomBlockModel(blockModelIndex); + } + { + ModelResourceLocation blockModelLocation = new ModelResourceLocation("forestry:greenhouse.window_up"); + ModelResourceLocation itemModelLocation = new ModelResourceLocation("forestry:greenhouse_window_up", "inventory"); + BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModelLocation, new ModelGreenhouseWindow(), PluginGreenhouse.getBlocks().roofWindow); + modelManager.registerCustomBlockModel(blockModelIndex); + } + { + ModelResourceLocation modelLocation = new ModelResourceLocation("forestry:camouflage_spray_can", "inventory"); + ModelEntry itemModelIndex = new ModelEntry(modelLocation, new ModelCamouflageSprayCan()); + modelManager.registerCustomModel(itemModelIndex); + } + } + + @Override + public void preInti() { + MinecraftForge.EVENT_BUS.register(new GreenhouseEventHandler()); + MinecraftForge.EVENT_BUS.register(this); + + ORIGINAL_GRASS_COLOR = BiomeColorHelper.GRASS_COLOR; + BiomeColorHelper.GRASS_COLOR = new BiomeColorHelper.ColorResolver() { + @Override + public int getColorAtPos(Biome biome, BlockPos blockPosition) { + COLOR_BLOCK_POSITION = blockPosition; + return ORIGINAL_GRASS_COLOR.getColorAtPos(biome, blockPosition); } + }; - if (greenhouseBlock != null) { - ModelResourceLocation blockModelLocation = new ModelResourceLocation("forestry:greenhouse." + greenhouseType); - ModelResourceLocation itemModelLocation = new ModelResourceLocation("forestry:greenhouse", "inventory"); - BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModelLocation, new ModelGreenhouse(), greenhouseBlock); - ModelManager.getInstance().registerCustomBlockModel(blockModelIndex); + ORIGINAL_FOLIAGE_COLOR = BiomeColorHelper.FOLIAGE_COLOR; + BiomeColorHelper.FOLIAGE_COLOR = new BiomeColorHelper.ColorResolver() { + @Override + public int getColorAtPos(Biome biome, BlockPos blockPosition) { + COLOR_BLOCK_POSITION = blockPosition; + return ORIGINAL_FOLIAGE_COLOR.getColorAtPos(biome, blockPosition); + } + }; + } + + @Override + public void inti() { + + } + + @SubscribeEvent + public void getFoliageColor(BiomeEvent.GetFoliageColor event) { + if (COLOR_BLOCK_POSITION != null) { + IGreenhouseBlock logicBlock = GreenhouseBlockManager.getInstance().getBlock(Minecraft.getMinecraft().world, COLOR_BLOCK_POSITION); + if (logicBlock != null && logicBlock.getProvider().isClosed()) { + IClimateContainer container = logicBlock.getProvider().getClimateContainer(); + IClimateState climateState = container.getState(); + double temperature = MathHelper.clamp(climateState.getTemperature(), 0.0F, 1.0F); + double humidity = MathHelper.clamp(climateState.getHumidity(), 0.0F, 1.0F); + event.setNewColor(ColorizerGrass.getGrassColor(temperature, humidity)); } } } + + @SubscribeEvent + public void getGrassColor(BiomeEvent.GetGrassColor event) { + if (COLOR_BLOCK_POSITION != null) { + IGreenhouseBlock logicBlock = GreenhouseBlockManager.getInstance().getBlock(Minecraft.getMinecraft().world, COLOR_BLOCK_POSITION); + if (logicBlock != null && logicBlock.getProvider().isClosed()) { + IClimateContainer container = logicBlock.getProvider().getClimateContainer(); + IClimateState climateState = container.getState(); + double temperature = MathHelper.clamp(climateState.getTemperature(), 0.0F, 1.0F); + double humidity = MathHelper.clamp(climateState.getHumidity(), 0.0F, 1.0F); + event.setNewColor(ColorizerGrass.getGrassColor(temperature, humidity)); + } + } + } + } diff --git a/src/main/java/forestry/greenhouse/proxy/package-info.java b/src/main/java/forestry/greenhouse/proxy/package-info.java index a9f0528f1..79b86dc0e 100644 --- a/src/main/java/forestry/greenhouse/proxy/package-info.java +++ b/src/main/java/forestry/greenhouse/proxy/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse.proxy; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/greenhouse/tiles/TileClimatiser.java b/src/main/java/forestry/greenhouse/tiles/TileClimatiser.java new file mode 100644 index 000000000..8a88575af --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileClimatiser.java @@ -0,0 +1,265 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse.tiles; + +import java.io.IOException; + +import net.minecraft.block.Block; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.CircuitSocketType; +import forestry.api.circuits.ICircuitBoard; +import forestry.api.circuits.ICircuitSocketType; +import forestry.api.climate.ClimateType; +import forestry.api.climate.IClimateSource; +import forestry.api.climate.IClimateSourceOwner; +import forestry.api.core.ICamouflageHandler; +import forestry.api.core.ICamouflagedTile; +import forestry.apiculture.network.packets.PacketActiveUpdate; +import forestry.core.circuits.ISocketable; +import forestry.core.climate.ClimateSource; +import forestry.core.climate.ClimateSourceType; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.network.IStreamableGui; +import forestry.core.network.PacketBufferForestry; +import forestry.core.tiles.IActivatable; +import forestry.core.tiles.TileForestry; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.NetworkUtil; +import forestry.greenhouse.blocks.BlockClimatiser; +import forestry.greenhouse.camouflage.CamouflageHandlerType; +import forestry.greenhouse.climate.ClimateSourceClimatiser; +import forestry.greenhouse.gui.ContainerClimatiser; +import forestry.greenhouse.gui.GuiClimatiser; +import forestry.greenhouse.multiblock.GreenhouseController; +import forestry.greenhouse.network.packets.PacketCamouflageSelectionServer; + +public abstract class TileClimatiser extends TileForestry implements IActivatable, IStreamableGui, IClimateSourceOwner, ICamouflagedTile, ICamouflageHandler, ISocketable { + + private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); + private final ClimateSource source; + private ItemStack camouflageBlock; + private boolean active; + + protected TileClimatiser(float change, float range, ClimateType type) { + this(new ClimateSourceClimatiser(type == ClimateType.HUMIDITY ? ClimateSourceType.HUMIDITY : ClimateSourceType.TEMPERATURE, change, range)); + } + + protected TileClimatiser(ClimateSource source) { + this.camouflageBlock = getDefaultCamouflageBlock(); + this.source = source; + this.source.setOwner(this); + } + + @Override + public ItemStack getCamouflageBlock() { + return camouflageBlock; + } + + @Override + public ItemStack getDefaultCamouflageBlock() { + return GreenhouseController.createDefaultCamouflageBlock(); + } + + /* ICamouflageHandler */ + @Override + public boolean setCamouflageBlock(ItemStack camouflageBlock, boolean sendClientUpdate) { + if (!ItemStackUtil.isIdenticalItem(camouflageBlock, this.camouflageBlock)) { + this.camouflageBlock = camouflageBlock; + + if (sendClientUpdate && world != null && world.isRemote) { + NetworkUtil.sendToServer(new PacketCamouflageSelectionServer(this, CamouflageHandlerType.TILE)); + world.markBlockRangeForRenderUpdate(pos, pos); + markDirty(); + } + return true; + } + return false; + } + + /* IActivatable */ + @Override + public boolean isActive() { + return active; + } + + @Override + public void setActive(boolean active) { + if (this.active == active) { + return; + } + + this.active = active; + + if (world != null) { + if (world.isRemote) { + world.markBlockRangeForRenderUpdate(getCoordinates(), getCoordinates()); + } else { + NetworkUtil.sendNetworkPacket(new PacketActiveUpdate(this), getCoordinates(), world); + } + } + } + + @Override + public void onChunkUnload() { + source.onChunkUnload(); + + super.onChunkUnload(); + } + + @Override + public void invalidate() { + source.invalidate(); + + super.invalidate(); + } + + @Override + protected void updateServerSide() { + source.update(); + + super.updateServerSide(); + } + + /* SAVING & LOADING */ + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + + if (data.hasKey("Camouflage")) { + camouflageBlock = new ItemStack(data.getCompoundTag("Camouflage")); + } + setActive(data.getBoolean("Active")); + + sockets.readFromNBT(data); + + ItemStack chip = sockets.getStackInSlot(0); + if (!chip.isEmpty()) { + ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(chip); + if (chipset != null) { + chipset.onLoad(this); + } + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound data) { + data = super.writeToNBT(data); + if (!camouflageBlock.isEmpty()) { + NBTTagCompound nbtTag = new NBTTagCompound(); + camouflageBlock.writeToNBT(nbtTag); + data.setTag("Camouflage", nbtTag); + } + data.setBoolean("Active", active); + + sockets.writeToNBT(data); + return data; + } + + @Override + public NBTTagCompound getUpdateTag() { + return writeToNBT(new NBTTagCompound()); + } + + @Override + public String getUnlocalizedTitle() { + Block block = getBlockType(); + String blockUnlocalizedName = block.getUnlocalizedName(); + if (block instanceof BlockClimatiser) { + blockUnlocalizedName += '.' + ((BlockClimatiser) block).getNameFromMeta(getBlockMetadata()); + } + return blockUnlocalizedName + ".name"; + } + + @Override + public IClimateSource getClimateSource() { + return source; + } + + @Override + public boolean isCircuitable() { + return true; + } + + @SideOnly(Side.CLIENT) + @Override + public GuiContainer getGui(EntityPlayer player, int data) { + return new GuiClimatiser(player, this); + } + + @Override + public Container getContainer(EntityPlayer player, int data) { + return new ContainerClimatiser(player.inventory, this); + } + + @Override + public void writeGuiData(PacketBufferForestry data) { + sockets.writeData(data); + } + + @Override + @SideOnly(Side.CLIENT) + public void readGuiData(PacketBufferForestry data) throws IOException { + sockets.readData(data); + } + + /* ISocketable */ + @Override + public int getSocketCount() { + return sockets.getSizeInventory(); + } + + @Override + public ItemStack getSocket(int slot) { + return sockets.getStackInSlot(slot); + } + + @Override + public void setSocket(int slot, ItemStack stack) { + + if (!stack.isEmpty() && !ChipsetManager.circuitRegistry.isChipset(stack)) { + return; + } + + // Dispose correctly of old chipsets + if (!sockets.getStackInSlot(slot).isEmpty()) { + if (ChipsetManager.circuitRegistry.isChipset(sockets.getStackInSlot(slot))) { + ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(sockets.getStackInSlot(slot)); + if (chipset != null) { + chipset.onRemoval(this); + } + } + } + + sockets.setInventorySlotContents(slot, stack); + if (stack.isEmpty()) { + return; + } + + ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack); + if (chipset != null) { + chipset.onInsertion(this); + } + } + + @Override + public ICircuitSocketType getSocketType() { + return CircuitSocketType.GREENHOUSE_CLIMATISER; + } +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileDehumidifier.java b/src/main/java/forestry/greenhouse/tiles/TileDehumidifier.java new file mode 100644 index 000000000..6d1c46021 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileDehumidifier.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 net.minecraft.item.ItemStack; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.ClimateType; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockClimatiserType; + +public class TileDehumidifier extends TileClimatiser { + + public TileDehumidifier() { + super(-0.075F, 5F, ClimateType.HUMIDITY); + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack getItemStack() { + return new ItemStack(PluginGreenhouse.getBlocks().climatiserBlock, 1, BlockClimatiserType.DEHUMIDIFIER.ordinal()); + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileFan.java b/src/main/java/forestry/greenhouse/tiles/TileFan.java new file mode 100644 index 000000000..2c08e4f5e --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileFan.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 net.minecraft.item.ItemStack; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.ClimateType; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockClimatiserType; + +public class TileFan extends TileClimatiser { + + public TileFan() { + super(-0.075F, 5F, ClimateType.TEMPERATURE); + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack getItemStack() { + return new ItemStack(PluginGreenhouse.getBlocks().climatiserBlock, 1, BlockClimatiserType.FAN.ordinal()); + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java index 41efd25fe..f98bfc90d 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java @@ -10,57 +10,53 @@ ******************************************************************************/ package forestry.greenhouse.tiles; +import javax.annotation.Nullable; import java.io.IOException; -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.core.ICamouflagedTile; -import forestry.api.core.IErrorLogic; -import forestry.api.core.IErrorLogicSource; -import forestry.api.multiblock.IGreenhouseComponent; -import forestry.api.multiblock.IMultiblockController; -import forestry.core.inventory.IInventoryAdapter; -import forestry.core.multiblock.MultiblockTileEntityForestry; -import forestry.core.network.IStreamableGui; -import forestry.core.network.PacketBufferForestry; -import forestry.core.network.packets.CamouflageSelectionType; -import forestry.core.network.packets.PacketCamouflageSelectServer; -import forestry.core.owner.IOwnedTile; -import forestry.core.owner.IOwnerHandler; -import forestry.core.tiles.ITitled; -import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.NetworkUtil; -import forestry.greenhouse.blocks.BlockGreenhouse; -import forestry.greenhouse.blocks.BlockGreenhouseDoor; -import forestry.greenhouse.blocks.BlockGreenhouseType; -import forestry.greenhouse.gui.ContainerGreenhouse; -import forestry.greenhouse.gui.GuiGreenhouse; -import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public abstract class TileGreenhouse extends MultiblockTileEntityForestry implements IGreenhouseComponent, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile { +import forestry.api.climate.IClimateContainer; +import forestry.api.climate.ImmutableClimateState; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.ICamouflageHandler; +import forestry.api.core.ICamouflagedTile; +import forestry.api.core.IErrorLogic; +import forestry.api.core.IErrorLogicSource; +import forestry.api.greenhouse.IGreenhouseHousing; +import forestry.api.greenhouse.IGreenhouseLimits; +import forestry.api.greenhouse.IGreenhouseProvider; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IMultiblockController; +import forestry.core.multiblock.MultiblockTileEntityForestry; +import forestry.core.network.IStreamableGui; +import forestry.core.network.PacketBufferForestry; +import forestry.core.owner.IOwnedTile; +import forestry.core.owner.IOwnerHandler; +import forestry.core.tiles.ITitled; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.NetworkUtil; +import forestry.greenhouse.camouflage.CamouflageHandlerType; +import forestry.greenhouse.gui.ContainerGreenhouse; +import forestry.greenhouse.gui.GuiGreenhouse; +import forestry.greenhouse.multiblock.GreenhouseController; +import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse; +import forestry.greenhouse.network.packets.PacketCamouflageSelectionServer; + +public abstract class TileGreenhouse extends MultiblockTileEntityForestry implements IGreenhouseComponent, IGreenhouseHousing, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile { protected ItemStack camouflageBlock; - protected TileGreenhouse() { + public TileGreenhouse() { super(new MultiblockLogicGreenhouse()); - camouflageBlock = ItemStack.EMPTY; - } - - @Override - public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { - if (newSate.getBlock() instanceof BlockGreenhouseDoor && oldState.getBlock() instanceof BlockGreenhouseDoor) { - return false; - } - return super.shouldRefresh(world, pos, oldState, newSate); + camouflageBlock = getDefaultCamouflageBlock(); } @Override @@ -75,13 +71,32 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry positionsInRange; - - private boolean active; - - 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); - this.positionsInRange = new HashSet(); - } - - protected TileGreenhouseClimatiser(IClimatiserDefinition definition) { - this(definition, 20 + ENERGY_PER_OPERATION / 25); - } - - @Override - public void onMachineBroken() { - positionsInRange.clear(); - } - - @Override - public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) { - positionsInRange.clear(); - float range = definition.getRange(); - - Iterable allInBox = BlockPos.getAllInBox(pos.add(-range, -range, -range), pos.add(range, range, range)); - for (BlockPos pos : allInBox) { - if (pos.distanceSq(this.pos) <= range) { - positionsInRange.add(pos); - } - } - } - - /* Network */ - @Override - protected void encodeDescriptionPacket(NBTTagCompound packetData) { - super.encodeDescriptionPacket(packetData); - packetData.setBoolean("Active", active); - } - - @Override - protected void decodeDescriptionPacket(NBTTagCompound packetData) { - super.decodeDescriptionPacket(packetData); - setActive(packetData.getBoolean("Active")); - } - - /* IActivatable */ - @Override - public boolean isActive() { - return active; - } - - @Override - public IClimatiserDefinition getDefinition() { - return definition; - } - - @Override - public IClimateSource getClimateSource() { - return source; - } - - public boolean canWork() { - MultiblockLogicGreenhouse logic = getMultiblockLogic(); - if (!logic.isConnected()) { - return false; - } - - EnergyManager energyManager = logic.getController().getEnergyManager(); - - return EnergyHelper.consumeEnergyToDoWork(energyManager, WORK_CYCLES, ENERGY_PER_OPERATION); - } - - @Override - public Set getPositionsInRange() { - return positionsInRange; - } - - @Override - public void setActive(boolean active) { - if (this.active == active) { - return; - } - - this.active = active; - - if (world != null) { - if (world.isRemote) { - world.markBlockRangeForRenderUpdate(getCoordinates(), getCoordinates()); - } else { - NetworkUtil.sendNetworkPacket(new PacketActiveUpdate(this), getCoordinates(), world); - } - } - } - -} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseControl.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseControl.java index cfa3576e8..08d5733b5 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseControl.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseControl.java @@ -10,13 +10,14 @@ ******************************************************************************/ package forestry.greenhouse.tiles; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + import forestry.api.greenhouse.DefaultGreenhouseListener; import forestry.api.greenhouse.IGreenhouseListener; import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IGreenhouseController; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; public class TileGreenhouseControl extends TileGreenhouse implements IGreenhouseComponent.Listener { diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDoor.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDoor.java deleted file mode 100644 index 5a4861244..000000000 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDoor.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse.tiles; - -import forestry.core.utils.ItemStackUtil; -import net.minecraft.item.ItemStack; - -public class TileGreenhouseDoor extends TileGreenhouse { - - public TileGreenhouseDoor() { - } - - @Override - public boolean setCamouflageBlock(String type, ItemStack camouflageBlock, boolean sendClientUpdate) { - if (!ItemStackUtil.isIdenticalItem(camouflageBlock, this.camouflageBlock)) { - super.setCamouflageBlock(type, camouflageBlock, sendClientUpdate); - TileGreenhouseDoor otherDoorTile = null; - if (world.getTileEntity(pos.up()) instanceof TileGreenhouseDoor) { - otherDoorTile = (TileGreenhouseDoor) world.getTileEntity(pos.up()); - } else if (world.getTileEntity(pos.down()) instanceof TileGreenhouseDoor) { - otherDoorTile = (TileGreenhouseDoor) world.getTileEntity(pos.down()); - } - if (otherDoorTile != null) { - return otherDoorTile.setCamouflageBlock(type, camouflageBlock, sendClientUpdate); - } - } - return false; - } - -} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseGearbox.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseGearbox.java index fc7b56c6d..f2e80ff95 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseGearbox.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseGearbox.java @@ -12,10 +12,12 @@ package forestry.greenhouse.tiles; import javax.annotation.Nullable; -import forestry.energy.EnergyManager; import net.minecraft.util.EnumFacing; + import net.minecraftforge.common.capabilities.Capability; +import forestry.energy.EnergyManager; + public class TileGreenhouseGearbox extends TileGreenhouse { public TileGreenhouseGearbox() { diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHatch.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHatch.java deleted file mode 100644 index 9816a17bf..000000000 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHatch.java +++ /dev/null @@ -1,277 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse.tiles; - -import javax.annotation.Nullable; -import java.io.IOException; - -import com.mojang.authlib.GameProfile; -import forestry.api.core.CamouflageManager; -import forestry.api.core.ICamouflageHandler; -import forestry.api.core.ICamouflagedTile; -import forestry.api.core.IErrorLogic; -import forestry.api.core.IErrorLogicSource; -import forestry.api.multiblock.IGreenhouseComponent; -import forestry.api.multiblock.IMultiblockController; -import forestry.api.multiblock.MultiblockTileEntityBase; -import forestry.core.network.IStreamableGui; -import forestry.core.network.PacketBufferForestry; -import forestry.core.network.packets.CamouflageSelectionType; -import forestry.core.network.packets.PacketCamouflageSelectServer; -import forestry.core.owner.IOwnedTile; -import forestry.core.owner.IOwnerHandler; -import forestry.core.tiles.TileUtil; -import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.NetworkUtil; -import forestry.core.utils.PlayerUtil; -import forestry.greenhouse.blocks.BlockGreenhouse; -import forestry.greenhouse.blocks.BlockGreenhouseType; -import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import net.minecraftforge.items.CapabilityItemHandler; - -public class TileGreenhouseHatch extends MultiblockTileEntityBase implements IGreenhouseComponent, IStreamableGui, IErrorLogicSource, IOwnedTile, ICamouflageHandler, ICamouflagedTile { - - @Nullable - private EnumFacing outwards; - private ItemStack camouflageBlock; - @Nullable - private GameProfile owner; - - public TileGreenhouseHatch() { - super(new MultiblockLogicGreenhouse()); - outwards = null; - camouflageBlock = ItemStack.EMPTY; - } - - @Nullable - public EnumFacing getOutwardsDir() { - return outwards; - } - - @Override - public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) { - world.notifyNeighborsOfStateChange(getPos(), world.getBlockState(pos).getBlock(), false); - markDirty(); - - recalculateOutwardsDirection(minCoord, maxCoord); - } - - @Override - public void onMachineBroken() { - world.notifyNeighborsOfStateChange(getPos(), world.getBlockState(pos).getBlock(), false); - markDirty(); - outwards = null; - } - - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound data) { - super.readFromNBT(data); - - if (data.hasKey("CamouflageBlock")) { - camouflageBlock = new ItemStack(data.getCompoundTag("CamouflageBlock")); - } - - if (data.hasKey("owner")) { - NBTTagCompound ownerNbt = data.getCompoundTag("owner"); - this.owner = PlayerUtil.readGameProfileFromNBT(ownerNbt); - } - } - - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound data) { - data = super.writeToNBT(data); - - if (!camouflageBlock.isEmpty()) { - NBTTagCompound nbtTag = new NBTTagCompound(); - camouflageBlock.writeToNBT(nbtTag); - data.setTag("CamouflageBlock", nbtTag); - } - - if (this.owner != null) { - NBTTagCompound nbt = new NBTTagCompound(); - PlayerUtil.writeGameProfile(nbt, owner); - data.setTag("owner", nbt); - } - - return data; - } - - /* IMultiblockComponent */ - @Nullable - @Override - public final GameProfile getOwner() { - return owner; - } - - public final void setOwner(GameProfile owner) { - this.owner = owner; - } - - /* CONSTRUCTION MATERIAL */ - @Override - public boolean setCamouflageBlock(String type, ItemStack camouflageBlock, boolean sendClientUpdate) { - if (!ItemStackUtil.isIdenticalItem(camouflageBlock, this.camouflageBlock)) { - this.camouflageBlock = camouflageBlock; - - if (sendClientUpdate && world != null && world.isRemote) { - NetworkUtil.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.TILE)); - } - return true; - } - return false; - } - - @Override - public ItemStack getCamouflageBlock(String type) { - return camouflageBlock; - } - - @Override - public ItemStack getDefaultCamouflageBlock(String type) { - return ItemStack.EMPTY; - } - - @Override - public boolean canHandleType(String type) { - return type.equals(getCamouflageType()); - } - - /* IStreamableGui */ - @Override - public void writeGuiData(PacketBufferForestry data) { - getMultiblockLogic().getController().writeGuiData(data); - } - - @Override - @SideOnly(Side.CLIENT) - public void readGuiData(PacketBufferForestry data) throws IOException { - getMultiblockLogic().getController().readGuiData(data); - } - - /* TILEFORESTRY */ - @Override - protected void encodeDescriptionPacket(NBTTagCompound packetData) { - super.encodeDescriptionPacket(packetData); - if (!camouflageBlock.isEmpty()) { - NBTTagCompound nbtTag = new NBTTagCompound(); - camouflageBlock.writeToNBT(nbtTag); - packetData.setTag("CamouflageBlock", nbtTag); - } - } - - @Override - protected void decodeDescriptionPacket(NBTTagCompound packetData) { - super.decodeDescriptionPacket(packetData); - if (packetData.hasKey("CamouflageBlock")) { - setCamouflageBlock(getCamouflageType(), new ItemStack(packetData.getCompoundTag("CamouflageBlock")), true); - } - } - - /* IErrorLogicSource */ - @Override - public IErrorLogic getErrorLogic() { - return getMultiblockLogic().getController().getErrorLogic(); - } - - @Override - public IOwnerHandler getOwnerHandler() { - return getMultiblockLogic().getController().getOwnerHandler(); - } - - @Override - public String getCamouflageType() { - if (getBlockType() instanceof BlockGreenhouse && ((BlockGreenhouse) getBlockType()).getGreenhouseType() == BlockGreenhouseType.GLASS) { - return CamouflageManager.GLASS; - } - return CamouflageManager.BLOCK; - } - - @Nullable - private TileEntity getOutwardsTile() { - if (outwards == null || world == null || pos == null) { - return null; - } - BlockPos offset = getPos().offset(outwards); - return TileUtil.getTile(world, offset); - } - - public void recalculateOutwardsDirection(BlockPos minCoord, BlockPos maxCoord) { - outwards = null; - - int facesMatching = 0; - if (maxCoord.getX() == getPos().getX() || minCoord.getX() == getPos().getX()) { - facesMatching++; - } - if (maxCoord.getY() == getPos().getY() || minCoord.getY() == getPos().getY()) { - facesMatching++; - } - if (maxCoord.getZ() == getPos().getZ() || minCoord.getZ() == getPos().getZ()) { - facesMatching++; - } - if (facesMatching == 1) { - if (maxCoord.getX() == getPos().getX()) { - outwards = EnumFacing.EAST; - } else if (minCoord.getX() == getPos().getX()) { - outwards = EnumFacing.WEST; - } else if (maxCoord.getZ() == getPos().getZ()) { - outwards = EnumFacing.SOUTH; - } else if (minCoord.getZ() == getPos().getZ()) { - outwards = EnumFacing.NORTH; - } else if (maxCoord.getY() == getPos().getY()) { - outwards = EnumFacing.UP; - } else { - outwards = EnumFacing.DOWN; - } - } - - if (((BlockGreenhouse) getBlockType()).getGreenhouseType() != BlockGreenhouseType.HATCH_OUTPUT && outwards != null) { - outwards = outwards.getOpposite(); - } - } - - @Override - @Nullable - public T getCapability(Capability capability, @Nullable EnumFacing facing) { - if (getOutwardsTile() != null) { - if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { - return getOutwardsTile().getCapability(capability, facing); - } - } - return super.getCapability(capability, facing); - } - - @Override - public boolean hasCapability(Capability capability, @Nullable EnumFacing facing) { - if (getOutwardsTile() != null) { - if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { - return getOutwardsTile().hasCapability(capability, facing); - } - } - return super.hasCapability(capability, facing); - } - - @Override - public World getWorldObj() { - return world; - } -} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseNursery.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseNursery.java deleted file mode 100644 index 432d1c3d9..000000000 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseNursery.java +++ /dev/null @@ -1,416 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse.tiles; - -import java.io.IOException; -import java.util.Collections; -import java.util.Random; -import java.util.Set; - -import javax.annotation.Nullable; - -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.api.core.IErrorLogic; -import forestry.api.core.IErrorState; -import forestry.api.genetics.IIndividual; -import forestry.api.lepidopterology.ButterflyManager; -import forestry.api.lepidopterology.IButterfly; -import forestry.api.lepidopterology.IButterflyCocoon; -import forestry.api.lepidopterology.IButterflyGenome; -import forestry.api.multiblock.IGreenhouseComponent; -import forestry.core.errors.EnumErrorCode; -import forestry.core.errors.ErrorLogic; -import forestry.core.inventory.IInventoryAdapter; -import forestry.core.network.IStreamableGui; -import forestry.core.network.PacketBufferForestry; -import forestry.core.tiles.IClimatised; -import forestry.core.utils.ClimateUtil; -import forestry.core.utils.InventoryUtil; -import forestry.energy.EnergyHelper; -import forestry.energy.EnergyManager; -import forestry.greenhouse.gui.ContainerGreenhouseNursery; -import forestry.greenhouse.gui.GuiGreenhouseNursery; -import forestry.greenhouse.inventory.InventoryNursery; -import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; -import forestry.lepidopterology.items.ItemButterflyGE; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ITickable; -import net.minecraft.util.NonNullList; -import net.minecraft.world.biome.Biome; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class TileGreenhouseNursery extends TileGreenhouse implements IGreenhouseComponent.Nursery, IStreamableGui, ITickable, IClimatised { - private static final int WORK_TICK_INTERVAL = 5; // one Forestry work tick happens every WORK_TICK_INTERVAL game ticks - private static final Random rand = new Random(); - private static final int ENERGY_PER_WORK_CYCLE = 3200; - private static final int MATURE_TIME_MULTIPLIER = 250; - private final ButterflyCanSpawnCache butterflyCanSpawnCache = new ButterflyCanSpawnCache(); - private final ErrorLogic errorHandler = new ErrorLogic(); - - private int workCounter; - private int ticksPerWorkCycle; - private int energyPerWorkCycle; - @Nullable - private IButterfly butterfly; - - private int tickCount = rand.nextInt(256); - - // the number of work ticks that this tile has had no power - private int noPowerTime = 0; - - private final InventoryNursery inventory; - - public TileGreenhouseNursery() { - this.inventory = new InventoryNursery(this); - } - - public int getWorkCounter() { - return workCounter; - } - - public void setTicksPerWorkCycle(int ticksPerWorkCycle) { - this.ticksPerWorkCycle = ticksPerWorkCycle; - this.workCounter = 0; - } - - public int getTicksPerWorkCycle() { - return ticksPerWorkCycle; - } - - public void setEnergyPerWorkCycle(int energyPerWorkCycle) { - this.energyPerWorkCycle = EnergyHelper.scaleForDifficulty(energyPerWorkCycle); - } - - public int getEnergyPerWorkCycle() { - return energyPerWorkCycle; - } - - @Override - public IErrorLogic getErrorLogic() { - return errorHandler; - } - - @Override - public void update() { - if(world.isRemote){ - return; - } - tickCount++; - - if (!updateOnInterval(WORK_TICK_INTERVAL)) { - return; - } - - if(!canWork()){ - return; - } - - int ticksPerWorkCycle = getTicksPerWorkCycle(); - if (workCounter >= ticksPerWorkCycle) { - if (workCycle()) { - workCounter = 0; - } - } - } - - protected final boolean updateOnInterval(int tickInterval) { - return tickCount % tickInterval == 0; - } - - protected boolean canWork(){ - moveCocoonToWorkSlot(); - ItemStack butterflyItem = getButterflyItem(); - boolean hasCocoon = !butterflyItem.isEmpty(); - - errorHandler.setCondition(!hasCocoon, EnumErrorCode.NO_RESOURCE_INVENTORY); - if(butterfly == null){ - butterfly = ButterflyManager.butterflyRoot.getMember(butterflyItem); - if(!butterflyItem.isEmpty() && butterfly == null){ - setInventorySlotContents(InventoryNursery.SLOT_WORK, ItemStack.EMPTY); - errorHandler.setCondition(true, EnumErrorCode.NO_RESOURCE_INVENTORY); - return false; - } - } - - int ticksPerWorkCycle = getTicksPerWorkCycle(); - - if (workCounter < ticksPerWorkCycle) { - EnergyManager energyManager = getMultiblockLogic().getController().getEnergyManager(); - if(energyManager == null){ - return false; - } - - int energyPerWorkCycle = getEnergyPerWorkCycle(); - - boolean consumedEnergy = EnergyHelper.consumeEnergyToDoWork(energyManager, ticksPerWorkCycle, energyPerWorkCycle); - if (consumedEnergy) { - errorHandler.setCondition(false, EnumErrorCode.NO_POWER); - workCounter++; - noPowerTime = 0; - if(workCounter >= ticksPerWorkCycle){ - butterflyCanSpawnCache.clear(); - } - } else { - noPowerTime++; - if (noPowerTime > 4) { - errorHandler.setCondition(true, EnumErrorCode.NO_POWER); - } - } - } - - if(butterfly == null){ - return hasCocoon; - } - Set butterflyErrors = butterflyCanSpawnCache.butterflyCanSpawn(butterfly, this); - for (IErrorState errorState : butterflyErrors) { - errorHandler.setCondition(true, errorState); - } - return !errorHandler.hasErrors(); - } - - protected boolean workCycle(){ - if(butterfly != null){ - if(canSpawnButterfly()){ - IGreenhouseControllerInternal controller = getMultiblockLogic().getController(); - if(controller.spawnButterfly(this)){ - setInventorySlotContents(InventoryNursery.SLOT_WORK, ItemStack.EMPTY); - setTicksPerWorkCycle(1); - setEnergyPerWorkCycle(0); - butterfly = null; - butterflyCanSpawnCache.clear(); - } - return false; - } else { - ItemStack stack = getButterflyItem(); - int age = getAge(); - int caterpillarMatureTime = getCaterpillarMatureTime(); - age++; - ItemButterflyGE.setAge(stack, age); - setTicksPerWorkCycle(caterpillarMatureTime); - setEnergyPerWorkCycle(ENERGY_PER_WORK_CYCLE); - } - } - return true; - } - - public boolean canSpawnButterfly(){ - int age = getAge(); - return age > 2 && butterfly != null; - } - - private int getCaterpillarMatureTime(){ - IButterflyGenome genome = butterfly.getGenome(); - float matureTime = genome.getLifespan() / (genome.getFertility() * 2); - matureTime*=MATURE_TIME_MULTIPLIER; - return Math.round(matureTime); - } - - private void moveCocoonToWorkSlot() { - if (!getStackInSlot(InventoryNursery.SLOT_WORK).isEmpty()) { - return; - } - - Integer slotIndex = getInputSlotIndex(); - if (slotIndex == null) { - return; - } - - ItemStack inputStack = inventory.getStackInSlot(slotIndex); - if (inputStack.isEmpty()) { - return; - } - - ItemStack stack = inputStack.copy(); - stack.setCount(1); - inputStack.shrink(1); - setInventorySlotContents(InventoryNursery.SLOT_WORK, stack); - if(inputStack.isEmpty()){ - inventory.setInventorySlotContents(slotIndex, ItemStack.EMPTY); - } - butterfly = ButterflyManager.butterflyRoot.getMember(stack); - int caterpillarMatureTime = getCaterpillarMatureTime(); - setTicksPerWorkCycle(caterpillarMatureTime); - setEnergyPerWorkCycle(ENERGY_PER_WORK_CYCLE); - } - - @Nullable - private Integer getInputSlotIndex() { - for (int slotIndex = 0; slotIndex < InventoryNursery.SLOT_INPUT_COUNT; slotIndex++) { - ItemStack inputStack = inventory.getStackInSlot(InventoryNursery.SLOT_INPUT_1 + slotIndex); - if (!inputStack.isEmpty()) { - return InventoryNursery.SLOT_INPUT_1 + slotIndex; - } - } - return null; - } - - private ItemStack getButterflyItem(){ - return getStackInSlot(InventoryNursery.SLOT_WORK); - } - - public int getAge(){ - ItemStack cocoon = getButterflyItem(); - if(cocoon.isEmpty() || !cocoon.hasTagCompound()){ - return -1; - } - return cocoon.getTagCompound().getInteger(ItemButterflyGE.NBT_AGE); - } - - public int getProgressScaled(int i) { - int ticksPerWorkCycle = getTicksPerWorkCycle(); - if (ticksPerWorkCycle == 0) { - return 0; - } - - return workCounter * i / ticksPerWorkCycle; - } - - @Override - public void writeGuiData(PacketBufferForestry data) { - super.writeGuiData(data); - data.writeVarInt(workCounter); - data.writeVarInt(getTicksPerWorkCycle()); - } - - @Override - @SideOnly(Side.CLIENT) - public void readGuiData(PacketBufferForestry data) throws IOException { - super.readGuiData(data); - workCounter = data.readVarInt(); - ticksPerWorkCycle = data.readVarInt(); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound data) { - super.writeToNBT(data); - data.setInteger("workCounter", workCounter); - data.setInteger("ticksPerWorkCycle", ticksPerWorkCycle); - data.setInteger("energyPerWorkCycle", energyPerWorkCycle); - return data; - } - - @Override - public void readFromNBT(NBTTagCompound data) { - super.readFromNBT(data); - workCounter = data.getInteger("workCounter"); - ticksPerWorkCycle = data.getInteger("ticksPerWorkCycle"); - energyPerWorkCycle = data.getInteger("energyPerWorkCycle"); - } - - @Override - public void addCocoonLoot(IButterflyCocoon cocoon, NonNullList cocoonDrops) { - for (ItemStack drop : cocoonDrops) { - InventoryUtil.tryAddStack(this, drop, InventoryNursery.SLOT_OUTPUT_1, InventoryNursery.SLOT_OUTPUT_COUNT, true); - } - } - - /* IGuiHandlerTile */ - @Override - @SideOnly(Side.CLIENT) - public GuiContainer getGui(EntityPlayer player, int data) { - return new GuiGreenhouseNursery(player, this); - } - - @Override - public Container getContainer(EntityPlayer player, int data) { - return new ContainerGreenhouseNursery(player.inventory, this); - } - - /* ITitled */ - @Override - public String getUnlocalizedTitle() { - return "for.gui.greenhouse.nursery.title"; - } - - @Override - public IInventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - public IButterfly getCaterpillar() { - return butterfly; - } - - @Nullable - @Override - public IIndividual getNanny() { - return null; - } - - @Override - public void setCaterpillar(IButterfly caterpillar) { - } - - @Override - public boolean canNurse(IButterfly caterpillar) { - return false; - } - - @Override - public Biome getBiome() { - return world.getBiome(pos); - } - - @Override - public EnumTemperature getTemperature() { - return EnumTemperature.getFromBiome(getBiome(), world, pos); - } - - @Override - public EnumHumidity getHumidity() { - return EnumHumidity.getFromValue(ClimateUtil.getHumidity(world, pos)); - } - - @Override - public float getExactHumidity() { - return ClimateUtil.getHumidity(world, pos); - } - - @Override - public float getExactTemperature() { - return ClimateUtil.getTemperature(world, pos); - } - - private static class ButterflyCanSpawnCache { - private static final int ticksPerCheckButterflyCanSpawn = 10; - - private Set butterflyCanSpawnCached = Collections.emptySet(); - private int butterflzCanSpawnCooldown = 0; - - public Set butterflyCanSpawn(IButterfly butterfly, TileGreenhouseNursery nursery) { - if (butterflzCanSpawnCooldown <= 0) { - if(nursery.canSpawnButterfly()){ - butterflyCanSpawnCached = butterfly.getCanSpawn(nursery, null); - }else{ - butterflyCanSpawnCached = butterfly.getCanGrow(nursery, null); - } - butterflzCanSpawnCooldown = ticksPerCheckButterflyCanSpawn; - } else { - butterflzCanSpawnCooldown--; - } - - return butterflyCanSpawnCached; - } - - public void clear() { - butterflyCanSpawnCached.clear(); - butterflzCanSpawnCooldown = 0; - } - } - -} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhousePlain.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhousePlain.java index faa72c872..8884f544d 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhousePlain.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhousePlain.java @@ -10,5 +10,44 @@ ******************************************************************************/ package forestry.greenhouse.tiles; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import forestry.api.multiblock.IGreenhouseController; +import forestry.api.multiblock.IMultiblockController; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockGreenhouse; +import forestry.greenhouse.blocks.BlockGreenhouseType; + public class TileGreenhousePlain extends TileGreenhouse { + @Override + public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) { + super.onMachineAssembled(multiblockController, minCoord, maxCoord); + + IGreenhouseController greenhouseController = (IGreenhouseController) multiblockController; + + // set border block state + int bandY = maxCoord.getY(); + if (getPos().getY() == bandY) { + BlockGreenhouseType type = BlockGreenhouseType.BORDER; + if (getPos().equals(greenhouseController.getCenterCoordinates())) { + type = BlockGreenhouseType.BORDER_CENTER; + } + this.world.setBlockState(getPos(), PluginGreenhouse.getBlocks().greenhouseBlock.getDefaultState().withProperty(BlockGreenhouse.TYPE, type), 2); + } + } + + @Override + public void onMachineBroken() { + super.onMachineBroken(); + + // set border block state back to normal + this.world.setBlockState(getPos(), PluginGreenhouse.getBlocks().greenhouseBlock.getDefaultState().withProperty(BlockGreenhouse.TYPE, BlockGreenhouseType.PLAIN), 2); + } + + @Override + public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { + return oldState.getBlock() != newSate.getBlock(); + } } diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseFan.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseScreen.java similarity index 56% rename from src/main/java/forestry/greenhouse/tiles/TileGreenhouseFan.java rename to src/main/java/forestry/greenhouse/tiles/TileGreenhouseScreen.java index 659e4c1d0..32c947cec 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseFan.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseScreen.java @@ -10,17 +10,8 @@ ******************************************************************************/ 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 TileGreenhouseScreen extends TileGreenhouse { -public class TileGreenhouseFan extends TileGreenhouseClimatiser { - - private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5F, EnumClimatiserTypes.TEMPERATURE); - - public TileGreenhouseFan() { - super(DEFINITION); + public TileGreenhouseScreen() { } - } diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseValve.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseValve.java deleted file mode 100644 index 5d86cd910..000000000 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseValve.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse.tiles; - -import javax.annotation.Nullable; - -import forestry.core.fluids.ITankManager; -import forestry.core.tiles.ILiquidTankTile; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; - -public class TileGreenhouseValve extends TileGreenhouse implements ILiquidTankTile { - - @Override - public ITankManager getTankManager() { - return getMultiblockLogic().getController().getTankManager(); - } - - @Override - public boolean hasCapability(Capability capability, @Nullable EnumFacing facing) { - if (super.hasCapability(capability, facing)) { - return true; - } - return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY; - } - - @Override - @Nullable - public T getCapability(Capability capability, @Nullable EnumFacing facing) { - if (super.hasCapability(capability, facing)) { - return super.getCapability(capability, facing); - } - if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { - return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(getTankManager()); - } - return null; - } -} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseWindow.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseWindow.java index 65717f7fb..c41bd4d6f 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseWindow.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseWindow.java @@ -12,26 +12,85 @@ package forestry.greenhouse.tiles; import javax.annotation.Nullable; -import forestry.api.climate.EnumClimatiserModes; -import forestry.api.climate.EnumClimatiserTypes; -import forestry.api.climate.IClimatiserDefinition; -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.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; -public class TileGreenhouseWindow extends TileGreenhouseClimatiser { +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.IClimateSource; +import forestry.api.climate.IClimateSourceOwner; +import forestry.apiculture.network.packets.PacketActiveUpdate; +import forestry.core.tiles.IActivatable; +import forestry.core.utils.NetworkUtil; +import forestry.greenhouse.blocks.BlockGreenhouseWindow; +import forestry.greenhouse.climate.ClimateSourceWindow; + +public class TileGreenhouseWindow extends TileEntity implements IActivatable, IClimateSourceOwner { + private final ClimateSourceWindow source; @Nullable private WindowMode mode; - private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.001F, EnumClimatiserModes.BOTH, 5F, EnumClimatiserTypes.BOTH); + private String glass; + private boolean active; public TileGreenhouseWindow() { - super(DEFINITION, new GreenhouseClimateWindow(20)); + source = new ClimateSourceWindow(0.05F, 5F); + source.setOwner(this); + glass = "glass"; + } + + @Override + public IClimateSource getClimateSource() { + return source; + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack getItemStack() { + return ((BlockGreenhouseWindow) getBlockType()).getItem(glass); + } + + @Override + public boolean isCircuitable() { + return false; + } + + @Override + public BlockPos getCoordinates() { + return pos; + } + + /* IActivatable */ + @Override + public boolean isActive() { + return active; + } + + @Override + public void setActive(boolean active) { + if (this.active == active) { + return; + } + + this.active = active; + + if (world != null) { + if (world.isRemote) { + world.markBlockRangeForRenderUpdate(getCoordinates(), getCoordinates()); + } else { + NetworkUtil.sendNetworkPacket(new PacketActiveUpdate(this), getCoordinates(), world); + } + } + } + + @Override + public World getWorldObj() { + return world; } public void onNeighborBlockChange() { @@ -50,55 +109,59 @@ public class TileGreenhouseWindow extends TileGreenhouseClimatiser { } IBlockState state = world.getBlockState(pos); BlockPos blockedPos; - if (state.getBlock() == PluginGreenhouse.getBlocks().getGreenhouseBlock(BlockGreenhouseType.WINDOW_UP)) { + if (((BlockGreenhouseWindow) state.getBlock()).isRoofWindow()) { blockedPos = getCoordinates().offset(EnumFacing.UP); } else { - blockedPos = getCoordinates().offset(state.getValue(BlockGreenhouse.FACING)); + blockedPos = getCoordinates().offset(state.getValue(BlockGreenhouseWindow.FACING)); } return world.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")]); + if (data.hasKey("Glass")) { + glass = data.getString("Glass"); } } @Override - protected void encodeDescriptionPacket(NBTTagCompound packetData) { + public NBTTagCompound writeToNBT(NBTTagCompound data) { if (mode != null) { - packetData.setShort("mode", (short) mode.ordinal()); + data.setShort("mode", (short) mode.ordinal()); } - super.encodeDescriptionPacket(packetData); + if (glass != null) { + data.setString("Glass", glass); + } + return super.writeToNBT(data); } @Override - public boolean canWork() { - return true; + public NBTTagCompound getUpdateTag() { + NBTTagCompound data = super.getUpdateTag(); + if (mode != null) { + data.setShort("mode", (short) mode.ordinal()); + } + if (glass != null) { + data.setString("Glass", glass); + } + return data; } - public void setMode(WindowMode mode) { - this.mode = mode; - setActive(mode == WindowMode.OPEN); + @Override + public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { + return oldState.getBlock() != newSate.getBlock(); + } + + public String getGlass() { + return glass; + } + + public void setGlass(String glass) { + this.glass = glass; } @Nullable @@ -106,6 +169,11 @@ public class TileGreenhouseWindow extends TileGreenhouseClimatiser { return mode; } + public void setMode(WindowMode mode) { + this.mode = mode; + setActive(mode == WindowMode.OPEN); + } + public enum WindowMode { PLAYER, BLOCK, CONTROL, OPEN } diff --git a/src/main/java/forestry/greenhouse/tiles/TileHeater.java b/src/main/java/forestry/greenhouse/tiles/TileHeater.java new file mode 100644 index 000000000..41037bab1 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileHeater.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 net.minecraft.item.ItemStack; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.ClimateType; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockClimatiserType; + +public class TileHeater extends TileClimatiser { + + public TileHeater() { + super(0.075F, 5F, ClimateType.TEMPERATURE); + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack getItemStack() { + return new ItemStack(PluginGreenhouse.getBlocks().climatiserBlock, 1, BlockClimatiserType.HEATER.ordinal()); + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileHumidifier.java b/src/main/java/forestry/greenhouse/tiles/TileHumidifier.java new file mode 100644 index 000000000..507cb0c07 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileHumidifier.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 net.minecraft.item.ItemStack; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.climate.ClimateType; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockClimatiserType; + +public class TileHumidifier extends TileClimatiser { + + public TileHumidifier() { + super(0.075F, 5F, ClimateType.HUMIDITY); + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack getItemStack() { + return new ItemStack(PluginGreenhouse.getBlocks().climatiserBlock, 1, BlockClimatiserType.HUMIDIFIER.ordinal()); + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileHygroregulator.java b/src/main/java/forestry/greenhouse/tiles/TileHygroregulator.java new file mode 100644 index 000000000..285e6c64c --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileHygroregulator.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * 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 javax.annotation.Nullable; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; + +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.config.Constants; +import forestry.core.fluids.FilteredTank; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; +import forestry.core.fluids.TankManager; +import forestry.core.recipes.HygroregulatorRecipe; +import forestry.core.tiles.ILiquidTankTile; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockClimatiserType; +import forestry.greenhouse.climate.ClimateSourceHygroregulator; +import forestry.greenhouse.gui.ContainerHygroregulator; +import forestry.greenhouse.gui.GuiHygroregulator; +import forestry.greenhouse.inventory.InventoryHygroregulator; + +public class TileHygroregulator extends TileClimatiser implements ILiquidTankTile { + + private final HygroregulatorRecipe[] recipes; + + private final TankManager tankManager; + private final FilteredTank liquidTank; + + public TileHygroregulator() { + super(new ClimateSourceHygroregulator(5F)); + + setInternalInventory(new InventoryHygroregulator(this)); + + Fluid water = FluidRegistry.WATER; + Fluid lava = FluidRegistry.LAVA; + Fluid liquidIce = Fluids.ICE.getFluid(); + + this.liquidTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY).setFilters(water, lava, liquidIce); + + this.tankManager = new TankManager(this, liquidTank); + + this.recipes = new HygroregulatorRecipe[]{new HygroregulatorRecipe(new FluidStack(water, 1), 1, 0.05f, -0.005f), + new HygroregulatorRecipe(new FluidStack(lava, 1), 10, -0.05f, +0.005f), + new HygroregulatorRecipe(new FluidStack(liquidIce, 1), 10, 0.075f, -0.01f)}; + } + + public FilteredTank getLiquidTank() { + return liquidTank; + } + + @Override + protected void updateServerSide() { + if (updateOnInterval(20)) { + // Check if we have suitable items waiting in the item slot + FluidHelper.drainContainers(tankManager, this, 0); + } + } + + /* SAVING & LOADING */ + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + tankManager.readFromNBT(nbttagcompound); + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { + nbttagcompound = super.writeToNBT(nbttagcompound); + tankManager.writeToNBT(nbttagcompound); + return nbttagcompound; + } + + /* ITitled */ + @Override + public String getUnlocalizedTitle() { + return "for.gui.greenhouse.hygroregulator.title"; + } + + @Override + @SideOnly(Side.CLIENT) + public GuiContainer getGui(EntityPlayer player, int data) { + return new GuiHygroregulator(player.inventory, this); + } + + @Override + public Container getContainer(EntityPlayer player, int data) { + return new ContainerHygroregulator(player.inventory, this); + } + + /* UPDATING */ + @Nullable + public HygroregulatorRecipe getRecipe(FluidStack liquid) { + HygroregulatorRecipe recipe = null; + for (HygroregulatorRecipe rec : recipes) { + if (rec.liquid.isFluidEqual(liquid)) { + recipe = rec; + break; + } + } + return recipe; + } + + /* ILIQUIDTANKCONTAINER */ + @Override + public TankManager getTankManager() { + return tankManager; + } + + @Override + @Nullable + public T getCapability(Capability capability, @Nullable EnumFacing facing) { + if (super.hasCapability(capability, facing)) { + return super.getCapability(capability, facing); + } + if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { + return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager); + } + return null; + } + + @Override + public boolean hasCapability(Capability capability, @Nullable EnumFacing facing) { + return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || + super.hasCapability(capability, facing); + } + + public HygroregulatorRecipe[] getRecipes() { + return recipes; + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack getItemStack() { + return new ItemStack(PluginGreenhouse.getBlocks().climatiserBlock, 1, BlockClimatiserType.HYGRO.ordinal()); + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/package-info.java b/src/main/java/forestry/greenhouse/tiles/package-info.java index fe9fd54ee..a784253f4 100644 --- a/src/main/java/forestry/greenhouse/tiles/package-info.java +++ b/src/main/java/forestry/greenhouse/tiles/package-info.java @@ -6,4 +6,5 @@ package forestry.greenhouse.tiles; import javax.annotation.ParametersAreNonnullByDefault; import forestry.core.utils.FieldsAreNonnullByDefault; + import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/lepidopterology/blocks/BlockButterflyNursery.java b/src/main/java/forestry/lepidopterology/blocks/BlockButterflyNursery.java new file mode 100644 index 000000000..be7baa1f7 --- /dev/null +++ b/src/main/java/forestry/lepidopterology/blocks/BlockButterflyNursery.java @@ -0,0 +1,5 @@ +package forestry.lepidopterology.blocks; + +public class BlockButterflyNursery { + +} diff --git a/src/main/java/forestry/lepidopterology/genetics/Butterfly.java b/src/main/java/forestry/lepidopterology/genetics/Butterfly.java index 7af598ec4..35ae40867 100755 --- a/src/main/java/forestry/lepidopterology/genetics/Butterfly.java +++ b/src/main/java/forestry/lepidopterology/genetics/Butterfly.java @@ -226,9 +226,10 @@ public class Butterfly extends IndividualLiving implements IButterfly { } private boolean isAcceptedEnvironment(World world, int x, int y, int z) { - Biome biome = world.getBiome(new BlockPos(x, y, z)); - EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, world, new BlockPos(x, y, z)); - EnumHumidity biomeHumidity = EnumHumidity.getFromValue(ClimateUtil.getHumidity(world, new BlockPos(x, y, z))); + BlockPos pos = new BlockPos(x, y, z); + Biome biome = world.getBiome(pos); + EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, world, pos); + EnumHumidity biomeHumidity = EnumHumidity.getFromValue(ClimateUtil.getHumidity(world, pos)); return AlleleManager.climateHelper.isWithinLimits(biomeTemperature, biomeHumidity, getGenome().getPrimary().getTemperature(), getGenome().getToleranceTemp(), getGenome().getPrimary().getHumidity(), getGenome().getToleranceHumid()); diff --git a/src/main/java/forestry/lepidopterology/tiles/TileCocoon.java b/src/main/java/forestry/lepidopterology/tiles/TileCocoon.java index 5dc974cf1..0d81306a5 100644 --- a/src/main/java/forestry/lepidopterology/tiles/TileCocoon.java +++ b/src/main/java/forestry/lepidopterology/tiles/TileCocoon.java @@ -10,37 +10,11 @@ ******************************************************************************/ package forestry.lepidopterology.tiles; -import javax.annotation.Nullable; -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - import com.google.common.base.Preconditions; -import forestry.api.genetics.IAllele; -import forestry.api.greenhouse.GreenhouseManager; -import forestry.api.lepidopterology.ButterflyManager; -import forestry.api.lepidopterology.IButterfly; -import forestry.api.lepidopterology.IButterflyCocoon; -import forestry.api.lepidopterology.IButterflyGenome; -import forestry.api.multiblock.IGreenhouseComponent; -import forestry.api.multiblock.IGreenhouseComponent.Nursery; -import forestry.api.multiblock.IGreenhouseController; -import forestry.api.multiblock.IMultiblockComponent; -import forestry.core.network.IStreamable; -import forestry.core.network.PacketBufferForestry; -import forestry.core.network.packets.PacketTileStream; -import forestry.core.owner.IOwnedTile; -import forestry.core.owner.IOwnerHandler; -import forestry.core.owner.OwnerHandler; -import forestry.core.utils.ItemStackUtil; -import forestry.core.utils.Log; -import forestry.core.utils.NBTUtilForestry; -import forestry.core.utils.NetworkUtil; -import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; -import forestry.lepidopterology.genetics.Butterfly; -import forestry.lepidopterology.genetics.ButterflyDefinition; +import javax.annotation.Nullable; +import java.io.IOException; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLiving; @@ -52,9 +26,28 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.api.genetics.IAllele; +import forestry.api.lepidopterology.ButterflyManager; +import forestry.api.lepidopterology.IButterfly; +import forestry.api.lepidopterology.IButterflyCocoon; +import forestry.api.lepidopterology.IButterflyGenome; +import forestry.core.network.IStreamable; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.packets.PacketTileStream; +import forestry.core.owner.IOwnedTile; +import forestry.core.owner.IOwnerHandler; +import forestry.core.owner.OwnerHandler; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.Log; +import forestry.core.utils.NBTUtilForestry; +import forestry.core.utils.NetworkUtil; +import forestry.lepidopterology.genetics.Butterfly; +import forestry.lepidopterology.genetics.ButterflyDefinition; + public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, IButterflyCocoon { private final OwnerHandler ownerHandler = new OwnerHandler(); private int age; @@ -181,12 +174,6 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I world.notifyBlockUpdate(pos, blockState, blockState, 0); } else if (caterpillar.canTakeFlight(world, getPos().getX(), getPos().getY(), getPos().getZ())) { NonNullList cocoonDrops = caterpillar.getCocoonDrop(this); - for(IGreenhouseComponent.Nursery nursery : getNursery(world, pos)){ - nursery.addCocoonLoot(this, cocoonDrops); - if(isListEmpty(cocoonDrops)){ - break; - } - } for (ItemStack drop : cocoonDrops) { ItemStackUtil.dropItemStackAsEntity(drop, world, pos); } @@ -195,28 +182,6 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, I } } } - - private Set getNursery(World world, BlockPos pos) { - if (GreenhouseManager.greenhouseHelper == null) { - return Collections.emptySet(); - } - IGreenhouseController controller = GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos); - if (controller != null) { - Set nurserys; - if (controller instanceof IGreenhouseControllerInternal) { - nurserys = ((IGreenhouseControllerInternal) controller).getButterflyNurserys(); - }else{ - nurserys = new HashSet<>(); - for (IMultiblockComponent greenhouseComponent : controller.getComponents()) { - if (greenhouseComponent instanceof Nursery) { - nurserys.add((Nursery) greenhouseComponent); - } - } - } - return nurserys; - } - return Collections.emptySet(); - } private boolean isListEmpty(NonNullList cocoonDrops){ if(cocoonDrops.isEmpty()){ diff --git a/src/main/java/forestry/plugins/ForestryPluginUids.java b/src/main/java/forestry/plugins/ForestryPluginUids.java index b9b9b66c0..7da9fa8b9 100644 --- a/src/main/java/forestry/plugins/ForestryPluginUids.java +++ b/src/main/java/forestry/plugins/ForestryPluginUids.java @@ -28,4 +28,8 @@ public class ForestryPluginUids { public static final String ACT_ADD = "forestry.actuallyadditions"; public static final String HARVESTCRAFT = "forestry.harvestcraft"; public static final String IMMERSIVE_ENGINEERING = "forestry.immersiveengineering"; + public static final String MAGICAL_AGRICULTURE = "forestry.mysticalagriculture"; + public static final String RUSTIC = "forestry.rustic"; + public static final String ROOTS = "forestry.roots"; + public static final String BETTER_WITH_MODS = "forestry.betterwithmods"; } diff --git a/src/main/java/forestry/plugins/compat/CompatPlugin.java b/src/main/java/forestry/plugins/compat/CompatPlugin.java new file mode 100644 index 000000000..6aef1face --- /dev/null +++ b/src/main/java/forestry/plugins/compat/CompatPlugin.java @@ -0,0 +1,82 @@ +package forestry.plugins.compat; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import forestry.core.utils.Log; +import forestry.core.utils.ModUtil; +import forestry.plugins.BlankForestryPlugin; + +public abstract class CompatPlugin extends BlankForestryPlugin { + + protected final String modName; + protected final String modID; + + public CompatPlugin(String modName, String modID) { + this.modName = modName; + this.modID = modID; + } + + @Override + public final boolean isAvailable() { + return ModUtil.isModLoaded(modID); + } + + @Override + public final String getFailMessage() { + return modName + " not found"; + } + + @Nullable + protected ItemStack getItemStack(@Nonnull String itemName) { + return getItemStack(itemName, 0); + } + + @Nullable + protected ItemStack getItemStack(@Nonnull String itemName, int meta) { + Item item = getItem(itemName); + if (item == null) { + return null; + } + return new ItemStack(item, 1, meta); + } + + @Nullable + protected Block getBlock(@Nonnull String blockName) { + ResourceLocation key = new ResourceLocation(modID, blockName); + if (ForgeRegistries.BLOCKS.containsKey(key)) { + return ForgeRegistries.BLOCKS.getValue(key); + } + Log.error("Could not find block {}", key); + return null; + } + + @Nullable + protected Item getItem(String itemName) { + ResourceLocation key = new ResourceLocation(modID, itemName); + if (ForgeRegistries.ITEMS.containsKey(key)) { + return ForgeRegistries.ITEMS.getValue(key); + } + Log.error("Could not find item {}", key); + return null; + } + + @Nullable + protected Fluid getFluid(String fluidName) { + Fluid fluid = FluidRegistry.getFluid(fluidName); + if (fluid == null) { + Log.error("Could not find fluid {}", fluidName); + } + return fluid; + } +} diff --git a/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java b/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java index 70ef2953a..2af5f2d04 100644 --- a/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java +++ b/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java @@ -3,39 +3,28 @@ package forestry.plugins.compat; import javax.annotation.Nullable; import java.util.Arrays; -import forestry.api.core.ForestryAPI; -import forestry.api.recipes.RecipeManagers; -import forestry.core.fluids.Fluids; -import forestry.core.utils.Log; -import forestry.core.utils.ModUtil; -import forestry.farming.FarmRegistry; -import forestry.farming.logic.FarmableAgingCrop; -import forestry.plugins.BlankForestryPlugin; -import forestry.plugins.ForestryPlugin; -import forestry.plugins.ForestryPluginUids; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; + import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import forestry.api.core.ForestryAPI; +import forestry.api.recipes.RecipeManagers; +import forestry.core.fluids.Fluids; +import forestry.farming.logic.FarmableAgingCrop; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; @ForestryPlugin(pluginID = ForestryPluginUids.ACT_ADD, name = "Actually Additions", author = "Ellpeck", url = "http://ellpeck.de/actadd", unlocalizedDescription = "for.plugin.actuallyadditions.description") -public class PluginActuallyAdditions extends BlankForestryPlugin { +public class PluginActuallyAdditions extends CompatPlugin { private static final String ACT_ADD = "actuallyadditions"; - @Override - public boolean isAvailable() { - return ModUtil.isModLoaded(ACT_ADD); - } - - @Override - public String getFailMessage() { - return "Actually Additions not found!"; + public PluginActuallyAdditions() { + super("Actually Additions", ACT_ADD); } @Override @@ -79,46 +68,15 @@ public class PluginActuallyAdditions extends BlankForestryPlugin { } } - private static void registerSeedPlant(@Nullable Item seedItem, String blockName) { + private void registerSeedPlant(@Nullable Item seedItem, String blockName) { if (seedItem != null) { Block plantBlock = getBlock(blockName); if (plantBlock != null) { FarmableAgingCrop crop = new FarmableAgingCrop(new ItemStack(seedItem), plantBlock, BlockCrops.AGE, 7); - FarmRegistry.getInstance().registerFarmables("farmWheat", crop); + ForestryAPI.farmRegistry.registerFarmables("farmWheat", crop); FarmableAgingCrop cropOrchard = new FarmableAgingCrop(new ItemStack(seedItem), plantBlock, BlockCrops.AGE, 7, 0); - FarmRegistry.getInstance().registerFarmables("farmOrchard", cropOrchard); + ForestryAPI.farmRegistry.registerFarmables("farmOrchard", cropOrchard); } } } - - @Nullable - private static Fluid getFluid(String fluidName) { - Fluid fluid = FluidRegistry.getFluid(fluidName); - if (fluid == null) { - Log.error("Could not find fluid {}", fluidName); - } - return fluid; - } - - @Nullable - private static Block getBlock(String blockName) { - ResourceLocation key = new ResourceLocation(ACT_ADD, blockName); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - return ForgeRegistries.BLOCKS.getValue(key); - } else { - Log.error("Could not find {}", key); - return null; - } - } - - @Nullable - private static Item getItem(String itemName) { - ResourceLocation key = new ResourceLocation(ACT_ADD, itemName); - if (ForgeRegistries.ITEMS.containsKey(key)) { - return ForgeRegistries.ITEMS.getValue(key); - } else { - Log.error("Could not find {}", key); - return null; - } - } } diff --git a/src/main/java/forestry/plugins/compat/PluginBetterWithMods.java b/src/main/java/forestry/plugins/compat/PluginBetterWithMods.java new file mode 100644 index 000000000..9ccc16281 --- /dev/null +++ b/src/main/java/forestry/plugins/compat/PluginBetterWithMods.java @@ -0,0 +1,46 @@ +package forestry.plugins.compat; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockCrops; +import net.minecraft.block.properties.PropertyBool; +import net.minecraft.block.properties.PropertyInteger; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; + +import forestry.api.core.ForestryAPI; +import forestry.api.farming.IFarmRegistry; +import forestry.api.recipes.RecipeManagers; +import forestry.core.config.Constants; +import forestry.core.fluids.Fluids; +import forestry.farming.logic.FarmableDoubleCrop; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; + +@ForestryPlugin(pluginID = ForestryPluginUids.BETTER_WITH_MODS, name = "Better With Mods", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.plugin.betterwithmods.description") +public class PluginBetterWithMods extends CompatPlugin { + public PluginBetterWithMods() { + super("Better With Mods", "betterwithmods"); + } + + @Override + public void registerRecipes() { + IFarmRegistry farmRegistry = ForestryAPI.farmRegistry; + int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + PropertyBool TOP = PropertyBool.create("top"); + PropertyInteger AGE = BlockCrops.AGE; + ItemStack hempSeed = getItemStack("hemp"); + Block hempCrop = getBlock("hemp"); + + if (hempSeed != null && hempCrop != null) { + IBlockState defaultState = hempCrop.getDefaultState(); + IBlockState planted = defaultState.withProperty(AGE, 0).withProperty(TOP, false); + IBlockState mature = defaultState.withProperty(AGE, 7).withProperty(TOP, false); + IBlockState topMature = defaultState.withProperty(AGE, 7).withProperty(TOP, true); + + farmRegistry.registerFarmables("farmWheat", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, false)); + farmRegistry.registerFarmables("farmOrchard", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, true)); + + RecipeManagers.squeezerManager.addRecipe(10, hempSeed, Fluids.SEED_OIL.getFluid(seedAmount)); + } + } +} diff --git a/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java b/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java index 83407b81a..ee9074803 100644 --- a/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java +++ b/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java @@ -12,6 +12,16 @@ package forestry.plugins.compat; import java.util.Collections; +import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.fml.common.registry.ForgeRegistries; + import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuitLayout; import forestry.api.core.ForestryAPI; @@ -23,21 +33,12 @@ import forestry.core.items.EnumElectronTube; import forestry.core.utils.BlockUtil; import forestry.core.utils.Log; import forestry.core.utils.ModUtil; -import forestry.farming.FarmRegistry; import forestry.farming.circuits.CircuitFarmLogic; import forestry.farming.logic.FarmLogicEnder; import forestry.farming.logic.FarmableAgingCrop; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; import forestry.plugins.ForestryPluginUids; -import net.minecraft.block.Block; -import net.minecraft.block.properties.IProperty; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.registry.ForgeRegistries; @ForestryPlugin(pluginID = ForestryPluginUids.EXTRA_UTILITIES, name = "ExtraUtilities", author = "Nirek", url = Constants.URL, unlocalizedDescription = "for.plugin.extrautilities.description") public class PluginExtraUtilities extends BlankForestryPlugin { @@ -72,7 +73,7 @@ public class PluginExtraUtilities extends BlankForestryPlugin { } else { int harvestAge = Collections.max(growthProperty.getAllowedValues()); int replantAge = enderLillyBlock.getDefaultState().getValue(growthProperty); - FarmRegistry.getInstance().registerFarmables("farmEnder", new FarmableAgingCrop(new ItemStack(enderLillyItem), enderLillyBlock, growthProperty, harvestAge, replantAge)); + ForestryAPI.farmRegistry.registerFarmables("farmEnder", new FarmableAgingCrop(new ItemStack(enderLillyItem), enderLillyBlock, growthProperty, harvestAge, replantAge)); Circuits.farmEnderManaged = new CircuitFarmLogic("managedEnder", new FarmLogicEnder()); } } diff --git a/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java b/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java index 20da60637..10ce970e8 100644 --- a/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java +++ b/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java @@ -10,9 +10,13 @@ ******************************************************************************/ package forestry.plugins.compat; -import javax.annotation.Nullable; - import com.google.common.collect.ImmutableList; + +import net.minecraft.block.Block; +import net.minecraft.block.properties.PropertyInteger; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + import forestry.api.core.ForestryAPI; import forestry.api.farming.IFarmRegistry; import forestry.api.fuels.FuelManager; @@ -24,52 +28,17 @@ import forestry.core.config.Constants; import forestry.core.fluids.Fluids; import forestry.core.items.ItemRegistryCore; import forestry.core.recipes.RecipeUtil; -import forestry.core.utils.ModUtil; -import forestry.farming.FarmRegistry; import forestry.farming.logic.FarmableAgingCrop; -import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; import forestry.plugins.ForestryPluginUids; -import net.minecraft.block.Block; -import net.minecraft.block.properties.PropertyInteger; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.registry.ForgeRegistries; @ForestryPlugin(pluginID = ForestryPluginUids.HARVESTCRAFT, name = "HarvestCraft", author = "Nirek", url = Constants.URL, unlocalizedDescription = "for.plugin.harvestcraft.description") -public class PluginHarvestCraft extends BlankForestryPlugin { +public class PluginHarvestCraft extends CompatPlugin { private static final String HC = "harvestcraft"; - @Override - public boolean isAvailable() { - return ModUtil.isModLoaded(HC); - } - - @Override - public String getFailMessage() { - return "HarvestCraft not found"; - } - - @Nullable - private static ItemStack getItemStack(String itemName) { - ResourceLocation key = new ResourceLocation(HC, itemName); - if (ForgeRegistries.ITEMS.containsKey(key)) { - return new ItemStack(ForgeRegistries.ITEMS.getValue(key), 1); - } else { - return null; - } - } - - @Nullable - private static Block getBlock(String blockName) { - ResourceLocation key = new ResourceLocation(HC, blockName); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - return ForgeRegistries.BLOCKS.getValue(key); - } else { - return null; - } + public PluginHarvestCraft() { + super("HarvestCraft", HC); } @Override @@ -206,7 +175,7 @@ public class PluginHarvestCraft extends BlankForestryPlugin { genericCropsBuilder.addAll(herbs); genericCropsBuilder.addAll(spices); - IFarmRegistry farmRegistry = FarmRegistry.getInstance(); + IFarmRegistry farmRegistry = ForestryAPI.farmRegistry; ImmutableList genericCrops = genericCropsBuilder.build(); diff --git a/src/main/java/forestry/plugins/compat/PluginImmersiveEngineering.java b/src/main/java/forestry/plugins/compat/PluginImmersiveEngineering.java index 456abf7cf..487934300 100644 --- a/src/main/java/forestry/plugins/compat/PluginImmersiveEngineering.java +++ b/src/main/java/forestry/plugins/compat/PluginImmersiveEngineering.java @@ -1,108 +1,68 @@ package forestry.plugins.compat; -import javax.annotation.Nullable; - import com.google.common.base.Optional; -import forestry.api.core.ForestryAPI; -import forestry.api.farming.ICrop; -import forestry.api.fuels.FuelManager; -import forestry.api.fuels.GeneratorFuel; -import forestry.api.recipes.RecipeManagers; -import forestry.core.config.Constants; -import forestry.core.fluids.Fluids; -import forestry.core.utils.ModUtil; -import forestry.farming.FarmRegistry; -import forestry.farming.logic.CropDestroy; -import forestry.farming.logic.FarmableBase; -import forestry.plugins.BlankForestryPlugin; -import forestry.plugins.ForestryPlugin; -import forestry.plugins.ForestryPluginUids; + +import java.util.stream.Stream; + import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import forestry.api.core.ForestryAPI; +import forestry.api.farming.IFarmRegistry; +import forestry.api.fuels.FuelManager; +import forestry.api.fuels.GeneratorFuel; +import forestry.api.recipes.RecipeManagers; +import forestry.core.config.Constants; +import forestry.core.fluids.Fluids; +import forestry.farming.logic.FarmableDoubleCrop; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; @ForestryPlugin(pluginID = ForestryPluginUids.IMMERSIVE_ENGINEERING, name = "ImmersiveEngineering", author = "marcin212", url = Constants.URL, unlocalizedDescription = "for.plugin.immersiveengineering.description") -public class PluginImmersiveEngineering extends BlankForestryPlugin { - private static final String IE = "immersiveengineering"; +public class PluginImmersiveEngineering extends CompatPlugin { - @Override - public boolean isAvailable() { - return ModUtil.isModLoaded(IE); - } - - @Override - public String getFailMessage() { - return "ImmersiveEngineering not found"; + public PluginImmersiveEngineering() { + super("ImmersiveEngineering", "immersiveengineering"); } @Override public void postInit() { + IFarmRegistry farmRegistry = ForestryAPI.farmRegistry; ItemStack hempSeed = getItemStack("seed"); Block hempCrop = getBlock("hemp"); if (hempCrop != null) { int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); - IProperty age = hempCrop.getBlockState().getProperties().stream().filter(p -> p.getName().equals("type")).findAny().orElseGet(null); + Stream> propertyStream = hempCrop.getBlockState().getProperties().stream(); + IProperty age = propertyStream.filter(p -> p.getName().equals("type")).findAny().orElseGet(null); if (hempSeed != null && hempCrop != Blocks.AIR && age != null) { Optional bottom0 = age.parseValue("bottom0"); + Optional bottom4 = age.parseValue("bottom4"); Optional top0 = age.parseValue("top0"); if (bottom0.isPresent() && top0.isPresent()) { IBlockState defaultState = hempCrop.getDefaultState(); IBlockState planted = defaultState.withProperty(age, (Comparable) bottom0.get()); - IBlockState mature = defaultState.withProperty(age, (Comparable) top0.get()); - FarmRegistry.getInstance().registerFarmables("farmWheat", new FarmableBase(hempSeed, planted, mature, false) { - @Override - public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { - IBlockState stateUp = world.getBlockState(pos.up()); - if (stateUp != matureState) { - return null; - } - return new CropDestroy(world, stateUp, pos.up(), null); - } - }); + IBlockState mature = defaultState.withProperty(age, (Comparable) bottom4.get()); + IBlockState topMature = defaultState.withProperty(age, (Comparable) top0.get()); + + farmRegistry.registerFarmables("farmWheat", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, false)); + farmRegistry.registerFarmables("farmOrchard", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, true)); RecipeManagers.squeezerManager.addRecipe(10, hempSeed, Fluids.SEED_OIL.getFluid(seedAmount)); } } } Fluid ethanol = FluidRegistry.getFluid("ethanol"); - if(ethanol != null){ + if (ethanol != null) { GeneratorFuel ethanolFuel = new GeneratorFuel(new FluidStack(ethanol, 1), (int) (32 * ForestryAPI.activeMode.getFloatSetting("fuel.ethanol.generator")), 4); FuelManager.generatorFuel.put(ethanol, ethanolFuel); } } - - @Nullable - private static Block getBlock(String blockName) { - ResourceLocation key = new ResourceLocation(IE, blockName); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - return ForgeRegistries.BLOCKS.getValue(key); - } else { - return null; - } - } - - @Nullable - private static ItemStack getItemStack(String itemName, int meta) { - ResourceLocation key = new ResourceLocation(IE, itemName); - if (ForgeRegistries.ITEMS.containsKey(key)) { - return new ItemStack(ForgeRegistries.ITEMS.getValue(key), 1, meta); - } else { - return null; - } - } - - @Nullable - private static ItemStack getItemStack(String itemName) { - return getItemStack(itemName, 0); - } } diff --git a/src/main/java/forestry/plugins/compat/PluginMalisisDoors.java b/src/main/java/forestry/plugins/compat/PluginMalisisDoors.java deleted file mode 100644 index 183f725dd..000000000 --- a/src/main/java/forestry/plugins/compat/PluginMalisisDoors.java +++ /dev/null @@ -1,28 +0,0 @@ -package forestry.plugins.compat; - -import forestry.api.core.CamouflageManager; -import forestry.core.config.Constants; -import forestry.core.utils.ModUtil; -import forestry.plugins.BlankForestryPlugin; -import forestry.plugins.ForestryPlugin; -import forestry.plugins.ForestryPluginUids; - -@ForestryPlugin(pluginID = ForestryPluginUids.MALISIS_DOORES, name = "malisisdoors", author = "nedelosk", url = Constants.URL, unlocalizedDescription = "for.plugin.malisisDoors.description") -public class PluginMalisisDoors extends BlankForestryPlugin { - - @Override - public boolean isAvailable() { - return ModUtil.isModLoaded("malisisdoors"); - } - - @Override - public String getFailMessage() { - return "Malisis Door's not found"; - } - - @Override - public void preInit() { - CamouflageManager.camouflageAccess.addModIdToBlackList("door", "malisisdoors"); - } - -} diff --git a/src/main/java/forestry/plugins/compat/PluginMysticalAgriculture.java b/src/main/java/forestry/plugins/compat/PluginMysticalAgriculture.java new file mode 100644 index 000000000..11d294e3e --- /dev/null +++ b/src/main/java/forestry/plugins/compat/PluginMysticalAgriculture.java @@ -0,0 +1,159 @@ +package forestry.plugins.compat; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockCrops; +import net.minecraft.item.ItemStack; + +import forestry.api.core.ForestryAPI; +import forestry.api.farming.IFarmRegistry; +import forestry.api.recipes.RecipeManagers; +import forestry.core.config.Constants; +import forestry.core.fluids.Fluids; +import forestry.farming.logic.FarmableAgingCrop; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; + +@ForestryPlugin(pluginID = ForestryPluginUids.MAGICAL_AGRICULTURE, name = "Mystical Agriculture", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.plugin.mysticalagriculture.description") +public class PluginMysticalAgriculture extends CompatPlugin { + private static final String MAGICAL_AGRICULTURE = "mysticalagriculture"; + + public PluginMysticalAgriculture() { + super("Mystical Agriculture", MAGICAL_AGRICULTURE); + } + + @Override + public void registerRecipes() { + if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) { + ImmutableList crops = ImmutableList.of( + "stone", + "dirt", + "nature", + "wood", + "water", + "ice", + "fire", + "dye", + "nether", + "coal", + "iron", + "nether_quartz", + "glowstone", + "redstone", + "obsidian", + "gold", + "lapis_lazuli", + "end", + "experience", + "diamond", + "emerald", + "zombie", + "pig", + "chicken", + "cow", + "sheep", + "slime", + "skeleton", + "creeper", + "spider", + "rabbit", + "guardian", + "blaze", + "ghast", + "enderman", + "wither_skeleton", + "rubber", + "silicon", + "sulfur", + "aluminum", + "copper", + "saltpeter", + "tin", + "bronze", + "zinc", + "brass", + "silver", + "lead", + "steel", + "nickel", + "constantan", + "electrum", + "invar", + "mithril", + "tungsten", + "titanium", + "chrome", + "platinum", + "iridium", + "ruby", + "sapphire", + "peridot", + "amber", + "topaz", + "malachite", + "tanzanite", + "blizz", + "blitz", + "basalz", + "signalum", + "lumium", + "enderium", + "aluminum_brass", + "knightslime", + "ardite", + "cobalt", + "manyullyn", + "electrical_steel", + "redstone_alloy", + "conductive_iron", + "soularium", "dark_steel", + "pulsating_iron", + "energetic_alloy", + "vibrant_alloy", + "mystical_flower", + "manasteel", + "terrasteel", + "osmium", + "glowstone_ingot", + "refined_obsidian", + "aquarium", + "cold_iron", + "star_steel", + "adamantine", + "marble", + "limestone", + "basalt", + "apatite", + "meteoric_iron", + "desh", + "vinteum", + "chimerite", + "blue_topaz", + "moonstone", + "sunstone", + "ender_amethyst", + "draconium", + "yellorium", + "certus_quartz", + "fluix", + "quartz_enriched_iron" + ); + + IFarmRegistry farmRegistry = ForestryAPI.farmRegistry; + int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + + for (String cropName : crops) { + ItemStack seeds = getItemStack(cropName + "_seeds"); + Block block = getBlock(cropName + "_crop"); + if (seeds != null) { + RecipeManagers.squeezerManager.addRecipe(10, seeds, Fluids.SEED_OIL.getFluid(seedAmount)); + } + if (seeds != null && block != null) { + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(seeds, block, BlockCrops.AGE, 7)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(seeds, block, BlockCrops.AGE, 7, 0)); + } + } + } + } +} diff --git a/src/main/java/forestry/plugins/compat/PluginRoots.java b/src/main/java/forestry/plugins/compat/PluginRoots.java new file mode 100644 index 000000000..f10a7227e --- /dev/null +++ b/src/main/java/forestry/plugins/compat/PluginRoots.java @@ -0,0 +1,64 @@ +package forestry.plugins.compat; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockCrops; +import net.minecraft.item.ItemStack; + +import forestry.api.core.ForestryAPI; +import forestry.api.farming.IFarmRegistry; +import forestry.api.recipes.RecipeManagers; +import forestry.core.config.Constants; +import forestry.core.fluids.Fluids; +import forestry.farming.logic.FarmableAgingCrop; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; + +@ForestryPlugin(pluginID = ForestryPluginUids.ROOTS, name = "Roots", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.plugin.roots.description") +public class PluginRoots extends CompatPlugin { + public PluginRoots() { + super("Roots", "roots"); + } + + @Override + public void registerRecipes() { + ImmutableList crops = ImmutableList.of( + "moonglow", + "terra_moss", + "aubergine" + ); + + ImmutableList seeds = ImmutableList.of( + "moontinged_seed", + "terra_moss_spore", + "aubergine_seeds" + ); + + ImmutableList fruits = ImmutableList.of( + "moonglow_leaf", + "terra_moss_ball", + "aubergine_item" + ); + + IFarmRegistry farmRegistry = ForestryAPI.farmRegistry; + int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + int juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 25; + + for (int i = 0; i < fruits.size(); i++) { + ItemStack seed = getItemStack(seeds.get(i)); + Block block = getBlock(crops.get(i)); + ItemStack fruit = getItemStack(fruits.get(i)); + if (seed != null && i != 1) { + RecipeManagers.squeezerManager.addRecipe(10, seed, Fluids.SEED_OIL.getFluid(seedAmount)); + } + if (fruit != null && i == 2) { + RecipeManagers.squeezerManager.addRecipe(10, fruit, Fluids.JUICE.getFluid(juiceAmount)); + } + if (seed != null && block != null) { + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(seed, block, BlockCrops.AGE, 7)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(seed, block, BlockCrops.AGE, 7, 0)); + } + } + } +} diff --git a/src/main/java/forestry/plugins/compat/PluginRustic.java b/src/main/java/forestry/plugins/compat/PluginRustic.java new file mode 100644 index 000000000..124f45cb2 --- /dev/null +++ b/src/main/java/forestry/plugins/compat/PluginRustic.java @@ -0,0 +1,78 @@ +package forestry.plugins.compat; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.block.Block; +import net.minecraft.block.properties.PropertyInteger; +import net.minecraft.item.ItemStack; + +import forestry.api.core.ForestryAPI; +import forestry.api.farming.IFarmRegistry; +import forestry.api.recipes.RecipeManagers; +import forestry.core.config.Constants; +import forestry.core.fluids.Fluids; +import forestry.farming.logic.FarmableAgingCrop; +import forestry.farming.logic.FarmableRusticGrape; +import forestry.farming.logic.FarmableRusticSapling; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; + +@ForestryPlugin(pluginID = ForestryPluginUids.RUSTIC, name = "rustic", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.plugin.rustic.description") +public class PluginRustic extends CompatPlugin { + + public PluginRustic() { + super("Rustic", "rustic"); + } + + @Override + public void registerRecipes() { + ImmutableList fruits = ImmutableList.of( + "tomato", + "chili_pepper" + ); + ImmutableList crops = ImmutableList.of( + "tomato", + "chili" + ); + PropertyInteger cropAge = PropertyInteger.create("age", 0, 3); + int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + int juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple"); + IFarmRegistry farmRegistry = ForestryAPI.farmRegistry; + + ItemStack grapes = getItemStack("grapes"); + ItemStack grapeSeeds = getItemStack("grape_stem"); + Block grapeLeaves = getBlock("grape_leaves"); + if (grapeSeeds != null) { + RecipeManagers.squeezerManager.addRecipe(10, grapeSeeds, Fluids.SEED_OIL.getFluid(seedAmount)); + } + if (grapes != null) { + RecipeManagers.squeezerManager.addRecipe(10, grapes, Fluids.JUICE.getFluid(juiceAmount / 12)); + } + if (grapeLeaves != null) { + farmRegistry.registerFarmables("farmOrchard", new FarmableRusticGrape(grapeLeaves)); + } + + ItemStack sapling = getItemStack("sapling"); + ItemStack ironBerries = getItemStack("ironberries"); + ItemStack olives = getItemStack("olives"); + if (sapling != null && ironBerries != null && olives != null) { + farmRegistry.registerFarmables("farmArboreal", new FarmableRusticSapling(sapling.getItem(), new ItemStack[]{ironBerries, olives})); + } + + for (int i = 0; i < fruits.size(); i++) { + String fruitName = fruits.get(i); + ItemStack seeds = getItemStack(fruitName + "_seeds"); + Block block = getBlock(crops.get(i) + "_crop"); + ItemStack fruit = getItemStack(fruitName); + if (seeds != null) { + RecipeManagers.squeezerManager.addRecipe(10, seeds, Fluids.SEED_OIL.getFluid(seedAmount)); + } + if (fruit != null) { + RecipeManagers.squeezerManager.addRecipe(10, fruit, Fluids.JUICE.getFluid(juiceAmount / 25)); + } + if (seeds != null && block != null) { + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(seeds, block, cropAge, 3, 2)); + } + } + } +} diff --git a/src/main/java/forestry/storage/items/ItemBackpack.java b/src/main/java/forestry/storage/items/ItemBackpack.java index 51a2716b0..5e9a5578d 100755 --- a/src/main/java/forestry/storage/items/ItemBackpack.java +++ b/src/main/java/forestry/storage/items/ItemBackpack.java @@ -35,9 +35,30 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.items.IItemHandler; + import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import net.minecraftforge.items.IItemHandler; + +import forestry.api.core.IModelManager; +import forestry.api.storage.BackpackStowEvent; +import forestry.api.storage.EnumBackpackType; +import forestry.api.storage.IBackpackDefinition; +import forestry.core.config.Config; +import forestry.core.config.Constants; +import forestry.core.gui.GuiHandler; +import forestry.core.inventory.ItemHandlerInventoryManipulator; +import forestry.core.inventory.ItemInventory; +import forestry.core.inventory.StandardStackFilters; +import forestry.core.items.IColoredItem; +import forestry.core.items.ItemWithGui; +import forestry.core.tiles.TileUtil; +import forestry.core.utils.Translator; +import forestry.storage.BackpackMode; +import forestry.storage.gui.ContainerBackpack; +import forestry.storage.gui.GuiBackpack; +import forestry.storage.gui.GuiBackpackT2; +import forestry.storage.inventory.ItemInventoryBackpack; import forestry.api.core.IModelManager; import forestry.api.storage.BackpackStowEvent; @@ -202,10 +223,6 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem { public void addInformation(ItemStack itemstack, @Nullable World world, List list, ITooltipFlag flag) { super.addInformation(itemstack, world, list, flag); - if (type == EnumBackpackType.WOVEN) { - list.add(Translator.translateToLocalFormatted("item.for.bag.woven.tooltip")); - } - int occupied = ItemInventory.getOccupiedSlotCount(itemstack); BackpackMode mode = getMode(itemstack); diff --git a/src/main/resources/assets/forestry/blockstates/ash_block.json b/src/main/resources/assets/forestry/blockstates/ash_block.json new file mode 100644 index 000000000..18de09233 --- /dev/null +++ b/src/main/resources/assets/forestry/blockstates/ash_block.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "forestry:ash_block" } + } +} diff --git a/src/main/resources/assets/forestry/blockstates/ash_brick.json b/src/main/resources/assets/forestry/blockstates/ash_brick.json new file mode 100644 index 000000000..6e8bbce89 --- /dev/null +++ b/src/main/resources/assets/forestry/blockstates/ash_brick.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "forestry:ash_brick" } + } +} diff --git a/src/main/resources/assets/forestry/blockstates/ash_stairs.json b/src/main/resources/assets/forestry/blockstates/ash_stairs.json new file mode 100644 index 000000000..2293cd559 --- /dev/null +++ b/src/main/resources/assets/forestry/blockstates/ash_stairs.json @@ -0,0 +1,44 @@ +{ + "variants": { + "facing=east,half=bottom,shape=straight": { "model": "forestry:ash_stairs" }, + "facing=west,half=bottom,shape=straight": { "model": "forestry:ash_stairs", "y": 180, "uvlock": true }, + "facing=south,half=bottom,shape=straight": { "model": "forestry:ash_stairs", "y": 90, "uvlock": true }, + "facing=north,half=bottom,shape=straight": { "model": "forestry:ash_stairs", "y": 270, "uvlock": true }, + "facing=east,half=bottom,shape=outer_right": { "model": "forestry:ash_outer_stairs" }, + "facing=west,half=bottom,shape=outer_right": { "model": "forestry:ash_outer_stairs", "y": 180, "uvlock": true }, + "facing=south,half=bottom,shape=outer_right": { "model": "forestry:ash_outer_stairs", "y": 90, "uvlock": true }, + "facing=north,half=bottom,shape=outer_right": { "model": "forestry:ash_outer_stairs", "y": 270, "uvlock": true }, + "facing=east,half=bottom,shape=outer_left": { "model": "forestry:ash_outer_stairs", "y": 270, "uvlock": true }, + "facing=west,half=bottom,shape=outer_left": { "model": "forestry:ash_outer_stairs", "y": 90, "uvlock": true }, + "facing=south,half=bottom,shape=outer_left": { "model": "forestry:ash_outer_stairs" }, + "facing=north,half=bottom,shape=outer_left": { "model": "forestry:ash_outer_stairs", "y": 180, "uvlock": true }, + "facing=east,half=bottom,shape=inner_right": { "model": "forestry:ash_inner_stairs" }, + "facing=west,half=bottom,shape=inner_right": { "model": "forestry:ash_inner_stairs", "y": 180, "uvlock": true }, + "facing=south,half=bottom,shape=inner_right": { "model": "forestry:ash_inner_stairs", "y": 90, "uvlock": true }, + "facing=north,half=bottom,shape=inner_right": { "model": "forestry:ash_inner_stairs", "y": 270, "uvlock": true }, + "facing=east,half=bottom,shape=inner_left": { "model": "forestry:ash_inner_stairs", "y": 270, "uvlock": true }, + "facing=west,half=bottom,shape=inner_left": { "model": "forestry:ash_inner_stairs", "y": 90, "uvlock": true }, + "facing=south,half=bottom,shape=inner_left": { "model": "forestry:ash_inner_stairs" }, + "facing=north,half=bottom,shape=inner_left": { "model": "forestry:ash_inner_stairs", "y": 180, "uvlock": true }, + "facing=east,half=top,shape=straight": { "model": "forestry:ash_stairs", "x": 180, "uvlock": true }, + "facing=west,half=top,shape=straight": { "model": "forestry:ash_stairs", "x": 180, "y": 180, "uvlock": true }, + "facing=south,half=top,shape=straight": { "model": "forestry:ash_stairs", "x": 180, "y": 90, "uvlock": true }, + "facing=north,half=top,shape=straight": { "model": "forestry:ash_stairs", "x": 180, "y": 270, "uvlock": true }, + "facing=east,half=top,shape=outer_right": { "model": "forestry:ash_outer_stairs", "x": 180, "y": 90, "uvlock": true }, + "facing=west,half=top,shape=outer_right": { "model": "forestry:ash_outer_stairs", "x": 180, "y": 270, "uvlock": true }, + "facing=south,half=top,shape=outer_right": { "model": "forestry:ash_outer_stairs", "x": 180, "y": 180, "uvlock": true }, + "facing=north,half=top,shape=outer_right": { "model": "forestry:ash_outer_stairs", "x": 180, "uvlock": true }, + "facing=east,half=top,shape=outer_left": { "model": "forestry:ash_outer_stairs", "x": 180, "uvlock": true }, + "facing=west,half=top,shape=outer_left": { "model": "forestry:ash_outer_stairs", "x": 180, "y": 180, "uvlock": true }, + "facing=south,half=top,shape=outer_left": { "model": "forestry:ash_outer_stairs", "x": 180, "y": 90, "uvlock": true }, + "facing=north,half=top,shape=outer_left": { "model": "forestry:ash_outer_stairs", "x": 180, "y": 270, "uvlock": true }, + "facing=east,half=top,shape=inner_right": { "model": "forestry:ash_inner_stairs", "x": 180, "y": 90, "uvlock": true }, + "facing=west,half=top,shape=inner_right": { "model": "forestry:ash_inner_stairs", "x": 180, "y": 270, "uvlock": true }, + "facing=south,half=top,shape=inner_right": { "model": "forestry:ash_inner_stairs", "x": 180, "y": 180, "uvlock": true }, + "facing=north,half=top,shape=inner_right": { "model": "forestry:ash_inner_stairs", "x": 180, "uvlock": true }, + "facing=east,half=top,shape=inner_left": { "model": "forestry:ash_inner_stairs", "x": 180, "uvlock": true }, + "facing=west,half=top,shape=inner_left": { "model": "forestry:ash_inner_stairs", "x": 180, "y": 180, "uvlock": true }, + "facing=south,half=top,shape=inner_left": { "model": "forestry:ash_inner_stairs", "x": 180, "y": 90, "uvlock": true }, + "facing=north,half=top,shape=inner_left": { "model": "forestry:ash_inner_stairs", "x": 180, "y": 270, "uvlock": true } + } +} diff --git a/src/main/resources/assets/forestry/blockstates/greenhouse.door.json b/src/main/resources/assets/forestry/blockstates/greenhouse.door.json deleted file mode 100644 index 09c3e2d59..000000000 --- a/src/main/resources/assets/forestry/blockstates/greenhouse.door.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "variants": { - "facing=east,half=lower,hinge=left,open=false": { "model": "forestry:greenhouse.door_bottom" }, - "facing=south,half=lower,hinge=left,open=false": { "model": "forestry:greenhouse.door_bottom", "y": 90 }, - "facing=west,half=lower,hinge=left,open=false": { "model": "forestry:greenhouse.door_bottom", "y": 180 }, - "facing=north,half=lower,hinge=left,open=false": { "model": "forestry:greenhouse.door_bottom", "y": 270 }, - "facing=east,half=lower,hinge=right,open=false": { "model": "forestry:greenhouse.door_bottom_rh" }, - "facing=south,half=lower,hinge=right,open=false": { "model": "forestry:greenhouse.door_bottom_rh", "y": 90 }, - "facing=west,half=lower,hinge=right,open=false": { "model": "forestry:greenhouse.door_bottom_rh", "y": 180 }, - "facing=north,half=lower,hinge=right,open=false": { "model": "forestry:greenhouse.door_bottom_rh", "y": 270 }, - "facing=east,half=lower,hinge=left,open=true": { "model": "forestry:greenhouse.door_bottom_rh", "y": 90 }, - "facing=south,half=lower,hinge=left,open=true": { "model": "forestry:greenhouse.door_bottom_rh", "y": 180 }, - "facing=west,half=lower,hinge=left,open=true": { "model": "forestry:greenhouse.door_bottom_rh", "y": 270 }, - "facing=north,half=lower,hinge=left,open=true": { "model": "forestry:greenhouse.door_bottom_rh" }, - "facing=east,half=lower,hinge=right,open=true": { "model": "forestry:greenhouse.door_bottom", "y": 270 }, - "facing=south,half=lower,hinge=right,open=true": { "model": "forestry:greenhouse.door_bottom" }, - "facing=west,half=lower,hinge=right,open=true": { "model": "forestry:greenhouse.door_bottom", "y": 90 }, - "facing=north,half=lower,hinge=right,open=true": { "model": "forestry:greenhouse.door_bottom", "y": 180 }, - "facing=east,half=upper,hinge=left,open=false": { "model": "forestry:greenhouse.door_top" }, - "facing=south,half=upper,hinge=left,open=false": { "model": "forestry:greenhouse.door_top", "y": 90 }, - "facing=west,half=upper,hinge=left,open=false": { "model": "forestry:greenhouse.door_top", "y": 180 }, - "facing=north,half=upper,hinge=left,open=false": { "model": "forestry:greenhouse.door_top", "y": 270 }, - "facing=east,half=upper,hinge=right,open=false": { "model": "forestry:greenhouse.door_top_rh" }, - "facing=south,half=upper,hinge=right,open=false": { "model": "forestry:greenhouse.door_top_rh", "y": 90 }, - "facing=west,half=upper,hinge=right,open=false": { "model": "forestry:greenhouse.door_top_rh", "y": 180 }, - "facing=north,half=upper,hinge=right,open=false": { "model": "forestry:greenhouse.door_top_rh", "y": 270 }, - "facing=east,half=upper,hinge=left,open=true": { "model": "forestry:greenhouse.door_top_rh", "y": 90 }, - "facing=south,half=upper,hinge=left,open=true": { "model": "forestry:greenhouse.door_top_rh", "y": 180 }, - "facing=west,half=upper,hinge=left,open=true": { "model": "forestry:greenhouse.door_top_rh", "y": 270 }, - "facing=north,half=upper,hinge=left,open=true": { "model": "forestry:greenhouse.door_top_rh" }, - "facing=east,half=upper,hinge=right,open=true": { "model": "forestry:greenhouse.door_top", "y": 270 }, - "facing=south,half=upper,hinge=right,open=true": { "model": "forestry:greenhouse.door_top" }, - "facing=west,half=upper,hinge=right,open=true": { "model": "forestry:greenhouse.door_top", "y": 90 }, - "facing=north,half=upper,hinge=right,open=true": { "model": "forestry:greenhouse.door_top", "y": 180 } - } -} diff --git a/src/main/resources/assets/forestry/blockstates/greenhouse.sprinkler.json b/src/main/resources/assets/forestry/blockstates/greenhouse.sprinkler.json deleted file mode 100644 index d8a44536c..000000000 --- a/src/main/resources/assets/forestry/blockstates/greenhouse.sprinkler.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "forge_marker": 1, - "defaults": { - "textures": { - } - }, - "variants": { - "normal": [{}], - "inventory": [{ - "transform": "forge:default-block", - "model": "forestry:greenhouse.sprinkler_base", - "submodel": { - "ring": { "model": "forestry:greenhouse.sprinkler_iron" } - } - }], - "static": { - "true": { - "model": "forestry:greenhouse.sprinkler_base" - }, - "false": { - "model": "forestry:greenhouse.sprinkler_iron" - } - } - } -} diff --git a/src/main/resources/assets/forestry/blockstates/greenhouse.window.json b/src/main/resources/assets/forestry/blockstates/greenhouse.window.json index 186f2d176..be47d64cb 100644 --- a/src/main/resources/assets/forestry/blockstates/greenhouse.window.json +++ b/src/main/resources/assets/forestry/blockstates/greenhouse.window.json @@ -7,10 +7,10 @@ "variants": { "state": { "on": { - "model": "forestry:greenhouse.window_open" + "model": "forestry:greenhouse_window_open" }, "off": { - "model": "forestry:greenhouse.window_closed" + "model": "forestry:greenhouse_window_closed" } }, "facing":{ @@ -24,9 +24,6 @@ }, "north": { "y": 180 - }, - "up": { - "x": 90 } } } diff --git a/src/main/resources/assets/forestry/blockstates/greenhouse.window_up.json b/src/main/resources/assets/forestry/blockstates/greenhouse.window_up.json index 07a09ee28..cfee8202b 100644 --- a/src/main/resources/assets/forestry/blockstates/greenhouse.window_up.json +++ b/src/main/resources/assets/forestry/blockstates/greenhouse.window_up.json @@ -7,10 +7,10 @@ "variants": { "state": { "on": { - "model": "forestry:greenhouse.window_up_open" + "model": "forestry:greenhouse_window_up_open" }, "off": { - "model": "forestry:greenhouse.window_up_closed" + "model": "forestry:greenhouse_window_up_closed" } }, "facing":{ @@ -24,9 +24,6 @@ }, "north": { "y": 180 - }, - "up": { - "x": 90 } } } diff --git a/src/main/resources/assets/forestry/blockstates/humus.json b/src/main/resources/assets/forestry/blockstates/humus.json index 1b63fc402..22210320a 100644 --- a/src/main/resources/assets/forestry/blockstates/humus.json +++ b/src/main/resources/assets/forestry/blockstates/humus.json @@ -3,6 +3,12 @@ "degrade=0": { "model": "forestry:soil/humus" }, "degrade=1": { "model": "forestry:soil/humus" }, "degrade=2": { "model": "forestry:soil/humus" }, - "degrade=3": { "model": "forestry:soil/humus" } + "degrade=3": { "model": "forestry:soil/humus" }, + "degrade=4": { "model": "forestry:soil/humus" }, + "degrade=5": { "model": "forestry:soil/humus" }, + "degrade=6": { "model": "forestry:soil/humus" }, + "degrade=7": { "model": "forestry:soil/humus" }, + "degrade=8": { "model": "forestry:soil/humus" }, + "degrade=9": { "model": "forestry:soil/humus" } } } \ No newline at end of file diff --git a/src/main/resources/assets/forestry/blockstates/wood_pile_decorative.json b/src/main/resources/assets/forestry/blockstates/wood_pile_decorative.json new file mode 100644 index 000000000..45b3035dd --- /dev/null +++ b/src/main/resources/assets/forestry/blockstates/wood_pile_decorative.json @@ -0,0 +1,8 @@ +{ + "variants": { + "axis=y": { "model": "forestry:wood_pile" }, + "axis=z": { "model": "forestry:wood_pile", "x": 90 }, + "axis=x": { "model": "forestry:wood_pile", "x": 90, "y": 90 }, + "axis=none": { "model": "forestry:wood_pile" } + } +} diff --git a/src/main/resources/assets/forestry/models/block/ash_block.json b/src/main/resources/assets/forestry/models/block/ash_block.json new file mode 100644 index 000000000..80d1ae7b9 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/ash_block.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "forestry:blocks/ash" + } +} diff --git a/src/main/resources/assets/forestry/models/block/ash_brick.json b/src/main/resources/assets/forestry/models/block/ash_brick.json new file mode 100644 index 000000000..685354f6b --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/ash_brick.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "forestry:blocks/ash_brick" + } +} diff --git a/src/main/resources/assets/forestry/models/block/ash_inner_stairs.json b/src/main/resources/assets/forestry/models/block/ash_inner_stairs.json new file mode 100644 index 000000000..496bdfa8a --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/ash_inner_stairs.json @@ -0,0 +1,8 @@ +{ + "parent": "block/inner_stairs", + "textures": { + "bottom": "forestry:blocks/ash_brick", + "top": "forestry:blocks/ash_brick", + "side": "forestry:blocks/ash_brick" + } +} diff --git a/src/main/resources/assets/forestry/models/block/ash_outer_stairs.json b/src/main/resources/assets/forestry/models/block/ash_outer_stairs.json new file mode 100644 index 000000000..ead5a58af --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/ash_outer_stairs.json @@ -0,0 +1,8 @@ +{ + "parent": "block/outer_stairs", + "textures": { + "bottom": "forestry:blocks/ash_brick", + "top": "forestry:blocks/ash_brick", + "side": "forestry:blocks/ash_brick" + } +} diff --git a/src/main/resources/assets/forestry/models/block/ash_stairs.json b/src/main/resources/assets/forestry/models/block/ash_stairs.json new file mode 100644 index 000000000..6639b5661 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/ash_stairs.json @@ -0,0 +1,8 @@ +{ + "parent": "block/stairs", + "textures": { + "bottom": "forestry:blocks/ash_brick", + "top": "forestry:blocks/ash_brick", + "side": "forestry:blocks/ash_brick" + } +} diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.door_bottom.json b/src/main/resources/assets/forestry/models/block/greenhouse.door_bottom.json deleted file mode 100644 index 5f32e330b..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.door_bottom.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "parent": "block/door_bottom", - "textures": { - "bottom": "blocks/glass_green", - "top": "blocks/glass_green" - } -} diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.door_bottom_rh.json b/src/main/resources/assets/forestry/models/block/greenhouse.door_bottom_rh.json deleted file mode 100644 index 7225cc63f..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.door_bottom_rh.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "parent": "block/door_bottom_rh", - "textures": { - "bottom": "blocks/glass_green", - "top": "blocks/glass_green" - } -} diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.door_top.json b/src/main/resources/assets/forestry/models/block/greenhouse.door_top.json deleted file mode 100644 index 4487a9dae..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.door_top.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "parent": "block/door_top", - "textures": { - "bottom": "blocks/glass_green", - "top": "blocks/glass_green" - } -} diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.door_top_rh.json b/src/main/resources/assets/forestry/models/block/greenhouse.door_top_rh.json deleted file mode 100644 index 1820f8469..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.door_top_rh.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "parent": "block/door_top_rh", - "textures": { - "bottom": "blocks/glass_green", - "top": "blocks/glass_green" - } -} diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.window_closed.json b/src/main/resources/assets/forestry/models/block/greenhouse.window_closed.json deleted file mode 100644 index 47e9b1c8a..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.window_closed.json +++ /dev/null @@ -1,110 +0,0 @@ -{ -"textures": { - "texture": "blocks/glass_green", - "particle": "blocks/glass_green" -}, -"elements": [ -{ - "from": [ 3, 0, 0 ], - "to": [ 13, 3, 15 ], - "faces": { - "down": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "up": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, - "south": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 3, 13, 0 ], - "to": [ 13, 16, 15 ], - "faces": { - "down": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "up": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, - "south": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 3, 0 ], - "to": [ 3, 13, 15 ], - "faces": { - "north": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, - "south": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } - } -}, -{ - "from": [ 13, 3, 0 ], - "to": [ 16, 13, 15 ], - "faces": { - "north": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, - "south": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 13, 0 ], - "to": [ 3, 16, 15 ], - "faces": { - "up": { "uv": [ 0, 0, 16, 3 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, - "south": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 0 ], - "to": [ 3, 3, 15 ], - "faces": { - "down": { "uv": [ 16, 3, 0, 0 ], "rotation": 90, "texture": "#texture" }, - "north": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, - "south": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 13, 13, 0 ], - "to": [ 16, 16, 15 ], - "faces": { - "up": { "uv": [ 0, 13, 16, 16 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, - "south": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 0 ], - "to": [ 16, 3, 15 ], - "faces": { - "down": { "uv": [ 16, 16, 0, 13 ], "rotation": 90, "texture": "#texture" }, - "north": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, - "south": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 15 ], - "to": [ 16, 16, 16 ], - "faces": { - "down": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, - "up": { "uv": [ 0, 15, 16, 16 ], "texture": "#texture" }, - "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, - "west": { "uv": [ 15, 0, 16, 16 ], "texture": "#texture" }, - "east": { "uv": [ 0, 0, 1, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 3, 3, 15 ], - "to": [ 13, 13, 15.0625 ], - "faces": { - "north": { "uv": [ 3, 3, 13, 13 ], "texture": "#texture" } - } -} -] -} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.window_open.json b/src/main/resources/assets/forestry/models/block/greenhouse.window_open.json deleted file mode 100644 index f5813dad8..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.window_open.json +++ /dev/null @@ -1,119 +0,0 @@ -{ -"textures": { - "texture": "blocks/glass_green", - "particle": "blocks/glass_green", - "log_oak": "blocks/log_oak" -}, -"elements": [ -{ - "from": [ 3, 0, 0 ], - "to": [ 13, 3, 15 ], - "faces": { - "down": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "up": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, - "south": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 3, 13, 0 ], - "to": [ 13, 16, 15 ], - "faces": { - "down": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "up": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, - "south": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 3, 0 ], - "to": [ 3, 13, 15 ], - "faces": { - "north": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, - "south": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } - } -}, -{ - "from": [ 13, 3, 0 ], - "to": [ 16, 13, 15 ], - "faces": { - "north": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, - "south": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 13, 0 ], - "to": [ 3, 16, 15 ], - "faces": { - "up": { "uv": [ 0, 0, 16, 3 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, - "south": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 0 ], - "to": [ 3, 3, 15 ], - "faces": { - "down": { "uv": [ 16, 3, 0, 0 ], "rotation": 90, "texture": "#texture" }, - "north": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, - "south": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 13, 13, 0 ], - "to": [ 16, 16, 15 ], - "faces": { - "up": { "uv": [ 0, 13, 16, 16 ], "rotation": 270, "texture": "#texture" }, - "north": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, - "south": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 0 ], - "to": [ 16, 3, 15 ], - "faces": { - "down": { "uv": [ 16, 16, 0, 13 ], "rotation": 90, "texture": "#texture" }, - "north": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, - "south": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 15 ], - "to": [ 16, 16, 16 ], - "rotation": { "origin": [ 0, 16, 15 ], "axis": "x", "angle": -45 }, - "faces": { - "down": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, - "up": { "uv": [ 0, 15, 16, 16 ], "texture": "#texture" }, - "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, - "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, - "west": { "uv": [ 15, 0, 16, 16 ], "texture": "#texture" }, - "east": { "uv": [ 0, 0, 1, 16 ], "texture": "#texture" } - } -}, -{ - "from": [ 7.5, 0, 21.5 ], - "to": [ 8.5, 9.5, 22.5 ], - "rotation": { "origin": [ 7.5, 9.5, 21.5 ], "axis": "x", "angle": 45 }, - "faces": { - "down": { "uv": [ 16, 16, 16, 15 ], "texture": "#log_oak" }, - "up": { "uv": [ 0, 15, 0, 16 ], "texture": "#log_oak" }, - "north": { "uv": [ 16, 3, 16, 16 ], "texture": "#log_oak" }, - "south": { "uv": [ 0, 3, 0, 16 ], "texture": "#log_oak" }, - "west": { "uv": [ 15, 3, 16, 16 ], "texture": "#log_oak" }, - "east": { "uv": [ 0, 3, 1, 16 ], "texture": "#log_oak" } - } -} -] -} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.window_up_closed.json b/src/main/resources/assets/forestry/models/block/greenhouse.window_up_closed.json deleted file mode 100644 index e1511c5dd..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.window_up_closed.json +++ /dev/null @@ -1,110 +0,0 @@ -{ -"textures": { - "texture": "blocks/glass_green", - "particle": "blocks/glass_green" -}, -"elements": [ -{ - "from": [ 3, 0, 13 ], - "to": [ 13, 15, 16 ], - "faces": { - "down": { "uv": [ 3, 13, 13, 16 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, - "north": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" }, - "south": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 3, 0, 0 ], - "to": [ 13, 15, 3 ], - "faces": { - "down": { "uv": [ 3, 0, 13, 3 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, - "north": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" }, - "south": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 3 ], - "to": [ 3, 15, 13 ], - "faces": { - "down": { "uv": [ 13, 3, 16, 13 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 3 ], - "to": [ 16, 15, 13 ], - "faces": { - "down": { "uv": [ 0, 3, 3, 13 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 0 ], - "to": [ 3, 15, 3 ], - "faces": { - "down": { "uv": [ 13, 0, 16, 3 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, - "north": { "uv": [ 0, 0, 16, 3 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "rotation": 270, "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 13 ], - "to": [ 3, 15, 16 ], - "faces": { - "down": { "uv": [ 13, 13, 16, 16 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, - "south": { "uv": [ 16, 3, 0, 0 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "rotation": 270, "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 0 ], - "to": [ 16, 15, 3 ], - "faces": { - "down": { "uv": [ 0, 0, 3, 3 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, - "north": { "uv": [ 0, 13, 16, 16 ], "rotation": 90, "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 13 ], - "to": [ 16, 15, 16 ], - "faces": { - "down": { "uv": [ 0, 13, 3, 16 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, - "south": { "uv": [ 16, 16, 0, 13 ], "rotation": 90, "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 0, 15, 0 ], - "to": [ 16, 16, 16 ], - "faces": { - "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, - "north": { "uv": [ 0, 15, 16, 16 ], "rotation": 180, "texture": "#texture" }, - "south": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, - "west": { "uv": [ 15, 0, 16, 16 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 0, 1, 16 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 3, 14.9375, 3 ], - "to": [ 13, 15, 13 ], - "faces": { - "down": { "uv": [ 3, 3, 13, 13 ], "rotation": 180, "texture": "#texture" } - } -} -] -} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse.window_up_open.json b/src/main/resources/assets/forestry/models/block/greenhouse.window_up_open.json deleted file mode 100644 index a7617fb86..000000000 --- a/src/main/resources/assets/forestry/models/block/greenhouse.window_up_open.json +++ /dev/null @@ -1,119 +0,0 @@ -{ -"textures": { - "texture": "blocks/glass_green", - "particle": "blocks/glass_green", - "log_oak": "blocks/log_oak" -}, -"elements": [ -{ - "from": [ 3, 0, 13 ], - "to": [ 13, 15, 16 ], - "faces": { - "down": { "uv": [ 3, 13, 13, 16 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, - "north": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" }, - "south": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 3, 0, 0 ], - "to": [ 13, 15, 3 ], - "faces": { - "down": { "uv": [ 3, 0, 13, 3 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, - "north": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" }, - "south": { "uv": [ 16, 13, 0, 3 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 3 ], - "to": [ 3, 15, 13 ], - "faces": { - "down": { "uv": [ 13, 3, 16, 13 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 3 ], - "to": [ 16, 15, 13 ], - "faces": { - "down": { "uv": [ 0, 3, 3, 13 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, - "west": { "uv": [ 0, 3, 16, 13 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 3, 16, 13 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 0 ], - "to": [ 3, 15, 3 ], - "faces": { - "down": { "uv": [ 13, 0, 16, 3 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, - "north": { "uv": [ 0, 0, 16, 3 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 0, 16, 3 ], "rotation": 270, "texture": "#texture" } - } -}, -{ - "from": [ 0, 0, 13 ], - "to": [ 3, 15, 16 ], - "faces": { - "down": { "uv": [ 13, 13, 16, 16 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, - "south": { "uv": [ 16, 3, 0, 0 ], "rotation": 90, "texture": "#texture" }, - "west": { "uv": [ 0, 13, 16, 16 ], "rotation": 270, "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 0 ], - "to": [ 16, 15, 3 ], - "faces": { - "down": { "uv": [ 0, 0, 3, 3 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, - "north": { "uv": [ 0, 13, 16, 16 ], "rotation": 90, "texture": "#texture" }, - "east": { "uv": [ 0, 0, 16, 3 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 13, 0, 13 ], - "to": [ 16, 15, 16 ], - "faces": { - "down": { "uv": [ 0, 13, 3, 16 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, - "south": { "uv": [ 16, 16, 0, 13 ], "rotation": 90, "texture": "#texture" }, - "east": { "uv": [ 0, 13, 16, 16 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 0, 14.5, -0.5 ], - "to": [ 16, 15.5, 15.5 ], - "rotation": { "origin": [ 0, 15.5, -0.5 ], "axis": "x", "angle": -45 }, - "faces": { - "down": { "uv": [ 0, 0, 16, 16 ], "rotation": 180, "texture": "#texture" }, - "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, - "north": { "uv": [ 0, 15, 16, 16 ], "rotation": 180, "texture": "#texture" }, - "south": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, - "west": { "uv": [ 15, 0, 16, 16 ], "rotation": 270, "texture": "#texture" }, - "east": { "uv": [ 0, 0, 1, 16 ], "rotation": 90, "texture": "#texture" } - } -}, -{ - "from": [ 7.5, 21, 7.5 ], - "to": [ 8.5, 22, 17 ], - "rotation": { "origin": [ 7.5, 22, 7.5 ], "axis": "x", "angle": 45 }, - "faces": { - "down": { "uv": [ 16, 3, 16, 16 ], "rotation": 180, "texture": "#log_oak" }, - "up": { "uv": [ 0, 3, 0, 16 ], "texture": "#log_oak" }, - "north": { "uv": [ 0, 15, 0, 16 ], "rotation": 180, "texture": "#log_oak" }, - "south": { "uv": [ 16, 16, 16, 15 ], "texture": "#log_oak" }, - "west": { "uv": [ 15, 3, 16, 16 ], "rotation": 270, "texture": "#log_oak" }, - "east": { "uv": [ 0, 3, 1, 16 ], "rotation": 90, "texture": "#log_oak" } - } -} -] -} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse_window_closed.json b/src/main/resources/assets/forestry/models/block/greenhouse_window_closed.json new file mode 100644 index 000000000..e9799e70b --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/greenhouse_window_closed.json @@ -0,0 +1,106 @@ +{ + "textures": { + "texture": "blocks/glass", + "particle": "blocks/glass" + }, + "elements": [ + { + "from": [ 3, 0, 0 ], + "to": [ 13, 3, 15 ], + "faces": { + "down": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 }, + "up": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, + "south": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 3, 13, 0 ], + "to": [ 13, 16, 15 ], + "faces": { + "down": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 }, + "up": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, + "south": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 3, 0 ], + "to": [ 3, 13, 15 ], + "faces": { + "north": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, + "south": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } + } + }, + { + "from": [ 13, 3, 0 ], + "to": [ 16, 13, 15 ], + "faces": { + "north": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, + "south": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 13, 0 ], + "to": [ 3, 16, 15 ], + "faces": { + "up": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, + "south": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, + "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 3, 3, 15 ], + "faces": { + "down": { "uv": [ 16, 3, 0, 0 ], "texture": "#texture", "rotation": 90 }, + "north": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, + "south": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, + "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 13, 13, 0 ], + "to": [ 16, 16, 15 ], + "faces": { + "up": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, + "south": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, + "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } + } + }, + { + "from": [ 13, 0, 0 ], + "to": [ 16, 3, 15 ], + "faces": { + "down": { "uv": [ 16, 16, 0, 13 ], "texture": "#texture", "rotation": 90 }, + "north": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, + "south": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, + "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 0, 15 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, + "up": { "uv": [ 0, 15, 16, 16 ], "texture": "#texture" }, + "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, + "west": { "uv": [ 15, 0, 16, 16 ], "texture": "#texture" }, + "east": { "uv": [ 0, 0, 1, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 3, 3, 15 ], + "to": [ 13, 13, 15.0625 ], + "faces": { + "north": { "uv": [ 3, 3, 13, 13 ], "texture": "#texture" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse_window_open.json b/src/main/resources/assets/forestry/models/block/greenhouse_window_open.json new file mode 100644 index 000000000..02980a026 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/greenhouse_window_open.json @@ -0,0 +1,115 @@ +{ + "textures": { + "texture": "blocks/glass", + "particle": "blocks/glass", + "log_oak": "blocks/log_oak" + }, + "elements": [ + { + "from": [ 3, 0, 0 ], + "to": [ 13, 3, 15 ], + "faces": { + "down": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 }, + "up": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, + "south": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 3, 13, 0 ], + "to": [ 13, 16, 15 ], + "faces": { + "down": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 }, + "up": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, + "south": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 3, 0 ], + "to": [ 3, 13, 15 ], + "faces": { + "north": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, + "south": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } + } + }, + { + "from": [ 13, 3, 0 ], + "to": [ 16, 13, 15 ], + "faces": { + "north": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, + "south": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 13, 0 ], + "to": [ 3, 16, 15 ], + "faces": { + "up": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, + "south": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, + "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 3, 3, 15 ], + "faces": { + "down": { "uv": [ 16, 3, 0, 0 ], "texture": "#texture", "rotation": 90 }, + "north": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, + "south": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, + "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 13, 13, 0 ], + "to": [ 16, 16, 15 ], + "faces": { + "up": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 270 }, + "north": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, + "south": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, + "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture" } + } + }, + { + "from": [ 13, 0, 0 ], + "to": [ 16, 3, 15 ], + "faces": { + "down": { "uv": [ 16, 16, 0, 13 ], "texture": "#texture", "rotation": 90 }, + "north": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, + "south": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, + "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 0, 0, 15 ], + "to": [ 16, 16, 16 ], + "rotation": { "origin": [ 0, 16, 15 ], "axis": "x", "angle": -45 }, + "faces": { + "down": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, + "up": { "uv": [ 0, 15, 16, 16 ], "texture": "#texture" }, + "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, + "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, + "west": { "uv": [ 15, 0, 16, 16 ], "texture": "#texture" }, + "east": { "uv": [ 0, 0, 1, 16 ], "texture": "#texture" } + } + }, + { + "from": [ 7.5, 0, 21.5 ], + "to": [ 8.5, 9.5, 22.5 ], + "rotation": { "origin": [ 7.5, 9.5, 21.5 ], "axis": "x", "angle": 45 }, + "faces": { + "down": { "uv": [ 16, 16, 16, 15 ], "texture": "#log_oak" }, + "up": { "uv": [ 0, 15, 0, 16 ], "texture": "#log_oak" }, + "north": { "uv": [ 16, 3, 16, 16 ], "texture": "#log_oak" }, + "south": { "uv": [ 0, 3, 0, 16 ], "texture": "#log_oak" }, + "west": { "uv": [ 15, 3, 16, 16 ], "texture": "#log_oak" }, + "east": { "uv": [ 0, 3, 1, 16 ], "texture": "#log_oak" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse_window_up_closed.json b/src/main/resources/assets/forestry/models/block/greenhouse_window_up_closed.json new file mode 100644 index 000000000..0b01c9cd1 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/greenhouse_window_up_closed.json @@ -0,0 +1,106 @@ +{ + "textures": { + "texture": "blocks/glass", + "particle": "blocks/glass" + }, + "elements": [ + { + "from": [ 3, 0, 13 ], + "to": [ 13, 15, 16 ], + "faces": { + "down": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, + "north": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 }, + "south": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 3, 0, 0 ], + "to": [ 13, 15, 3 ], + "faces": { + "down": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, + "north": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 }, + "south": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 0, 0, 3 ], + "to": [ 3, 15, 13 ], + "faces": { + "down": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 13, 0, 3 ], + "to": [ 16, 15, 13 ], + "faces": { + "down": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 3, 15, 3 ], + "faces": { + "down": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, + "north": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 90 }, + "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 270 } + } + }, + { + "from": [ 0, 0, 13 ], + "to": [ 3, 15, 16 ], + "faces": { + "down": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, + "south": { "uv": [ 16, 3, 0, 0 ], "texture": "#texture", "rotation": 90 }, + "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 270 } + } + }, + { + "from": [ 13, 0, 0 ], + "to": [ 16, 15, 3 ], + "faces": { + "down": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, + "north": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 90 }, + "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 13, 0, 13 ], + "to": [ 16, 15, 16 ], + "faces": { + "down": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, + "south": { "uv": [ 16, 16, 0, 13 ], "texture": "#texture", "rotation": 90 }, + "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 0, 15, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, + "north": { "uv": [ 0, 15, 16, 16 ], "texture": "#texture", "rotation": 180 }, + "south": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, + "west": { "uv": [ 15, 0, 16, 16 ], "texture": "#texture", "rotation": 270 }, + "east": { "uv": [ 0, 0, 1, 16 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 3, 14.9375, 3 ], + "to": [ 13, 15, 13 ], + "faces": { + "down": { "uv": [ 3, 3, 13, 13 ], "texture": "#texture", "rotation": 180 } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/greenhouse_window_up_open.json b/src/main/resources/assets/forestry/models/block/greenhouse_window_up_open.json new file mode 100644 index 000000000..1494506e3 --- /dev/null +++ b/src/main/resources/assets/forestry/models/block/greenhouse_window_up_open.json @@ -0,0 +1,115 @@ +{ + "textures": { + "texture": "blocks/glass", + "particle": "blocks/glass", + "log_oak": "blocks/log_oak" + }, + "elements": [ + { + "from": [ 3, 0, 13 ], + "to": [ 13, 15, 16 ], + "faces": { + "down": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 3, 13, 13, 16 ], "texture": "#texture" }, + "north": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 }, + "south": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 3, 0, 0 ], + "to": [ 13, 15, 3 ], + "faces": { + "down": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 3, 0, 13, 3 ], "texture": "#texture" }, + "north": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 }, + "south": { "uv": [ 16, 13, 0, 3 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 0, 0, 3 ], + "to": [ 3, 15, 13 ], + "faces": { + "down": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 13, 0, 3 ], + "to": [ 16, 15, 13 ], + "faces": { + "down": { "uv": [ 0, 3, 3, 13 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 13, 3, 16, 13 ], "texture": "#texture" }, + "west": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 270 }, + "east": { "uv": [ 0, 3, 16, 13 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 3, 15, 3 ], + "faces": { + "down": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture" }, + "north": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 90 }, + "west": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 270 } + } + }, + { + "from": [ 0, 0, 13 ], + "to": [ 3, 15, 16 ], + "faces": { + "down": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture" }, + "south": { "uv": [ 16, 3, 0, 0 ], "texture": "#texture", "rotation": 90 }, + "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 270 } + } + }, + { + "from": [ 13, 0, 0 ], + "to": [ 16, 15, 3 ], + "faces": { + "down": { "uv": [ 0, 0, 3, 3 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 13, 0, 16, 3 ], "texture": "#texture" }, + "north": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 90 }, + "east": { "uv": [ 0, 0, 16, 3 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 13, 0, 13 ], + "to": [ 16, 15, 16 ], + "faces": { + "down": { "uv": [ 0, 13, 3, 16 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 13, 13, 16, 16 ], "texture": "#texture" }, + "south": { "uv": [ 16, 16, 0, 13 ], "texture": "#texture", "rotation": 90 }, + "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 0, 14.5, -0.5 ], + "to": [ 16, 15.5, 15.5 ], + "rotation": { "origin": [ 0, 15.5, -0.5 ], "axis": "x", "angle": -45 }, + "faces": { + "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture", "rotation": 180 }, + "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#texture" }, + "north": { "uv": [ 0, 15, 16, 16 ], "texture": "#texture", "rotation": 180 }, + "south": { "uv": [ 16, 16, 0, 15 ], "texture": "#texture" }, + "west": { "uv": [ 15, 0, 16, 16 ], "texture": "#texture", "rotation": 270 }, + "east": { "uv": [ 0, 0, 1, 16 ], "texture": "#texture", "rotation": 90 } + } + }, + { + "from": [ 7.5, 21, 7.5 ], + "to": [ 8.5, 22, 17 ], + "rotation": { "origin": [ 7.5, 22, 7.5 ], "axis": "x", "angle": 45 }, + "faces": { + "down": { "uv": [ 16, 3, 16, 16 ], "texture": "#log_oak", "rotation": 180 }, + "up": { "uv": [ 0, 3, 0, 16 ], "texture": "#log_oak" }, + "north": { "uv": [ 0, 15, 0, 16 ], "texture": "#log_oak", "rotation": 180 }, + "south": { "uv": [ 16, 16, 16, 15 ], "texture": "#log_oak" }, + "west": { "uv": [ 15, 3, 16, 16 ], "texture": "#log_oak", "rotation": 270 }, + "east": { "uv": [ 0, 3, 1, 16 ], "texture": "#log_oak", "rotation": 90 } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/forestry/models/block/wood_pile.json b/src/main/resources/assets/forestry/models/block/wood_pile.json index 656859633..d03ca687d 100644 --- a/src/main/resources/assets/forestry/models/block/wood_pile.json +++ b/src/main/resources/assets/forestry/models/block/wood_pile.json @@ -1,4 +1,5 @@ { + "uvlock": true, "textures": { "particle": "blocks/log_oak", "texture": "blocks/log_oak", @@ -9,7 +10,7 @@ "from": [ 1, 0, 1 ], "to": [ 7, 16, 7 ], "faces": { - "down": { "uv": [ 1, 9, 7, 15 ], "texture": "#texture" }, + "down": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "up": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "north": { "uv": [ 9, 15, 15, 16 ], "texture": "#texture" }, "south": { "uv": [ 1, 15, 7, 16 ], "texture": "#texture" }, @@ -69,7 +70,7 @@ "from": [ 9, 0, 1 ], "to": [ 15, 16, 7 ], "faces": { - "down": { "uv": [ 1, 9, 7, 15 ], "texture": "#texture" }, + "down": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "up": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "north": { "uv": [ 9, 15, 15, 16 ], "texture": "#texture" }, "south": { "uv": [ 1, 15, 7, 16 ], "texture": "#texture" }, @@ -129,7 +130,7 @@ "from": [ 1, 0, 9 ], "to": [ 7, 16, 15 ], "faces": { - "down": { "uv": [ 1, 9, 7, 15 ], "texture": "#texture" }, + "down": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "up": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "north": { "uv": [ 9, 15, 15, 16 ], "texture": "#texture" }, "south": { "uv": [ 1, 15, 7, 16 ], "texture": "#texture" }, @@ -189,7 +190,7 @@ "from": [ 9, 0, 9 ], "to": [ 15, 16, 15 ], "faces": { - "down": { "uv": [ 1, 9, 7, 15 ], "texture": "#texture" }, + "down": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "up": { "uv": [ 5, 5, 11, 11 ], "texture": "#top" }, "north": { "uv": [ 9, 15, 15, 16 ], "texture": "#texture" }, "south": { "uv": [ 1, 15, 7, 16 ], "texture": "#texture" }, diff --git a/src/main/resources/assets/forestry/models/item/ash_block.json b/src/main/resources/assets/forestry/models/item/ash_block.json new file mode 100644 index 000000000..87b7fd390 --- /dev/null +++ b/src/main/resources/assets/forestry/models/item/ash_block.json @@ -0,0 +1,10 @@ +{ + "parent": "forestry:block/ash_block", + "display": { + "thirdperson": { + "rotation": [ 10, -45, 170 ], + "translation": [ 0, 1.5, -2.75 ], + "scale": [ 0.375, 0.375, 0.375 ] + } + } +} diff --git a/src/main/resources/assets/forestry/models/item/ash_brick.json b/src/main/resources/assets/forestry/models/item/ash_brick.json new file mode 100644 index 000000000..3b6946344 --- /dev/null +++ b/src/main/resources/assets/forestry/models/item/ash_brick.json @@ -0,0 +1,10 @@ +{ + "parent": "forestry:block/ash_brick", + "display": { + "thirdperson": { + "rotation": [ 10, -45, 170 ], + "translation": [ 0, 1.5, -2.75 ], + "scale": [ 0.375, 0.375, 0.375 ] + } + } +} diff --git a/src/main/resources/assets/forestry/models/item/ash_stairs.json b/src/main/resources/assets/forestry/models/item/ash_stairs.json new file mode 100644 index 000000000..28566c451 --- /dev/null +++ b/src/main/resources/assets/forestry/models/item/ash_stairs.json @@ -0,0 +1,3 @@ +{ + "parent": "forestry:block/ash_stairs" +} diff --git a/src/main/resources/assets/forestry/models/item/forester.json b/src/main/resources/assets/forestry/models/item/forester.json new file mode 100644 index 000000000..b051442ee --- /dev/null +++ b/src/main/resources/assets/forestry/models/item/forester.json @@ -0,0 +1,3 @@ +{ + "parent": "forestry:item/factory_tesr" +} diff --git a/src/main/resources/assets/forestry/models/item/greenhouse.door.json b/src/main/resources/assets/forestry/models/item/greenhouse.door.json deleted file mode 100644 index d72b401d0..000000000 --- a/src/main/resources/assets/forestry/models/item/greenhouse.door.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "forestry:items/greenhouse.door" - } -} diff --git a/src/main/resources/assets/forestry/models/item/greenhouse_screen.json b/src/main/resources/assets/forestry/models/item/greenhouse_screen.json new file mode 100644 index 000000000..fab4da2a0 --- /dev/null +++ b/src/main/resources/assets/forestry/models/item/greenhouse_screen.json @@ -0,0 +1,9 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "forestry:items/greenhouse_screen_0", + "layer1": "forestry:items/greenhouse_screen_1", + "layer2": "forestry:items/greenhouse_screen_2", + "layer3": "forestry:items/greenhouse_screen_3" + } +} diff --git a/src/main/resources/assets/forestry/models/item/greenhouse.window_up.json b/src/main/resources/assets/forestry/models/item/greenhouse_window.json similarity index 86% rename from src/main/resources/assets/forestry/models/item/greenhouse.window_up.json rename to src/main/resources/assets/forestry/models/item/greenhouse_window.json index 089ee1160..49d29ea33 100644 --- a/src/main/resources/assets/forestry/models/item/greenhouse.window_up.json +++ b/src/main/resources/assets/forestry/models/item/greenhouse_window.json @@ -1,5 +1,5 @@ { - "parent": "forestry:block/greenhouse.window_up_open", + "parent": "forestry:block/greenhouse_window_open", "display": { "thirdperson_righthand": { "rotation": [ 75, 135, 0 ], @@ -33,8 +33,8 @@ }, "gui": { "rotation": [ 30, 45, 0 ], - "translation": [ 0, -1.5, 0 ], - "scale": [ 0.5, 0.5, 0.5 ] + "translation": [ -1, -1.5, 0 ], + "scale": [ 0.45, 0.45, 0.45 ] } } } diff --git a/src/main/resources/assets/forestry/models/item/greenhouse.window.json b/src/main/resources/assets/forestry/models/item/greenhouse_window_up.json similarity index 93% rename from src/main/resources/assets/forestry/models/item/greenhouse.window.json rename to src/main/resources/assets/forestry/models/item/greenhouse_window_up.json index 089ee1160..b8feeeeb4 100644 --- a/src/main/resources/assets/forestry/models/item/greenhouse.window.json +++ b/src/main/resources/assets/forestry/models/item/greenhouse_window_up.json @@ -1,5 +1,5 @@ { - "parent": "forestry:block/greenhouse.window_up_open", + "parent": "forestry:block/greenhouse_window_up_open", "display": { "thirdperson_righthand": { "rotation": [ 75, 135, 0 ], diff --git a/src/main/resources/assets/forestry/textures/blocks/ash.png b/src/main/resources/assets/forestry/textures/blocks/ash.png new file mode 100644 index 000000000..f425b93ce Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/ash.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/ash_brick.png b/src/main/resources/assets/forestry/textures/blocks/ash_brick.png new file mode 100644 index 000000000..210fe7921 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/ash_brick.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/border.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/border.png new file mode 100644 index 000000000..51b38f8d6 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/border.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/border_top.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/border_top.png new file mode 100644 index 000000000..7b354e826 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/border_top.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/border_top_center.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/border_top_center.png new file mode 100644 index 000000000..c04470ca0 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/border_top_center.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/butterfly_hatch.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/butterfly_hatch.png deleted file mode 100644 index 370eea4a9..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/greenhouse/butterfly_hatch.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/climate_control.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/climate_control.png deleted file mode 100644 index b3fbfd303..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/greenhouse/climate_control.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/greenhouse_screen_0.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/greenhouse_screen_0.png new file mode 100644 index 000000000..642c23997 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/greenhouse_screen_0.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/greenhouse_screen_1.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/greenhouse_screen_1.png new file mode 100644 index 000000000..8c73ecf7c Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/greenhouse_screen_1.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/hygroregulator.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/hygroregulator.png new file mode 100644 index 000000000..af1213556 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/hygroregulator.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/top.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/top.png new file mode 100644 index 000000000..57c3de8d9 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/top.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/valve.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/valve.png deleted file mode 100644 index 391e293cb..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/greenhouse/valve.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/gui/climatiser.png b/src/main/resources/assets/forestry/textures/gui/climatiser.png new file mode 100644 index 000000000..ee807399d Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/climatiser.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse.png b/src/main/resources/assets/forestry/textures/gui/greenhouse.png index 6f07862b1..098a78772 100644 Binary files a/src/main/resources/assets/forestry/textures/gui/greenhouse.png and b/src/main/resources/assets/forestry/textures/gui/greenhouse.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse_hygroregulator.png b/src/main/resources/assets/forestry/textures/gui/greenhouse_hygroregulator.png new file mode 100644 index 000000000..731fdf84e Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/greenhouse_hygroregulator.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse_nursery.png b/src/main/resources/assets/forestry/textures/gui/greenhouse_nursery.png deleted file mode 100644 index bb515729f..000000000 Binary files a/src/main/resources/assets/forestry/textures/gui/greenhouse_nursery.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse_screen.png b/src/main/resources/assets/forestry/textures/gui/greenhouse_screen.png new file mode 100644 index 000000000..029a7dcf0 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/greenhouse_screen.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/misc/humidity.png b/src/main/resources/assets/forestry/textures/gui/misc/humidity.png new file mode 100644 index 000000000..c77176331 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/misc/humidity.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/misc/temperature.png b/src/main/resources/assets/forestry/textures/gui/misc/temperature.png new file mode 100644 index 000000000..e9e72f502 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/misc/temperature.png differ diff --git a/src/main/resources/assets/forestry/textures/items/camouflage_spray_can.png b/src/main/resources/assets/forestry/textures/items/camouflage_spray_can.png index cfadfc42a..dc7cd161c 100644 Binary files a/src/main/resources/assets/forestry/textures/items/camouflage_spray_can.png and b/src/main/resources/assets/forestry/textures/items/camouflage_spray_can.png differ diff --git a/src/main/resources/assets/forestry/textures/items/camouflage_spray_can_filled.png b/src/main/resources/assets/forestry/textures/items/camouflage_spray_can_filled.png index bc9b2c7bc..6a93f337d 100644 Binary files a/src/main/resources/assets/forestry/textures/items/camouflage_spray_can_filled.png and b/src/main/resources/assets/forestry/textures/items/camouflage_spray_can_filled.png differ diff --git a/src/main/resources/assets/forestry/textures/items/greenhouse.door.png b/src/main/resources/assets/forestry/textures/items/greenhouse.door.png deleted file mode 100644 index f7c602e69..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/greenhouse.door.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/greenhouse_screen_0.png b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_0.png new file mode 100644 index 000000000..bc3b7fb4f Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_0.png differ diff --git a/src/main/resources/assets/forestry/textures/items/greenhouse_screen_1.png b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_1.png new file mode 100644 index 000000000..a4ed51ec7 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_1.png differ diff --git a/src/main/resources/assets/forestry/textures/items/greenhouse_screen_2.png b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_2.png new file mode 100644 index 000000000..6bf8ecad9 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_2.png differ diff --git a/src/main/resources/assets/forestry/textures/items/greenhouse_screen_3.png b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_3.png new file mode 100644 index 000000000..ae4f60759 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/greenhouse_screen_3.png differ diff --git a/src/main/resources/config/forestry/colour.properties b/src/main/resources/config/forestry/colour.properties index f3ba3fec6..3b7f9360f 100755 --- a/src/main/resources/config/forestry/colour.properties +++ b/src/main/resources/config/forestry/colour.properties @@ -18,8 +18,9 @@ gui.beealyzer.dominant=ec3661 gui.mail.lettertext=cfa738 gui.mail.text=6689dc -gui.greenhouse.temperature.text=404040 -gui.greenhouse.humidity.text=404040 +gui.greenhouse.temperature.header=404040 +gui.greenhouse.humidity.header=404040 +gui.greenhouse.sources.subheader=aaafb8 ledger.error.background=ff3535 ledger.error.header=e1c92f @@ -39,6 +40,16 @@ ledger.climate.header=e1c92f ledger.climate.subheader=aaafb8 ledger.climate.text=000000 +ledger.modifier.temperature.background=c5c159 +ledger.modifier.temperature.header=e1c92f +ledger.modifier.temperature.subheader=aaafb8 +ledger.modifier.temperature.text=000000 + +ledger.modifier.humidity.background=39b3c6 +ledger.modifier.humidity.header=e1c92f +ledger.modifier.humidity.subheader=aaafb8 +ledger.modifier.humidity.text=000000 + ledger.power.background=d46c1f ledger.power.header=e1c92f ledger.power.subheader=aaafb8 diff --git a/src/main/resources/forestry_at.cfg b/src/main/resources/forestry_at.cfg index 03d3a1c43..64a146f7b 100644 --- a/src/main/resources/forestry_at.cfg +++ b/src/main/resources/forestry_at.cfg @@ -7,5 +7,9 @@ public net.minecraft.client.renderer.texture.TextureMap field_110574_e # mapRegi public net.minecraft.client.renderer.texture.TextureMap func_110569_e()V # initMissingImage +public-f net.minecraft.world.biome.BiomeColorHelper field_180291_a # GRASS_COLOR +public-f net.minecraft.world.biome.BiomeColorHelper field_180289_b # FOLIAGE_COLOR +public net.minecraft.world.biome.BiomeColorHelper$ColorResolver + #InventoryPlayer public net.minecraft.entity.player.InventoryPlayer func_184436_a(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z # canMergeStacks