Skip to content

Commit

Permalink
0.1.1 - Mod Water, Compat, Thermometer HUD
Browse files Browse the repository at this point in the history
Adds update checker
Adds configurable Material.WATER from mods
Adds some default json settings for mod compatibilitiy (Biomes O' Plenty, LycanitesMobs, Simple Camp Fire)
Adds a toggleable thermometer HUD, displays if a thermometer is in your inventory.
The display isn't in a great place but it'll work for now.

Refactored ArmorTemperature and BlockTemperature to be generic, JsonTemperature and JsonPropertyTemperature.
  • Loading branch information
Charles445 committed Feb 2, 2020
1 parent 7bae4cc commit d1c4ee1
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 57 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge'


version = "1.12.2-0.1.0"
version = "1.12.2-0.1.1"
group = "com.charles445.simpledifficulty" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "SimpleDifficulty"

Expand Down
7 changes: 3 additions & 4 deletions modupdatechecker.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"homepage": "https://www.curseforge.com/minecraft/mc-mods/simpledifficulty/files",
"promos": {
"1.12.2-latest": "0.1.2",
"1.12.2-recommended": "0.1.2"
"1.12.2-latest": "0.1.1",
"1.12.2-recommended": "0.1.1"
},
"1.12.2": {
"0.1.2": "Dummy update to test out the update checker",
"0.1.1": "Update Checker, Mod Compatibility, Configurable mod water temperatures",
"0.1.1": "Update Checker, Mod Compatibility, Thermometer HUD, Configurable mod water temperatures",
"0.1.0": "Initial Release"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
modid = SimpleDifficulty.MODID,
name = SimpleDifficulty.NAME,
version = SimpleDifficulty.VERSION,
acceptedMinecraftVersions = "[1.12]"
acceptedMinecraftVersions = "[1.12]",
updateJSON = "https://raw.githubusercontent.com/Charles445/SimpleDifficulty/master/modupdatechecker.json"

)
public class SimpleDifficulty
{
public static final String MODID = "simpledifficulty";
public static final String NAME = "SimpleDifficulty";
public static final String VERSION = "0.1.0";
public static final String VERSION = "0.1.1";

@Mod.Instance(SimpleDifficulty.MODID)
public static SimpleDifficulty instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ public enum ClientOptions implements IConfigOption
/*Boolean*/ DEBUG ("debug"),
/*Boolean*/ DRAW_THIRST_SATURATION ("drawThirstSaturation"),
/*Boolean*/ ENABLE_THERMOMETER ("enableThermometer"),
/*Boolean*/ ALTERNATE_TEMP ("alternateTemp");
/*Boolean*/ ALTERNATE_TEMP ("alternateTemp"),
/*BOOLEAN*/ HUD_THERMOMETER ("hudThermometer");

String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.charles445.simpledifficulty.client.gui;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import com.charles445.simpledifficulty.api.SDCapabilities;
import com.charles445.simpledifficulty.api.SDItems;
import com.charles445.simpledifficulty.api.config.ClientConfig;
import com.charles445.simpledifficulty.api.config.ClientOptions;
import com.charles445.simpledifficulty.api.config.QuickConfig;
Expand All @@ -11,13 +14,18 @@
import com.charles445.simpledifficulty.api.temperature.TemperatureUtil;
import com.charles445.simpledifficulty.debug.DebugUtil;
import com.charles445.simpledifficulty.util.RenderUtil;
import com.charles445.simpledifficulty.util.WorldUtil;

import ibxm.Player;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -30,7 +38,6 @@ public class TemperatureGui
private int updateCounter = 0;
private final Random rand = new Random();
public static final ResourceLocation ICONS = new ResourceLocation("simpledifficulty:textures/gui/icons.png");

//Position on the icons sheet
private static final int texturepos_X = 0;
private static final int texturepos_Y = 32;
Expand All @@ -48,6 +55,13 @@ public class TemperatureGui
private static final int texturepos_Y_alt_BG = 96;
private int alternateTemperature = 0;

private int worldThermometerTemperature = 0;
private boolean hasThermometer = false;
private static final int texturepos_X_therm = 0;
private static final int texturepos_Y_therm = 192;
private static final int thermometer_per_row = 8;
private static final int textureWidthTherm = 16;
private static final int textureHeightTherm = 16;

@SubscribeEvent
public void onPreRenderGameOverlay(RenderGameOverlayEvent.Pre event)
Expand Down Expand Up @@ -75,6 +89,8 @@ private void renderTemperatureIcon(int width, int height, int temperature)
{
GlStateManager.enableBlend();

// ---

TemperatureEnum tempEnum = TemperatureUtil.getTemperatureEnum(temperature);

int bgXOffset = textureWidth * tempEnum.ordinal();
Expand Down Expand Up @@ -231,6 +247,20 @@ else if(tempEnum == TemperatureEnum.BURNING)
RenderUtil.drawTexturedModalRect(x, y, texturepos_X + ovrXOffset, texturepos_Y + ovrYOffset, textureWidth, textureHeight);
}

//Thermometer

if(hasThermometer && ClientConfig.instance.getBoolean(ClientOptions.HUD_THERMOMETER) && ClientConfig.instance.getBoolean(ClientOptions.ENABLE_THERMOMETER))
{
int therm_position = worldThermometerTemperature - TemperatureEnum.FREEZING.getLowerBound();

int therm_x = (therm_position % thermometer_per_row)*textureWidthTherm + texturepos_X_therm;
int therm_y = (therm_position / thermometer_per_row)*textureHeightTherm + texturepos_Y_therm;


//TODO configure where this thing draws

RenderUtil.drawTexturedModalRect(x, y - 18, therm_x, therm_y, textureWidthTherm, textureHeightTherm);
}
// - - -


Expand Down Expand Up @@ -262,10 +292,27 @@ public void onClientTick(TickEvent.ClientTickEvent event)
}
//}

if(updateCounter % 15 == 12 && QuickConfig.isTemperatureEnabled() && ClientConfig.instance.getBoolean(ClientOptions.ALTERNATE_TEMP))
if(updateCounter % 15 == 12 && QuickConfig.isTemperatureEnabled())
{
if(minecraftInstance.player != null)
alternateTemperature = TemperatureUtil.clampTemperature(TemperatureUtil.getPlayerTargetTemperature(minecraftInstance.player));
{
EntityPlayer player = minecraftInstance.player;
World world = player.getEntityWorld();

if(ClientConfig.instance.getBoolean(ClientOptions.ALTERNATE_TEMP))
{
alternateTemperature = TemperatureUtil.clampTemperature(TemperatureUtil.getPlayerTargetTemperature(player));
}

if(ClientConfig.instance.getBoolean(ClientOptions.HUD_THERMOMETER) && ClientConfig.instance.getBoolean(ClientOptions.ENABLE_THERMOMETER))
{

worldThermometerTemperature = TemperatureUtil.clampTemperature((int)WorldUtil.calculateClientWorldEntityTemperature(world, player));

//TODO Verify this is how you're supposed to check for items in player inventory
hasThermometer = player.inventory.hasItemStack(new ItemStack(SDItems.thermometer));
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.charles445.simpledifficulty.compat;

import static com.charles445.simpledifficulty.config.JsonConfig.armorTemperatures;
import static com.charles445.simpledifficulty.config.JsonConfig.blockTemperatures;
import static com.charles445.simpledifficulty.config.JsonConfig.fluidTemperatures;

import com.charles445.simpledifficulty.config.json.JsonPropertyTemperature;
import com.charles445.simpledifficulty.config.json.JsonTemperature;
import com.charles445.simpledifficulty.config.json.PropertyValue;

public class JsonCompatDefaults
{
public static JsonCompatDefaults instance = new JsonCompatDefaults();
//Default mod support for JSON

public void populate()
{
populateBiomesOPlenty();
populateLycanitesMobs();
populateSimpleCampfire();
}

//Biomes O' Plenty
private void populateBiomesOPlenty()
{
fluidTemperatures.put("hot_spring_water", temperature(3.0f));
}

//Lycanites Mobs
private void populateLycanitesMobs()
{
blockTemperatures.put("lycanitesmobs:purelava", propTemp(15.0f));

//TODO considering adding the ooze to actually chill the surrounding area
//That could be fun
}

//Simple Camp Fire
private void populateSimpleCampfire()
{
blockTemperatures.put("campfire:campfire", propTemp(7.0f));
}



//Utility

private JsonTemperature temperature(float temp)
{
return new JsonTemperature(temp);
}

private JsonPropertyTemperature propTemp(float temp)
{
return new JsonPropertyTemperature(temp);
}

private JsonPropertyTemperature propTemp(float temp, PropertyValue... props)
{
return new JsonPropertyTemperature(temp, props);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import com.charles445.simpledifficulty.SimpleDifficulty;
import com.charles445.simpledifficulty.api.SDBlocks;
import com.charles445.simpledifficulty.api.SDItems;
import com.charles445.simpledifficulty.compat.JsonCompatDefaults;
import com.charles445.simpledifficulty.config.json.PropertyValue;
import com.charles445.simpledifficulty.config.json.ArmorTemperature;
import com.charles445.simpledifficulty.config.json.BlockTemperature;
import com.charles445.simpledifficulty.config.json.JsonTemperature;
import com.charles445.simpledifficulty.config.json.JsonPropertyTemperature;
import com.charles445.simpledifficulty.config.json.MaterialTemperature;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -31,49 +32,55 @@ public class JsonConfig
//TODO this whole thing isn't good
//TODO now that I get how this stuff works, sort of, make it better

public static Map<String, ArmorTemperature> armorTemperatures = new HashMap<String, ArmorTemperature>();

public static Map<String, BlockTemperature> blockTemperatures = new HashMap<String, BlockTemperature>();
//TODO a way for mods to set defaults for themselves via the API



public static Map<String, JsonTemperature> armorTemperatures = new HashMap<String, JsonTemperature>();

public static Map<String, JsonPropertyTemperature> blockTemperatures = new HashMap<String, JsonPropertyTemperature>();

public static Map<String, JsonTemperature> fluidTemperatures = new HashMap<String, JsonTemperature>();

//TODO customizable materials? Probably not
public static MaterialTemperature materialTemperature = new MaterialTemperature();

public static void init(File jsonDirectory)
{
armorTemperatures.put(SDItems.wool_helmet.getRegistryName().toString(), new ArmorTemperature(2.0f));
armorTemperatures.put(SDItems.wool_chestplate.getRegistryName().toString(), new ArmorTemperature(2.0f));
armorTemperatures.put(SDItems.wool_leggings.getRegistryName().toString(), new ArmorTemperature(2.0f));
armorTemperatures.put(SDItems.wool_boots.getRegistryName().toString(), new ArmorTemperature(2.0f));
//Setup default JSON

armorTemperatures.put(SDItems.ice_helmet.getRegistryName().toString(), new ArmorTemperature(-2.0f));
armorTemperatures.put(SDItems.ice_chestplate.getRegistryName().toString(), new ArmorTemperature(-2.0f));
armorTemperatures.put(SDItems.ice_leggings.getRegistryName().toString(), new ArmorTemperature(-2.0f));
armorTemperatures.put(SDItems.ice_boots.getRegistryName().toString(), new ArmorTemperature(-2.0f));
armorTemperatures.put(SDItems.wool_helmet.getRegistryName().toString(), new JsonTemperature(2.0f));
armorTemperatures.put(SDItems.wool_chestplate.getRegistryName().toString(), new JsonTemperature(2.0f));
armorTemperatures.put(SDItems.wool_leggings.getRegistryName().toString(), new JsonTemperature(2.0f));
armorTemperatures.put(SDItems.wool_boots.getRegistryName().toString(), new JsonTemperature(2.0f));

armorTemperatures.put(SDItems.ice_helmet.getRegistryName().toString(), new JsonTemperature(-2.0f));
armorTemperatures.put(SDItems.ice_chestplate.getRegistryName().toString(), new JsonTemperature(-2.0f));
armorTemperatures.put(SDItems.ice_leggings.getRegistryName().toString(), new JsonTemperature(-2.0f));
armorTemperatures.put(SDItems.ice_boots.getRegistryName().toString(), new JsonTemperature(-2.0f));

armorTemperatures = processJson("armorTemperatures.json", armorTemperatures, new TypeToken<Map<String, ArmorTemperature>>(){}.getType(), jsonDirectory);
blockTemperatures.put(SDBlocks.campfire.getRegistryName().toString(), new JsonPropertyTemperature(7.0f, new PropertyValue("burning","true")));
blockTemperatures.put(Blocks.LIT_FURNACE.getRegistryName().toString(), new JsonPropertyTemperature(3.0f));
blockTemperatures.put(Blocks.LAVA.getRegistryName().toString(), new JsonPropertyTemperature(15.0f));
blockTemperatures.put(Blocks.FLOWING_LAVA.getRegistryName().toString(), new JsonPropertyTemperature(15.0f));
blockTemperatures.put(Blocks.MAGMA.getRegistryName().toString(), new JsonPropertyTemperature(12.5f));

//blockTemperatures.put(Blocks.LIT_FURNACE.getRegistryName().toString(),
// new BlockTemperature(3.0f, new BlockProperty("burning","true")));

blockTemperatures.put(SDBlocks.campfire.getRegistryName().toString(), new BlockTemperature(7.0f, new PropertyValue("burning","true")));
blockTemperatures.put(Blocks.LIT_FURNACE.getRegistryName().toString(), new BlockTemperature(3.0f));
blockTemperatures.put(Blocks.LAVA.getRegistryName().toString(), new BlockTemperature(15.0f));
blockTemperatures.put(Blocks.FLOWING_LAVA.getRegistryName().toString(), new BlockTemperature(15.0f));
blockTemperatures.put(Blocks.MAGMA.getRegistryName().toString(), new BlockTemperature(12.5f));
//materialTemperature is not a Map

blockTemperatures = processJson("blockTemperatures.json", blockTemperatures, new TypeToken<Map<String, BlockTemperature>>(){}.getType(), jsonDirectory);
//Mod Compatibility

materialTemperature = processJson("materialTemperature.json", materialTemperature, new TypeToken<MaterialTemperature>(){}.getType(), jsonDirectory);
JsonCompatDefaults.instance.populate();

/*
for(Map.Entry<String, BlockTemperature> entry : blockTemperatures.entrySet())
{
SimpleDifficulty.logger.debug(entry.getKey());
SimpleDifficulty.logger.debug(entry.getValue().temperature);
SimpleDifficulty.logger.debug(entry.getValue().properties.size());
}
*/
//TODO consider how fluidTemperatures should actually be stored. is Fluid name a reliable way to get their name?


//Process JSON

armorTemperatures = processJson("armorTemperatures.json", armorTemperatures, new TypeToken<Map<String, JsonTemperature>>(){}.getType(), jsonDirectory);
blockTemperatures = processJson("blockTemperatures.json", blockTemperatures, new TypeToken<Map<String, JsonPropertyTemperature>>(){}.getType(), jsonDirectory);
fluidTemperatures = processJson("fluidTemperatures.json", fluidTemperatures, new TypeToken<Map<String, JsonTemperature>>(){}.getType(), jsonDirectory);
materialTemperature = processJson("materialTemperature.json", materialTemperature, new TypeToken<MaterialTemperature>(){}.getType(), jsonDirectory);
}

public static <T> T processJson(String jsonFileName, final T container, Type type, File jsonDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ public static class SDCFGClientConfig
@Config.Name("EnableThermometer")
public boolean enableThermometer = true;

@Config.Comment("Whether thermometers in your inventory will display on your HUD")
@Config.Name("HUDThermometer")
public boolean hudThermometer = true;

@Config.Comment("Client config debug")
@Config.Name("ClientConfigDebug")
public boolean clientdebug = false;
Expand Down Expand Up @@ -299,6 +303,7 @@ public static void sendLocalClientConfigToAPI()
ClientConfig.instance.put(ClientOptions.DRAW_THIRST_SATURATION, client.drawThirstSaturation);
ClientConfig.instance.put(ClientOptions.ENABLE_THERMOMETER, client.enableThermometer);
ClientConfig.instance.put(ClientOptions.ALTERNATE_TEMP, client.alternateTemp);
ClientConfig.instance.put(ClientOptions.HUD_THERMOMETER, client.hudThermometer);
ClientConfig.instance.put(ClientOptions.DEBUG, client.clientdebug);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;

public class BlockTemperature
public class JsonPropertyTemperature
{
@SerializedName("properties")
public Map<String,String> properties;

@SerializedName("temperature")
public float temperature;

public BlockTemperature(float temperature, PropertyValue ... props)
public JsonPropertyTemperature(float temperature, PropertyValue ... props)
{
this.temperature = temperature;
this.properties = new HashMap<String,String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.google.gson.annotations.SerializedName;

public class ArmorTemperature
public class JsonTemperature
{
@SerializedName("temperature")
public float temperature;

public ArmorTemperature(float temperature)
public JsonTemperature(float temperature)
{
this.temperature = temperature;
}
}
}
Loading

0 comments on commit d1c4ee1

Please sign in to comment.