diff --git a/common/tan/ToughAsNails.java b/common/tan/ToughAsNails.java index 366e15a0a..e3e037919 100644 --- a/common/tan/ToughAsNails.java +++ b/common/tan/ToughAsNails.java @@ -2,7 +2,7 @@ package tan; import net.minecraftforge.common.MinecraftForge; import tan.core.TANPlayerStats; -import tan.core.TANTemperatureSources; +import tan.core.TANTemperature; import tan.handler.ConnectionHandler; import tan.handler.RenderOverlayEventHandler; import tan.handler.TickHandlerServer; @@ -33,7 +33,7 @@ public class ToughAsNails public void preInit(FMLPreInitializationEvent event) { TANPlayerStats.init(); - TANTemperatureSources.init(); + TANTemperature.init(); } @EventHandler diff --git a/common/tan/api/TemperatureRegistry.java b/common/tan/api/TemperatureRegistry.java deleted file mode 100644 index 59b590318..000000000 --- a/common/tan/api/TemperatureRegistry.java +++ /dev/null @@ -1,40 +0,0 @@ -package tan.api; - -import java.util.HashMap; - -import net.minecraft.item.ItemStack; - -public class TemperatureRegistry -{ - public static HashMap temperatureSources = new HashMap(); - - public static TemperatureSource getTemperatureSource(int id, int metadata) - { - return temperatureSources.get(id + ";" + metadata); - } - - public static TemperatureSource getTemperatureSource(int id) - { - return getTemperatureSource(id, 0); - } - - public static void registerTemperatureSource(int id, int metadata, TemperatureSource temperatureSource) - { - if (metadata == -1) - { - for (int i = 0; i < 16; i++) - { - temperatureSources.put(id + ";" + i, temperatureSource); - } - } - else - { - temperatureSources.put(id + ";" + metadata, temperatureSource); - } - } - - public static void registerTemperatureSource(int id, TemperatureSource temperatureSource) - { - registerTemperatureSource(id, 0, temperatureSource); - } -} diff --git a/common/tan/api/TemperatureSource.java b/common/tan/api/TemperatureSource.java deleted file mode 100644 index 3e16f0993..000000000 --- a/common/tan/api/TemperatureSource.java +++ /dev/null @@ -1,13 +0,0 @@ -package tan.api; - -public class TemperatureSource -{ - public float temperature; - public float rate; - - public TemperatureSource(float temperature, float rate) - { - this.temperature = temperature; - this.rate = rate; - } -} diff --git a/common/tan/api/temperature/ITemperatureModifier.java b/common/tan/api/temperature/ITemperatureModifier.java new file mode 100644 index 000000000..a3f7cb5bb --- /dev/null +++ b/common/tan/api/temperature/ITemperatureModifier.java @@ -0,0 +1,9 @@ +package tan.api.temperature; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.world.World; + +public interface ITemperatureModifier +{ + public float modifyTemperature(World world, EntityPlayerMP player); +} diff --git a/common/tan/api/temperature/TemperatureRegistry.java b/common/tan/api/temperature/TemperatureRegistry.java new file mode 100644 index 000000000..8b06e1609 --- /dev/null +++ b/common/tan/api/temperature/TemperatureRegistry.java @@ -0,0 +1,55 @@ +package tan.api.temperature; + +import java.util.ArrayList; +import java.util.HashMap; + +public class TemperatureRegistry +{ + public static HashMap temperatureSources = new HashMap(); + public static ArrayList temperatureModifiers = new ArrayList(); + + public static float getTemperatureSourceModifier(int id, int metadata) + { + float modifier = 0; + + try + { + modifier = temperatureSources.get(id + ";" + metadata); + } + catch (Exception e) + { + + } + return modifier; + } + + public static float getTemperatureSourceModifier(int id) + { + return getTemperatureSourceModifier(id, 0); + } + + public static void registerTemperatureModifier(ITemperatureModifier temperatureModifier) + { + temperatureModifiers.add(temperatureModifier); + } + + public static void registerTemperatureSource(int id, int metadata, float modifier) + { + if (metadata == -1) + { + for (int i = 0; i < 16; i++) + { + temperatureSources.put(id + ";" + i, modifier); + } + } + else + { + temperatureSources.put(id + ";" + metadata, modifier); + } + } + + public static void registerTemperatureSource(int id, float modifier) + { + registerTemperatureSource(id, 0, modifier); + } +} diff --git a/common/tan/core/TANTemperature.java b/common/tan/core/TANTemperature.java new file mode 100644 index 000000000..6f6f23555 --- /dev/null +++ b/common/tan/core/TANTemperature.java @@ -0,0 +1,24 @@ +package tan.core; + +import net.minecraft.block.Block; +import tan.api.temperature.TemperatureRegistry; +import tan.temperaturemodifiers.TemperatureSourceModifier; + +public class TANTemperature +{ + public static void init() + { + registerTemperatureModifiers(); + registerTemperatureSources(); + } + + private static void registerTemperatureModifiers() + { + TemperatureRegistry.registerTemperatureModifier(new TemperatureSourceModifier()); + } + + private static void registerTemperatureSources() + { + TemperatureRegistry.registerTemperatureSource(Block.fire.blockID, -1, 4F); + } +} diff --git a/common/tan/core/TANTemperatureSources.java b/common/tan/core/TANTemperatureSources.java deleted file mode 100644 index 841b526ba..000000000 --- a/common/tan/core/TANTemperatureSources.java +++ /dev/null @@ -1,18 +0,0 @@ -package tan.core; - -import net.minecraft.block.Block; -import tan.api.TemperatureRegistry; -import tan.api.TemperatureSource; - -public class TANTemperatureSources -{ - public static void init() - { - registerTemperatureSources(); - } - - private static void registerTemperatureSources() - { - TemperatureRegistry.registerTemperatureSource(Block.fire.blockID, -1, new TemperatureSource(43F, 0.80F)); - } -} diff --git a/common/tan/stats/TemperatureStat.java b/common/tan/stats/TemperatureStat.java index 45cbf4488..278f9f72b 100644 --- a/common/tan/stats/TemperatureStat.java +++ b/common/tan/stats/TemperatureStat.java @@ -1,19 +1,15 @@ package tan.stats; import java.text.DecimalFormat; -import java.util.ArrayList; -import net.minecraft.block.Block; import net.minecraft.util.MathHelper; +import net.minecraft.world.biome.BiomeGenBase; import tan.api.TANStat; -import tan.api.TemperatureRegistry; -import tan.api.TemperatureSource; +import tan.api.temperature.ITemperatureModifier; +import tan.api.temperature.TemperatureRegistry; public class TemperatureStat extends TANStat { - private ArrayList averageAimedTemperatures = new ArrayList(); - private ArrayList averageRates = new ArrayList(); - @Override public void update() { @@ -24,19 +20,18 @@ public class TemperatureStat extends TANStat float originalTemperature = tanData.getFloat(getStatName()); float temperature = originalTemperature; - float aimedTemperature = 0F; - float rate = 0F; + float[] temperatureRainfall = getEnvironmentTemperatureRainfall(x, y, z); - calculateSourceAndEnvironment(x, y, z); + float aimedTemperature = temperatureRainfall[0]; - for (float averageAimedTemperature : averageAimedTemperatures) + for (ITemperatureModifier temperatureModifier : TemperatureRegistry.temperatureModifiers) { - aimedTemperature += averageAimedTemperature; + float modifier = temperatureModifier.modifyTemperature(world, player); + + aimedTemperature += modifier; } - aimedTemperature /= averageAimedTemperatures.size(); - - DecimalFormat twoDForm = new DecimalFormat("#.#"); + DecimalFormat twoDForm = new DecimalFormat("#.##"); try { @@ -47,27 +42,26 @@ public class TemperatureStat extends TANStat } - for (float averageRate : averageRates) - { - rate += averageRate; - } - - rate = (rate / averageRates.size()) / 10; - - if (world.rand.nextFloat() <= rate) + if (world.rand.nextFloat() <= temperatureRainfall[1]) { if (temperature > aimedTemperature) { - temperature -= 0.1F; + temperature -= 0.01F; } else if (temperature < aimedTemperature) { - temperature += 0.1F; + temperature += 0.01F; } } - averageAimedTemperatures.clear(); - averageRates.clear(); + try + { + temperature = Float.parseFloat(twoDForm.format(temperature)); + } + catch (Exception e) + { + + } if (temperature != originalTemperature) { @@ -77,18 +71,15 @@ public class TemperatureStat extends TANStat } } - private void calculateSourceAndEnvironment(int x, int y, int z) + private float[] getEnvironmentTemperatureRainfall(int x, int y, int z) { - float averageAimedSourceTemperature = 0F; - float averageSourceRate = 0F; - - int sourceDivider = 0; + float[] temperatureRainfall = new float[2]; float averageAimedEnvironmentTemperature = 0F; - float averageEnvironmentRate = 0F; - + float rainfall = 0.25F; + int environmentDivider = 0; - + for (int ix = -2; ix <= 2; ix++) { for (int iy = -1; iy <= 1; iy++) @@ -98,39 +89,39 @@ public class TemperatureStat extends TANStat int blockID = world.getBlockId(x + ix, y + iy, z + iz); int metadata = world.getBlockMetadata(x + ix, y + iy, z + iz); - TemperatureSource temperatureSource = TemperatureRegistry.getTemperatureSource(blockID, metadata); - - if (temperatureSource != null) - { - averageAimedSourceTemperature += temperatureSource.temperature; - averageSourceRate += temperatureSource.rate; - - sourceDivider++; - } - else - { - averageAimedEnvironmentTemperature += ((world.getBiomeGenForCoords(x + ix, z + iz).temperature / 2) * 20) + 27; - averageEnvironmentRate += 0.25F; + BiomeGenBase biome = world.getBiomeGenForCoords(x + ix, z + iz); - environmentDivider++; - } + averageAimedEnvironmentTemperature += ((biome.temperature / 2) * 20) + 27; + + rainfall = (biome.rainfall / 2) / 10; + + environmentDivider++; } } } - if (sourceDivider != 0) - { - float aimedSourceTemperature = averageAimedSourceTemperature /= sourceDivider; - averageAimedTemperatures.add(aimedSourceTemperature); - } - if (environmentDivider != 0) - { - float aimedEnvironmentTemperature = averageAimedEnvironmentTemperature /= environmentDivider; - averageAimedTemperatures.add(aimedEnvironmentTemperature); - } + temperatureRainfall[0] = averageAimedEnvironmentTemperature / environmentDivider; + temperatureRainfall[1] = rainfall; + + return temperatureRainfall; + } + + public boolean isDay() + { + float celestialAngle = world.getCelestialAngle(0.0F); - if (sourceDivider != 0) averageRates.add(averageSourceRate /= sourceDivider); - if (environmentDivider != 0) averageRates.add(averageEnvironmentRate /= environmentDivider); + if (celestialAngle >= 0.75F && celestialAngle <= 1.0F || celestialAngle >= 0.0F && celestialAngle <= 0.25F) return true; + + return false; + } + + public boolean isNight() + { + float celestialAngle = world.getCelestialAngle(0.0F); + + if (celestialAngle >= 0.25F && celestialAngle <= 0.75F) return true; + + return false; } @Override diff --git a/common/tan/temperaturemodifiers/TemperatureSourceModifier.java b/common/tan/temperaturemodifiers/TemperatureSourceModifier.java new file mode 100644 index 000000000..1f676978c --- /dev/null +++ b/common/tan/temperaturemodifiers/TemperatureSourceModifier.java @@ -0,0 +1,57 @@ +package tan.temperaturemodifiers; + +import java.util.ArrayList; +import java.util.Collections; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import tan.api.temperature.ITemperatureModifier; +import tan.api.temperature.TemperatureRegistry; + +public class TemperatureSourceModifier implements ITemperatureModifier +{ + @Override + public float modifyTemperature(World world, EntityPlayerMP player) + { + ArrayList temperatureModifiers = new ArrayList(); + + int x = MathHelper.floor_double(player.posX); + int y = MathHelper.floor_double(player.posY); + int z = MathHelper.floor_double(player.posZ); + + for (int ix = -2; ix <= 2; ix++) + { + for (int iy = -1; iy <= 1; iy++) + { + for (int iz = -2; iz <= 2; iz++) + { + int blockID = world.getBlockId(x + ix, y + iy, z + iz); + int metadata = world.getBlockMetadata(x + ix, y + iy, z + iz); + + float temperatureModifier = TemperatureRegistry.getTemperatureSourceModifier(blockID, metadata); + + temperatureModifiers.add(temperatureModifier); + } + } + } + + float total = 0F; + int divider = 0; + + for (float temperatureModifier : temperatureModifiers) + { + total += temperatureModifier; + divider++; + } + + if ((total / divider) > 0) + { + return Collections.max(temperatureModifiers); + } + else + { + return Collections.min(temperatureModifiers); + } + } +}