Skip to content

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
Easy JSON Configuration Ingame!

Hold the item you want to configure in your main hand, and then run the command you want to use.
/simpledifficulty addArmor <temperature>
/simpledifficulty addBlock <temperature>
/simpledifficulty addConsumableTemperature <group> <temperature> <duration>
/simpledifficulty addConsumableThirst <amount> <saturation> <thirstyChance>
/simpledifficulty addFluid <temperature>

After you've changed things, you can write it all to the actual json files with
/simpledifficulty exportJson

The load JSON got changed to
/simpledifficulty reloadJson

Remember, "reload" will make you lose any in-game changes if you don't "export" first!

Also added an ability for mods to disable their own mod compatibility.
This'll let mod makers replace the built-in compatibility with their own.
  • Loading branch information
Charles445 committed Feb 4, 2020
1 parent c088a29 commit 87d65ec
Show file tree
Hide file tree
Showing 14 changed files with 609 additions and 47 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.2.0"
version = "1.12.2-0.2.1"
group = "com.charles445.simpledifficulty" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "SimpleDifficulty"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SimpleDifficulty
{
public static final String MODID = "simpledifficulty";
public static final String NAME = "SimpleDifficulty";
public static final String VERSION = "0.2.0";
public static final String VERSION = "0.2.1";

@Mod.Instance(SimpleDifficulty.MODID)
public static SimpleDifficulty instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.charles445.simpledifficulty.api;

import java.util.ArrayList;
import java.util.List;

public class SDCompatibility
{
/**
* Don't change this directly, use {@link #disableBuiltInModJsonConfiguration(String) disableBuiltInModJsonConfiguration}
* <br>
*/
public static List<String> disabledDefaultJson = new ArrayList<String>();

/**
* Don't change this directly, use {@link #disableBuiltInModCompatibility(String) disableBuiltInModCompatibility}
* <br>
*/
public static List<String> disabledCompletely = new ArrayList<String>();

/**
* Call this in preInit or init with your mod's modid.<br>
* SimpleDifficulty won't automatically make settings for your mod.<br>
* This is useful if you want to make defaults yourself.
* @param modid
*/
public static void disableBuiltInModJsonConfiguration(String modid)
{
disabledDefaultJson.add(modid);
}

/**
* Call this in preInit or init with your mod's modid<br>
* SimpleDifficulty will stop automatically being compatible with your mod.<br>
* This is useful if you want to make the mod compatibility in your own way!<br>
* NOTE that this will disable any built in mod json configuration as well.
*/
public static void disableBuiltInModCompatibility(String modid)
{
disabledDefaultJson.add(modid);
disabledCompletely.add(modid);
}


}
115 changes: 100 additions & 15 deletions src/main/java/com/charles445/simpledifficulty/api/config/JsonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
import com.charles445.simpledifficulty.api.config.json.JsonTemperature;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;

public class JsonConfig
{
public static Map<String, JsonTemperature> armorTemperatures = new HashMap<String, JsonTemperature>();
public static Map<String, List<JsonPropertyTemperature>> blockTemperatures = new HashMap<String, List<JsonPropertyTemperature>>();
public static Map<String, JsonTemperature> fluidTemperatures = new HashMap<String, JsonTemperature>();
public static Map<String, List<JsonConsumableTemperature>> consumableTemperature = new HashMap<String, List<JsonConsumableTemperature>>();
public static Map<String, List<JsonConsumableThirst>> consumableThirst = new HashMap<String, List<JsonConsumableThirst>>();
public static Map<String, JsonTemperature> fluidTemperatures = new HashMap<String, JsonTemperature>();

//TODO jdoc

Expand All @@ -39,16 +38,64 @@ public static void registerArmorTemperature(String registryName, float temperatu

//Blocks

public static void registerBlockTemperature(Block block, float temperature, JsonPropertyValue... properties)
public static boolean registerBlockTemperature(Block block, float temperature, JsonPropertyValue... properties)
{
registerBlockTemperature(block.getRegistryName().toString(), temperature, properties);
return registerBlockTemperature(block.getRegistryName().toString(), temperature, properties);
}

public static void registerBlockTemperature(String registryName, float temperature, JsonPropertyValue... properties)
public static boolean registerBlockTemperature(String registryName, float temperature, JsonPropertyValue... properties)
{
if(!blockTemperatures.containsKey(registryName))
blockTemperatures.put(registryName, new ArrayList<JsonPropertyTemperature>());
blockTemperatures.get(registryName).add(new JsonPropertyTemperature(temperature,properties));

final List<JsonPropertyTemperature> currentList = blockTemperatures.get(registryName);
JsonPropertyTemperature result = new JsonPropertyTemperature(temperature,properties);

if(properties.length>0)
{
//With property
for(int i=0;i<currentList.size();i++)
{
JsonPropertyTemperature jpt = currentList.get(i);
if(jpt.matchesDescribedProperties(properties))
{
currentList.set(i, result);
return true;
}
}

currentList.add(result);
return true;
}
else
{
//No property
//Do NOT interfere with it if one with a property specification exists, and return false

for(int i=0;i<currentList.size();i++)
{
JsonPropertyTemperature jpt = currentList.get(i);
if(jpt.properties.keySet().size() > 0)
{
return false;
}
}

//Okay, none with properties got found, go through it again and look for the one to replace as usual
for(int i=0;i<currentList.size();i++)
{
JsonPropertyTemperature jpt = currentList.get(i);
if(jpt.properties.keySet().size() == 0)
{
currentList.set(i, result);
return true;
}
}

currentList.add(result);
return true;
}

}

//Fluid
Expand All @@ -60,35 +107,73 @@ public static void registerFluidTemperature(String fluidName, float temperature)

//Consumable Temperature



public static void registerConsumableTemperature(String group, ItemStack stack, float temperature, int duration)
{
String registryName = stack.getItem().getRegistryName().toString();

int metadata = -1;
if(stack.getHasSubtypes())
metadata = stack.getMetadata();

registerConsumableTemperature(group, registryName, metadata, temperature, duration);
}

public static void registerConsumableTemperature(String group, String registryName, int metadata, float temperature, int duration)
{
if(!consumableTemperature.containsKey(registryName))
consumableTemperature.put(registryName, new ArrayList<JsonConsumableTemperature>());

if(stack.getHasSubtypes())
consumableTemperature.get(registryName).add(new JsonConsumableTemperature(group, temperature, stack.getMetadata(), duration));
else
consumableTemperature.get(registryName).add(new JsonConsumableTemperature(group, temperature, -1, duration));
final List<JsonConsumableTemperature> currentList = consumableTemperature.get(registryName);

JsonConsumableTemperature result = new JsonConsumableTemperature(group, temperature, metadata, duration);

for(int i=0; i<currentList.size(); i++)
{
JsonConsumableTemperature jct = currentList.get(i);
if(jct.matches(metadata))
{
currentList.set(i, result);
return;
}
}

currentList.add(result);
}

//ConsumableThirst

public static void registerConsumableThirst(ItemStack stack, int amount, float saturation, float thirstChance)
public static void registerConsumableThirst(ItemStack stack, int amount, float saturation, float thirstyChance)
{
int metadata = -1;
String registryName = stack.getItem().getRegistryName().toString();

int metadata = -1;
if(stack.getHasSubtypes())
metadata = stack.getMetadata();

registerConsumableThirst(stack.getItem().getRegistryName().toString(), metadata, amount, saturation, thirstChance);
registerConsumableThirst(stack.getItem().getRegistryName().toString(), metadata, amount, saturation, thirstyChance);
}

public static void registerConsumableThirst(String registryName, int metadata, int amount, float saturation, float thirstChance)
public static void registerConsumableThirst(String registryName, int metadata, int amount, float saturation, float thirstyChance)
{
if(!consumableThirst.containsKey(registryName))
consumableThirst.put(registryName, new ArrayList<JsonConsumableThirst>());

consumableThirst.get(registryName).add(new JsonConsumableThirst(metadata,amount,saturation,thirstChance));
final List<JsonConsumableThirst> currentList = consumableThirst.get(registryName);

JsonConsumableThirst result = new JsonConsumableThirst(metadata, amount, saturation, thirstyChance);

for(int i=0; i<currentList.size(); i++)
{
JsonConsumableThirst jct = currentList.get(i);
if(jct.matches(metadata))
{
currentList.set(i, result);
return;
}
}

currentList.add(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public boolean matches(ItemStack stack)
{
return metadata == -1 || metadata == 32767 || metadata == stack.getMetadata();
}

public boolean matches(int meta)
{
return metadata == -1 || metadata == 32767 || metadata == meta;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public boolean matches(ItemStack stack)
{
return metadata == -1 || metadata == 32767 || metadata == stack.getMetadata();
}

public boolean matches(int meta)
{
return metadata == -1 || metadata == 32767 || metadata == meta;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ public boolean matchesState(IBlockState blockstate)

return true;
}

public boolean matchesDescribedProperties(JsonPropertyValue... props)
{
if(props.length != properties.keySet().size())
return false;

for(JsonPropertyValue prop : props)
{
if(!properties.containsKey(prop.property))
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TemperatureRegistry
/**
* Map of modifiers that the temperature system uses.
* <br>
* It is recommended to add modifiers with {@link #registerModifier(ITemperatureModifier) registerModifier
* It is recommended to add modifiers with {@link #registerModifier(ITemperatureModifier) registerModifier}
* <br>
*/
public static LinkedHashMap<String, ITemperatureModifier> modifiers = new LinkedHashMap<String, ITemperatureModifier>();
Expand Down
Loading

0 comments on commit 87d65ec

Please sign in to comment.