mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-18 19:29:08 +00:00
Added 1.7.10 port.
This commit is contained in:
1 parent
db900d3b60
commit
2d92c4f724
54 files changed
+4012
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import minetweaker.tasks.RegisterZenClassesTask;
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'forge'
|
||||
minecraft{version = "1.7.10-10.13.0.1152"}
|
||||
version = "1.7.10-3.0.0"
|
||||
archivesBaseName = project.projectDir.name
|
||||
|
||||
dependencies {
|
||||
dependencies {
|
||||
compile project(':ZenScript')
|
||||
compile project(':MineTweaker3-API')
|
||||
}
|
||||
}
|
||||
|
||||
task makeRegistry(type: RegisterZenClassesTask) {
|
||||
inputDir = file('build/classes/main')
|
||||
outputDir = file('build/classes/main')
|
||||
className = 'minetweaker.mc172.MineTweakerRegistry'
|
||||
}
|
||||
|
||||
tasks.jar.dependsOn(makeRegistry)
|
||||
|
||||
processResources
|
||||
{
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version':project.version, 'mcversion':project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else, thats not the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'mcmod.info'
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+4
@@ -0,0 +1,4 @@
|
||||
#Sun Jun 05 18:58:07 CEST 2011
|
||||
version=1
|
||||
eclipse.preferences.version=1
|
||||
refresh.enabled=true
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
#Sun Jun 05 19:03:53 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.debug.ui.UseContextualLaunch=false
|
||||
Console.highWaterMark=88000
|
||||
org.eclipse.debug.ui.PREF_LAUNCH_PERSPECTIVES=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\r\n<launchPerspectives/>\r\n
|
||||
org.eclipse.debug.ui.user_view_bindings=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\r\n<viewBindings>\r\n<view id\="org.eclipse.ui.console.ConsoleView">\r\n<perspective id\="org.eclipse.jdt.ui.JavaPerspective" userAction\="opened"/>\r\n</view>\r\n</viewBindings>\r\n
|
||||
StringVariablePreferencePage=130,107,107,86,
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
#Sun Jun 05 18:58:07 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.epp.usagedata.gathering.enabled=false
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#Sun Sep 18 16:44:39 NZST 2011
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=ignore
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=ignore
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
#Sun Jun 05 18:58:05 CEST 2011
|
||||
spacesForTabs=true
|
||||
eclipse.preferences.version=1
|
||||
overviewRuler_migration=migrated_3.1
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
#Sun Jun 05 18:58:07 CEST 2011
|
||||
IMPORT_FILES_AND_FOLDERS_MODE=prompt
|
||||
IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE=prompt
|
||||
SAVE_ALL_BEFORE_BUILD=true
|
||||
eclipse.preferences.version=1
|
||||
tipsAndTricks=true
|
||||
platformState=1287081747687
|
||||
quickStart=false
|
||||
PROBLEMS_FILTERS_MIGRATE=true
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
#Sun Jun 05 18:50:08 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
showIntro=false
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/Minecraft/lib/net/minecraft/launchwrapper/1.8/launchwrapper-1.8.jar"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="net.minecraft.launchwrapper.Launch"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--version 1.7 --tweakClass cpw.mods.fml.common.launcher.FMLTweaker --username=ForgeDevName --accessToken FML --userProperties={}"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Minecraft"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xincgc -Xmx1024M -Xms1024M -Dfml.ignoreInvalidMinecraftCertificates=true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc}"/>
|
||||
</launchConfiguration>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/Minecraft/src/net/minecraft/server/MinecraftServer.java"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="cpw.mods.fml.relauncher.ServerLaunchWrapper"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Minecraft"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xincgc -Xmx1024M -Xms1024M"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc}"/>
|
||||
</launchConfiguration>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchHistory>
|
||||
<launchGroup id="org.eclipse.ui.externaltools.launchGroup">
|
||||
<mruHistory/>
|
||||
<favorites/>
|
||||
</launchGroup>
|
||||
<launchGroup id="org.eclipse.debug.ui.launchGroup.profile">
|
||||
<mruHistory/>
|
||||
<favorites/>
|
||||
</launchGroup>
|
||||
<launchGroup id="org.eclipse.debug.ui.launchGroup.debug">
|
||||
<mruHistory>
|
||||
<launch memento="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration local="true" path="Client"/> "/>
|
||||
<launch memento="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration local="true" path="Server"/> "/>
|
||||
</mruHistory>
|
||||
<favorites/>
|
||||
</launchGroup>
|
||||
<launchGroup id="org.eclipse.debug.ui.launchGroup.run">
|
||||
<mruHistory>
|
||||
<launch memento="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration local="true" path="Client"/> "/>
|
||||
<launch memento="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration local="true" path="Server"/> "/>
|
||||
</mruHistory>
|
||||
<favorites/>
|
||||
</launchGroup>
|
||||
</launchHistory>
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
#Tue May 06 21:57:37 CEST 2014
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
|
||||
@@ -0,0 +1,23 @@
|
||||
package minetweaker.mc1710;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.network.MineTweakerLoadScriptsPacket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class FMLEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent ev) {
|
||||
if (ev.player instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) ev.player;
|
||||
MineTweakerMod.NETWORK.sendTo(
|
||||
new MineTweakerLoadScriptsPacket(MineTweakerAPI.tweaker.getScriptData()),
|
||||
player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ForgeEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onCrafted(PlayerEvent.ItemCraftedEvent ev) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
package minetweaker.mc1710;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Implements the /minetweaker command set.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerCommand implements ICommand {
|
||||
// ###########################
|
||||
// ## Public static methods ##
|
||||
// ###########################
|
||||
|
||||
public static void sendChatMessage(ICommandSender sender, String message) {
|
||||
sender.addChatMessage(new ChatComponentText(message));
|
||||
}
|
||||
|
||||
private static final List<String> aliases = Arrays.asList("mt");
|
||||
|
||||
// #######################################
|
||||
// ## ICommand interface implementation ##
|
||||
// #######################################
|
||||
|
||||
@Override
|
||||
public int compareTo(Object arg0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "minetweaker";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return StringUtil.join(new String[] {
|
||||
"",
|
||||
"minetweaker reload",
|
||||
" Reloads all scripts",
|
||||
"minetweaker names",
|
||||
" Outputs a list of all item names in the game to the minetweaker log",
|
||||
"minetweaker liquids",
|
||||
" Outputs a list of all liquid names in the game to the minetweaker log",
|
||||
"minetweaker inventory",
|
||||
" Lists all items in your inventory",
|
||||
"minetweaker hand",
|
||||
" Outputs the name of the item in your hand",
|
||||
"minetweaker oredict",
|
||||
" Outputs all ore dictionary entries in the game to the minetweaker log",
|
||||
"minetweaker oredict <name>",
|
||||
" Outputs all items in the given ore dictionary entry to the minetweaker log",
|
||||
"minetweaker mods",
|
||||
" Outputs all active mod IDs in the game",
|
||||
"minetweaker name <id>",
|
||||
" Outputs the name for the given item ID"
|
||||
}, "\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCommandAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] arguments) {
|
||||
if (arguments.length == 0) {
|
||||
sendChatMessage(icommandsender, "Please provide a command. Use /help minetweaker for more info.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (arguments[0].equals("reload")) {
|
||||
MineTweakerMod.INSTANCE.reload();
|
||||
|
||||
String message = "Scripts have been reloaded";
|
||||
sendChatMessage(icommandsender, message);
|
||||
} else if (arguments[0].equals("names")) {
|
||||
Set<String> keys = Item.itemRegistry.getKeys();
|
||||
String[] sortedKeys = new String[keys.size()];
|
||||
int sortedKeyIndex = 0;
|
||||
for (String key : keys) sortedKeys[sortedKeyIndex++] = key;
|
||||
Arrays.sort(sortedKeys);
|
||||
|
||||
for (String key : sortedKeys) {
|
||||
Item item = (Item) Item.itemRegistry.getObject(key);
|
||||
|
||||
String displayName = "";
|
||||
|
||||
try {
|
||||
displayName = " -- " + new ItemStack(item, 1, 0).getDisplayName();
|
||||
} catch (Exception ex) {
|
||||
// some mods (such as buildcraft) may throw exceptions when calling
|
||||
// getDisplayName on a item stack that doesn't contain valid NBT data
|
||||
}
|
||||
|
||||
String message = "<" + key + ">" + displayName;
|
||||
MineTweakerAPI.logger.logCommand(message);
|
||||
}
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
} else if (arguments[0].equals("liquids")) {
|
||||
for (Map.Entry<String, Fluid> entry : FluidRegistry.getRegisteredFluids().entrySet()) {
|
||||
String message = "<liquid:" + entry.getKey() + "> -- " + entry.getValue().getLocalizedName();
|
||||
MineTweakerAPI.logger.logCommand(message);
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
} else if (arguments[0].equals("inventory")) {
|
||||
if (icommandsender instanceof EntityPlayer) {
|
||||
InventoryPlayer inventory = ((EntityPlayer) icommandsender).inventory;
|
||||
for(int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack != null) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
if (stack.getItemDamage() > 0) {
|
||||
description.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
description.append('>');
|
||||
|
||||
if (stack.stackSize != 1) {
|
||||
description.append('*').append(stack.stackSize);
|
||||
}
|
||||
|
||||
sendChatMessage(icommandsender, new MCItemStack(stack).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Inventory command can only be executed by players");
|
||||
}
|
||||
} else if (arguments[0].equals("hand")) {
|
||||
if (icommandsender instanceof EntityPlayer) {
|
||||
InventoryPlayer inventory = ((EntityPlayer) icommandsender).inventory;
|
||||
ItemStack stack = inventory.getCurrentItem();
|
||||
if (stack != null) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
if (stack.getItemDamage() > 0) {
|
||||
description.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
description.append('>');
|
||||
|
||||
if (stack.stackSize != 1) {
|
||||
description.append('*').append(stack.stackSize);
|
||||
}
|
||||
|
||||
sendChatMessage(icommandsender, new MCItemStack(stack).toString());
|
||||
}
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Hand command can only be executed by players");
|
||||
}
|
||||
} else if (arguments[0].equals("oredict")) {
|
||||
if (arguments.length > 2) {
|
||||
String entryName = arguments[2];
|
||||
List<ItemStack> ores = OreDictionary.getOres(entryName);
|
||||
if (ores.isEmpty()) {
|
||||
sendChatMessage(icommandsender, "Entry doesn't exist");
|
||||
return;
|
||||
} else {
|
||||
MineTweakerAPI.logger.logCommand("Ore entries for " + entryName + ":");
|
||||
for (ItemStack ore : ores) {
|
||||
MineTweakerAPI.logger.logCommand(" " + new MCItemStack(ore).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String entryName : OreDictionary.getOreNames()) {
|
||||
MineTweakerAPI.logger.logCommand("Ore entries for " + entryName + ":");
|
||||
List<ItemStack> ores = OreDictionary.getOres(entryName);
|
||||
for (ItemStack ore : ores) {
|
||||
MineTweakerAPI.logger.logCommand(" " + new MCItemStack(ore).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
} else if (arguments[0].equals("mods")) {
|
||||
List<ModContainer> mods = Loader.instance().getActiveModList();
|
||||
MineTweakerAPI.logger.logCommand("Mods list:");
|
||||
for (ModContainer mod : mods) {
|
||||
sendChatMessage(icommandsender, mod.getModId());
|
||||
MineTweakerAPI.logger.logCommand("Mod: " + mod.getModId());
|
||||
}
|
||||
} else if (arguments[0].equals("name")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "missing id parameter");
|
||||
} else {
|
||||
try {
|
||||
int id = Integer.parseInt(arguments[1]);
|
||||
Item item = Item.getItemById(id);
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(Item.itemRegistry.getNameForObject(item));
|
||||
description.append('>');
|
||||
sendChatMessage(icommandsender, description.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
MineTweakerAPI.logger.logCommand("ID must be an integer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if (arguments[0].equals("name")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide an item id");
|
||||
} else {
|
||||
try {
|
||||
ITweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
sendChatMessage(icommandsender, "Name for " + item.toIdString() + ": " + MineTweakerUtil.formatItemName(item.getName()));
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, ex.getMessage());
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, ex.getExplanation());
|
||||
}
|
||||
}
|
||||
} else if (arguments[0].equals("liquid")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide a liquid container item id");
|
||||
} else {
|
||||
try {
|
||||
TweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
//#ifdef MC152
|
||||
//+if (LiquidContainerRegistry.isLiquid(item.make(1))) {
|
||||
//+sendChatMessage(icommandsender, "Liquid name: " + item.getName());
|
||||
//+} else if (LiquidContainerRegistry.isFilledContainer(item.make(1))) {
|
||||
//+sendChatMessage(icommandsender, "Liquid name: " + LiquidContainerRegistry.getLiquidForFilledItem(item.make(1)).asItemStack().getItemName());
|
||||
//+} else {
|
||||
//+sendChatMessage(icommandsender, "This item is not a liquid or liquid container");
|
||||
//+}
|
||||
//#else
|
||||
if (item.getItemId() == 9) {
|
||||
sendChatMessage(icommandsender, "Liquid name: fluid.tile.water");
|
||||
} else if (item.getItemId() == 11) {
|
||||
sendChatMessage(icommandsender, "Liquid name: fluid.tile.lava");
|
||||
} else if (Block.blocksList[item.getItemId()] != null && Block.blocksList[item.getItemId()] instanceof IFluidBlock) {
|
||||
sendChatMessage(icommandsender, "Liquid name: " + ((IFluidBlock)(Block.blocksList[item.getItemId()])).getFluid().getUnlocalizedName());
|
||||
} else if (FluidContainerRegistry.isFilledContainer(item.make(1))) {
|
||||
sendChatMessage(icommandsender, "Liquid name: " + FluidContainerRegistry.getFluidForFilledItem(item.make(1)).getFluid().getUnlocalizedName());
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "This item is not a liquid or liquid container");
|
||||
}
|
||||
//#endif
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, ex.getMessage());
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, ex.getExplanation());
|
||||
}
|
||||
}
|
||||
} else if (arguments[0].equals("oredict")) {
|
||||
if (arguments.length == 1) {
|
||||
String[] names = OreDictionary.getOreNames();
|
||||
Arrays.sort(names);
|
||||
for (String name : names) {
|
||||
sendChatMessage(icommandsender, "[" + name + "]");
|
||||
ArrayList<ItemStack> entries = OreDictionary.getOres(name);
|
||||
for (ItemStack stack : entries) {
|
||||
//#ifdef MC152
|
||||
//+sendChatMessage(icommandsender,
|
||||
//+" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
//+MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItemName()));
|
||||
//#else
|
||||
sendChatMessage(icommandsender,
|
||||
" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getUnlocalizedName()));
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (Character.isDigit(arguments[1].charAt(0))) {
|
||||
TweakerItemPattern item = TweakerItem.parse(arguments[1]).asItemPattern();
|
||||
for (String name : OreDictionary.getOreNames()) {
|
||||
for (ItemStack stack : OreDictionary.getOres(name)) {
|
||||
if (item.matches(stack)) {
|
||||
sendChatMessage(icommandsender, " " + name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (ItemStack stack : OreDictionary.getOres(arguments[1])) {
|
||||
//#ifdef MC152
|
||||
//+sendChatMessage(icommandsender,
|
||||
//+" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
//+MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItemName()));
|
||||
//#else
|
||||
sendChatMessage(icommandsender,
|
||||
" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getUnlocalizedName()));
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id or ore dictionary entry");
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id or ore dictionary entry");
|
||||
}
|
||||
}
|
||||
} else if (arguments[0].equals("recipes")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide an item id");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
sendChatMessage(icommandsender, "Recipes for item " + item.toIdString());
|
||||
|
||||
TweakerItemPattern pattern = item.asItemPattern();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
if (pattern.matches(recipe.getRecipeOutput())) {
|
||||
sendChatMessage(icommandsender, " " + MineTweakerUtil.getRecipeString(recipe));
|
||||
}
|
||||
}
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
}
|
||||
} else if (arguments[0].equals("fuel")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide an item id");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
ItemStack stack = item.make(1);
|
||||
int value = TileEntityFurnace.getItemBurnTime(stack);
|
||||
int regValue = GameRegistry.getFuelValue(stack);
|
||||
|
||||
sendChatMessage(icommandsender, "Fuel for " + item.toIdString() + " = " + value);
|
||||
if (value != regValue) {
|
||||
sendChatMessage(icommandsender, "The value is hardcoded and cannot be altered.");
|
||||
}
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
}
|
||||
} else if (arguments[0].equals("reload")) {
|
||||
if (!MineTweaker.instance.canRollback()) {
|
||||
sendChatMessage(icommandsender, "Previous server script contained permanent actions, cannot reload. A restart is required to reload scripts.");
|
||||
} else {
|
||||
MineTweaker.instance.reloadScripts();
|
||||
sendChatMessage(icommandsender, "Script reloaded, updating all players");
|
||||
}
|
||||
} else if (arguments[0].equals("logdamage=on")) {
|
||||
DamageTweaker.logDamage = true;
|
||||
sendChatMessage(icommandsender, "Damage logging turned on");
|
||||
sendChatMessage(icommandsender, "Info: logging is sent to the development console");
|
||||
} else if (arguments[0].equals("logdamage=off")) {
|
||||
DamageTweaker.logDamage = false;
|
||||
sendChatMessage(icommandsender, "Damage logging turned off");
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Unrecognized minetweaker command");
|
||||
}*/
|
||||
|
||||
//MineCraftCompat.sendChatMessage(icommandsender, "[" + Arrays2.join(arguments, ", ") + "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender icommandsender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> addTabCompletionOptions(ICommandSender icommandsender,
|
||||
String[] astring) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsernameIndex(String[] astring, int i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerLogger implements ILogger {
|
||||
private Writer writer;
|
||||
|
||||
public MineTweakerLogger() {
|
||||
File logFile = new File("minetweaker.log");
|
||||
if (logFile.exists()) logFile.delete();
|
||||
|
||||
try {
|
||||
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(logFile)));
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.append("COMMAND: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("COMMAND: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.append("INFO: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("INFO: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.append("WARNING: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("WARNING: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
try {
|
||||
writer.append("ERROR: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("ERROR: " + message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import java.io.File;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.furnace.FuelTweaker;
|
||||
import minetweaker.mc1710.furnace.MCFurnaceManager;
|
||||
import minetweaker.mc1710.mods.MCLoadedMods;
|
||||
import minetweaker.mc1710.network.MineTweakerLoadScriptsHandler;
|
||||
import minetweaker.mc1710.network.MineTweakerLoadScriptsPacket;
|
||||
import minetweaker.mc1710.oredict.MCOreDict;
|
||||
import minetweaker.mc1710.recipes.MCRecipeManager;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import minetweaker.runtime.IScriptProvider;
|
||||
import minetweaker.runtime.providers.ScriptProviderCascade;
|
||||
import minetweaker.runtime.providers.ScriptProviderDirectory;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
/**
|
||||
* Main mod class. Performs some general logic, initialization of the API and
|
||||
* FML event handling.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@Mod(modid = MineTweakerMod.MODID, version = MineTweakerMod.MCVERSION + "-3.0.0")
|
||||
public class MineTweakerMod {
|
||||
public static final String MODID = "MineTweaker";
|
||||
public static final String MCVERSION = "1.7.2";
|
||||
|
||||
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
|
||||
|
||||
private static final String[] REGISTRIES = {
|
||||
"minetweaker.mods.ic2.ClassRegistry",
|
||||
"minetweaker.mods.nei.ClassRegistry"
|
||||
};
|
||||
|
||||
static {
|
||||
NETWORK.registerMessage(MineTweakerLoadScriptsHandler.class, MineTweakerLoadScriptsPacket.class, 0, Side.CLIENT);
|
||||
}
|
||||
|
||||
@Mod.Instance(MODID)
|
||||
public static MineTweakerMod INSTANCE;
|
||||
|
||||
private final IScriptProvider scriptsGlobal;
|
||||
|
||||
private boolean iAmServer = false;
|
||||
|
||||
public MineTweakerMod() {
|
||||
MineTweakerAPI.oreDict = new MCOreDict();
|
||||
MineTweakerAPI.recipes = new MCRecipeManager();
|
||||
MineTweakerAPI.logger = new MineTweakerLogger();
|
||||
MineTweakerAPI.furnace = new MCFurnaceManager();
|
||||
MineTweakerAPI.loadedMods = new MCLoadedMods();
|
||||
|
||||
File globalDir = new File("scripts");
|
||||
if (!globalDir.exists()) {
|
||||
globalDir.mkdirs();
|
||||
}
|
||||
|
||||
scriptsGlobal = new ScriptProviderDirectory(globalDir);
|
||||
MineTweakerAPI.tweaker.setScriptProvider(scriptsGlobal);
|
||||
}
|
||||
|
||||
public boolean iAmServer() {
|
||||
return iAmServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all scripts.
|
||||
*/
|
||||
public void reload() {
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
MineTweakerAPI.tweaker.load();
|
||||
|
||||
if (iAmServer) {
|
||||
// execute script on all connected clients
|
||||
NETWORK.sendToAll(new MineTweakerLoadScriptsPacket(MineTweakerAPI.tweaker.getScriptData()));
|
||||
}
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### FML Event Handlers ###
|
||||
// ##########################
|
||||
|
||||
@EventHandler
|
||||
public void onLoad(FMLPreInitializationEvent ev) {
|
||||
MinecraftForge.EVENT_BUS.register(new FMLEventHandler());
|
||||
FMLCommonHandler.instance().bus().register(new FMLEventHandler());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPostInit(FMLPostInitializationEvent ev) {
|
||||
MineTweakerAPI.registerClassRegistry(MineTweakerRegistry.class);
|
||||
|
||||
for (String registry : REGISTRIES) {
|
||||
MineTweakerAPI.registerClassRegistry(registry);
|
||||
}
|
||||
|
||||
FuelTweaker.INSTANCE.register();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent ev) {
|
||||
// starts before loading worlds
|
||||
// perfect place to start MineTweaker!
|
||||
|
||||
File scriptsDir = new File(MineTweakerHacks.getWorldDirectory(ev.getServer()), "scripts");
|
||||
if (!scriptsDir.exists()) {
|
||||
scriptsDir.mkdir();
|
||||
}
|
||||
|
||||
iAmServer = true;
|
||||
|
||||
IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir);
|
||||
IScriptProvider cascaded = new ScriptProviderCascade(scriptsGlobal, scriptsLocal);
|
||||
MineTweakerAPI.tweaker.setScriptProvider(cascaded);
|
||||
reload();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent ev) {
|
||||
ev.registerServerCommand(new MineTweakerCommand());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerStopped(FMLServerStoppedEvent ev) {
|
||||
iAmServer = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerRegistry {
|
||||
public static void getClasses(List<Class> classes) {
|
||||
// method stub, actual content is generated by build process
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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.brackets;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IngredientAny;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.expression.ExpressionInt;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler(priority=100)
|
||||
public class ItemBracketHandler implements IBracketHandler {
|
||||
public static IItemStack getItem(String name, int meta) {
|
||||
Item item = (Item) Item.itemRegistry.getObject(name);
|
||||
if (item != null) {
|
||||
return new MCItemStack(new ItemStack(item, 1, meta), true);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final IZenSymbol symbolAny;
|
||||
private final JavaMethod method;
|
||||
|
||||
public ItemBracketHandler() {
|
||||
symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
|
||||
method = MineTweakerAPI.getJavaMethod(
|
||||
ItemBracketHandler.class,
|
||||
"getItem",
|
||||
String.class, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
// any symbol
|
||||
if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
|
||||
return symbolAny;
|
||||
}
|
||||
|
||||
// detect special cases:
|
||||
// item: at the start means item-specific syntax
|
||||
// :xxx with xxx an integer means sub-item syntax
|
||||
// :* means any-subitem-syntax
|
||||
int fromIndex = 0;
|
||||
int toIndex = tokens.size();
|
||||
int meta = 0;
|
||||
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("item") && tokens.get(1).getValue().equals(":")) {
|
||||
fromIndex = 2;
|
||||
}
|
||||
if (tokens.get(tokens.size() - 1).getType() == ZenTokener.T_INTVALUE
|
||||
&& tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
||||
toIndex = tokens.size() - 2;
|
||||
meta = Integer.parseInt(tokens.get(tokens.size() - 1).getValue());
|
||||
} else if (tokens.get(tokens.size() - 1).getValue().equals("*")
|
||||
&& tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
||||
toIndex = tokens.size() - 2;
|
||||
meta = OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return find(tokens, fromIndex, toIndex, meta);
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex, int meta) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
Item item = (Item) Item.itemRegistry.getObject(valueBuilder.toString());
|
||||
if (item != null) {
|
||||
return new ItemReferenceSymbol(valueBuilder.toString(), meta);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class ItemReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
private final int meta;
|
||||
|
||||
public ItemReferenceSymbol(String name, int meta) {
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name),
|
||||
new ExpressionInt(position, meta, ZenType.INT));
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package minetweaker.mc1710.brackets;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc1710.liquid.MCLiquidStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler
|
||||
public class LiquidBracketHandler implements IBracketHandler {
|
||||
public static ILiquidStack getLiquid(String name) {
|
||||
Fluid fluid = FluidRegistry.getFluid(name);
|
||||
if (fluid != null) {
|
||||
return new MCLiquidStack(new FluidStack(fluid, 1));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) {
|
||||
return find(tokens, 2, tokens.size());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
Fluid fluid = FluidRegistry.getFluid(valueBuilder.toString());
|
||||
if (fluid != null) {
|
||||
return new LiquidReferenceSymbol(valueBuilder.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class LiquidReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
|
||||
public LiquidReferenceSymbol(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
JavaMethod method = JavaMethod.get(
|
||||
GlobalRegistry.getTypeRegistry(),
|
||||
LiquidBracketHandler.class,
|
||||
"getLiquid",
|
||||
String.class);
|
||||
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.brackets;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc1710.oredict.MCOreDictEntry;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler
|
||||
public class OreBracketHandler implements IBracketHandler {
|
||||
public static IOreDictEntry getOre(String name) {
|
||||
return new MCOreDictEntry(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")) {
|
||||
return find(tokens, 2, tokens.size());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
return new OreReferenceSymbol(valueBuilder.toString());
|
||||
}
|
||||
|
||||
private class OreReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
|
||||
public OreReferenceSymbol(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
JavaMethod method = JavaMethod.get(
|
||||
GlobalRegistry.getTypeRegistry(),
|
||||
OreBracketHandler.class,
|
||||
"getOre",
|
||||
String.class);
|
||||
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import minetweaker.api.data.DataByte;
|
||||
import minetweaker.api.data.DataByteArray;
|
||||
import minetweaker.api.data.DataDouble;
|
||||
import minetweaker.api.data.DataFloat;
|
||||
import minetweaker.api.data.DataInt;
|
||||
import minetweaker.api.data.DataIntArray;
|
||||
import minetweaker.api.data.DataList;
|
||||
import minetweaker.api.data.DataLong;
|
||||
import minetweaker.api.data.DataMap;
|
||||
import minetweaker.api.data.DataShort;
|
||||
import minetweaker.api.data.DataString;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.data.IDataConverter;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTTagByteArray;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagFloat;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagLong;
|
||||
import net.minecraft.nbt.NBTTagShort;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class NBTConverter implements IDataConverter<NBTBase> {
|
||||
private static final NBTConverter INSTANCE = new NBTConverter();
|
||||
|
||||
public static NBTBase from(IData data) {
|
||||
return data.convert(INSTANCE);
|
||||
}
|
||||
|
||||
public static IData from(NBTBase nbt, boolean immutable) {
|
||||
if (nbt == null) return null;
|
||||
|
||||
switch (nbt.getId()) {
|
||||
case 1: // byte
|
||||
return new DataByte(((NBTBase.NBTPrimitive) nbt).func_150290_f());
|
||||
case 2: // short
|
||||
return new DataShort(((NBTBase.NBTPrimitive) nbt).func_150289_e());
|
||||
case 3: // int
|
||||
return new DataInt(((NBTBase.NBTPrimitive) nbt).func_150287_d());
|
||||
case 4: // long
|
||||
return new DataLong(((NBTBase.NBTPrimitive) nbt).func_150291_c());
|
||||
case 5: // float
|
||||
return new DataFloat(((NBTBase.NBTPrimitive) nbt).func_150288_h());
|
||||
case 6: // double
|
||||
return new DataDouble(((NBTBase.NBTPrimitive) nbt).func_150286_g());
|
||||
case 7: // byte[]
|
||||
return new DataByteArray(((NBTTagByteArray) nbt).func_150292_c(), immutable);
|
||||
case 8: // string
|
||||
return new DataString(((NBTTagString) nbt).func_150285_a_());
|
||||
case 9: { // list
|
||||
List<IData> values = new ArrayList<IData>();
|
||||
List<NBTBase> original = MineTweakerHacks.getTagList((NBTTagList) nbt);
|
||||
for (NBTBase value : original) {
|
||||
values.add(from(value, immutable));
|
||||
}
|
||||
return new DataList(values, immutable);
|
||||
}
|
||||
case 10: { // compound
|
||||
Map<String, IData> values = new HashMap<String, IData>();
|
||||
NBTTagCompound original = (NBTTagCompound) nbt;
|
||||
for (String key : (Set<String>)original.func_150296_c()) {
|
||||
values.put(key, from(original.getTag(key), immutable));
|
||||
}
|
||||
return new DataMap(values, immutable);
|
||||
}
|
||||
case 11: // int[]
|
||||
return new DataIntArray(((NBTTagIntArray) nbt).func_150302_c(), immutable);
|
||||
default:
|
||||
throw new RuntimeException("Unknown tag type: " + nbt.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateMap(NBTTagCompound nbt, IData data) {
|
||||
NBTUpdater updater = new NBTUpdater(nbt);
|
||||
data.convert(updater);
|
||||
}
|
||||
|
||||
public NBTConverter() {}
|
||||
|
||||
@Override
|
||||
public NBTBase fromBool(boolean value) {
|
||||
return new NBTTagInt(value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromByte(byte value) {
|
||||
return new NBTTagByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromShort(short value) {
|
||||
return new NBTTagShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromInt(int value) {
|
||||
return new NBTTagInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromLong(long value) {
|
||||
return new NBTTagLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromFloat(float value) {
|
||||
return new NBTTagFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromDouble(double value) {
|
||||
return new NBTTagDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromString(String value) {
|
||||
return new NBTTagString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromList(List<IData> values) {
|
||||
NBTTagList result = new NBTTagList();
|
||||
for (IData value : values) {
|
||||
result.appendTag(from(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromMap(Map<String, IData> values) {
|
||||
NBTTagCompound result = new NBTTagCompound();
|
||||
for (Map.Entry<String, IData> entry : values.entrySet()) {
|
||||
result.setTag(entry.getKey(), from(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromByteArray(byte[] value) {
|
||||
return new NBTTagByteArray(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromIntArray(int[] value) {
|
||||
return new NBTTagIntArray(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.data;
|
||||
|
||||
import java.util.Map;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.data.IDataConverter;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class NBTUpdater extends NBTConverter implements IDataConverter<NBTBase> {
|
||||
private final NBTTagCompound nbt;
|
||||
|
||||
public NBTUpdater(NBTTagCompound compound) {
|
||||
this.nbt = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromMap(Map<String, IData> map) {
|
||||
for (Map.Entry<String, IData> entry : map.entrySet()) {
|
||||
if (nbt.hasKey(entry.getKey())) {
|
||||
if (entry.getValue() == null) {
|
||||
nbt.removeTag(entry.getKey());
|
||||
} else {
|
||||
if (nbt.getTag(entry.getKey()).getId() == 10) {
|
||||
NBTTagCompound tag = (NBTTagCompound) nbt.getTag(entry.getKey());
|
||||
nbt.setTag(entry.getKey(), entry.getValue().convert(new NBTUpdater(nbt)));
|
||||
} else {
|
||||
nbt.setTag(entry.getKey(), NBTConverter.from(entry.getValue()));
|
||||
}
|
||||
}
|
||||
} else if (entry.getValue() != null) {
|
||||
nbt.setTag(entry.getKey(), from(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.furnace;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import cpw.mods.fml.common.IFuelHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
|
||||
public class FuelTweaker {
|
||||
public static final FuelTweaker INSTANCE = new FuelTweaker();
|
||||
|
||||
private List<IFuelHandler> original;
|
||||
private final HashMap<String, List<SetFuelPattern>> quickList = new HashMap<String, List<SetFuelPattern>>();
|
||||
|
||||
private FuelTweaker() {}
|
||||
|
||||
public void register() {
|
||||
try {
|
||||
Field fuelHandlers = GameRegistry.class.getDeclaredField("fuelHandlers");
|
||||
fuelHandlers.setAccessible(true);
|
||||
original = (List<IFuelHandler>) fuelHandlers.get(null);
|
||||
List<IFuelHandler> modified = new ArrayList<IFuelHandler>();
|
||||
modified.add(new OverridingFuelHandler());
|
||||
fuelHandlers.set(null, modified);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not get GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
} catch (SecurityException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
} catch (IllegalAccessException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
}
|
||||
}
|
||||
|
||||
public void addFuelPattern(SetFuelPattern pattern) {
|
||||
List<IItemStack> items = pattern.getPattern().getItems();
|
||||
if (items == null) {
|
||||
MineTweakerAPI.logger.logError("Cannot set fuel for <*>");
|
||||
return;
|
||||
}
|
||||
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
if (!quickList.containsKey(item.getName())) {
|
||||
quickList.put(item.getName(), new ArrayList<SetFuelPattern>());
|
||||
}
|
||||
quickList.get(item.getName()).add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFuelPattern(SetFuelPattern pattern) {
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
if (!quickList.containsKey(item.getName())) {
|
||||
quickList.put(item.getName(), new ArrayList<SetFuelPattern>());
|
||||
}
|
||||
quickList.get(item.getName()).add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
private class OverridingFuelHandler implements IFuelHandler {
|
||||
@Override
|
||||
public int getBurnTime(ItemStack fuel) {
|
||||
IItemStack stack = new MCItemStack(fuel);
|
||||
String name = fuel.getUnlocalizedName();
|
||||
if (quickList.containsKey(name)) {
|
||||
for (SetFuelPattern override : quickList.get(name)) {
|
||||
if (override.getPattern().matches(stack)) {
|
||||
return override.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
for (IFuelHandler handler : original) {
|
||||
max = Math.max(max, handler.getBurnTime(fuel));
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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.furnace;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.util.MineTweakerUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCFurnaceManager implements IFurnaceManager {
|
||||
public MCFurnaceManager() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(IIngredient output, IIngredient input) {
|
||||
if (output == null) throw new IllegalArgumentException("output cannot be null");
|
||||
|
||||
Map<ItemStack, ItemStack> smeltingList = FurnaceRecipes.smelting().getSmeltingList();
|
||||
|
||||
List<ItemStack> toRemove = new ArrayList<ItemStack>();
|
||||
List<ItemStack> toRemoveValues = new ArrayList<ItemStack>();
|
||||
for (Map.Entry<ItemStack, ItemStack> entry : smeltingList.entrySet()) {
|
||||
if (output.matches(new MCItemStack(entry.getValue()))
|
||||
&& (input == null || input.matches(new MCItemStack(entry.getKey())))) {
|
||||
toRemove.add(entry.getKey());
|
||||
toRemoveValues.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove.isEmpty()) {
|
||||
MineTweakerAPI.logger.logWarning("No furnace recipes for " + output.toString());
|
||||
} else {
|
||||
MineTweakerAPI.tweaker.apply(new RemoveAction(toRemove, toRemoveValues));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(IItemStack output, IIngredient input, double xp) {
|
||||
List<IItemStack> items = input.getItems();
|
||||
if (items == null) {
|
||||
MineTweakerAPI.logger.logError("Cannot turn " + input.toString() + " into a furnace recipe");
|
||||
}
|
||||
|
||||
ItemStack[] items2 = MineTweakerUtil.getItemStacks(items);
|
||||
ItemStack output2 = (ItemStack) output.getInternal();
|
||||
MineTweakerAPI.tweaker.apply(new AddRecipeAction(input, items2, output2, xp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuel(IIngredient item, int fuel) {
|
||||
MineTweakerAPI.tweaker.apply(new SetFuelAction(new SetFuelPattern(item, fuel)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFuel(IItemStack item) {
|
||||
return GameRegistry.getFuelValue((ItemStack) item.getInternal());
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class RemoveAction implements IUndoableAction {
|
||||
private final List<ItemStack> items;
|
||||
private final List<ItemStack> values;
|
||||
|
||||
public RemoveAction(List<ItemStack> items, List<ItemStack> values) {
|
||||
this.items = items;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (ItemStack item : items) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().put(items.get(i), values.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + items.size() + " furnace recipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + items.size() + " furnace recipes";
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final IIngredient ingredient;
|
||||
private final ItemStack[] input;
|
||||
private final ItemStack output;
|
||||
private final double xp;
|
||||
|
||||
public AddRecipeAction(IIngredient ingredient, ItemStack[] input, ItemStack output, double xp) {
|
||||
this.ingredient = ingredient;
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (ItemStack inputStack : input) {
|
||||
FurnaceRecipes.smelting().func_151394_a(inputStack, output, (float) xp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (ItemStack inputStack : input) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().remove(inputStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding furnace recipe for " + ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing furnace recipe for " + ingredient;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SetFuelAction implements IUndoableAction {
|
||||
private final SetFuelPattern pattern;
|
||||
|
||||
public SetFuelAction(SetFuelPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
FuelTweaker.INSTANCE.addFuelPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
FuelTweaker.INSTANCE.removeFuelPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting fuel for " + pattern.getPattern();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing fuel for " + pattern.getPattern();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.mc1710.furnace;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
public class SetFuelPattern {
|
||||
private final IIngredient pattern;
|
||||
private final int value;
|
||||
|
||||
public SetFuelPattern(IIngredient pattern, int value) {
|
||||
this.pattern = pattern;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public IIngredient getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -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.mc1710.item;
|
||||
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCItemDefinition implements IItemDefinition {
|
||||
private final Item item;
|
||||
|
||||
public MCItemDefinition(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* 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.item;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.mc1710.liquid.MCLiquidStack;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemCondition;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientItem;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCItemStack implements IItemStack {
|
||||
private final ItemStack stack;
|
||||
private final List<IItemStack> items;
|
||||
private IData tag = null;
|
||||
private boolean wildcardSize;
|
||||
|
||||
public MCItemStack(ItemStack itemStack) {
|
||||
if (itemStack == null) throw new IllegalArgumentException("stack cannot be null");
|
||||
|
||||
stack = itemStack.copy();
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
}
|
||||
|
||||
public MCItemStack(ItemStack itemStack, boolean wildcardSize) {
|
||||
this(itemStack);
|
||||
|
||||
this.wildcardSize = wildcardSize;
|
||||
}
|
||||
|
||||
private MCItemStack(ItemStack itemStack, IData tag) {
|
||||
if (itemStack == null) throw new IllegalArgumentException("stack cannot be null");
|
||||
|
||||
stack = itemStack;
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDefinition getDefinition() {
|
||||
return new MCItemDefinition(stack.getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return stack.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
return stack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getTag() {
|
||||
if (tag == null) {
|
||||
if (stack.stackTagCompound == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tag = NBTConverter.from(stack.stackTagCompound, true);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage() {
|
||||
return stack.getMaxDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack getLiquid() {
|
||||
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
return liquid == null ? null : new MCLiquidStack(liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient anyDamage() {
|
||||
if (stack.getItem().getHasSubtypes()) {
|
||||
MineTweakerAPI.logger.logWarning("subitems don't have damaged states");
|
||||
return this;
|
||||
} else {
|
||||
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, OreDictionary.WILDCARD_VALUE);
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withDamage(int damage) {
|
||||
if (stack.getItem().getHasSubtypes()) {
|
||||
MineTweakerAPI.logger.logWarning("subitems don't have damaged states");
|
||||
return this;
|
||||
} else {
|
||||
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, damage);
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withAmount(int amount) {
|
||||
ItemStack result = new ItemStack(stack.getItem(), amount, stack.getItemDamage());
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withTag(IData tag) {
|
||||
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, stack.getItemDamage());
|
||||
if (tag == null) {
|
||||
result.stackTagCompound = null;
|
||||
} else {
|
||||
result.stackTagCompound = (NBTTagCompound) NBTConverter.from(tag);
|
||||
}
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack updateTag(IData tagUpdate) {
|
||||
if (tag == null) {
|
||||
if (stack.stackTagCompound == null) {
|
||||
return withTag(tagUpdate);
|
||||
}
|
||||
|
||||
tag = NBTConverter.from(stack.stackTagCompound, true);
|
||||
}
|
||||
|
||||
IData updated = tag.update(tagUpdate);
|
||||
return withTag(updated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return stack.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack amount(int amount) {
|
||||
return withAmount(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientItem(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[] { transformer });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientItem(this, null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientItem(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
ItemStack internal = (ItemStack) item.getInternal();
|
||||
if (internal == null) {
|
||||
throw new RuntimeException("Invalid item: " + item);
|
||||
}
|
||||
|
||||
return internal.getItem() == stack.getItem()
|
||||
&& (wildcardSize || internal.stackSize == stack.stackSize)
|
||||
&& (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE
|
||||
|| stack.getItemDamage() == internal.getItemDamage()
|
||||
|| (!stack.getHasSubtypes() && !stack.getItem().isDamageable()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
if (iitems == null || iitems.size() != 1) return false;
|
||||
return matches(iitems.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('<');
|
||||
result.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
|
||||
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
result.append(":*");
|
||||
} else if (stack.getItemDamage() > 0) {
|
||||
result.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
result.append('>');
|
||||
|
||||
if (stack.getTagCompound() != null) {
|
||||
result.append(".withTag(");
|
||||
result.append(NBTConverter.from(stack.getTagCompound(), wildcardSize).toString());
|
||||
result.append(")");
|
||||
}
|
||||
|
||||
if (!wildcardSize) {
|
||||
result.append(" * ").append(stack.stackSize);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* 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.liquid;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCLiquidDefinition implements ILiquidDefinition {
|
||||
private final Fluid fluid;
|
||||
|
||||
public MCLiquidDefinition(Fluid fluid) {
|
||||
this.fluid = fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return fluid.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return fluid.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack asStack(int millibuckets) {
|
||||
return new MCLiquidStack(new FluidStack(fluid, millibuckets));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLuminosity() {
|
||||
return fluid.getLuminosity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLuminosity(int value) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetLuminosity(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDensity() {
|
||||
return fluid.getDensity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDensity(int density) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetDensity(density));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTemperature() {
|
||||
return fluid.getTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(int temperature) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetTemperature(temperature));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViscosity() {
|
||||
return fluid.getViscosity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setViscosity(int viscosity) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetViscosity(viscosity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGaseous() {
|
||||
return fluid.isGaseous();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGaseous(boolean gaseous) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetGaseous(gaseous));
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private class ActionSetLuminosity implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetLuminosity(int newValue) {
|
||||
oldValue = getLuminosity();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setLuminosity(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setLuminosity(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " luminosity to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " luminosity to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetDensity implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetDensity(int newValue) {
|
||||
oldValue = getDensity();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setDensity(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setDensity(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " density to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " density to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetTemperature implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetTemperature(int newValue) {
|
||||
oldValue = getTemperature();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setTemperature(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setTemperature(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " temperature to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " temperature to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetViscosity implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetViscosity(int newValue) {
|
||||
oldValue = getViscosity();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setViscosity(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setViscosity(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " viscosity to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " viscosity to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetGaseous implements IUndoableAction {
|
||||
private final boolean oldValue;
|
||||
private final boolean newValue;
|
||||
|
||||
public ActionSetGaseous(boolean newValue) {
|
||||
oldValue = isGaseous();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setGaseous(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setGaseous(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " gaseous to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " gaseous to " + oldValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.liquid;
|
||||
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCLiquidStack implements ILiquidStack {
|
||||
private final FluidStack stack;
|
||||
private IData tag = null;
|
||||
|
||||
public MCLiquidStack(FluidStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
private MCLiquidStack(FluidStack stack, IData tag) {
|
||||
this.stack = stack;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidDefinition getDefinition() {
|
||||
return new MCLiquidDefinition(stack.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return stack.getFluid().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return stack.getFluid().getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return stack.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getTag() {
|
||||
if (tag == null) {
|
||||
if (stack.tag == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tag = NBTConverter.from(stack.tag, true);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack withTag(IData data) {
|
||||
FluidStack result = new FluidStack(stack.fluidID, stack.amount);
|
||||
result.tag = (NBTTagCompound) NBTConverter.from(data);
|
||||
return new MCLiquidStack(result, data.immutable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack withAmount(int amount) {
|
||||
FluidStack result = new FluidStack(stack.fluidID, amount);
|
||||
result.tag = stack.tag;
|
||||
return new MCLiquidStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLuminosity() {
|
||||
return stack.getFluid().getLuminosity(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDensity() {
|
||||
return stack.getFluid().getDensity(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTemperature() {
|
||||
return stack.getFluid().getTemperature(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViscosity() {
|
||||
return stack.getFluid().getViscosity(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGaseous() {
|
||||
return stack.getFluid().isGaseous(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package minetweaker.mc1710.mods;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import minetweaker.api.mods.ILoadedMods;
|
||||
import minetweaker.api.mods.IMod;
|
||||
import stanhebben.zenscript.util.MappingIterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCLoadedMods implements ILoadedMods {
|
||||
public MCLoadedMods() {}
|
||||
|
||||
@Override
|
||||
public boolean contains(String name) {
|
||||
return Loader.isModLoaded(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMod get(String name) {
|
||||
for (ModContainer mod : Loader.instance().getActiveModList()) {
|
||||
if (mod.getModId().equals(name)) {
|
||||
return new MCMod(mod);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IMod> iterator() {
|
||||
List<ModContainer> mods = Loader.instance().getActiveModList();
|
||||
return new MappingIterator<ModContainer, IMod>(mods.iterator()) {
|
||||
@Override
|
||||
public IMod map(ModContainer value) {
|
||||
return new MCMod(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.mods;
|
||||
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import minetweaker.api.mods.IMod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCMod implements IMod {
|
||||
private final ModContainer mod;
|
||||
|
||||
public MCMod(ModContainer mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return mod.getModId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mod.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return mod.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return mod.getMetadata().description;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.network;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.MineTweakerMod;
|
||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerLoadScriptsHandler implements IMessageHandler<MineTweakerLoadScriptsPacket, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(MineTweakerLoadScriptsPacket message, MessageContext ctx) {
|
||||
if (!MineTweakerMod.INSTANCE.iAmServer()) {
|
||||
/*IScriptProvider scriptProvider = new ScriptProviderMemory(message.getData());
|
||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator myGroup = scripts.next();
|
||||
System.out.println("Scripts: " + myGroup.getGroupName());
|
||||
|
||||
while (myGroup.next()) {
|
||||
System.out.println("Script name: " + myGroup.getName());
|
||||
}
|
||||
}*/
|
||||
MineTweakerAPI.tweaker.setScriptProvider(new ScriptProviderMemory(message.getData()));
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
MineTweakerAPI.tweaker.load();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.network;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerLoadScriptsPacket implements IMessage {
|
||||
private byte[] data;
|
||||
|
||||
public MineTweakerLoadScriptsPacket() {
|
||||
// used for deserialization
|
||||
}
|
||||
|
||||
public MineTweakerLoadScriptsPacket(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int size = buf.readInt();
|
||||
data = new byte[size];
|
||||
buf.readBytes(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(data.length);
|
||||
buf.writeBytes(data);
|
||||
}
|
||||
}
|
||||
@@ -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.mc1710.oredict;
|
||||
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCOreDict implements IOreDict {
|
||||
@Override
|
||||
public IOreDictEntry get(String name) {
|
||||
return new MCOreDictEntry(OreDictionary.getOreID(name));
|
||||
}
|
||||
}
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
* 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.oredict;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemCondition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.oredict.IngredientOreDict;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCOreDictEntry implements IOreDictEntry {
|
||||
private static final List<ArrayList<ItemStack>> OREDICT_CONTENTS = MineTweakerHacks.getOreIdStacks();
|
||||
private static final List<ArrayList<ItemStack>> OREDICT_CONTENTS_UN = MineTweakerHacks.getOreIdStacksUn();
|
||||
|
||||
private final Integer id;
|
||||
|
||||
public MCOreDictEntry(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public MCOreDictEntry(String id) {
|
||||
this.id = OreDictionary.getOreID(id);
|
||||
}
|
||||
|
||||
// ####################################
|
||||
// ### IOreDictEntry implementation ###
|
||||
// ####################################
|
||||
|
||||
@Override
|
||||
public void add(IItemStack item) {
|
||||
ItemStack stack = (ItemStack) item.getInternal();
|
||||
if (stack == null) {
|
||||
MineTweakerAPI.logger.logError("not a valid item");
|
||||
} else {
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddItem(id, stack));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(IOreDictEntry entry) {
|
||||
if (entry instanceof MCOreDictEntry) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddAll(id, ((MCOreDictEntry) entry).id));
|
||||
} else {
|
||||
MineTweakerAPI.logger.logError("not a valid entry");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(IItemStack item) {
|
||||
ItemStack result = null;
|
||||
for (ItemStack itemStack : OreDictionary.getOres(id)) {
|
||||
if (item.matches(new MCItemStack(itemStack))) {
|
||||
result = itemStack;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveItem(id, result));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IItemStack item) {
|
||||
for (ItemStack itemStack : OreDictionary.getOres(id)) {
|
||||
if (item.matches(new MCItemStack(itemStack))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IOreDictEntry other) {
|
||||
if (other instanceof MCOreDictEntry) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionMirror(id, ((MCOreDictEntry) other).id));
|
||||
} else {
|
||||
MineTweakerAPI.logger.logError("not a valid oredict entry");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<IItemStack>();
|
||||
for (ItemStack item : OreDictionary.getOres(id)) {
|
||||
result.add(new MCItemStack(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOreDict(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[] { transformer });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOreDict(this, null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOreDict(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return contains(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
for (IItemStack item : items) {
|
||||
if (!matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return OreDictionary.getOreName(id);
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class ActionAddItem implements IUndoableAction {
|
||||
private final Integer id;
|
||||
private final ItemStack item;
|
||||
|
||||
public ActionAddItem(Integer id, ItemStack item) {
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
OreDictionary.registerOre(id, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
OREDICT_CONTENTS.get(id).remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding " + item.getDisplayName() + " to ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ActionMirror implements IUndoableAction {
|
||||
private final Integer idTarget;
|
||||
private final Integer idSource;
|
||||
|
||||
private final ArrayList<ItemStack> targetCopy;
|
||||
private final ArrayList<ItemStack> targetCopyUn;
|
||||
|
||||
public ActionMirror(Integer idTarget, Integer idSource) {
|
||||
this.idTarget = idTarget;
|
||||
this.idSource = idSource;
|
||||
|
||||
targetCopy = OREDICT_CONTENTS.get(idTarget);
|
||||
targetCopyUn = OREDICT_CONTENTS_UN.get(idTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
OREDICT_CONTENTS.set(idTarget, OREDICT_CONTENTS.get(idSource));
|
||||
OREDICT_CONTENTS_UN.set(idTarget, OREDICT_CONTENTS_UN.get(idSource));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
OREDICT_CONTENTS.set(idTarget, targetCopy);
|
||||
OREDICT_CONTENTS_UN.set(idTarget, targetCopyUn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Mirroring " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Undoing mirror of " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ActionRemoveItem implements IUndoableAction {
|
||||
private final Integer id;
|
||||
private final ItemStack item;
|
||||
|
||||
public ActionRemoveItem(Integer id, ItemStack item) {
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
OREDICT_CONTENTS.get(id).remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
OREDICT_CONTENTS.get(id).add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + item.getDisplayName() + " to ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ActionAddAll implements IUndoableAction {
|
||||
private final Integer idTarget;
|
||||
private final Integer idSource;
|
||||
|
||||
public ActionAddAll(Integer idTarget, Integer idSource) {
|
||||
this.idTarget = idTarget;
|
||||
this.idSource = idSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
List<ItemStack> ores = OreDictionary.getOres(idTarget);
|
||||
for (ItemStack stack : OreDictionary.getOres(idSource)) {
|
||||
ores.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
List<ItemStack> ores = OreDictionary.getOres(idTarget);
|
||||
for (ItemStack stack : OreDictionary.getOres(idSource)) {
|
||||
ores.remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Copying contents of ore dictionary entry " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing contents of ore dictionary entry " + OreDictionary.getOreName(idSource) + " from " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.player;
|
||||
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCPlayer implements IPlayer {
|
||||
private final EntityPlayer player;
|
||||
|
||||
public MCPlayer(EntityPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return player.getCommandSenderName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getData() {
|
||||
return NBTConverter.from(player.getEntityData(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IData data) {
|
||||
NBTConverter.updateMap(player.getEntityData(), data);
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.ICraftingInventory;
|
||||
import minetweaker.mc1710.player.MCPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCCraftingInventory implements ICraftingInventory {
|
||||
private static final ThreadLocal<MCCraftingInventory> cache = new ThreadLocal<MCCraftingInventory>();
|
||||
|
||||
public static MCCraftingInventory get(InventoryCrafting inventory) {
|
||||
if (cache.get() == null || cache.get().inventory != inventory) {
|
||||
MCCraftingInventory result = new MCCraftingInventory(inventory);
|
||||
cache.set(result);
|
||||
return result;
|
||||
} else {
|
||||
MCCraftingInventory result = cache.get();
|
||||
result.update();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private final InventoryCrafting inventory;
|
||||
private IItemStack[] stacks;
|
||||
private ItemStack[] original;
|
||||
private int stackCount;
|
||||
private MCPlayer player;
|
||||
|
||||
private MCCraftingInventory(InventoryCrafting inventory) {
|
||||
this.inventory = inventory;
|
||||
width = height = (int) Math.sqrt(inventory.getSizeInventory());
|
||||
stacks = new IItemStack[width * height];
|
||||
original = new ItemStack[stacks.length];
|
||||
stackCount = 0;
|
||||
update();
|
||||
|
||||
Container container = MineTweakerHacks.getCraftingContainer(inventory);
|
||||
List<Slot> slots = container.inventorySlots;
|
||||
if (!slots.isEmpty() && slots.get(0) instanceof SlotCrafting) {
|
||||
SlotCrafting slotCrafting = (SlotCrafting) slots.get(0);
|
||||
EntityPlayer playerEntity = MineTweakerHacks.getCraftingSlotPlayer(slotCrafting);
|
||||
player = new MCPlayer(playerEntity);
|
||||
} else {
|
||||
player = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (inventory.getSizeInventory() != original.length) {
|
||||
width = height = (int) Math.sqrt(inventory.getSizeInventory());
|
||||
stacks = new IItemStack[inventory.getSizeInventory()];
|
||||
original = new ItemStack[stacks.length];
|
||||
stackCount = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (changed(i)) {
|
||||
//System.out.println("Slot " + i + " changed");
|
||||
original[i] = inventory.getStackInSlot(i);
|
||||
if (inventory.getStackInSlot(i) != null) {
|
||||
if (stacks[i] == null) stackCount++;
|
||||
stacks[i] = new MCItemStack(original[i]);
|
||||
} else {
|
||||
if (stacks[i] != null) stackCount--;
|
||||
stacks[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.out.println("Num stack count: " + stackCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackCount() {
|
||||
return stackCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getStack(int i) {
|
||||
return stacks[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getStack(int x, int y) {
|
||||
return stacks[y * width + x];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int x, int y, IItemStack stack) {
|
||||
//System.out.println("SetStack(" + x + ", " + y + ") " + stack);
|
||||
|
||||
int ix = y * width + x;
|
||||
if (stack != stacks[ix]) {
|
||||
if (stack == null) {
|
||||
stackCount--;
|
||||
inventory.setInventorySlotContents(ix, null);
|
||||
} else {
|
||||
inventory.setInventorySlotContents(ix, (ItemStack) stack.getInternal());
|
||||
|
||||
if (stacks[ix] == null) {
|
||||
stackCount++;
|
||||
}
|
||||
}
|
||||
stacks[ix] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int i, IItemStack stack) {
|
||||
//System.out.println("SetStack(" + i + ") " + stack);
|
||||
|
||||
if (stack != stacks[i]) {
|
||||
if (stack == null) {
|
||||
stackCount--;
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
} else {
|
||||
inventory.setInventorySlotContents(i, (ItemStack) stack.getInternal());
|
||||
|
||||
if (stacks[i] == null) {
|
||||
stackCount++;
|
||||
}
|
||||
}
|
||||
stacks[i] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean changed(int i) {
|
||||
if (original[i] != inventory.getStackInSlot(i)) return true;
|
||||
if (original[i] != null && stacks[i].getAmount() != original[i].stackSize) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+358
@@ -0,0 +1,358 @@
|
||||
package minetweaker.mc1710.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.oredict.MCOreDictEntry;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.IRecipeFunction;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCRecipeManager implements IRecipeManager {
|
||||
private final List<IRecipe> recipes;
|
||||
|
||||
public MCRecipeManager() {
|
||||
recipes = (List<IRecipe>) CraftingManager.getInstance().getRecipeList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(IIngredient output) {
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe recipe = recipes.get(i);
|
||||
|
||||
// certain special recipes have no predefined output. ignore those
|
||||
// since these cannot be removed with MineTweaker scripts
|
||||
if (recipe.getRecipeOutput() != null) {
|
||||
if (output.matches(new MCItemStack(recipe.getRecipeOutput()))) {
|
||||
toRemove.add(recipe);
|
||||
removeIndex.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
||||
return toRemove.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
|
||||
if (output.getInternal() == null) {
|
||||
MineTweakerAPI.logger.logError("invalid output item");
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
|
||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddRecipe(irecipe));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function) {
|
||||
if (output.getInternal() == null) {
|
||||
MineTweakerAPI.logger.logError("invalid output item");
|
||||
return;
|
||||
}
|
||||
|
||||
ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function);
|
||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddRecipe(irecipe));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
|
||||
int ingredientsWidth = 0;
|
||||
int ingredientsHeight = 0;
|
||||
|
||||
if (ingredients != null) {
|
||||
ingredientsHeight = ingredients.length;
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length);
|
||||
}
|
||||
}
|
||||
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
outer: for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe recipe = recipes.get(i);
|
||||
|
||||
if (recipe.getRecipeOutput() == null || !output.matches(new MCItemStack(recipe.getRecipeOutput()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ingredients != null) {
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes srecipe = (ShapedRecipes) recipe;
|
||||
if (ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < ingredientsHeight; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
for (int k = 0; k < ingredientsWidth; k++) {
|
||||
IIngredient ingredient = k > row.length ? null : row[k];
|
||||
ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k];
|
||||
|
||||
if (!matches(recipeIngredient, ingredient)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
ShapedOreRecipe srecipe = (ShapedOreRecipe) recipe;
|
||||
int recipeWidth = MineTweakerHacks.getShapedOreRecipeWidth(srecipe);
|
||||
int recipeHeight = srecipe.getRecipeSize() / recipeWidth;
|
||||
if (ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < ingredientsHeight; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
for (int k = 0; k < ingredientsWidth; k++) {
|
||||
IIngredient ingredient = k > row.length ? null : row[k];
|
||||
Object input = srecipe.getInput()[j * recipeWidth + k];
|
||||
if (!matches(input, ingredient)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (recipe instanceof ShapedRecipe) {
|
||||
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
toRemove.add(recipe);
|
||||
removeIndex.add(i);
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
||||
return toRemove.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
outer: for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe recipe = recipes.get(i);
|
||||
|
||||
if (recipe.getRecipeOutput() == null || !output.matches(new MCItemStack(recipe.getRecipeOutput()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ingredients != null) {
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
|
||||
|
||||
if (ingredients.length > srecipe.getRecipeSize()) {
|
||||
continue;
|
||||
} else if (!wildcard && ingredients.length < srecipe.getRecipeSize()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
checkIngredient: for (int j = 0; j < ingredients.length; j++) {
|
||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||
if (matches(srecipe.recipeItems.get(k), ingredients[j])) {
|
||||
continue checkIngredient;
|
||||
}
|
||||
}
|
||||
|
||||
continue outer;
|
||||
}
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe;
|
||||
ArrayList<Object> inputs = srecipe.getInput();
|
||||
|
||||
if (inputs.size() < ingredients.length) {
|
||||
continue;
|
||||
} if (!wildcard && inputs.size() > ingredients.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
checkIngredient: for (int j = 0; j < ingredients.length; j++) {
|
||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||
if (matches(inputs.get(k), ingredients[j])) {
|
||||
continue checkIngredient;
|
||||
}
|
||||
}
|
||||
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
toRemove.add(recipe);
|
||||
removeIndex.add(i);
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
||||
return toRemove.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack craft(IItemStack[][] contents) {
|
||||
Container container = new ContainerVirtual();
|
||||
|
||||
int width = 0;
|
||||
int height = contents.length;
|
||||
for (IItemStack[] row : contents) {
|
||||
width = Math.max(width, row.length);
|
||||
}
|
||||
|
||||
ItemStack[] iContents = new ItemStack[width * height];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < contents[i].length; j++) {
|
||||
if (contents[i][j] != null) {
|
||||
Object internal = contents[i][j].getInternal();
|
||||
if (internal != null && (internal instanceof ItemStack)) {
|
||||
iContents[i * width + j] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InventoryCrafting inventory = new InventoryCrafting(container, width, height);
|
||||
for (int i = 0; i < iContents.length; i++) {
|
||||
inventory.setInventorySlotContents(i, iContents[i]);
|
||||
}
|
||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(inventory, null);
|
||||
if (result == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new MCItemStack(result);
|
||||
}
|
||||
}
|
||||
|
||||
private class ContainerVirtual extends Container {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer var1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionRemoveRecipes implements IUndoableAction {
|
||||
private final List<Integer> removingIndices;
|
||||
private final List<IRecipe> removingRecipes;
|
||||
|
||||
public ActionRemoveRecipes(List<IRecipe> recipes, List<Integer> indices) {
|
||||
this.removingIndices = indices;
|
||||
this.removingRecipes = recipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (int i = removingIndices.size() - 1; i >= 0; i--) {
|
||||
recipes.remove((int) removingIndices.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (int i = 0; i < removingIndices.size(); i++) {
|
||||
recipes.add(removingIndices.get(i), removingRecipes.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + removingIndices.size() + " recipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + removingIndices.size() + " recipes";
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionAddRecipe implements IUndoableAction {
|
||||
private final IRecipe recipe;
|
||||
|
||||
public ActionAddRecipe(IRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
recipes.remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean matches(Object input, IIngredient ingredient) {
|
||||
if ((input == null) != (ingredient == null)) {
|
||||
return false;
|
||||
} else if (ingredient != null) {
|
||||
if (input instanceof ItemStack) {
|
||||
if (!ingredient.matches(new MCItemStack((ItemStack) input))) {
|
||||
return false;
|
||||
}
|
||||
} else if (input instanceof String) {
|
||||
if (!ingredient.contains(new MCOreDictEntry((String) input))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class RecipeConverter {
|
||||
private RecipeConverter() {}
|
||||
|
||||
public static final int TYPE_ADVANCED = 0;
|
||||
public static final int TYPE_ORE = 1;
|
||||
public static final int TYPE_BASIC = 2;
|
||||
|
||||
private static int getIngredientType(IIngredient pattern) {
|
||||
Object internal = pattern.getInternal();
|
||||
if (internal == null) {
|
||||
return TYPE_ADVANCED;
|
||||
} else if (internal instanceof ItemStack) {
|
||||
return TYPE_BASIC;
|
||||
} else {
|
||||
return TYPE_ORE;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getRecipeType(IIngredient[] ingredients) {
|
||||
int type = TYPE_BASIC;
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
type = Math.min(type, getIngredientType(ingredient));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static IRecipe convert(ShapelessRecipe recipe) {
|
||||
IIngredient[] ingredients = recipe.getIngredients();
|
||||
int type = getRecipeType(ingredients);
|
||||
|
||||
if (type == TYPE_BASIC) {
|
||||
ItemStack[] items = new ItemStack[ingredients.length];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
items[i] = (ItemStack) ingredients[i].getInternal();
|
||||
}
|
||||
return new ShapelessRecipeBasic(items, recipe);
|
||||
} else if (type == TYPE_ORE) {
|
||||
Object[] items = new Object[ingredients.length];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
items[i] = ingredients[i].getInternal();
|
||||
}
|
||||
return new ShapelessRecipeOre(items, recipe);
|
||||
} else {
|
||||
return new ShapelessRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static IRecipe convert(ShapedRecipe recipe) {
|
||||
IIngredient[] ingredients = recipe.getIngredients();
|
||||
byte[] posx = recipe.getIngredientsX();
|
||||
byte[] posy = recipe.getIngredientsY();
|
||||
|
||||
// determine recipe type
|
||||
int type = getRecipeType(ingredients);
|
||||
|
||||
// construct recipe
|
||||
if (type == TYPE_BASIC) {
|
||||
System.out.println("Converted to basic recipe");
|
||||
ItemStack[] basicIngredients = new ItemStack[recipe.getHeight() * recipe.getWidth()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
basicIngredients[posx[i] + posy[i] * recipe.getWidth()] = (ItemStack) ingredients[i].getInternal();
|
||||
}
|
||||
|
||||
return new ShapedRecipeBasic(basicIngredients, recipe);
|
||||
} else if (type == TYPE_ORE) {
|
||||
System.out.println("Converted to ore recipe");
|
||||
Object[] converted = new Object[recipe.getHeight() * recipe.getWidth()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
converted[posx[i] + posy[i] * recipe.getWidth()] = ingredients[i].getInternal();
|
||||
}
|
||||
|
||||
// arguments contents:
|
||||
// 1) recipe patterns
|
||||
// 2) characters + ingredients
|
||||
|
||||
int counter = 0;
|
||||
String[] parts = new String[recipe.getHeight()];
|
||||
ArrayList rarguments = new ArrayList();
|
||||
for (int i = 0; i < recipe.getHeight(); i++) {
|
||||
char[] pattern = new char[recipe.getWidth()];
|
||||
for (int j = 0; j < recipe.getWidth(); j++) {
|
||||
int off = i * recipe.getWidth() + j;
|
||||
if (converted[off] == null) {
|
||||
pattern[j] = ' ';
|
||||
} else {
|
||||
pattern[j] = (char) ('A' + counter);
|
||||
rarguments.add(pattern[j]);
|
||||
rarguments.add(converted[off]);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
parts[i] = new String(pattern);
|
||||
}
|
||||
|
||||
rarguments.addAll(0, Arrays.asList(parts));
|
||||
|
||||
return new ShapedRecipeOre(rarguments.toArray(), recipe);
|
||||
} else {
|
||||
System.out.println("Converted to advanced recipe");
|
||||
return new ShapedRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* TODO: NEI integration for this kind of recipes.
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipeAdvanced implements IRecipe {
|
||||
private final ShapedRecipe recipe;
|
||||
|
||||
public ShapedRecipeAdvanced(ShapedRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return recipe.getWidth() * recipe.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return (ItemStack) recipe.getOutput().getInternal();
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipeBasic extends ShapedRecipes {
|
||||
private final ShapedRecipe recipe;
|
||||
|
||||
public ShapedRecipeBasic(ItemStack[] basicInputs, ShapedRecipe recipe) {
|
||||
super(recipe.getWidth(), recipe.getHeight(), basicInputs, (ItemStack) recipe.getOutput().getInternal());
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
IItemStack result = recipe.getCraftingResult(MCCraftingInventory.get(inventory));
|
||||
if (result == null) {
|
||||
return null;
|
||||
} else {
|
||||
return ((ItemStack) result.getInternal()).copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipeOre extends ShapedOreRecipe {
|
||||
private final ShapedRecipe recipe;
|
||||
|
||||
public ShapedRecipeOre(Object[] contents, ShapedRecipe recipe) {
|
||||
super((ItemStack) recipe.getOutput().getInternal(), contents);
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipeAdvanced implements IRecipe {
|
||||
private final ShapelessRecipe recipe;
|
||||
|
||||
public ShapelessRecipeAdvanced(ShapelessRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return recipe.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return (ItemStack) recipe.getOutput().getInternal();
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipeBasic extends ShapelessRecipes {
|
||||
private final ShapelessRecipe recipe;
|
||||
|
||||
public ShapelessRecipeBasic(ItemStack[] ingredients, ShapelessRecipe recipe) {
|
||||
super((ItemStack) recipe.getOutput().getInternal(), Arrays.asList(ingredients));
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipeOre extends ShapelessOreRecipe {
|
||||
private final ShapelessRecipe recipe;
|
||||
|
||||
public ShapelessRecipeOre(Object[] ingredients, ShapelessRecipe recipe) {
|
||||
super((ItemStack) recipe.getOutput().getInternal(), ingredients);
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
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.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
/**
|
||||
* Common class for all runtime hacks (stuff requiring reflection). It is not
|
||||
* unexpected to have it break with new minecraft versions and may need regular
|
||||
* adjustment - as such, those have been collected here.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerHacks {
|
||||
private static final Field NBTTAGLIST_TAGLIST;
|
||||
private static final Field OREDICTIONARY_IDTOSTACK;
|
||||
private static final Field OREDICTIONARY_IDTOSTACKUN;
|
||||
private static final Field MINECRAFTSERVER_ANVILFILE;
|
||||
private static final Field SHAPEDORERECIPE_WIDTH;
|
||||
private static final Field INVENTORYCRAFTING_EVENTHANDLER;
|
||||
private static final Field SLOTCRAFTING_PLAYER;
|
||||
|
||||
static {
|
||||
NBTTAGLIST_TAGLIST = getField(NBTTagList.class, MineTweakerObfuscation.NBTTAGLIST_TAGLIST);
|
||||
OREDICTIONARY_IDTOSTACK = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_IDTOSTACK);
|
||||
OREDICTIONARY_IDTOSTACKUN = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_IDTOSTACKUN);
|
||||
MINECRAFTSERVER_ANVILFILE = getField(MinecraftServer.class, MineTweakerObfuscation.MINECRAFTSERVER_ANVILFILE);
|
||||
SHAPEDORERECIPE_WIDTH = getField(ShapedOreRecipe.class, new String[] {"width"});
|
||||
INVENTORYCRAFTING_EVENTHANDLER = getField(InventoryCrafting.class, MineTweakerObfuscation.INVENTORYCRAFTING_EVENTHANDLER);
|
||||
SLOTCRAFTING_PLAYER = getField(SlotCrafting.class, MineTweakerObfuscation.SLOTCRAFTING_PLAYER);
|
||||
}
|
||||
|
||||
private MineTweakerHacks() {}
|
||||
|
||||
public static List<NBTBase> getTagList(NBTTagList list) {
|
||||
if (NBTTAGLIST_TAGLIST == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (List) NBTTAGLIST_TAGLIST.get(list);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return null;
|
||||
} catch (IllegalAccessException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ArrayList<ItemStack>> getOreIdStacks() {
|
||||
try {
|
||||
return (List<ArrayList<ItemStack>>) OREDICTIONARY_IDTOSTACK.get(null);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("ERROR - could not load ore dictionary stacks!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ArrayList<ItemStack>> getOreIdStacksUn() {
|
||||
try {
|
||||
return (List<ArrayList<ItemStack>>) OREDICTIONARY_IDTOSTACKUN.get(null);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("ERROR - could not load ore dictionary stacks!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getAnvilFile(MinecraftServer server) {
|
||||
try {
|
||||
return (File) MINECRAFTSERVER_ANVILFILE.get(server);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not load anvil file!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getWorldDirectory(MinecraftServer server) {
|
||||
if (server.isDedicatedServer()) {
|
||||
return server.getFile("world");
|
||||
} else {
|
||||
File worldsDir = getAnvilFile(server);
|
||||
if (worldsDir == null) return null;
|
||||
|
||||
return new File(worldsDir, server.getFolderName());
|
||||
}
|
||||
}
|
||||
|
||||
public static int getShapedOreRecipeWidth(ShapedOreRecipe recipe) {
|
||||
try {
|
||||
return SHAPEDORERECIPE_WIDTH.getInt(recipe);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not load anvil file!");
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
public static Container getCraftingContainer(InventoryCrafting inventory) {
|
||||
try {
|
||||
return (Container) INVENTORYCRAFTING_EVENTHANDLER.get(inventory);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get inventory eventhandler");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) {
|
||||
try {
|
||||
return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get inventory eventhandler");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private Methods ###
|
||||
// #######################
|
||||
|
||||
private static Field getField(Class cls, String[] names) {
|
||||
for (String name : names) {
|
||||
try {
|
||||
Field field = cls.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (NoSuchFieldException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class MineTweakerObfuscation {
|
||||
private MineTweakerObfuscation() {}
|
||||
|
||||
public static final String[] NBTTAGLIST_TAGLIST = {"tagList", "field_74747_a"};
|
||||
public static final String[] CRAFTINGMANAGER_RECIPES = {"recipes", "field_77597_b"};
|
||||
public static final String[] OREDICTIONARY_IDTOSTACK = {"idToStack"};
|
||||
public static final String[] OREDICTIONARY_IDTOSTACKUN = {"idToStackUn"};
|
||||
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"};
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerUtil {
|
||||
public static ItemStack[] getItemStacks(IItemStack... items) {
|
||||
ItemStack[] output = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
Object internal = items[i].getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static ItemStack[] getItemStacks(List<IItemStack> items) {
|
||||
ItemStack[] output = new ItemStack[items.size()];
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Object internal = items.get(i).getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static IItemStack[] getIItemStacks(ItemStack... items) {
|
||||
IItemStack[] result = new IItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = new MCItemStack(items[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IItemStack[] getIItemStacks(List<ItemStack> items) {
|
||||
IItemStack[] result = new IItemStack[items.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new MCItemStack(items.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"modid": "MineTweaker3",
|
||||
"name": "MineTweaker 3",
|
||||
"version": "1.7.10-3.0.0",
|
||||
"mcversion": "1.7.10",
|
||||
"description": "Customize your minecraft experience!",
|
||||
"url": "http://minetweaker3.powerofbytes.com/wiki/",
|
||||
"credits": "Stan Hebben",
|
||||
"authors": [ "Stan Hebben" ],
|
||||
}
|
||||
]
|
||||
@@ -25,6 +25,19 @@ task wrapper(type: Wrapper, description: 'Creates and deploys the Gradle wrapper
|
||||
|
||||
subprojects.each { subproject -> evaluationDependsOn( subproject.path ) }
|
||||
|
||||
task assembleMC1710(type: Jar, dependsOn: [\
|
||||
':ZenScript:build',
|
||||
':MineTweaker3-API:build',
|
||||
':MineTweaker3-MC1710-Main:build'/*,
|
||||
':MineTweaker3-MC172-Mod-IC2:build',
|
||||
':MineTweaker3-MC172-Mod-NEI:build'*/]) {
|
||||
from zipTree(project(":ZenScript").jar.archivePath)
|
||||
from zipTree(project(':MineTweaker3-API').jar.archivePath)
|
||||
from zipTree(project(':MineTweaker3-MC1710-Main').jar.archivePath)
|
||||
/* from zipTree(project(':MineTweaker3-MC172-Mod-IC2').jar.archivePath)
|
||||
from zipTree(project(':MineTweaker3-MC172-Mod-NEI').jar.archivePath)*/
|
||||
}
|
||||
|
||||
task assembleMC172(type: Jar, dependsOn: [\
|
||||
':ZenScript:build',
|
||||
':MineTweaker3-API:build',
|
||||
|
||||
Reference in new issue
Block a user