Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/com/NovaCraft/BookshelfPowerTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public byte[] transform(String className, String transformedClassName, byte[] or
return originalClassBytes;
}

CoremodConfig.ensureLoaded();
if (!CoremodConfig.enableBookshelfPowerTransformer) {
return originalClassBytes;
}

System.out.println("[NovaCraft] Patching ContainerEnchantment: " + transformedClassName);

//No idea what this is doing beyond this point other than finding the correct strings in the classes above and altering them
Expand All @@ -49,7 +54,7 @@ public void visitMethodInsn(int opcode, String calledClassOwner, String calledMe
//Target only the call to EnchantmentHelper.calcItemStackEnchantability
if (calledClassOwner.equals("net/minecraft/enchantment/EnchantmentHelper") && calledMethodName.equals("calcItemStackEnchantability")) {
super.visitInsn(Opcodes.SWAP);
super.visitInsn(Opcodes.ICONST_2);
super.visitLdcInsn(Integer.valueOf(CoremodConfig.bookshelfPowerDivisor));
super.visitInsn(Opcodes.IDIV);
super.visitInsn(Opcodes.SWAP);
}
Expand Down
140 changes: 140 additions & 0 deletions src/main/java/com/NovaCraft/CoremodConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.NovaCraft;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

final class CoremodConfig {
private static final String CONFIG_DIRECTORY = "config/NovaCraft";
private static final String CONFIG_FILE_NAME = "NovaCraft_Base.cfg";

private static final boolean DEFAULT_ENABLE_BOOKSHELF_POWER_TRANSFORMER = true;
private static final int DEFAULT_BOOKSHELF_POWER_DIVISOR = 2;
private static final boolean DEFAULT_ENABLE_SPIDER_SPEED_TRANSFORMER = true;
private static final double DEFAULT_SPIDER_MOVEMENT_SPEED_MULTIPLIER = 2.0D;

static boolean enableBookshelfPowerTransformer = DEFAULT_ENABLE_BOOKSHELF_POWER_TRANSFORMER;
static int bookshelfPowerDivisor = DEFAULT_BOOKSHELF_POWER_DIVISOR;
static boolean enableSpiderSpeedTransformer = DEFAULT_ENABLE_SPIDER_SPEED_TRANSFORMER;
static double spiderMovementSpeedMultiplier = DEFAULT_SPIDER_MOVEMENT_SPEED_MULTIPLIER;

private static boolean loaded;

private CoremodConfig() {
}

static synchronized void ensureLoaded() {
if (!loaded) {
load();
}
}

private static void load() {
enableBookshelfPowerTransformer = DEFAULT_ENABLE_BOOKSHELF_POWER_TRANSFORMER;
bookshelfPowerDivisor = DEFAULT_BOOKSHELF_POWER_DIVISOR;
enableSpiderSpeedTransformer = DEFAULT_ENABLE_SPIDER_SPEED_TRANSFORMER;
spiderMovementSpeedMultiplier = DEFAULT_SPIDER_MOVEMENT_SPEED_MULTIPLIER;

File configFile = new File(CONFIG_DIRECTORY, CONFIG_FILE_NAME);
if (!configFile.exists()) {
loaded = true;
return;
}

BufferedReader reader = null;

try {
reader = new BufferedReader(new FileReader(configFile));
String line;

while ((line = reader.readLine()) != null) {
parseLine(line.trim());
}
} catch (IOException e) {
log("Failed to load ASM config from NovaCraft_Base.cfg, using defaults. " + e.getMessage());
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}

loaded = true;
}

private static void parseLine(String line) {
if (line.length() < 4 || line.startsWith("#")) {
return;
}

if (line.charAt(1) != ':') {
return;
}

int equalsIndex = line.indexOf('=');
if (equalsIndex <= 2) {
return;
}

String key = line.substring(2, equalsIndex).trim();
String rawValue = line.substring(equalsIndex + 1).trim();

if ("enableBookshelfPowerTransformer".equals(key)) {
enableBookshelfPowerTransformer = parseBoolean(key, rawValue, DEFAULT_ENABLE_BOOKSHELF_POWER_TRANSFORMER);
} else if ("bookshelfPowerDivisor".equals(key)) {
bookshelfPowerDivisor = parseInt(key, rawValue, DEFAULT_BOOKSHELF_POWER_DIVISOR, 1);
} else if ("enableSpiderSpeedTransformer".equals(key)) {
enableSpiderSpeedTransformer = parseBoolean(key, rawValue, DEFAULT_ENABLE_SPIDER_SPEED_TRANSFORMER);
} else if ("spiderMovementSpeedMultiplier".equals(key)) {
spiderMovementSpeedMultiplier = parseDouble(key, rawValue, DEFAULT_SPIDER_MOVEMENT_SPEED_MULTIPLIER, 0.0D);
}
}

private static boolean parseBoolean(String key, String rawValue, boolean defaultValue) {
if ("true".equalsIgnoreCase(rawValue) || "false".equalsIgnoreCase(rawValue)) {
return Boolean.parseBoolean(rawValue);
}

log("Invalid boolean for " + key + ": " + rawValue + ". Using default " + defaultValue + ".");
return defaultValue;
}

private static int parseInt(String key, String rawValue, int defaultValue, int minValue) {
try {
int value = Integer.parseInt(rawValue.trim());

if (value < minValue) {
log("Value for " + key + " must be at least " + minValue + ". Using default " + defaultValue + ".");
return defaultValue;
}

return value;
} catch (NumberFormatException e) {
log("Invalid integer for " + key + ": " + rawValue + ". Using default " + defaultValue + ".");
return defaultValue;
}
}

private static double parseDouble(String key, String rawValue, double defaultValue, double minValue) {
try {
double value = Double.parseDouble(rawValue.trim());

if (Double.isNaN(value) || Double.isInfinite(value) || value < minValue) {
log("Value for " + key + " must be a finite number greater than or equal to " + minValue + ". Using default " + defaultValue + ".");
return defaultValue;
}

return value;
} catch (NumberFormatException e) {
log("Invalid decimal for " + key + ": " + rawValue + ". Using default " + defaultValue + ".");
return defaultValue;
}
}

private static void log(String message) {
System.out.println("[NovaCraft][ASM Config] " + message);
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/NovaCraft/SpiderSpeedTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
if (!transformedName.equals("net.minecraft.entity.monster.EntitySpider") && !transformedName.equals("net.minecraft.entity.monster.EntityCaveSpider"))
return basicClass;

CoremodConfig.ensureLoaded();
if (!CoremodConfig.enableSpiderSpeedTransformer) {
return basicClass;
}

System.out.println("[SpiderTransformer] Patching EntitySpider...");

ClassNode classNode = new ClassNode();
Expand All @@ -36,7 +41,7 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)

if (value == 0.800000011920929D) {

ldc.cst = 1.600000023841858D;
ldc.cst = value * CoremodConfig.spiderMovementSpeedMultiplier;
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/NovaCraft/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class Configs {
public static boolean disableEnchantedGoldenAppleRecipe;
public static boolean enableWeaponsToAllignWithVanilla;
public static boolean enableHalfNaturalRegenInEnd;
public static boolean enableBookshelfPowerTransformer;
public static int bookshelfPowerDivisor;
public static boolean enableSpiderSpeedTransformer;
public static double spiderMovementSpeedMultiplier;

//Vanilla Ore Generation Alterations
public static boolean disableRegularVanillaGen;
Expand Down Expand Up @@ -142,6 +146,20 @@ public static void loadConfigs(File configFile) {
enableDebugMode = conf.getBoolean("enableDebugMode", "Important Options", false, "Enables log messages for location of structures generating or if a crash was prevented.");
enableNewCaveSounds = conf.getBoolean("enableNewCaveSounds", "Important Options", true, "Enables New Cave Sounds.");
enableHalfNaturalRegenInEnd = conf.getBoolean("enableHalfNaturalRegenInEnd", "Important Options", true, "Enables Half Natural Regeneration speed for the player while in the End.");

//Important Options
enableBookshelfPowerTransformer = conf.getBoolean("enableBookshelfPowerTransformer", "Important Options", true, "Enables the startup ASM patch that changes enchantment table bookshelf power.");
prop = conf.get("Important Options", "bookshelfPowerDivisor", 2);
prop.comment = "Startup ASM option. Divides the bookshelf count before enchantability is calculated. 1 = vanilla, 2 = half power.";
bookshelfPowerDivisor = Math.max(1, prop.getInt(2));
enableSpiderSpeedTransformer = conf.getBoolean("enableSpiderSpeedTransformer", "Important Options", true, "Enables the startup ASM patch that changes spider and cave spider movement speed.");
prop = conf.get("Important Options", "spiderMovementSpeedMultiplier", 2.0D);
prop.comment = "Startup ASM option. Multiplies vanilla spider movement speed. 1.0 = vanilla, 2.0 = double speed, 0.5 = half speed.";
spiderMovementSpeedMultiplier = prop.getDouble(2.0D);
if (spiderMovementSpeedMultiplier <= 0.0D || Double.isNaN(spiderMovementSpeedMultiplier) || Double.isInfinite(spiderMovementSpeedMultiplier)) {
spiderMovementSpeedMultiplier = 2.0D;
}

enableStrongholdAlterations = conf.getBoolean("enableStrongholdAlterations", "Important Options", true, "Enables Stronghold Alterations.");
enableMaxStrongholdSpawners = conf.getBoolean("enableMaxStrongholdSpawners", "Misc", false, "Enables that most rooms in the stronghold have a spawner in them.");
enableCrackedEndPortalFrame = conf.getBoolean("enableCrackedEndPortalFrame", "Misc", true, "Enables that several end portal frames are cracked and must be repaired in the Stronghold.");
Expand Down