Skip to content

Commit

Permalink
Large fix commit. Updated thermometer to show temperature based on wo…
Browse files Browse the repository at this point in the history
…rld location. Thermometer now works in item frame. Added configuration for temperature modifiers of various types. Added configurable thermometer bounds. Added toggle for whether or not thermometer is affected by rain chill. Added asanetargoss's 1.11 PR for withering plant stems. Added configuration options for hibernating crops (such as trees) and configuration for crops which wither without implementing the API. Added command for retrieving temperature at world location.
  • Loading branch information
TimTinkers committed Jul 14, 2017
1 parent 55845cf commit b32f4c2
Show file tree
Hide file tree
Showing 32 changed files with 2,143 additions and 1,502 deletions.
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
minecraft_version=1.9.4
forge_version=12.17.0.1968
minecraft_version=1.10.2
forge_version=12.18.3.2316
mod_version=1.1.1
mappings_version=snapshot_nodoc_20160519
35 changes: 30 additions & 5 deletions src/main/java/toughasnails/api/config/GameplayOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,36 @@
package toughasnails.api.config;

public enum GameplayOption implements ISyncedOption {
ENABLE_LOWERED_STARTING_HEALTH("Enable Lowered Starting Health"),
ENABLE_THIRST("Enable Thirst"),
ENABLE_TEMPERATURE("Enable Body Temperature"),
ENABLE_SEASONS("Enable Seasons"),
DRINKS("Drinks");
ENABLE_LOWERED_STARTING_HEALTH("Enable Lowered Starting Health"), //
ENABLE_THIRST("Enable Thirst"), //
ENABLE_TEMPERATURE("Enable Body Temperature"), //
ENABLE_SEASONS("Enable Seasons"), //
DRINKS("Drinks"), //
OVERRIDE_THERMOMETER_LIMITS("Override Thermometer Limits"), //
THERMOMETER_LOWER_BOUND("Thermometer Lower Bound"), //
THERMOMETER_UPPER_BOUND("Thermometer Upper Bound"), //
RAIN_CHILL("Enable Rain Chill on World Blocks"), //
BIOME_TEMP_MODIFIER("Biome Temperature Modification Scaling"), //
ALTITUDE_TEMP_MODIFIER("Altitude Temperature Modification Scaling"), //
WET_TEMP_MODIFIER("Temperature Modifier for being Wet"), //
SNOW_TEMP_MODIFIER("Temperature Modifier for Snow"), //
TIME_TEMP_MODIFIER("Time of Day Temperature Modification Scaling"), //
TIME_EXTREMITY_MODIFIER("Temperature Scaling for Time of Day Extremities"), //
EARLY_AUTUMN_MODIFIER("Temperature Modifier for the EARLY_AUTUMN Season"), //
MID_AUTUMN_MODIFIER("Temperature Modifier for the MID_AUTUMN Season"), //
LATE_AUTUMN_MODIFIER("Temperature Modifier for the LATE_AUTUMN Season"), //
EARLY_WINTER_MODIFIER("Temperature Modifier for the EARLY_WINTER Season"), //
MID_WINTER_MODIFIER("Temperature Modifier for the MID_WINTER Season"), //
LATE_WINTER_MODIFIER("Temperature Modifier for the LATE_WINTER Season"), //
EARLY_SPRING_MODIFIER("Temperature Modifier for the EARLY_SPRING Season"), //
MID_SPRING_MODIFIER("Temperature Modifier for the MID_SPRING Season"), //
LATE_SPRING_MODIFIER("Temperature Modifier for the LATE_SPRING Season"), //
EARLY_SUMMER_MODIFIER("Temperature Modifier for the EARLY_SUMMER Season"), //
MID_SUMMER_MODIFIER("Temperature Modifier for the MID_SUMMER Season"), //
LATE_SUMMER_MODIFIER("Temperature Modifier for the LATE_SUMMER Season"), //
TEMPERATURE_WITHERING("Crops Wither by Temperature"), //
HIBERNATING("Crops which Hibernate and don't Decay"), //
CROPS("Crops");

private final String optionName;

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/toughasnails/api/config/SyncedConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public static boolean getBooleanValue(ISyncedOption option) {
return Boolean.valueOf(optionsToSync.get(option.getOptionName()).value);
}

public static int getIntegerValue(ISyncedOption option) {
return Integer.valueOf(optionsToSync.get(option.getOptionName()).value);
}

public static float getFloatValue(ISyncedOption option) {
return Float.valueOf(optionsToSync.get(option.getOptionName()).value);
}

public static List<String> getListValue(ISyncedOption option) {
SyncedConfigEntry value = optionsToSync.get(option.getOptionName());
String rawList = value.value;
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/toughasnails/api/season/IHibernatingCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/

package toughasnails.api.season;

/**
* 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
* Crops using this interface in 1.10 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)
*
* Please note that due to how Java bytecode works, you must explicitly
* implement this interface if your class overrides updateTick.
*/
public interface IHibernatingCrop {

Expand Down
189 changes: 97 additions & 92 deletions src/main/java/toughasnails/asm/ASMHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,96 +25,101 @@

import com.google.common.collect.Lists;

public class ASMHelper
{
public static final Logger LOGGER = LogManager.getLogger("ToughAsNails Transformer");

public static boolean methodEquals(MethodNode methodNode, String[] names, String desc)
{
boolean nameMatches = false;

for (String name : names)
{
if (methodNode.name.equals(name))
{
nameMatches = true;
break;
}
}

return nameMatches && methodNode.desc.equals(desc);
}

public static void clearNextInstructions(MethodNode methodNode, AbstractInsnNode insnNode)
{
Iterator<AbstractInsnNode> iterator = methodNode.instructions.iterator(methodNode.instructions.indexOf(insnNode));

while (iterator.hasNext())
{
iterator.next();
iterator.remove();
}
}

public static MethodInsnNode getUniqueMethodInsnNode(MethodNode methodNode, int opcode, String owner, String[] names, String desc)
{
List<MethodInsnNode> matchedMethodNodes = matchMethodInsnNodes(methodNode, opcode, owner, names, desc);

if (matchedMethodNodes.isEmpty()) throw new RuntimeException("No method instruction node found matching " + owner + " " + names[0] + " " + desc);
if (matchedMethodNodes.size() > 1) LOGGER.warn("Too many matched instructions were found in " + methodNode.name + " for " + owner + " " + names[0] + " " + desc + ". Crashes or bugs may occur!");

return matchedMethodNodes.get(matchedMethodNodes.size() - 1);
}

public static List<MethodInsnNode> matchMethodInsnNodes(MethodNode methodNode, int opcode, String owner, String[] names, String desc)
{
ArrayList<MethodInsnNode> matches = Lists.newArrayList();
ArrayList<String> validMethodNames = Lists.newArrayList(names);

for (AbstractInsnNode insnNode : methodNode.instructions.toArray())
{
if (insnNode instanceof MethodInsnNode && insnNode.getOpcode() == opcode)
{
MethodInsnNode methodInsnNode = (MethodInsnNode)insnNode;

if (methodInsnNode.owner.equals(owner) & validMethodNames.contains(methodInsnNode.name) && methodInsnNode.desc.equals(desc))
{
matches.add(methodInsnNode);
}
}
}

return matches;
}

public static void verifyClassHash(String className, byte[] bytes, String... expectedHashes)
{
String currentHash = DigestUtils.md5Hex(bytes);

if (!Lists.newArrayList(expectedHashes).contains(currentHash))
{
String error = String.format("Unexpected hash %s detected for class %s. Crashes or bugs may occur!", currentHash, className);
LOGGER.error(error);
}
else
{
LOGGER.info(String.format("Valid hash %s found for class %s.", currentHash, className));
}
}

private static Printer printer = new Textifier();
private static TraceMethodVisitor methodVisitor = new TraceMethodVisitor(printer);

public static void printMethod(MethodNode methodNode)
{
for (AbstractInsnNode insnNode : methodNode.instructions.toArray())
{
insnNode.accept(methodVisitor);
StringWriter stringWriter = new StringWriter();
printer.print(new PrintWriter(stringWriter));
printer.getText().clear();

LOGGER.info(stringWriter.toString().replace("\n", ""));
}
}
public class ASMHelper {
public static final Logger LOGGER = LogManager
.getLogger("ToughAsNails Transformer");

public static boolean methodEquals(MethodNode methodNode, String[] names,
String desc) {
boolean nameMatches = false;

for (String name : names) {
if (methodNode.name.equals(name)) {
nameMatches = true;
break;
}
}

return nameMatches && methodNode.desc.equals(desc);
}

public static void clearNextInstructions(MethodNode methodNode,
AbstractInsnNode insnNode) {
Iterator<AbstractInsnNode> iterator = methodNode.instructions
.iterator(methodNode.instructions.indexOf(insnNode));

while (iterator.hasNext()) {
iterator.next();
iterator.remove();
}
}

public static MethodInsnNode getUniqueMethodInsnNode(MethodNode methodNode,
int opcode, String owner, String[] names, String desc) {
List<MethodInsnNode> matchedMethodNodes = matchMethodInsnNodes(
methodNode, opcode, owner, names, desc);

if (matchedMethodNodes.isEmpty())
throw new RuntimeException(
"No method instruction node found matching " + owner + " "
+ names[0] + " " + desc);
if (matchedMethodNodes.size() > 1)
LOGGER.warn("Too many matched instructions were found in "
+ methodNode.name + " for " + owner + " " + names[0] + " "
+ desc + ". Crashes or bugs may occur!");

return matchedMethodNodes.get(matchedMethodNodes.size() - 1);
}

public static List<MethodInsnNode> matchMethodInsnNodes(
MethodNode methodNode, int opcode, String owner, String[] names,
String desc) {
ArrayList<MethodInsnNode> matches = Lists.newArrayList();
ArrayList<String> validMethodNames = Lists.newArrayList(names);

for (AbstractInsnNode insnNode : methodNode.instructions.toArray()) {
if (insnNode instanceof MethodInsnNode
&& insnNode.getOpcode() == opcode) {
MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode;

if (methodInsnNode.owner.equals(owner)
& validMethodNames.contains(methodInsnNode.name)
&& methodInsnNode.desc.equals(desc)) {
matches.add(methodInsnNode);
}
}
}

return matches;
}

public static void verifyClassHash(String className, byte[] bytes,
String... expectedHashes) {
String currentHash = DigestUtils.md5Hex(bytes);

if (!Lists.newArrayList(expectedHashes).contains(currentHash)) {
String error = String.format(
"Unexpected hash %s detected for class %s. Crashes or bugs may occur!",
currentHash, className);
LOGGER.error(error);
} else {
LOGGER.info(String.format("Valid hash %s found for class %s.",
currentHash, className));
}
}

private static Printer printer = new Textifier();
private static TraceMethodVisitor methodVisitor = new TraceMethodVisitor(
printer);

public static void printMethod(MethodNode methodNode) {
for (AbstractInsnNode insnNode : methodNode.instructions.toArray()) {
insnNode.accept(methodVisitor);
StringWriter stringWriter = new StringWriter();
printer.print(new PrintWriter(stringWriter));
printer.getText().clear();

LOGGER.info(stringWriter.toString().replace("\n", ""));
}
}
}
57 changes: 28 additions & 29 deletions src/main/java/toughasnails/asm/ObfHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,32 @@

import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;

public class ObfHelper
{
public static String createMethodDescriptor(boolean obfuscated, String returnType, String... types)
{
String result = "(";

for (String type : types)
{
if (type.length() == 1) result += type;
else
{
result += "L" + (obfuscated ? FMLDeobfuscatingRemapper.INSTANCE.unmap(type) : type) + ";";
}
}

if (returnType.length() > 1)
{
returnType = "L" + unmapType(obfuscated, returnType) + ";";
}

result += ")" + returnType;

return result;
}

public static String unmapType(boolean obfuscated, String type)
{
return obfuscated ? FMLDeobfuscatingRemapper.INSTANCE.unmap(type) : type;
}
public class ObfHelper {
public static String createMethodDescriptor(boolean obfuscated,
String returnType, String... types) {
String result = "(";

for (String type : types) {
if (type.length() == 1)
result += type;
else {
result += "L" + (obfuscated
? FMLDeobfuscatingRemapper.INSTANCE.unmap(type) : type)
+ ";";
}
}

if (returnType.length() > 1) {
returnType = "L" + unmapType(obfuscated, returnType) + ";";
}

result += ")" + returnType;

return result;
}

public static String unmapType(boolean obfuscated, String type) {
return obfuscated ? FMLDeobfuscatingRemapper.INSTANCE.unmap(type)
: type;
}
}
Loading

0 comments on commit b32f4c2

Please sign in to comment.