mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-26 06:42:57 +00:00
- Implemented item renaming
- Did a little bit of work on asset handling
This commit is contained in:
1 parent
3a9a784084
commit
9b51082c4b
16 files changed
+300
No files matched your search
@@ -19,6 +19,7 @@ import minetweaker.runtime.Tweaker;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.api.resource.IResourceManager;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
@@ -36,6 +37,8 @@ import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
* - Set the ore dictionary
|
||||
* - Set the recipe manager
|
||||
* - Set the furnace manager
|
||||
* - Set event manager
|
||||
* - Set resource manager
|
||||
*
|
||||
* - Register additional global symbols to the GlobalRegistry (recipes,
|
||||
* minetweaker, oreDict, logger, as well as the official set of functions)
|
||||
@@ -101,6 +104,19 @@ public class MineTweakerAPI {
|
||||
*/
|
||||
public static ILoadedMods loadedMods = null;
|
||||
|
||||
/**
|
||||
* Access point to the global resource manager. Note that each script group also
|
||||
* has its own local resource manager.
|
||||
*/
|
||||
public static IResourceManager resources = null;
|
||||
|
||||
/**
|
||||
* Register a class registry class. Such class must have (at least) a public
|
||||
* static method called "getClasses" with accepts a List of classes and which
|
||||
* stores its classes into that list.
|
||||
*
|
||||
* @param registryClass
|
||||
*/
|
||||
public static void registerClassRegistry(Class registryClass) {
|
||||
try {
|
||||
Method method = registryClass.getMethod("getClasses", List.class);
|
||||
|
||||
@@ -13,6 +13,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -29,6 +30,9 @@ public interface IItemStack extends IIngredient {
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
@ZenSetter("displayName")
|
||||
public void setDisplayName(String name);
|
||||
|
||||
@ZenGetter("damage")
|
||||
public int getDamage();
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.resource;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.resource.IResourceFile")
|
||||
public interface IResourceFile {
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.resource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IResourceManager {
|
||||
/**
|
||||
* Retrieves a resource file. Returns null if the resource dosen't exist.
|
||||
*
|
||||
* @param module
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public IResourceFile getResource(String module, String name);
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.actions;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.mc164.util.MineTweakerHacks;
|
||||
import net.minecraft.util.StringTranslate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class SetTranslationAction implements IUndoableAction {
|
||||
private static final StringTranslate INSTANCE = MineTweakerHacks.getStringTranslateInstance();
|
||||
private static final Charset UTF8 = Charset.forName("utf-8");
|
||||
|
||||
private final String key;
|
||||
private final String newValue;
|
||||
private final String oldValue;
|
||||
|
||||
public SetTranslationAction(String key, String value) {
|
||||
this.key = key;
|
||||
newValue = value;
|
||||
oldValue = INSTANCE.translateKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
set(key, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
set(key, oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Translating " + key + " to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Reverting " + key + " to " + oldValue;
|
||||
}
|
||||
|
||||
private static void set(String key, String value) {
|
||||
StringTranslate.inject(new ByteArrayInputStream((key + "=" + value).getBytes(UTF8)));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientItem;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.mc164.actions.SetTranslationAction;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -71,6 +72,11 @@ public class MCItemStack implements IItemStack {
|
||||
public String getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String name) {
|
||||
MineTweakerAPI.tweaker.apply(new SetTranslationAction(getName() + ".name", name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.inventory.SlotCrafting;import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.StringTranslate;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
@@ -115,6 +116,16 @@ public class MineTweakerHacks {
|
||||
}
|
||||
}
|
||||
|
||||
public static StringTranslate getStringTranslateInstance() {
|
||||
try {
|
||||
Field field = getField(StringTranslate.class, MineTweakerObfuscation.STRINGTRANSLATE_INSTANCE);
|
||||
return (StringTranslate) field.get(null);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get string translator");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private Methods ###
|
||||
// #######################
|
||||
|
||||
+1
@@ -18,4 +18,5 @@ public class MineTweakerObfuscation {
|
||||
public static final String[] MINECRAFTSERVER_ANVILFILE = {"anvilFile", "field_71308_o"};
|
||||
public static final String[] INVENTORYCRAFTING_EVENTHANDLER = {"eventHandler", "field_70465_c"};
|
||||
public static final String[] SLOTCRAFTING_PLAYER = {"thePlayer", "field_75238_b"};
|
||||
public static final String[] STRINGTRANSLATE_INSTANCE = {"instance", "field_74817_a"};
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc1710.actions;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import net.minecraft.util.StringTranslate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class SetTranslationAction implements IUndoableAction {
|
||||
private static final StringTranslate INSTANCE = MineTweakerHacks.getStringTranslateInstance();
|
||||
private static final Charset UTF8 = Charset.forName("utf-8");
|
||||
|
||||
private final String key;
|
||||
private final String newValue;
|
||||
private final String oldValue;
|
||||
|
||||
public SetTranslationAction(String key, String value) {
|
||||
this.key = key;
|
||||
newValue = value;
|
||||
oldValue = INSTANCE.translateKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
set(key, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
set(key, oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Translating " + key + " to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Reverting " + key + " to " + oldValue;
|
||||
}
|
||||
|
||||
private static void set(String key, String value) {
|
||||
StringTranslate.inject(new ByteArrayInputStream((key + "=" + value).getBytes(UTF8)));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientItem;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.mc1710.actions.SetTranslationAction;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -72,6 +73,11 @@ public class MCItemStack implements IItemStack {
|
||||
public String getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String name) {
|
||||
MineTweakerAPI.tweaker.apply(new SetTranslationAction(getName() + ".name", name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.inventory.SlotCrafting;import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.StringTranslate;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
@@ -127,6 +128,16 @@ public class MineTweakerHacks {
|
||||
}
|
||||
}
|
||||
|
||||
public static StringTranslate getStringTranslateInstance() {
|
||||
try {
|
||||
Field field = getField(StringTranslate.class, MineTweakerObfuscation.STRINGTRANSLATE_INSTANCE);
|
||||
return (StringTranslate) field.get(null);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get string translator");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private Methods ###
|
||||
// #######################
|
||||
|
||||
+1
@@ -20,4 +20,5 @@ public class MineTweakerObfuscation {
|
||||
public static final String[] MINECRAFTSERVER_ANVILFILE = {"anvilFile", "field_71308_o"};
|
||||
public static final String[] INVENTORYCRAFTING_EVENTHANDLER = {"eventHandler", "field_70465_c"};
|
||||
public static final String[] SLOTCRAFTING_PLAYER = {"thePlayer", "field_75238_b"};
|
||||
public static final String[] STRINGTRANSLATE_INSTANCE = {"instance", "field_74817_a"};
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc172.actions;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.mc172.util.MineTweakerHacks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.StringTranslate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class SetTranslationAction implements IUndoableAction {
|
||||
private static final StringTranslate INSTANCE = MineTweakerHacks.getStringTranslateInstance();
|
||||
private static final Charset UTF8 = Charset.forName("utf-8");
|
||||
|
||||
private final String key;
|
||||
private final String newValue;
|
||||
private final String oldValue;
|
||||
|
||||
public SetTranslationAction(String key, String value) {
|
||||
this.key = key;
|
||||
newValue = value;
|
||||
oldValue = INSTANCE.translateKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
set(key, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
set(key, oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Translating " + key + " to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Reverting " + key + " to " + oldValue;
|
||||
}
|
||||
|
||||
private static void set(String key, String value) {
|
||||
StringTranslate.inject(new ByteArrayInputStream((key + "=" + value).getBytes(UTF8)));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientItem;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.mc172.actions.SetTranslationAction;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -72,6 +73,11 @@ public class MCItemStack implements IItemStack {
|
||||
public String getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String name) {
|
||||
MineTweakerAPI.tweaker.apply(new SetTranslationAction(getName() + ".name", name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.inventory.SlotCrafting;import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.StringTranslate;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
@@ -127,6 +128,16 @@ public class MineTweakerHacks {
|
||||
}
|
||||
}
|
||||
|
||||
public static StringTranslate getStringTranslateInstance() {
|
||||
try {
|
||||
Field field = getField(StringTranslate.class, MineTweakerObfuscation.STRINGTRANSLATE_INSTANCE);
|
||||
return (StringTranslate) field.get(null);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get string translator");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private Methods ###
|
||||
// #######################
|
||||
|
||||
+1
@@ -20,4 +20,5 @@ public class MineTweakerObfuscation {
|
||||
public static final String[] MINECRAFTSERVER_ANVILFILE = {"anvilFile", "field_71308_o"};
|
||||
public static final String[] INVENTORYCRAFTING_EVENTHANDLER = {"eventHandler", "field_70465_c"};
|
||||
public static final String[] SLOTCRAFTING_PLAYER = {"thePlayer", "field_75238_b"};
|
||||
public static final String[] STRINGTRANSLATE_INSTANCE = {"instance", "field_74817_a"};
|
||||
}
|
||||
Reference in new issue
Block a user