mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 12:32:29 +00:00
- Added 1.7.10 Buildcraft support
- Exceptions can now log to the minetweaker log, for easier bug resolution - /mt hand now copies to the clipboard too - /mt hand now outputs ore dictionary entries to which it belongs - Reducing verbosity a bit
This commit is contained in:
1 parent
86a3568e9e
commit
a8aae17d8a
29 files changed
+1289
-24
No files matched your search
@@ -216,6 +216,19 @@ public class MineTweakerAPI {
|
||||
getLogger().logError(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error message. Error messages indicate a real problem and
|
||||
* indicate that things won't run properly. The scripting system will
|
||||
* still make a best-effort attempt at executing the rest of the scripts,
|
||||
* but that might cause additional errors and issues.
|
||||
*
|
||||
* @param message error message
|
||||
* @param exception exception that was caught related to the error
|
||||
*/
|
||||
public static void logError(String message, Throwable exception) {
|
||||
getLogger().logError(message, exception);
|
||||
}
|
||||
|
||||
// ###################################
|
||||
// ### Plugin registration methods ###
|
||||
// ###################################
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package minetweaker;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -124,7 +127,7 @@ public class MineTweakerImplementationAPI {
|
||||
|
||||
MineTweakerAPI.logCommand("Liquids:");
|
||||
for (ILiquidDefinition liquid : liquids) {
|
||||
MineTweakerAPI.logCommand("<" + liquid.getName() + "> -- " + liquid.getDisplayName());
|
||||
MineTweakerAPI.logCommand("<liquid:" + liquid.getName() + "> -- " + liquid.getDisplayName());
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
@@ -204,7 +207,14 @@ public class MineTweakerImplementationAPI {
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
IItemStack hand = player.getCurrentItem();
|
||||
if (hand != null) {
|
||||
player.sendChat(hand.toString());
|
||||
String value = hand.toString();
|
||||
player.sendChat(value);
|
||||
copyToClipboard(value);
|
||||
|
||||
List<IOreDictEntry> entries = hand.getOres();
|
||||
for (IOreDictEntry entry : entries) {
|
||||
player.sendChat("Is in <ore:" + entry.getName() + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
@@ -576,6 +586,16 @@ public class MineTweakerImplementationAPI {
|
||||
MineTweakerAPI.apply(new AddMineTweakerCommandAction(new MineTweakerCommand(name, description, function)));
|
||||
}
|
||||
|
||||
// ##############################
|
||||
// ### Private static methods ###
|
||||
// ##############################
|
||||
|
||||
private static void copyToClipboard(String value) {
|
||||
StringSelection stringSelection = new StringSelection(value);
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(stringSelection, null);
|
||||
}
|
||||
|
||||
// ############################
|
||||
// ### Public inner classes ###
|
||||
// ############################
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
@@ -40,4 +42,13 @@ public interface IItemDefinition {
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack makeStack(@Optional int meta);
|
||||
|
||||
/**
|
||||
* Returns all ore entries containing this item. Also contains ore entries
|
||||
* that refer to a specific sub-item.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
public List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
@@ -180,4 +182,13 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenCaster
|
||||
public IBlock asBlock();
|
||||
|
||||
/**
|
||||
* Retrieves all the ores referring to this item. Includes wildcard ore
|
||||
* entries.
|
||||
*
|
||||
* @return ore entries containing this item stack
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
public List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
@@ -21,14 +22,16 @@ import minetweaker.runtime.ILogger;
|
||||
*/
|
||||
public class FileLogger implements ILogger {
|
||||
private final Writer writer;
|
||||
private final PrintWriter printWriter;
|
||||
|
||||
public FileLogger(File output) {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
printWriter = new PrintWriter(writer);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException("File not found");
|
||||
throw new RuntimeException("Could not open log file " + output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +67,16 @@ public class FileLogger implements ILogger {
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
try {
|
||||
writer.write("ERROR: " + message + "\n");
|
||||
if (exception != null) {
|
||||
exception.printStackTrace(printWriter);
|
||||
}
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
|
||||
@@ -76,11 +76,16 @@ public class MTLogger implements ILogger {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logError(message);
|
||||
logger.logError(message, exception);
|
||||
}
|
||||
|
||||
String message2 = "ERROR: " + message;
|
||||
|
||||
@@ -24,4 +24,7 @@ public interface ILogger {
|
||||
|
||||
@ZenMethod
|
||||
public void logError(String message);
|
||||
|
||||
@ZenMethod
|
||||
public void logError(String message, Throwable exception);
|
||||
}
|
||||
@@ -137,8 +137,7 @@ public class MTTweaker implements ITweaker {
|
||||
//ex.printStackTrace();
|
||||
MineTweakerAPI.logError("Error parsing " + ex.getFile().getFileName() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logError("Error loading " + script.getName() + ": " + ex.toString());
|
||||
ex.printStackTrace();
|
||||
MineTweakerAPI.logError("Error loading " + script.getName() + ": " + ex.toString(), ex);
|
||||
}
|
||||
|
||||
if (reader != null) {
|
||||
@@ -156,9 +155,8 @@ public class MTTweaker implements ITweaker {
|
||||
// execute scripts
|
||||
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
|
||||
module.getMain().run();
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
} catch (Throwable ex) {
|
||||
MineTweakerAPI.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user