Finish work

This commit is contained in:
Nedelosk committed 2016-06-12 20:42:09 +02:00
1 parent 2cd76bdad7
commit cc53894473
17 files changed
+156 -45

No files matched your search

+2
View File
@@ -26,6 +26,7 @@ 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;
@@ -81,6 +82,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());
configFolder = new File(event.getModConfigurationDirectory(), Constants.MOD_ID);
Config.load();
@@ -24,10 +24,17 @@ public interface IClimateManager {
void removeRegion(IClimateRegion region);
void addSource(IClimateSource source);
void removeSource(IClimateSource source);
@Nullable
IClimateRegion getRegionForPos(World world, BlockPos pos);
@Nonnull
Map<Integer, List<IClimateRegion>> getRegions();
@Nonnull
Map<Integer, List<IClimateSource>> getSources();
}
@@ -19,6 +19,9 @@ public interface IClimateRegion extends INbtReadable, INbtWritable {
@Nonnull
World getWorld();
/**
* Update the climate in a region, all 20 world ticks.
*/
void updateClimate();
@Nonnull
@@ -5,6 +5,19 @@
******************************************************************************/
package forestry.api.core.climate;
import net.minecraft.util.math.BlockPos;
/**
* A climate source is used to change the climate in a region.
*/
public interface IClimateSource {
/**
* @param tickCount The current tick count.
* @param region The climate region, in that the source stands.
*/
void changeClimate(int tickCount, IClimateRegion region);
BlockPos getPos();
}
@@ -10,12 +10,12 @@ import forestry.api.multiblock.IGreenhouseController;
public interface IGreenhouseListener {
/**
* Called before the greenhouse work.
* Called before the greenhouse update the climate system.
*
* @param greenhouse The greenhouse multiblock.
* @param greenhouse The greenhouse of the listener.
* @param canWork The actual {@link Boolean} value.
* @return True if the greenhouse can work.
* @return True if the greenhouse can update the climate.
*/
<G extends IGreenhouseController & IGreenhouseHousing> boolean canWork(G greenhouse, boolean canWork);
boolean canWork(IGreenhouseController greenhouse, boolean canWork);
}
@@ -5,6 +5,7 @@
******************************************************************************/
package forestry.api.multiblock;
import forestry.api.core.climate.IClimateSource;
import forestry.api.greenhouse.IGreenhouseListener;
import forestry.api.lepidopterology.IButterflyCocoon;
import net.minecraft.item.ItemStack;
@@ -20,8 +21,7 @@ public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> exte
interface Door extends IGreenhouseComponent {
}
interface Climatiser extends IGreenhouseComponent {
void changeClimate(int tickCount, IGreenhouseController controller);
interface Climatiser extends IGreenhouseComponent, IClimateSource {
}
interface ButterflyHatch extends IGreenhouseComponent {
@@ -0,0 +1,40 @@
package forestry.core.climate;
import java.util.HashMap;
import java.util.Map;
import forestry.api.core.ForestryAPI;
import forestry.api.core.climate.IClimateRegion;
import forestry.api.core.climate.IClimateSource;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
public class ClimateEventHandler {
Map<Integer, Integer> serverTicks;
public ClimateEventHandler() {
serverTicks = new HashMap<>();
}
@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent event) {
int dim = event.world.provider.getDimension();
if (event.phase == TickEvent.Phase.END) {
if(!serverTicks.containsKey(Integer.valueOf(dim))){
serverTicks.put(Integer.valueOf(dim), 1);
}
int ticks = serverTicks.get(Integer.valueOf(dim));
if(ticks % 20 == 0){
for(IClimateRegion region : ForestryAPI.climateManager.getRegions().get(Integer.valueOf(dim))){
region.updateClimate();
}
}
for(IClimateSource source : ForestryAPI.climateManager.getSources().get(Integer.valueOf(dim))){
source.changeClimate(ticks, ForestryAPI.climateManager.getRegionForPos(event.world, source.getPos()));
}
serverTicks.put(Integer.valueOf(dim), ticks+1);
}
}
}
@@ -18,6 +18,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import forestry.api.core.climate.IClimateManager;
import forestry.api.core.climate.IClimatePosition;
import forestry.api.core.climate.IClimateRegion;
@@ -36,7 +38,7 @@ public class ClimateManager implements IClimateManager{
return;
}
List<IClimateRegion> regions = getOrCreateRegions(region.getWorld());
List<BlockPos> positions = (List<BlockPos>) region.getPositions().keySet();
Set<BlockPos> positions = region.getPositions().keySet();
for(IClimateRegion otherRegion : regions){
for(BlockPos pos : otherRegion.getPositions().keySet()){
if(positions.contains(pos)){
@@ -17,7 +17,7 @@ import forestry.api.core.climate.IClimatePosition;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
public class ClimatedPosition implements IClimatePosition {
public class ClimatePosition implements IClimatePosition {
@Nonnull
protected final IClimateRegion climateRegion;
@@ -26,12 +26,12 @@ public class ClimatedPosition implements IClimatePosition {
protected float temperature;
protected float humidity;
public ClimatedPosition(IClimateRegion climateRegion, BlockPos pos) {
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos) {
this.climateRegion = climateRegion;
this.pos = pos;
}
public ClimatedPosition(@Nonnull IClimateRegion climateRegion, @Nonnull BlockPos pos, float temperature, float humidity) {
public ClimatePosition(@Nonnull IClimateRegion climateRegion, @Nonnull BlockPos pos, float temperature, float humidity) {
this.climateRegion = climateRegion;
this.pos = pos;
this.temperature = temperature;
@@ -123,7 +123,7 @@ public class ClimateRoom implements IClimateRegion {
int yPos = positionTag.getInteger("YPos");
int zPos = positionTag.getInteger("ZPos");
BlockPos pos = new BlockPos(xPos, yPos, zPos);
ClimatedPosition position = new ClimatedPosition(this, pos);
ClimatePosition position = new ClimatePosition(this, pos);
position.readFromNBT(positionTag);
positions.put(pos, position);
}
@@ -14,7 +14,6 @@ import java.util.Random;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
@@ -27,7 +26,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import forestry.core.PluginCore;
import forestry.core.blocks.BlockResourceOre;
import forestry.core.blocks.EnumResourceType;
import forestry.core.climate.ClimateManager;
import forestry.core.config.Config;
import forestry.plugins.PluginManager;
@@ -23,6 +23,7 @@ import forestry.api.core.climate.IClimateRegion;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.IGreenhouseLogic;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.multiblock.IGreenhouseComponent.Listener;
import forestry.core.fluids.FakeTankManager;
import forestry.core.fluids.ITankManager;
import forestry.core.inventory.FakeInventoryAdapter;
@@ -96,4 +97,13 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
public IClimateRegion getRegion() {
return null;
}
@Override
public void clearRegion() {
}
@Override
public Set<Listener> getListenerComponents() {
return Collections.emptySet();
}
}
@@ -38,6 +38,7 @@ import forestry.api.core.ForestryAPI;
import forestry.api.core.ICamouflagedTile;
import forestry.api.core.climate.IClimatePosition;
import forestry.api.core.climate.IClimateRegion;
import forestry.api.core.climate.IClimateSource;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent;
@@ -52,7 +53,7 @@ import forestry.api.multiblock.IGreenhouseController;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.core.access.EnumAccess;
import forestry.core.climate.ClimateRoom;
import forestry.core.climate.ClimatedPosition;
import forestry.core.climate.ClimatePosition;
import forestry.core.config.Constants;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
@@ -81,7 +82,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
private final Set<IInternalBlock> internalBlocks = new HashSet<>();
private final Set<IGreenhouseComponent.Listener> listenerComponents = new HashSet<>();
private final Set<IGreenhouseComponent.Climatiser> climatiserComponents = new HashSet<>();
private final Set<IGreenhouseComponent.Active> activeComponents = new HashSet<>();
private final List<IGreenhouseLogic> logics = new ArrayList<>();
@@ -408,15 +408,17 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
Map<BlockPos, IClimatePosition> internalPositions = new HashMap<>();
for(IInternalBlock block : internalBlocks){
if(block != null){
internalPositions.put(block.getPos(), new ClimatedPosition(region, block.getPos()));
internalPositions.put(block.getPos(), new ClimatePosition(region, block.getPos()));
}
}
ForestryAPI.climateManager.removeRegion(region);
region = new ClimateRoom(region, internalPositions);
ForestryAPI.climateManager.addRegion(region);
}else{
Map<BlockPos, IClimatePosition> internalPositions = new HashMap<>();
for(IInternalBlock block : internalBlocks){
if(block != null){
internalPositions.put(block.getPos(), new ClimatedPosition(region, block.getPos()));
internalPositions.put(block.getPos(), new ClimatePosition(region, block.getPos()));
}
}
region = new ClimateRoom(this, internalPositions);
@@ -437,7 +439,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
if (newPart instanceof IGreenhouseComponent.Listener) {
listenerComponents.add((IGreenhouseComponent.Listener) newPart);
} else if (newPart instanceof IGreenhouseComponent.Climatiser) {
climatiserComponents.add((IGreenhouseComponent.Climatiser) newPart);
ForestryAPI.climateManager.addSource((IClimateSource) newPart);
} else if (newPart instanceof IGreenhouseComponent.Active) {
activeComponents.add((IGreenhouseComponent.Active) newPart);
}
@@ -448,7 +450,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
if (oldPart instanceof IGreenhouseComponent.Listener) {
listenerComponents.remove(oldPart);
} else if (oldPart instanceof IGreenhouseComponent.Climatiser) {
climatiserComponents.remove(oldPart);
ForestryAPI.climateManager.removeSource((IClimateSource) oldPart);
} else if (oldPart instanceof IGreenhouseComponent.Active) {
activeComponents.remove(oldPart);
}
@@ -456,10 +458,21 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
@Override
protected void onAssimilate(IMultiblockControllerInternal assimilated) {
if(assimilated != null && ((IGreenhouseControllerInternal)assimilated).getRegion() != null){
IGreenhouseControllerInternal internal = (IGreenhouseControllerInternal) assimilated;
if(region != null){
ForestryAPI.climateManager.removeRegion(region);
region = new ClimateRoom(region,internal.getRegion().getPositions());
ForestryAPI.climateManager.addRegion(region);
}
}
}
@Override
public void onAssimilated(IMultiblockControllerInternal assimilator) {
if(region != null){
ForestryAPI.climateManager.removeRegion(region);
}
}
@Override
@@ -475,20 +488,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
for (IGreenhouseComponent.Active activeComponent : activeComponents) {
activeComponent.updateServer(tickCount);
}
boolean canWork = true;
for (IGreenhouseComponent.Listener listenerComponent : listenerComponents) {
canWork = listenerComponent.getGreenhouseListener().canWork(this, canWork);
}
if (canWork) {
for (IGreenhouseComponent.Climatiser climatiser : climatiserComponents) {
climatiser.changeClimate(tickCount, this);
}
}
return canWork;
return false;
}
@Override
@@ -742,5 +743,15 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
public IClimateRegion getRegion() {
return region;
}
@Override
public void clearRegion() {
region = null;
}
@Override
public Set<IGreenhouseComponent.Listener> getListenerComponents() {
return listenerComponents;
}
}
@@ -15,6 +15,7 @@ import javax.annotation.Nullable;
import java.util.Set;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IGreenhouseController;
import forestry.core.access.IRestrictedAccess;
import forestry.core.fluids.ITankManager;
@@ -48,4 +49,11 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM
* @return All internal blocks of the greenhouse.
*/
Set<IInternalBlock> getInternalBlocks();
/**
* Set the region to null.
*/
void clearRegion();
Set<IGreenhouseComponent.Listener> getListenerComponents();
}
@@ -15,13 +15,14 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.client.model.animation.AnimationTESR;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import forestry.api.core.ForestryAPI;
import forestry.core.models.BlockModelIndex;
import forestry.core.proxy.Proxies;
import forestry.greenhouse.PluginGreenhouse;
import forestry.greenhouse.blocks.BlockGreenhouseType;
import forestry.greenhouse.models.ModelGreenhouse;
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
import forestry.plugins.ForestryPluginUids;
public class ProxyGreenhouseClient extends ProxyGreenhouse {
@@ -33,6 +34,10 @@ public class ProxyGreenhouseClient extends ProxyGreenhouse {
} else if (greenhouseType == BlockGreenhouseType.SPRINKLER) {
ClientRegistry.bindTileEntitySpecialRenderer(TileGreenhouseSprinkler.class, new AnimationTESR<>());
continue;
}else if(greenhouseType == BlockGreenhouseType.BUTTERFLY_HATCH){
if(!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)){
continue;
}
}
Proxies.render.registerBlockModel(new BlockModelIndex(new ModelResourceLocation("forestry:greenhouse." + greenhouseType),
new ModelResourceLocation("forestry:greenhouse", "inventory"), new ModelGreenhouse(),
@@ -18,7 +18,6 @@ import net.minecraft.util.math.BlockPos;
import forestry.api.core.climate.IClimatePosition;
import forestry.api.core.climate.IClimateRegion;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IGreenhouseController;
import forestry.api.multiblock.IMultiblockController;
import forestry.apiculture.network.packets.PacketActiveUpdate;
import forestry.core.proxy.Proxies;
@@ -81,12 +80,18 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
}
@Override
public void changeClimate(int tick, IGreenhouseController greenhouse) {
if(minPos != null && maxPos != null){
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse;
if (workingTime == 0 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) {
public void changeClimate(int tick, IClimateRegion region) {
IMultiblockController controller = getMultiblockLogic().getController();
if(getMultiblockLogic().isConnected() && controller != null && controller.isAssembled() && minPos != null && maxPos != null && region != null){
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller;
boolean canWork = true;
for (IGreenhouseComponent.Listener listenerComponent : greenhouseInternal.getListenerComponents()) {
if(canWork){
canWork = listenerComponent.getGreenhouseListener().canWork(greenhouseInternal, canWork);
}
}
if (canWork && workingTime == 0 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) {
int dimensionID = worldObj.provider.getDimension();
IClimateRegion region = greenhouse.getRegion();
for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){
IClimatePosition position = region.getPositions().get(pos);
@@ -22,7 +22,8 @@ import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import forestry.api.core.climate.IClimatePosition;
import forestry.api.core.climate.IClimateRegion;
import forestry.api.multiblock.IGreenhouseController;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IMultiblockController;
import forestry.core.config.Constants;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.proxy.Proxies;
@@ -51,12 +52,18 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
}
@Override
public void changeClimate(int tick, IGreenhouseController greenhouse) {
if(minPos != null && maxPos != null){
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse;
if (workingTime == 0 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) {
public void changeClimate(int tick, IClimateRegion region) {
IMultiblockController controller = getMultiblockLogic().getController();
if(getMultiblockLogic().isConnected() && controller != null && controller.isAssembled() && minPos != null && maxPos != null && region != null){
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller;
boolean canWork = true;
for (IGreenhouseComponent.Listener listenerComponent : greenhouseInternal.getListenerComponents()) {
if(canWork){
canWork = listenerComponent.getGreenhouseListener().canWork(greenhouseInternal, canWork);
}
}
if (canWork && workingTime == 0 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) {
int dimensionID = worldObj.provider.getDimension();
IClimateRegion region = greenhouse.getRegion();
for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){
IClimatePosition position = region.getPositions().get(pos);