mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-23 21:39:51 +00:00
Fix Climate Handler and add climate test mod for devs
This commit is contained in:
1 parent
1cd3e15ef9
commit
a05bc13852
2 files changed
+135
-27
No files matched your search
@@ -13,14 +13,10 @@ 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.client.Minecraft;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
@@ -31,6 +27,126 @@ public class ClimateEventHandler {
|
||||
public ClimateEventHandler() {
|
||||
serverTicks = new HashMap<>();
|
||||
}
|
||||
|
||||
//Climate test mode
|
||||
/*public static Pair<BlockPos, BlockPos> recalculateMinMaxCoords(Collection<BlockPos> 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().thePlayer;
|
||||
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().theWorld;
|
||||
List<IClimateRegion> regions = ForestryAPI.climateManager.getRegions().get(Integer.valueOf(world.provider.getDimension()));
|
||||
for(IClimateRegion region : regions){
|
||||
if(region != null){
|
||||
Map<BlockPos, IClimatePosition> positions = region.getPositions();
|
||||
Pair<BlockPos, BlockPos> 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<BlockPos, IClimatePosition> 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().func_189697_a(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().func_189696_b(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().func_189697_a(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().func_189696_b(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 onWorldTick(TickEvent.WorldTickEvent event) {
|
||||
|
||||
@@ -143,6 +143,7 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
climatedInfo.addHumidity(-Math.min(0.01F, climatedInfo.getHumidity() - climateControl.getControlHumidity()));
|
||||
}else{
|
||||
climatedInfo.addHumidity(Math.min(0.01F, climateControl.getControlHumidity() - climatedInfo.getHumidity()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,29 +157,20 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
boolean hasChange = false;
|
||||
if(climateControl.getControlTemperature() != temperature || climateControl.getControlHumidity() != humidity) {
|
||||
boolean updateTemp = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
boolean updateHum = climatedInfo.getHumidity() >= climateControl.getControlHumidity();
|
||||
if(updateTemp || updateHum){
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
IClimatePosition climatedInfoFace = positions.get(pos.offset(facing));
|
||||
if(climatedInfoFace != null){
|
||||
if(climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getTemperature() - climatedInfoFace.getTemperature());
|
||||
climatedInfo.addTemperature(-change);
|
||||
climatedInfoFace.addTemperature(change);
|
||||
updateTemp = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
hasChange = true;
|
||||
}
|
||||
if(climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getHumidity() - climatedInfoFace.getHumidity());
|
||||
climatedInfo.addHumidity(-change);
|
||||
climatedInfoFace.addHumidity(change);
|
||||
updateHum = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
hasChange = true;
|
||||
}
|
||||
if(!updateTemp && !updateHum){
|
||||
break;
|
||||
}
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
IClimatePosition climatedInfoFace = positions.get(pos.offset(facing));
|
||||
if(climatedInfoFace != null){
|
||||
if(climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getTemperature() - climatedInfoFace.getTemperature());
|
||||
climatedInfo.addTemperature(-change);
|
||||
climatedInfoFace.addTemperature(change);
|
||||
hasChange = true;
|
||||
}
|
||||
if(climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getHumidity() - climatedInfoFace.getHumidity());
|
||||
climatedInfo.addHumidity(-change);
|
||||
climatedInfoFace.addHumidity(change);
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user