mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 20:12:19 +00:00
Make climate update to a Runnable
This commit is contained in:
1 parent
1ac7a7de42
commit
1cd3e15ef9
2 files changed
+28
-15
No files matched your search
@@ -16,7 +16,11 @@ 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;
|
||||
|
||||
@@ -30,19 +34,28 @@ public class ClimateEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldTick(TickEvent.WorldTickEvent event) {
|
||||
Integer dim = Integer.valueOf(event.world.provider.getDimension());
|
||||
World world = event.world;
|
||||
if (event.phase == TickEvent.Phase.END) {
|
||||
if(!serverTicks.containsKey(dim)){
|
||||
serverTicks.put(dim, 1);
|
||||
MinecraftServer server = world.getMinecraftServer();
|
||||
if(server != null){
|
||||
server.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Integer dim = Integer.valueOf(event.world.provider.getDimension());
|
||||
if(!serverTicks.containsKey(dim)){
|
||||
serverTicks.put(dim, 1);
|
||||
}
|
||||
int ticks = serverTicks.get(dim);
|
||||
Map<Integer, List<IClimateRegion>> regions = ForestryAPI.climateManager.getRegions();
|
||||
if(regions != null && regions.containsKey(dim)){
|
||||
for(IClimateRegion region : regions.get(dim)){
|
||||
region.updateClimate(ticks);
|
||||
}
|
||||
}
|
||||
serverTicks.put(dim, ticks+1);
|
||||
}
|
||||
});
|
||||
}
|
||||
int ticks = serverTicks.get(dim);
|
||||
Map<Integer, List<IClimateRegion>> regions = ForestryAPI.climateManager.getRegions();
|
||||
if(regions != null && regions.containsKey(dim)){
|
||||
for(IClimateRegion region : regions.get(dim)){
|
||||
region.updateClimate(ticks);
|
||||
}
|
||||
}
|
||||
serverTicks.put(dim, ticks+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
return positions;
|
||||
}
|
||||
|
||||
public void addPosition(BlockPos pos, float temperature, float humidity){
|
||||
public synchronized void addPosition(BlockPos pos, float temperature, float humidity){
|
||||
IClimatePosition otherPosition = positions.get(pos);
|
||||
if(otherPosition != null){
|
||||
otherPosition.setHumidity(humidity);
|
||||
@@ -257,14 +257,14 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSource(IClimateSource source) {
|
||||
public synchronized void addSource(IClimateSource source) {
|
||||
if(!sources.contains(source)){
|
||||
sources.add(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSource(IClimateSource source) {
|
||||
public synchronized void removeSource(IClimateSource source) {
|
||||
if(sources.contains(source)){
|
||||
sources.remove(source);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user