diff --git a/src/main/java/toughasnails/api/season/IDecayableCrop.java b/src/main/java/toughasnails/api/season/IDecayableCrop.java index 89ddeeae..b2ce0a94 100644 --- a/src/main/java/toughasnails/api/season/IDecayableCrop.java +++ b/src/main/java/toughasnails/api/season/IDecayableCrop.java @@ -7,10 +7,15 @@ ******************************************************************************/ package toughasnails.api.season; -/** - * A marker interface which should be implemented by crops which decay - * in the winter in the absence of proper heating. +/** + * A marker interface which should be implemented by crops which decay in the + * winter in the absence of proper heating. + * + * Please note that due to how Java bytecode works, you must explicitly + * implement this interface if your class overrides updateTick. */ public interface IDecayableCrop { -} + // Crop will only decay in winter if this returns true + boolean shouldDecay(); +} \ No newline at end of file diff --git a/src/main/java/toughasnails/api/season/IHibernatingCrop.java b/src/main/java/toughasnails/api/season/IHibernatingCrop.java index f5f5dbe6..07d93f0b 100644 --- a/src/main/java/toughasnails/api/season/IHibernatingCrop.java +++ b/src/main/java/toughasnails/api/season/IHibernatingCrop.java @@ -7,10 +7,17 @@ ******************************************************************************/ package toughasnails.api.season; -/** - * A marker interface which should be implemented by crops which stop growing - * in the winter in the absence of proper heating. +/** + * An interface which should be implemented by crops which become inactive in + * the winter in the absence of proper heating. + * + * Crops using this interface should make sure they use Forge's crop growth + * events and appropriately cancel the crop growth when the event result is set + * to DENY. (See net.minecraftforge.event.BlockEvent$CropGrowEvent or + * alternatively net.minecraftforge.common.ForgeHooks.onCropsGrowPre) */ public interface IHibernatingCrop { - -} + + // Crop will only hibernate in winter if this returns true + boolean shouldHibernate(); +} \ No newline at end of file diff --git a/src/main/java/toughasnails/api/temperature/TemperatureHelper.java b/src/main/java/toughasnails/api/temperature/TemperatureHelper.java index 743d490b..a7cc1c12 100644 --- a/src/main/java/toughasnails/api/temperature/TemperatureHelper.java +++ b/src/main/java/toughasnails/api/temperature/TemperatureHelper.java @@ -17,7 +17,6 @@ import net.minecraft.world.World; import toughasnails.api.TANCapabilities; import toughasnails.api.stat.capability.ITemperature; -import toughasnails.api.stat.capability.IThirst; public class TemperatureHelper { diff --git a/src/main/java/toughasnails/asm/transformer/PamCropTransformer.java b/src/main/java/toughasnails/asm/transformer/PamCropTransformer.java index 73d10343..a17e4ce6 100644 --- a/src/main/java/toughasnails/asm/transformer/PamCropTransformer.java +++ b/src/main/java/toughasnails/asm/transformer/PamCropTransformer.java @@ -10,28 +10,35 @@ import toughasnails.asm.transformer.AbstractCropTransformer.WinterBehavior; // Pam's Harvestcraft compatibility -public class PamCropTransformer extends AbstractCropTransformer -{ - private static final String[] VALID_HASHES_CROP = new String[] { "03263774b5cda6bfeccc1622fd344710" }; - private static final String[] VALID_HASHES_FRUIT = new String[] { "da4a453d0bcd36b8db130e372865cb24" }; - private static final String[] VALID_HASHES_FRUIT_LOG = new String[] { "ce0043f49abbe83982be20cbf4989bb3" }; - - @Override - public byte[] transform(String name, String transformedName, byte[] basicClass) - { - if (transformedName.equals("com.pam.harvestcraft.blocks.growables.BlockPamCrop")) - { - return transformCrop(basicClass, !transformedName.equals(name), "BlockPamCrop", VALID_HASHES_CROP, WinterBehavior.DECAY); - } - if (transformedName.equals("com.pam.harvestcraft.blocks.growables.BlockPamFruit")) - { - return transformCrop(basicClass, !transformedName.equals(name), "BlockPamFruit", VALID_HASHES_FRUIT, WinterBehavior.HIBERNATE); - } - if (transformedName.equals("com.pam.harvestcraft.blocks.growables.BlockPamFruitLog")) - { - return transformCrop(basicClass, !transformedName.equals(name), "BlockPamFruitLog", VALID_HASHES_FRUIT_LOG, WinterBehavior.HIBERNATE); - } - - return basicClass; - } +public class PamCropTransformer extends AbstractCropTransformer { + private static final String[] VALID_HASHES_CROP = new String[] { + "03263774b5cda6bfeccc1622fd344710" }; + private static final String[] VALID_HASHES_FRUIT = new String[] { + "da4a453d0bcd36b8db130e372865cb24" }; + private static final String[] VALID_HASHES_FRUIT_LOG = new String[] { + "ce0043f49abbe83982be20cbf4989bb3" }; + + @Override + public byte[] transform(String name, String transformedName, + byte[] basicClass) { + if (transformedName + .equals("com.pam.harvestcraft.blocks.growables.BlockPamCrop")) { + return transformCrop(basicClass, !transformedName.equals(name), + "BlockPamCrop", VALID_HASHES_CROP, WinterBehavior.DECAY); + } + if (transformedName.equals( + "com.pam.harvestcraft.blocks.growables.BlockPamFruit")) { + return transformCrop(basicClass, !transformedName.equals(name), + "BlockPamFruit", VALID_HASHES_FRUIT, + WinterBehavior.HIBERNATE); + } + if (transformedName.equals( + "com.pam.harvestcraft.blocks.growables.BlockPamFruitLog")) { + return transformCrop(basicClass, !transformedName.equals(name), + "BlockPamFruitLog", VALID_HASHES_FRUIT_LOG, + WinterBehavior.HIBERNATE); + } + + return basicClass; + } } diff --git a/src/main/java/toughasnails/command/TANCommand.java b/src/main/java/toughasnails/command/TANCommand.java index fa33be4a..fad75fe6 100644 --- a/src/main/java/toughasnails/command/TANCommand.java +++ b/src/main/java/toughasnails/command/TANCommand.java @@ -6,6 +6,7 @@ import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; +import net.minecraft.command.CommandResultStats; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; import net.minecraft.entity.player.EntityPlayerMP; @@ -29,6 +30,12 @@ import toughasnails.season.SeasonTime; import toughasnails.temperature.TemperatureDebugger; import toughasnails.temperature.TemperatureHandler; +import toughasnails.temperature.modifier.AltitudeModifier; +import toughasnails.temperature.modifier.BiomeModifier; +import toughasnails.temperature.modifier.ObjectProximityModifier; +import toughasnails.temperature.modifier.SeasonModifier; +import toughasnails.temperature.modifier.TimeModifier; +import toughasnails.temperature.modifier.WeatherModifier; import toughasnails.thirst.ThirstHandler; public class TANCommand extends CommandBase { @@ -59,10 +66,16 @@ public void execute(MinecraftServer server, ICommandSender sender, throw new WrongUsageException("commands.toughasnails.usage"); } else if ("tempinfo".equals(args[0])) { displayTemperatureInfo(sender, args); + } else if ("tempat".equals(args[0])) { + if (args.length < 5 || args.length > 6) { + throw new WrongUsageException("commands.toughasnails.usage"); + } else { + retrieveTemperatureAt(sender, args); + } } else if ("settemp".equals(args[0])) { setTemperature(sender, args); } else if ("setseason".equals(args[0])) { - if (args.length != 3) { + if (args.length < 3 || args.length > 4) { throw new WrongUsageException("commands.toughasnails.usage"); } else { setSeason(sender, args); @@ -97,6 +110,87 @@ private void displayTemperatureInfo(ICommandSender sender, String[] args) } } + // tan tempat + private void retrieveTemperatureAt(ICommandSender sender, String[] args) + throws CommandException { + int dimensionID = 0; + int x = 0; + int y = 0; + int z = 0; + boolean printOutput = true; + try { + dimensionID = Integer.parseInt(args[1]); + x = Integer.parseInt(args[2]); + y = Integer.parseInt(args[3]); + z = Integer.parseInt(args[4]); + if (args.length >= 6) { + printOutput = Boolean.parseBoolean(args[5]); + } + } catch (NumberFormatException e) { + throw new WrongUsageException("commands.toughasnails.usage"); + } + + if (SyncedConfig.getBooleanValue(GameplayOption.ENABLE_TEMPERATURE)) { + World world = null; + WorldServer[] worldServers = FMLCommonHandler.instance() + .getMinecraftServerInstance().worldServers; + WorldServer candidate = FMLCommonHandler.instance() + .getMinecraftServerInstance() + .worldServerForDimension(dimensionID); + if (candidate == null) { + throw new WrongUsageException("commands.toughasnails.usage"); + } + + for (int i = 0; i < worldServers.length; i++) { + WorldServer target = worldServers[i]; + if (candidate.equals(target)) { + world = target; + break; + } + } + + if (world == null) { + throw new WrongUsageException("commands.toughasnails.usage"); + } + final TemperatureDebugger debugger = new TemperatureDebugger(); + AltitudeModifier altitudeModifier = new AltitudeModifier(debugger); + BiomeModifier biomeModifier = new BiomeModifier(debugger); + ObjectProximityModifier objectProximityModifier = new ObjectProximityModifier( + debugger); + WeatherModifier weatherModifier = new WeatherModifier(debugger); + TimeModifier timeModifier = new TimeModifier(debugger); + SeasonModifier seasonModifier = new SeasonModifier(debugger); + + BlockPos position = new BlockPos(x, y, z); + Temperature baseTemperature = new Temperature( + TemperatureHandler.TEMPERATURE_SCALE_MIDPOINT); + Temperature targetTemperature = biomeModifier.modifyTarget(world, + position, baseTemperature); + targetTemperature = altitudeModifier.modifyTarget(world, position, + targetTemperature); + targetTemperature = objectProximityModifier.modifyTarget(world, + position, targetTemperature); + targetTemperature = weatherModifier.modifyTarget(world, position, + targetTemperature); + targetTemperature = timeModifier.modifyTarget(world, position, + targetTemperature); + targetTemperature = seasonModifier.modifyTarget(world, position, + targetTemperature); + + int finalTemperature = targetTemperature.getRawValue(); + if (printOutput) { + sender.addChatMessage(new TextComponentTranslation( + "commands.toughasnails.tempat.success", dimensionID, x, + y, z, finalTemperature)); + } + sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, + finalTemperature); + } else { + sender.addChatMessage(new TextComponentTranslation( + "commands.toughasnails.tempat.disabled")); + } + } + private void setTemperature(ICommandSender sender, String[] args) throws CommandException { EntityPlayerMP player = getCommandSenderAsPlayer(sender); @@ -126,8 +220,12 @@ private void setTemperature(ICommandSender sender, String[] args) private void setSeason(ICommandSender sender, String[] args) throws CommandException { int dimensionID = 0; + boolean printOutput = true; try { dimensionID = Integer.parseInt(args[2]); + if (args.length >= 4) { + printOutput = Boolean.parseBoolean(args[3]); + } } catch (NumberFormatException e) { throw new WrongUsageException("commands.toughasnails.usage"); } @@ -172,8 +270,11 @@ private void setSeason(ICommandSender sender, String[] args) * SeasonTime.SUB_SEASON_DURATION * newSeason.ordinal(); seasonData.markDirty(); SeasonHandler.sendSeasonUpdate(world); - sender.addChatMessage(new TextComponentTranslation( - "commands.toughasnails.setseason.success", args[1])); + if (printOutput) { + sender.addChatMessage(new TextComponentTranslation( + "commands.toughasnails.setseason.success", + args[1])); + } } else { sender.addChatMessage(new TextComponentTranslation( "commands.toughasnails.setseason.fail", args[1])); diff --git a/src/main/java/toughasnails/item/ItemThermometer.java b/src/main/java/toughasnails/item/ItemThermometer.java index 305204d3..7c33a5b1 100644 --- a/src/main/java/toughasnails/item/ItemThermometer.java +++ b/src/main/java/toughasnails/item/ItemThermometer.java @@ -14,43 +14,104 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import toughasnails.api.season.SeasonHelper; +import toughasnails.api.temperature.Temperature; import toughasnails.api.temperature.TemperatureHelper; import toughasnails.api.temperature.TemperatureScale; -import toughasnails.season.SeasonTime; +import toughasnails.temperature.TemperatureDebugger; import toughasnails.temperature.TemperatureHandler; +import toughasnails.temperature.modifier.AltitudeModifier; +import toughasnails.temperature.modifier.BiomeModifier; +import toughasnails.temperature.modifier.ObjectProximityModifier; +import toughasnails.temperature.modifier.SeasonModifier; +import toughasnails.temperature.modifier.TimeModifier; +import toughasnails.temperature.modifier.WeatherModifier; -public class ItemThermometer extends Item -{ - public ItemThermometer() - { - this.addPropertyOverride(new ResourceLocation("temperature"), new IItemPropertyGetter() - { - @SideOnly(Side.CLIENT) - double field_185088_a; - @SideOnly(Side.CLIENT) - double field_185089_b; - @SideOnly(Side.CLIENT) - int ticks; - - @Override - @SideOnly(Side.CLIENT) - public float apply(ItemStack stack, World world, EntityLivingBase entity) - { - if (entity == null || !(entity instanceof EntityPlayer)) - return 0.0F; - - EntityPlayer player = (EntityPlayer)entity; - - if (world == null) world = entity.worldObj; - - TemperatureHandler tempHandler = (TemperatureHandler)TemperatureHelper.getTemperatureData(player); - return (float)MathHelper.clamp_double(tempHandler.debugger.targetTemperature, 0, TemperatureScale.getScaleTotal()) / (float)TemperatureScale.getScaleTotal(); - } - }); - } +public class ItemThermometer extends Item { + public ItemThermometer() { + this.addPropertyOverride(new ResourceLocation("temperature"), + new IItemPropertyGetter() { + @SideOnly(Side.CLIENT) + double field_185088_a; + @SideOnly(Side.CLIENT) + double field_185089_b; + @SideOnly(Side.CLIENT) + int ticks; + + @Override + @SideOnly(Side.CLIENT) + public float apply(ItemStack stack, World world, + EntityLivingBase entity) { + if (entity == null + || !(entity instanceof EntityPlayer)) { + Entity frame = stack.getItemFrame(); + if (frame != null) { + BlockPos framePosition = frame.getPosition(); + World frameWorld = frame.getEntityWorld(); + final TemperatureDebugger debugger = new TemperatureDebugger(); + AltitudeModifier altitudeModifier = new AltitudeModifier( + debugger); + BiomeModifier biomeModifier = new BiomeModifier( + debugger); + ObjectProximityModifier objectProximityModifier = new ObjectProximityModifier( + debugger); + WeatherModifier weatherModifier = new WeatherModifier( + debugger); + TimeModifier timeModifier = new TimeModifier( + debugger); + SeasonModifier seasonModifier = new SeasonModifier( + debugger); + + Temperature baseTemperature = new Temperature( + TemperatureHandler.TEMPERATURE_SCALE_MIDPOINT); + Temperature targetTemperature = biomeModifier + .modifyTarget(frameWorld, framePosition, + baseTemperature); + targetTemperature = altitudeModifier + .modifyTarget(frameWorld, framePosition, + targetTemperature); + targetTemperature = objectProximityModifier + .modifyTarget(frameWorld, framePosition, + targetTemperature); + targetTemperature = weatherModifier + .modifyTarget(frameWorld, framePosition, + targetTemperature); + targetTemperature = timeModifier.modifyTarget( + frameWorld, framePosition, + targetTemperature); + targetTemperature = seasonModifier.modifyTarget( + frameWorld, framePosition, + targetTemperature); + + int finalTemperature = targetTemperature + .getRawValue(); + return (float) MathHelper + .clamp_double(finalTemperature, 0, + TemperatureScale + .getScaleTotal()) + / (float) TemperatureScale + .getScaleTotal(); + } else { + return 0.0f; + } + } + + EntityPlayer player = (EntityPlayer) entity; + + if (world == null) + world = entity.worldObj; + + TemperatureHandler tempHandler = (TemperatureHandler) TemperatureHelper + .getTemperatureData(player); + return (float) MathHelper.clamp_double( + tempHandler.debugger.targetTemperature, 0, + TemperatureScale.getScaleTotal()) + / (float) TemperatureScale.getScaleTotal(); + } + }); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/AltitudeModifier.java b/src/main/java/toughasnails/temperature/modifier/AltitudeModifier.java index 3f2523be..ca29b351 100644 --- a/src/main/java/toughasnails/temperature/modifier/AltitudeModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/AltitudeModifier.java @@ -1,46 +1,56 @@ package toughasnails.temperature.modifier; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; import toughasnails.api.temperature.Temperature; import toughasnails.temperature.TemperatureDebugger; import toughasnails.temperature.TemperatureDebugger.Modifier; import toughasnails.temperature.TemperatureTrend; -import toughasnails.util.BiomeUtils; - -public class AltitudeModifier extends TemperatureModifier -{ - public static final int ALTITUDE_TARGET_MODIFIER = 3; - - - public AltitudeModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - return changeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - int temperatureLevel = temperature.getRawValue(); - int newTemperatureLevel = temperatureLevel; - - debugger.start(Modifier.ALTITUDE_TARGET, newTemperatureLevel); - - if (world.provider.isSurfaceWorld()) - { - newTemperatureLevel -= MathHelper.abs_int(MathHelper.floor_double(((64 - player.posY) / 64) * ALTITUDE_TARGET_MODIFIER) + 1); - } - - debugger.end(newTemperatureLevel); - - return new Temperature(newTemperatureLevel); - } + +public class AltitudeModifier extends TemperatureModifier { + public static final int ALTITUDE_TARGET_MODIFIER = 3; + + public AltitudeModifier(TemperatureDebugger debugger) { + super(debugger); + } + + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + return changeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + debugger.start(Modifier.ALTITUDE_TARGET, newTemperatureLevel); + + if (world.provider.isSurfaceWorld()) { + newTemperatureLevel -= MathHelper.abs_int(MathHelper.floor_double( + ((64 - player.posY) / 64) * ALTITUDE_TARGET_MODIFIER) + 1); + } + + debugger.end(newTemperatureLevel); + + return new Temperature(newTemperatureLevel); + } + + public Temperature modifyTarget(World world, BlockPos position, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + if (world.provider.isSurfaceWorld()) { + newTemperatureLevel -= MathHelper.abs_int(MathHelper.floor_double( + ((64 - position.getY()) / 64) * ALTITUDE_TARGET_MODIFIER) + + 1); + } + + return new Temperature(newTemperatureLevel); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/ArmorModifier.java b/src/main/java/toughasnails/temperature/modifier/ArmorModifier.java index ebf5ef57..ed684698 100644 --- a/src/main/java/toughasnails/temperature/modifier/ArmorModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/ArmorModifier.java @@ -2,9 +2,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import toughasnails.api.item.TANItems; import toughasnails.api.temperature.Temperature; @@ -12,132 +9,120 @@ import toughasnails.temperature.TemperatureDebugger.Modifier; import toughasnails.temperature.TemperatureTrend; -public class ArmorModifier extends TemperatureModifier -{ - public static final int ARMOR_RATE_MODIFIER = 25; - public static final int JELLED_SLIME_TARGET_MODIFIER = -1; - public static final int WOOL_TARGET_MODIFIER = 1; - - public ArmorModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - int newChangeRate = changeRate; - int armorRateModifier = ARMOR_RATE_MODIFIER; - - switch (trend) - { - case INCREASING: - armorRateModifier *= -1; - break; - - case STILL: - armorRateModifier = 0; - break; - } - - debugger.start(Modifier.ARMOR_RATE, newChangeRate); - - InventoryPlayer inventory = ((EntityPlayer)player).inventory; - - //Helmet - if (inventory.armorInventory[3] != null) - { - newChangeRate += armorRateModifier; - } - - //Chestplate - if (inventory.armorInventory[2] != null) - { - newChangeRate += armorRateModifier; - } - - //Legging - if (inventory.armorInventory[1] != null) - { - newChangeRate += armorRateModifier; - } - - //Boots - if (inventory.armorInventory[0] != null) - { - newChangeRate += armorRateModifier; - } - - debugger.end(newChangeRate); - - return newChangeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - int temperatureLevel = temperature.getRawValue(); - int newTemperatureLevel = temperatureLevel; - - debugger.start(Modifier.ARMOR_TARGET, newTemperatureLevel); - - InventoryPlayer inventory = ((EntityPlayer)player).inventory; - - //Helmet - if (inventory.armorInventory[3] != null) - { - if (inventory.armorInventory[3].getItem() == TANItems.wool_helmet) - { - newTemperatureLevel += WOOL_TARGET_MODIFIER; - } - if (inventory.armorInventory[3].getItem() == TANItems.jelled_slime_helmet) - { - newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; - } - } - - //Chestplate - if (inventory.armorInventory[2] != null) - { - if (inventory.armorInventory[2].getItem() == TANItems.wool_chestplate) - { - newTemperatureLevel += WOOL_TARGET_MODIFIER; - } - if (inventory.armorInventory[2].getItem() == TANItems.jelled_slime_chestplate) - { - newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; - } - } - - //Leggings - if (inventory.armorInventory[1] != null) - { - if (inventory.armorInventory[1].getItem() == TANItems.wool_leggings) - { - newTemperatureLevel += WOOL_TARGET_MODIFIER; - } - if (inventory.armorInventory[1].getItem() == TANItems.jelled_slime_leggings) - { - newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; - } - } - - //Boots - if (inventory.armorInventory[0] != null) - { - if (inventory.armorInventory[0].getItem() == TANItems.wool_boots) - { - newTemperatureLevel += WOOL_TARGET_MODIFIER; - } - if (inventory.armorInventory[0].getItem() == TANItems.jelled_slime_boots) - { - newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; - } - } - - debugger.end(newTemperatureLevel); - - return new Temperature(newTemperatureLevel); - } +public class ArmorModifier extends TemperatureModifier { + public static final int ARMOR_RATE_MODIFIER = 25; + public static final int JELLED_SLIME_TARGET_MODIFIER = -1; + public static final int WOOL_TARGET_MODIFIER = 1; + public ArmorModifier(TemperatureDebugger debugger) { + super(debugger); + } + + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + int newChangeRate = changeRate; + int armorRateModifier = ARMOR_RATE_MODIFIER; + + switch (trend) { + case INCREASING: + armorRateModifier *= -1; + break; + case STILL: + armorRateModifier = 0; + break; + default: + armorRateModifier = 0; + break; + } + + debugger.start(Modifier.ARMOR_RATE, newChangeRate); + + InventoryPlayer inventory = ((EntityPlayer) player).inventory; + + // Helmet + if (inventory.armorInventory[3] != null) { + newChangeRate += armorRateModifier; + } + + // Chestplate + if (inventory.armorInventory[2] != null) { + newChangeRate += armorRateModifier; + } + + // Legging + if (inventory.armorInventory[1] != null) { + newChangeRate += armorRateModifier; + } + + // Boots + if (inventory.armorInventory[0] != null) { + newChangeRate += armorRateModifier; + } + + debugger.end(newChangeRate); + + return newChangeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + debugger.start(Modifier.ARMOR_TARGET, newTemperatureLevel); + + InventoryPlayer inventory = ((EntityPlayer) player).inventory; + + // Helmet + if (inventory.armorInventory[3] != null) { + if (inventory.armorInventory[3].getItem() == TANItems.wool_helmet) { + newTemperatureLevel += WOOL_TARGET_MODIFIER; + } + if (inventory.armorInventory[3] + .getItem() == TANItems.jelled_slime_helmet) { + newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; + } + } + + // Chestplate + if (inventory.armorInventory[2] != null) { + if (inventory.armorInventory[2] + .getItem() == TANItems.wool_chestplate) { + newTemperatureLevel += WOOL_TARGET_MODIFIER; + } + if (inventory.armorInventory[2] + .getItem() == TANItems.jelled_slime_chestplate) { + newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; + } + } + + // Leggings + if (inventory.armorInventory[1] != null) { + if (inventory.armorInventory[1] + .getItem() == TANItems.wool_leggings) { + newTemperatureLevel += WOOL_TARGET_MODIFIER; + } + if (inventory.armorInventory[1] + .getItem() == TANItems.jelled_slime_leggings) { + newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; + } + } + + // Boots + if (inventory.armorInventory[0] != null) { + if (inventory.armorInventory[0].getItem() == TANItems.wool_boots) { + newTemperatureLevel += WOOL_TARGET_MODIFIER; + } + if (inventory.armorInventory[0] + .getItem() == TANItems.jelled_slime_boots) { + newTemperatureLevel += JELLED_SLIME_TARGET_MODIFIER; + } + } + + debugger.end(newTemperatureLevel); + + return new Temperature(newTemperatureLevel); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/BiomeModifier.java b/src/main/java/toughasnails/temperature/modifier/BiomeModifier.java index e48c441f..5bdde04c 100644 --- a/src/main/java/toughasnails/temperature/modifier/BiomeModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/BiomeModifier.java @@ -1,6 +1,7 @@ package toughasnails.temperature.modifier; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import toughasnails.api.temperature.Temperature; @@ -9,46 +10,75 @@ import toughasnails.temperature.TemperatureTrend; import toughasnails.util.BiomeUtils; -public class BiomeModifier extends TemperatureModifier -{ - public static final int MAX_TEMP_OFFSET = 10; - - public BiomeModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - Biome biome = world.getBiomeGenForCoords(player.getPosition()); - float humidity = biome.getRainfall(); - float humidityMultiplier = 2.0F * Math.abs((humidity % 1.0F) - 0.5F); - int newChangeRate = changeRate - (int)((10 * humidityMultiplier) * 20); - - debugger.start(Modifier.BIOME_HUMIDITY_RATE, changeRate); - debugger.end(newChangeRate); - - return newChangeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - Biome biome = world.getBiomeGenForCoords(player.getPosition()); - Biome biomeNorth = world.getBiomeGenForCoords(player.getPosition().add(0, 0, -10)); - Biome biomeSouth = world.getBiomeGenForCoords(player.getPosition().add(0, 0, 10)); - Biome biomeEast = world.getBiomeGenForCoords(player.getPosition().add(10, 0, 0)); - Biome biomeWest = world.getBiomeGenForCoords(player.getPosition().add(-10, 0, 0)); - - float biomeTemp = ((BiomeUtils.getBiomeTempNorm(biome) + BiomeUtils.getBiomeTempNorm(biomeNorth) + BiomeUtils.getBiomeTempNorm(biomeSouth) + BiomeUtils.getBiomeTempNorm(biomeEast) + BiomeUtils.getBiomeTempNorm(biomeWest)) / 5.0F); - - //Denormalize, multiply by the max temp offset, add to the current temp - int newTemperatureLevel = temperature.getRawValue() + (int)Math.round((biomeTemp * 2.0F - 1.0F) * MAX_TEMP_OFFSET); - - debugger.start(Modifier.BIOME_TEMPERATURE_TARGET, temperature.getRawValue()); - debugger.end(newTemperatureLevel); - - return new Temperature(newTemperatureLevel); - } +public class BiomeModifier extends TemperatureModifier { + public static final int MAX_TEMP_OFFSET = 10; + + public BiomeModifier(TemperatureDebugger debugger) { + super(debugger); + } + + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + Biome biome = world.getBiomeGenForCoords(player.getPosition()); + float humidity = biome.getRainfall(); + float humidityMultiplier = 2.0F * Math.abs((humidity % 1.0F) - 0.5F); + int newChangeRate = changeRate - (int) ((10 * humidityMultiplier) * 20); + + debugger.start(Modifier.BIOME_HUMIDITY_RATE, changeRate); + debugger.end(newChangeRate); + + return newChangeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + Biome biome = world.getBiomeGenForCoords(player.getPosition()); + Biome biomeNorth = world + .getBiomeGenForCoords(player.getPosition().add(0, 0, -10)); + Biome biomeSouth = world + .getBiomeGenForCoords(player.getPosition().add(0, 0, 10)); + Biome biomeEast = world + .getBiomeGenForCoords(player.getPosition().add(10, 0, 0)); + Biome biomeWest = world + .getBiomeGenForCoords(player.getPosition().add(-10, 0, 0)); + + float biomeTemp = ((BiomeUtils.getBiomeTempNorm(biome) + + BiomeUtils.getBiomeTempNorm(biomeNorth) + + BiomeUtils.getBiomeTempNorm(biomeSouth) + + BiomeUtils.getBiomeTempNorm(biomeEast) + + BiomeUtils.getBiomeTempNorm(biomeWest)) / 5.0F); + + // Denormalize, multiply by the max temp offset, add to the current temp + int newTemperatureLevel = temperature.getRawValue() + + (int) Math.round((biomeTemp * 2.0F - 1.0F) * MAX_TEMP_OFFSET); + + debugger.start(Modifier.BIOME_TEMPERATURE_TARGET, + temperature.getRawValue()); + debugger.end(newTemperatureLevel); + + return new Temperature(newTemperatureLevel); + } + + public Temperature modifyTarget(World world, BlockPos position, + Temperature temperature) { + Biome biome = world.getBiomeGenForCoords(position); + Biome biomeNorth = world.getBiomeGenForCoords(position.add(0, 0, -10)); + Biome biomeSouth = world.getBiomeGenForCoords(position.add(0, 0, 10)); + Biome biomeEast = world.getBiomeGenForCoords(position.add(10, 0, 0)); + Biome biomeWest = world.getBiomeGenForCoords(position.add(-10, 0, 0)); + + float biomeTemp = ((BiomeUtils.getBiomeTempNorm(biome) + + BiomeUtils.getBiomeTempNorm(biomeNorth) + + BiomeUtils.getBiomeTempNorm(biomeSouth) + + BiomeUtils.getBiomeTempNorm(biomeEast) + + BiomeUtils.getBiomeTempNorm(biomeWest)) / 5.0F); + + // Denormalize, multiply by the max temp offset, add to the current temp + int newTemperatureLevel = temperature.getRawValue() + + (int) Math.round((biomeTemp * 2.0F - 1.0F) * MAX_TEMP_OFFSET); + + return new Temperature(newTemperatureLevel); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/ObjectProximityModifier.java b/src/main/java/toughasnails/temperature/modifier/ObjectProximityModifier.java index cac867b8..68b3da96 100644 --- a/src/main/java/toughasnails/temperature/modifier/ObjectProximityModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/ObjectProximityModifier.java @@ -8,7 +8,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; import toughasnails.api.temperature.Temperature; import toughasnails.config.TANConfig; import toughasnails.temperature.BlockTemperatureData; @@ -18,117 +17,128 @@ import toughasnails.util.BlockStateUtils; //TODO: Replace this with something better -public class ObjectProximityModifier extends TemperatureModifier -{ - public ObjectProximityModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - int newChangeRate = changeRate; - BlockPos playerPos = player.getPosition(); - - int tempSourceBlocks = 0; - - //System.out.println(new Calendar(world).getSubSeason()); - - for (int x = -3; x <= 3; x++) - { - for (int y = -2; y <= 2; y++) - { - for (int z = -3; z <= 3; z++) - { - BlockPos pos = playerPos.add(x, y - 1, z); - IBlockState state = world.getBlockState(pos); - - if (getBlockTemperature(player, state) != 0.0F) tempSourceBlocks++; - } - } - } - - debugger.start(Modifier.NEARBY_BLOCKS_RATE, newChangeRate); - newChangeRate -= tempSourceBlocks * 20; - debugger.end(newChangeRate); - - return newChangeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - int temperatureLevel = temperature.getRawValue(); - int newTemperatureLevel = temperatureLevel; - BlockPos playerPos = player.getPosition(); - - float blockTemperatureModifier = 0.0F; - - for (int x = -3; x <= 3; x++) - { - for (int y = -2; y <= 2; y++) - { - for (int z = -3; z <= 3; z++) - { - BlockPos pos = playerPos.add(x, y - 1, z); - IBlockState state = world.getBlockState(pos); - - blockTemperatureModifier += getBlockTemperature(player, state); - } - } - } - - debugger.start(Modifier.NEARBY_BLOCKS_TARGET, newTemperatureLevel); - newTemperatureLevel += blockTemperatureModifier; - debugger.end(newTemperatureLevel); - - return new Temperature(newTemperatureLevel); - } - - public static float getBlockTemperature(EntityPlayer player, IBlockState state) - { - World world = player.worldObj; - Material material = state.getMaterial(); - Biome biome = world.getBiomeGenForCoords(player.getPosition()); - - String blockName = state.getBlock().getRegistryName().toString(); - - //Blocks - if (TANConfig.blockTemperatureData.containsKey(blockName)) - { - ArrayList blockTempData = TANConfig.blockTemperatureData.get(blockName); - - //Check if block has relevant state: - for (BlockTemperatureData tempData : blockTempData) - { - boolean bAllSpecifiedPropertiesMatch = true; - for (String comparisonProperty : tempData.useProperties) - { - IProperty targetProperty = BlockStateUtils.getPropertyByName(state, comparisonProperty); - - if (!(state.getValue(targetProperty) == tempData.state.getValue(targetProperty))) - { - bAllSpecifiedPropertiesMatch = false; - } - } - - if (bAllSpecifiedPropertiesMatch) - { - return tempData.blockTemperature; - } - } - - // If no matching states, then block is at ambient temperature: - return 0.0F; - } - - //Handle materials, but only if we didn't already find an actual block to use: - if (material == Material.FIRE) - { - return TANConfig.materialTemperatureData.fire; - } - - return 0.0F; - } +public class ObjectProximityModifier extends TemperatureModifier { + public ObjectProximityModifier(TemperatureDebugger debugger) { + super(debugger); + } + + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + int newChangeRate = changeRate; + BlockPos playerPos = player.getPosition(); + + int tempSourceBlocks = 0; + + // System.out.println(new Calendar(world).getSubSeason()); + + for (int x = -3; x <= 3; x++) { + for (int y = -2; y <= 2; y++) { + for (int z = -3; z <= 3; z++) { + BlockPos pos = playerPos.add(x, y - 1, z); + IBlockState state = world.getBlockState(pos); + + if (getBlockTemperature(state) != 0.0F) + tempSourceBlocks++; + } + } + } + + debugger.start(Modifier.NEARBY_BLOCKS_RATE, newChangeRate); + newChangeRate -= tempSourceBlocks * 20; + debugger.end(newChangeRate); + + return newChangeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + BlockPos playerPos = player.getPosition(); + + float blockTemperatureModifier = 0.0F; + + for (int x = -3; x <= 3; x++) { + for (int y = -2; y <= 2; y++) { + for (int z = -3; z <= 3; z++) { + BlockPos pos = playerPos.add(x, y - 1, z); + IBlockState state = world.getBlockState(pos); + + blockTemperatureModifier += getBlockTemperature(state); + } + } + } + + debugger.start(Modifier.NEARBY_BLOCKS_TARGET, newTemperatureLevel); + newTemperatureLevel += blockTemperatureModifier; + debugger.end(newTemperatureLevel); + + return new Temperature(newTemperatureLevel); + } + + public static float getBlockTemperature(IBlockState state) { + Material material = state.getMaterial(); + + String blockName = state.getBlock().getRegistryName().toString(); + + // Blocks + if (TANConfig.blockTemperatureData.containsKey(blockName)) { + ArrayList blockTempData = TANConfig.blockTemperatureData + .get(blockName); + + // Check if block has relevant state: + for (BlockTemperatureData tempData : blockTempData) { + boolean bAllSpecifiedPropertiesMatch = true; + for (String comparisonProperty : tempData.useProperties) { + IProperty targetProperty = BlockStateUtils + .getPropertyByName(state, comparisonProperty); + + if (!(state.getValue(targetProperty) == tempData.state + .getValue(targetProperty))) { + bAllSpecifiedPropertiesMatch = false; + } + } + + if (bAllSpecifiedPropertiesMatch) { + return tempData.blockTemperature; + } + } + + // If no matching states, then block is at ambient temperature: + return 0.0F; + } + + // Handle materials, but only if we didn't already find an actual block + // to use: + if (material == Material.FIRE) { + return TANConfig.materialTemperatureData.fire; + } + + return 0.0F; + } + + public Temperature modifyTarget(World world, BlockPos position, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + float blockTemperatureModifier = 0.0F; + + for (int x = -3; x <= 3; x++) { + for (int y = -2; y <= 2; y++) { + for (int z = -3; z <= 3; z++) { + BlockPos pos = position.add(x, y - 1, z); + IBlockState state = world.getBlockState(pos); + + blockTemperatureModifier += getBlockTemperature(state); + } + } + } + + newTemperatureLevel += blockTemperatureModifier; + + return new Temperature(newTemperatureLevel); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/PlayerStateModifier.java b/src/main/java/toughasnails/temperature/modifier/PlayerStateModifier.java index f069f66a..07509419 100644 --- a/src/main/java/toughasnails/temperature/modifier/PlayerStateModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/PlayerStateModifier.java @@ -1,74 +1,69 @@ package toughasnails.temperature.modifier; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import toughasnails.api.temperature.Temperature; import toughasnails.temperature.TemperatureDebugger; import toughasnails.temperature.TemperatureDebugger.Modifier; import toughasnails.temperature.TemperatureTrend; -public class PlayerStateModifier extends TemperatureModifier -{ - public static final int SPRINTING_RATE_MODIFIER = 200; - public static final int SPRINTING_TARGET_MODIFIER = 3; - - public PlayerStateModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - int newChangeRate = changeRate; - int sprintingRateModifier = SPRINTING_RATE_MODIFIER; - - switch (trend) - { - case INCREASING: - sprintingRateModifier *= -1; - break; - - case STILL: - sprintingRateModifier = 0; - break; - } - - debugger.start(Modifier.SPRINTING_RATE, newChangeRate); - - if (player.isSprinting()) - { - newChangeRate += sprintingRateModifier; - } - - debugger.end(newChangeRate); - debugger.start(Modifier.HEALTH_RATE, newChangeRate); - - newChangeRate -= (1.0 - (player.getHealth() / player.getMaxHealth())) * 200; - - debugger.end(newChangeRate); - - return newChangeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - int temperatureLevel = temperature.getRawValue(); - int newTemperatureLevel = temperatureLevel; - BlockPos playerPos = player.getPosition(); - - debugger.start(Modifier.SPRINTING_TARGET, newTemperatureLevel); - - if (player.isSprinting()) - { - newTemperatureLevel += SPRINTING_TARGET_MODIFIER; - } - - debugger.end(newTemperatureLevel); - - return new Temperature(newTemperatureLevel); - } +public class PlayerStateModifier extends TemperatureModifier { + public static final int SPRINTING_RATE_MODIFIER = 200; + public static final int SPRINTING_TARGET_MODIFIER = 3; + public PlayerStateModifier(TemperatureDebugger debugger) { + super(debugger); + } + + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + int newChangeRate = changeRate; + int sprintingRateModifier = SPRINTING_RATE_MODIFIER; + + switch (trend) { + case INCREASING: + sprintingRateModifier *= -1; + break; + case STILL: + sprintingRateModifier = 0; + break; + default: + sprintingRateModifier = 0; + break; + } + + debugger.start(Modifier.SPRINTING_RATE, newChangeRate); + + if (player.isSprinting()) { + newChangeRate += sprintingRateModifier; + } + + debugger.end(newChangeRate); + debugger.start(Modifier.HEALTH_RATE, newChangeRate); + + newChangeRate -= (1.0 - (player.getHealth() / player.getMaxHealth())) + * 200; + + debugger.end(newChangeRate); + + return newChangeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + debugger.start(Modifier.SPRINTING_TARGET, newTemperatureLevel); + + if (player.isSprinting()) { + newTemperatureLevel += SPRINTING_TARGET_MODIFIER; + } + + debugger.end(newTemperatureLevel); + + return new Temperature(newTemperatureLevel); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/SeasonModifier.java b/src/main/java/toughasnails/temperature/modifier/SeasonModifier.java index 556ca797..f1423b04 100644 --- a/src/main/java/toughasnails/temperature/modifier/SeasonModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/SeasonModifier.java @@ -8,6 +8,7 @@ package toughasnails.temperature.modifier; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import toughasnails.api.config.SyncedConfig; import toughasnails.api.season.Season.SubSeason; @@ -18,63 +19,104 @@ import toughasnails.temperature.TemperatureDebugger.Modifier; import toughasnails.temperature.TemperatureTrend; -public class SeasonModifier extends TemperatureModifier -{ - public SeasonModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - return changeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - int temperatureLevel = temperature.getRawValue(); - SubSeason season = SeasonHelper.getSeasonData(world).getSubSeason(); - - if (!(SyncedConfig.getBooleanValue(GameplayOption.ENABLE_SEASONS))) - { - season = SubSeason.MID_SUMMER; - } - - debugger.start(Modifier.SEASON_TARGET, temperatureLevel); - - if (world.provider.isSurfaceWorld()) - { - switch (season) - { - case MID_WINTER: case LATE_WINTER: - temperatureLevel -= 6; - break; - - case EARLY_SPRING: case EARLY_WINTER: - temperatureLevel -= 4; - break; - - case MID_SPRING: case LATE_AUTUMN: - temperatureLevel -= 2; - break; - - case MID_SUMMER: case EARLY_AUTUMN: - temperatureLevel += 2; - break; - - case LATE_SUMMER: - temperatureLevel += 4; - break; - - default: - break; - } - } - debugger.end(temperatureLevel); - - return new Temperature(temperatureLevel); - } +public class SeasonModifier extends TemperatureModifier { + public SeasonModifier(TemperatureDebugger debugger) { + super(debugger); + } + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + return changeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + SubSeason season = SeasonHelper.getSeasonData(world).getSubSeason(); + + if (!(SyncedConfig.getBooleanValue(GameplayOption.ENABLE_SEASONS))) { + season = SubSeason.MID_SUMMER; + } + + debugger.start(Modifier.SEASON_TARGET, temperatureLevel); + + if (world.provider.isSurfaceWorld()) { + switch (season) { + case MID_WINTER: + case LATE_WINTER: + temperatureLevel -= 6; + break; + + case EARLY_SPRING: + case EARLY_WINTER: + temperatureLevel -= 4; + break; + + case MID_SPRING: + case LATE_AUTUMN: + temperatureLevel -= 2; + break; + + case MID_SUMMER: + case EARLY_AUTUMN: + temperatureLevel += 2; + break; + + case LATE_SUMMER: + temperatureLevel += 4; + break; + + default: + break; + } + } + debugger.end(temperatureLevel); + + return new Temperature(temperatureLevel); + } + + public Temperature modifyTarget(World world, BlockPos position, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + SubSeason season = SeasonHelper.getSeasonData(world).getSubSeason(); + + if (!(SyncedConfig.getBooleanValue(GameplayOption.ENABLE_SEASONS))) { + season = SubSeason.MID_SUMMER; + } + + if (world.provider.isSurfaceWorld()) { + switch (season) { + case MID_WINTER: + case LATE_WINTER: + temperatureLevel -= 6; + break; + + case EARLY_SPRING: + case EARLY_WINTER: + temperatureLevel -= 4; + break; + + case MID_SPRING: + case LATE_AUTUMN: + temperatureLevel -= 2; + break; + + case MID_SUMMER: + case EARLY_AUTUMN: + temperatureLevel += 2; + break; + + case LATE_SUMMER: + temperatureLevel += 4; + break; + + default: + break; + } + } + + return new Temperature(temperatureLevel); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/TimeModifier.java b/src/main/java/toughasnails/temperature/modifier/TimeModifier.java index 0d274ddd..48fbddb5 100644 --- a/src/main/java/toughasnails/temperature/modifier/TimeModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/TimeModifier.java @@ -1,6 +1,7 @@ package toughasnails.temperature.modifier; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import toughasnails.api.temperature.Temperature; @@ -9,49 +10,71 @@ import toughasnails.temperature.TemperatureTrend; import toughasnails.util.BiomeUtils; -public class TimeModifier extends TemperatureModifier -{ - public static final int TIME_TARGET_MODIFIER = 7; - - /** - * Multiplies how much should the temperature be increased/decreased by the closer the - * biome temp is to a extreme hot or cold - */ - public static final float EXTREMITY_MULTIPLIER = 1.25F; - - public TimeModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - return changeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - Biome biome = world.getBiomeGenForCoords(player.getPosition()); - long worldTime = world.getWorldTime(); - - float extremityModifier = BiomeUtils.getBiomeTempExtremity(biome); - //Reaches the highest point during the middle of the day and at midnight. Normalized to be between -1 and 1 - float timeNorm = (-Math.abs(((worldTime + 6000) % 24000.0F) - 12000.0F) + 6000.0F) / 6000.0F; - - int temperatureLevel = temperature.getRawValue(); - int newTemperatureLevel = temperatureLevel; - - debugger.start(Modifier.TIME_TARGET, newTemperatureLevel); - - if (world.provider.isSurfaceWorld()) - { - newTemperatureLevel += TIME_TARGET_MODIFIER * timeNorm * (Math.max(1.0F, extremityModifier * EXTREMITY_MULTIPLIER)); - } - - debugger.end(newTemperatureLevel); - - return new Temperature(newTemperatureLevel); - } +public class TimeModifier extends TemperatureModifier { + public static final int TIME_TARGET_MODIFIER = 7; + + /** + * Multiplies how much should the temperature be increased/decreased by the + * closer the biome temp is to a extreme hot or cold + */ + public static final float EXTREMITY_MULTIPLIER = 1.25F; + + public TimeModifier(TemperatureDebugger debugger) { + super(debugger); + } + + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + return changeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + Biome biome = world.getBiomeGenForCoords(player.getPosition()); + long worldTime = world.getWorldTime(); + + float extremityModifier = BiomeUtils.getBiomeTempExtremity(biome); + // Reaches the highest point during the middle of the day and at + // midnight. Normalized to be between -1 and 1 + float timeNorm = (-Math.abs(((worldTime + 6000) % 24000.0F) - 12000.0F) + + 6000.0F) / 6000.0F; + + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + debugger.start(Modifier.TIME_TARGET, newTemperatureLevel); + + if (world.provider.isSurfaceWorld()) { + newTemperatureLevel += TIME_TARGET_MODIFIER * timeNorm * (Math + .max(1.0F, extremityModifier * EXTREMITY_MULTIPLIER)); + } + + debugger.end(newTemperatureLevel); + + return new Temperature(newTemperatureLevel); + } + + public Temperature modifyTarget(World world, BlockPos position, + Temperature temperature) { + Biome biome = world.getBiomeGenForCoords(position); + long worldTime = world.getWorldTime(); + + float extremityModifier = BiomeUtils.getBiomeTempExtremity(biome); + // Reaches the highest point during the middle of the day and at + // midnight. Normalized to be between -1 and 1 + float timeNorm = (-Math.abs(((worldTime + 6000) % 24000.0F) - 12000.0F) + + 6000.0F) / 6000.0F; + + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + if (world.provider.isSurfaceWorld()) { + newTemperatureLevel += TIME_TARGET_MODIFIER * timeNorm * (Math + .max(1.0F, extremityModifier * EXTREMITY_MULTIPLIER)); + } + + return new Temperature(newTemperatureLevel); + } } diff --git a/src/main/java/toughasnails/temperature/modifier/WeatherModifier.java b/src/main/java/toughasnails/temperature/modifier/WeatherModifier.java index 990f9515..ee56f45b 100644 --- a/src/main/java/toughasnails/temperature/modifier/WeatherModifier.java +++ b/src/main/java/toughasnails/temperature/modifier/WeatherModifier.java @@ -3,60 +3,73 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; import toughasnails.api.temperature.Temperature; import toughasnails.temperature.TemperatureDebugger; import toughasnails.temperature.TemperatureDebugger.Modifier; import toughasnails.temperature.TemperatureTrend; -public class WeatherModifier extends TemperatureModifier -{ - public static final int WET_RATE_MODIFIER = -750; - public static final int WET_TARGET_MODIFIER = -7; - public static final int SNOW_TARGET_MODIFIER = -10; - - public WeatherModifier(TemperatureDebugger debugger) - { - super(debugger); - } - - @Override - public int modifyChangeRate(World world, EntityPlayer player, int changeRate, TemperatureTrend trend) - { - int newChangeRate = changeRate; - - debugger.start(Modifier.WET_RATE, changeRate); - - if (player.isWet()) - { - newChangeRate += WET_RATE_MODIFIER; - } - - debugger.end(newChangeRate); - - return newChangeRate; - } - - @Override - public Temperature modifyTarget(World world, EntityPlayer player, Temperature temperature) - { - int temperatureLevel = temperature.getRawValue(); - int newTemperatureLevel = temperatureLevel; - - BlockPos playerPos = player.getPosition(); - - if (player.isWet()) - { - debugger.start(Modifier.WET_TARGET, newTemperatureLevel); - newTemperatureLevel += WET_TARGET_MODIFIER; - debugger.end(newTemperatureLevel); - } - else if (world.isRaining() && world.canSeeSky(playerPos) && world.getBiomeGenForCoords(playerPos).getEnableSnow()) - { - debugger.start(Modifier.SNOW_TARGET, newTemperatureLevel); - newTemperatureLevel += SNOW_TARGET_MODIFIER; - debugger.end(newTemperatureLevel); - } - - return new Temperature(newTemperatureLevel); - } +public class WeatherModifier extends TemperatureModifier { + public static final int WET_RATE_MODIFIER = -750; + public static final int WET_TARGET_MODIFIER = -7; + public static final int SNOW_TARGET_MODIFIER = -10; + + public WeatherModifier(TemperatureDebugger debugger) { + super(debugger); + } + + @Override + public int modifyChangeRate(World world, EntityPlayer player, + int changeRate, TemperatureTrend trend) { + int newChangeRate = changeRate; + + debugger.start(Modifier.WET_RATE, changeRate); + + if (player.isWet()) { + newChangeRate += WET_RATE_MODIFIER; + } + + debugger.end(newChangeRate); + + return newChangeRate; + } + + @Override + public Temperature modifyTarget(World world, EntityPlayer player, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + BlockPos playerPos = player.getPosition(); + + if (player.isWet()) { + debugger.start(Modifier.WET_TARGET, newTemperatureLevel); + newTemperatureLevel += WET_TARGET_MODIFIER; + debugger.end(newTemperatureLevel); + } else if (world.isRaining() && world.canSeeSky(playerPos) + && world.getBiomeGenForCoords(playerPos).getEnableSnow()) { + debugger.start(Modifier.SNOW_TARGET, newTemperatureLevel); + newTemperatureLevel += SNOW_TARGET_MODIFIER; + debugger.end(newTemperatureLevel); + } + + return new Temperature(newTemperatureLevel); + } + + public Temperature modifyTarget(World world, BlockPos position, + Temperature temperature) { + int temperatureLevel = temperature.getRawValue(); + int newTemperatureLevel = temperatureLevel; + + if (world.isRaining() && world.canSeeSky(position)) { + Biome biome = world.getBiomeGenForCoords(position); + if (biome.getEnableSnow()) { + newTemperatureLevel += SNOW_TARGET_MODIFIER; + } else if (biome.canRain()) { + newTemperatureLevel += WET_TARGET_MODIFIER; + } + } + + return new Temperature(newTemperatureLevel); + } } diff --git a/src/main/resources/assets/toughasnails/lang/en_US.lang b/src/main/resources/assets/toughasnails/lang/en_US.lang index e982ce83..58680151 100644 --- a/src/main/resources/assets/toughasnails/lang/en_US.lang +++ b/src/main/resources/assets/toughasnails/lang/en_US.lang @@ -25,6 +25,8 @@ commands.toughasnails.setthirst.success=Set thirst to %s commands.toughasnails.setthirst.disabled=Thirst is currently disabled! commands.toughasnails.sethealth.success=Set health to %s commands.toughasnails.sethealth.disabled=Health is currently disabled! +commands.toughasnails.tempat.success=Temperature at dimension %s: %s,%s,%s is %s +commands.toughasnails.tempat.disabled=Temperature is currently disabled! config.category.survivalSettings.title=Survival Settings