diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataBool.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataBool.java index 4e05584..45a4a82 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataBool.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataBool.java @@ -77,22 +77,22 @@ public class DataBool implements IData { @Override public IData getAt(int i) { - throw new RuntimeException("a bool is not indexable"); + throw new UnsupportedOperationException("a bool is not indexable"); } @Override public void setAt(int i, IData value) { - throw new RuntimeException("a bool is not indexable"); + throw new UnsupportedOperationException("a bool is not indexable"); } @Override public IData memberGet(String name) { - throw new RuntimeException("a bool is not indexable"); + throw new UnsupportedOperationException("a bool is not indexable"); } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("a bool is not indexable"); + throw new UnsupportedOperationException("a bool is not indexable"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByte.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByte.java index 8d47543..7d4eac2 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByte.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByte.java @@ -17,7 +17,7 @@ public class DataByte implements IData { @Override public boolean asBool() { - throw new RuntimeException("Cannot cast a byte to a bool"); + throw new IllegalDataException("Cannot cast a byte to a bool"); } @Override @@ -77,22 +77,22 @@ public class DataByte implements IData { @Override public IData getAt(int i) { - throw new RuntimeException("A byte is not indexable"); + throw new UnsupportedOperationException("A byte is not indexable"); } @Override public void setAt(int i, IData value) { - throw new RuntimeException("A byte is not indexable"); + throw new UnsupportedOperationException("A byte is not indexable"); } @Override public IData memberGet(String name) { - throw new RuntimeException("A byte is not indexable"); + throw new UnsupportedOperationException("A byte is not indexable"); } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("A byte is not indexable"); + throw new UnsupportedOperationException("A byte is not indexable"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByteArray.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByteArray.java index 1e11da9..406b024 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByteArray.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataByteArray.java @@ -74,51 +74,53 @@ public class DataByteArray implements IData { @Override public boolean asBool() { - throw new UnsupportedOperationException("Cannot cast an array to bool"); + throw new IllegalDataException("Cannot cast an array to bool"); } @Override public byte asByte() { - throw new UnsupportedOperationException("Cannot cast an array to byte"); + throw new IllegalDataException("Cannot cast an array to byte"); } @Override public short asShort() { - throw new UnsupportedOperationException("Cannot cast an array to short"); + throw new IllegalDataException("Cannot cast an array to short"); } @Override public int asInt() { - throw new UnsupportedOperationException("Cannot cast an array to int"); + throw new IllegalDataException("Cannot cast an array to int"); } @Override public long asLong() { - throw new UnsupportedOperationException("Cannot cast an array to long"); + throw new IllegalDataException("Cannot cast an array to long"); } @Override public float asFloat() { - throw new UnsupportedOperationException("Cannot cast an array to float"); + throw new IllegalDataException("Cannot cast an array to float"); } @Override public double asDouble() { - throw new UnsupportedOperationException("Cannot cast an array to double"); + throw new IllegalDataException("Cannot cast an array to double"); } @Override public String asString() { StringBuilder result = new StringBuilder(); - result.append("X\""); + result.append("["); + boolean first = true; for (byte value : data) { - String str = Integer.toHexString(value); - if (str.length() == 1) { - result.append('0'); - } - result.append(str); + if (first) + first = false; + else + result.append(", "); + + result.append(value); } - result.append('"'); + result.append("] as byte[]"); return result.toString(); } diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataDouble.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataDouble.java index f5c3ee5..8c44a84 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataDouble.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataDouble.java @@ -17,7 +17,7 @@ public class DataDouble implements IData { @Override public boolean asBool() { - throw new RuntimeException("Cannot cast a double to a bool"); + throw new IllegalDataException("Cannot cast a double to a bool"); } @Override @@ -77,22 +77,22 @@ public class DataDouble implements IData { @Override public IData getAt(int i) { - throw new RuntimeException("A double is not indexable"); + throw new UnsupportedOperationException("A double is not indexable"); } @Override public void setAt(int i, IData value) { - throw new RuntimeException("A double is not indexable"); + throw new UnsupportedOperationException("A double is not indexable"); } @Override public IData memberGet(String name) { - throw new RuntimeException("A double is not indexable"); + throw new UnsupportedOperationException("A double is not indexable"); } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("A double is not indexable"); + throw new UnsupportedOperationException("A double is not indexable"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataFloat.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataFloat.java index 1cdb170..6dd9677 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataFloat.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataFloat.java @@ -17,7 +17,7 @@ public class DataFloat implements IData { @Override public boolean asBool() { - throw new RuntimeException("Cannot cast a float to a bool"); + throw new IllegalDataException("Cannot cast a float to a bool"); } @Override @@ -77,22 +77,22 @@ public class DataFloat implements IData { @Override public IData getAt(int i) { - throw new RuntimeException("A float is not indexable"); + throw new UnsupportedOperationException("A float is not indexable"); } @Override public void setAt(int i, IData value) { - throw new RuntimeException("A float is not indexable"); + throw new UnsupportedOperationException("A float is not indexable"); } @Override public IData memberGet(String name) { - throw new RuntimeException("A float is not indexable"); + throw new UnsupportedOperationException("A float is not indexable"); } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("A float is not indexable"); + throw new UnsupportedOperationException("A float is not indexable"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataIntArray.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataIntArray.java index 1507d5c..b71356e 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataIntArray.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataIntArray.java @@ -74,37 +74,37 @@ public class DataIntArray implements IData { @Override public boolean asBool() { - throw new UnsupportedOperationException("Cannot cast an array to bool"); + throw new IllegalDataException("Cannot cast an array to bool"); } @Override public byte asByte() { - throw new UnsupportedOperationException("Cannot cast an array to byte"); + throw new IllegalDataException("Cannot cast an array to byte"); } @Override public short asShort() { - throw new UnsupportedOperationException("Cannot cast an array to short"); + throw new IllegalDataException("Cannot cast an array to short"); } @Override public int asInt() { - throw new UnsupportedOperationException("Cannot cast an array to int"); + throw new IllegalDataException("Cannot cast an array to int"); } @Override public long asLong() { - throw new UnsupportedOperationException("Cannot cast an array to long"); + throw new IllegalDataException("Cannot cast an array to long"); } @Override public float asFloat() { - throw new UnsupportedOperationException("Cannot cast an array to float"); + throw new IllegalDataException("Cannot cast an array to float"); } @Override public double asDouble() { - throw new UnsupportedOperationException("Cannot cast an array to double"); + throw new IllegalDataException("Cannot cast an array to double"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataList.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataList.java index c0c7e9f..ed6aff2 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataList.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataList.java @@ -21,37 +21,37 @@ public class DataList implements IData { @Override public boolean asBool() { - throw new RuntimeException("Cannot convert a list to a bool"); + throw new IllegalDataException("Cannot convert a list to a bool"); } @Override public byte asByte() { - throw new RuntimeException("Cannot convert a list to a byte"); + throw new IllegalDataException("Cannot convert a list to a byte"); } @Override public short asShort() { - throw new RuntimeException("Cannot convert a list to a short"); + throw new IllegalDataException("Cannot convert a list to a short"); } @Override public int asInt() { - throw new RuntimeException("Cannot convert a list to an int"); + throw new IllegalDataException("Cannot convert a list to an int"); } @Override public long asLong() { - throw new RuntimeException("Cannot convert a list to a long"); + throw new IllegalDataException("Cannot convert a list to a long"); } @Override public float asFloat() { - throw new RuntimeException("Cannot convert a list to a float"); + throw new IllegalDataException("Cannot convert a list to a float"); } @Override public double asDouble() { - throw new RuntimeException("Cannot convert a list to a double"); + throw new IllegalDataException("Cannot convert a list to a double"); } @Override @@ -119,7 +119,7 @@ public class DataList implements IData { @Override public void setAt(int i, IData value) { if (immutable) { - throw new RuntimeException("this list is immutable"); + throw new UnsupportedOperationException("this list is immutable"); } else { values.set(i, value); } @@ -127,12 +127,12 @@ public class DataList implements IData { @Override public IData memberGet(String name) { - throw new RuntimeException("Lists don't have members"); + throw new UnsupportedOperationException("Lists don't have members"); } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("Lists don't have members"); + throw new UnsupportedOperationException("Lists don't have members"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataLong.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataLong.java index 3228aa6..c3c16b0 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataLong.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataLong.java @@ -17,7 +17,7 @@ public class DataLong implements IData { @Override public boolean asBool() { - throw new RuntimeException("Cannot cast a long to a bool"); + throw new IllegalDataException("Cannot cast a long to a bool"); } @Override @@ -57,42 +57,42 @@ public class DataLong implements IData { @Override public List asList() { - throw new UnsupportedOperationException("Cannot cast a long to a list"); + return null; } @Override public Map asMap() { - throw new UnsupportedOperationException("Cannot cast a long to a map"); + return null; } @Override public byte[] asByteArray() { - throw new RuntimeException("Cannot cast a long to a byte array"); + return null; } @Override public int[] asIntArray() { - throw new RuntimeException("Cannot cast a long to an int array"); + return null; } @Override public IData getAt(int i) { - throw new RuntimeException("A long is not indexable"); + throw new UnsupportedOperationException("A long is not indexable"); } @Override public void setAt(int i, IData value) { - throw new RuntimeException("A long is not indexable"); + throw new UnsupportedOperationException("A long is not indexable"); } @Override public IData memberGet(String name) { - throw new RuntimeException("A long is not indexable"); + throw new UnsupportedOperationException("A long is not indexable"); } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("A long is not indexable"); + throw new UnsupportedOperationException("A long is not indexable"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataShort.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataShort.java index 7d00c1a..231985f 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataShort.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataShort.java @@ -17,7 +17,7 @@ public class DataShort implements IData { @Override public boolean asBool() { - throw new RuntimeException("Cannot cast a short to a bool"); + throw new IllegalDataException("Cannot cast a short to a bool"); } @Override @@ -77,22 +77,22 @@ public class DataShort implements IData { @Override public IData getAt(int i) { - throw new RuntimeException("A short is not indexable"); + throw new UnsupportedOperationException("A short is not indexable"); } @Override public void setAt(int i, IData value) { - throw new RuntimeException("A short is not indexable"); + throw new UnsupportedOperationException("A short is not indexable"); } @Override public IData memberGet(String name) { - throw new RuntimeException("A short is not indexable"); + throw new UnsupportedOperationException("A short is not indexable"); } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("A short is not indexable"); + throw new UnsupportedOperationException("A short is not indexable"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataString.java b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataString.java index 9474528..af972e4 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/data/DataString.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/data/DataString.java @@ -82,7 +82,7 @@ public class DataString implements IData { @Override public void setAt(int i, IData value) { - throw new RuntimeException("Strings are immutable"); + throw new UnsupportedOperationException("Strings are immutable"); } @Override @@ -90,13 +90,13 @@ public class DataString implements IData { if (name.equals("length")) { return new DataInt(value.length()); } else { - throw new RuntimeException("no such member: " + name); + throw new UnsupportedOperationException("no such member: " + name); } } @Override public void memberSet(String name, IData data) { - throw new RuntimeException("Strings are immutable"); + throw new UnsupportedOperationException("Strings are immutable"); } @Override diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/item/IngredientUnknown.java b/MineTweaker3-API/src/main/java/minetweaker/api/item/IngredientUnknown.java new file mode 100644 index 0000000..701c0c9 --- /dev/null +++ b/MineTweaker3-API/src/main/java/minetweaker/api/item/IngredientUnknown.java @@ -0,0 +1,105 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package minetweaker.api.item; + +import java.util.Collections; +import java.util.List; +import minetweaker.api.player.IPlayer; + +/** + * + * @author Stan + */ +public class IngredientUnknown implements IIngredient +{ + public static final IngredientUnknown INSTANCE = new IngredientUnknown(1); + + private final int size; + + public IngredientUnknown(int size) + { + this.size = size; + } + + @Override + public String getMark() + { + return null; + } + + @Override + public int getAmount() + { + return size; + } + + @Override + public List getItems() + { + return Collections.emptyList(); + } + + @Override + public IIngredient amount(int amount) + { + return new IngredientUnknown(amount); + } + + @Override + public IIngredient or(IIngredient ingredient) + { + return ingredient; + } + + @Override + public IIngredient transform(IItemTransformer transformer) + { + return this; + } + + @Override + public IIngredient only(IItemCondition condition) + { + return this; + } + + @Override + public IIngredient marked(String mark) + { + return this; + } + + @Override + public boolean matches(IItemStack item) + { + return false; + } + + @Override + public boolean contains(IIngredient ingredient) + { + return false; + } + + @Override + public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) + { + return item; + } + + @Override + public boolean hasTransformers() + { + return false; + } + + @Override + public Object getInternal() + { + return null; + } +} diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/player/IPlayer.java b/MineTweaker3-API/src/main/java/minetweaker/api/player/IPlayer.java index 7efd1ef..9251f06 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/player/IPlayer.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/player/IPlayer.java @@ -63,4 +63,7 @@ public interface IPlayer { // not an exposed method. risks abuse public void openBrowser(String url); + + // not an exposed method, so far. would it be useful? + public void copyToClipboard(String value); } diff --git a/MineTweaker3-API/src/main/java/minetweaker/util/StringUtil.java b/MineTweaker3-API/src/main/java/minetweaker/util/StringUtil.java new file mode 100644 index 0000000..25a61ad --- /dev/null +++ b/MineTweaker3-API/src/main/java/minetweaker/util/StringUtil.java @@ -0,0 +1,31 @@ +/* + * 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.util; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +/** + * + * @author Stan + */ +public class StringUtil +{ + private static final Charset UTF8 = Charset.forName("UTF-8"); + + private StringUtil() {} + + public static String decodeUTF8(byte[] data) + { + return UTF8.decode(ByteBuffer.wrap(data)).toString().trim(); + } + + public static byte[] encodeUTF8(String data) + { + return UTF8.encode(data).array(); + } +} diff --git a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java index ac1c9b2..4b7fd64 100644 --- a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java +++ b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java @@ -140,6 +140,14 @@ public class MineTweakerMod { } } + public void copyToClipboard(String user, String data) { + if (networkByUser.containsKey(user)) { + networkByUser.get(user).addToSendQueue(new Packet250CustomPayload( + MCPacketHandler.CHANNEL_OPENBROWSER, + MCPacketHandler.UTF8.encode(data).array())); + } + } + // ########################## // ### FML Event Handlers ### // ########################## diff --git a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/block/MCSpecificBlock.java b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/block/MCSpecificBlock.java index e0ac7e9..b7d4088 100644 --- a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/block/MCSpecificBlock.java +++ b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/block/MCSpecificBlock.java @@ -65,4 +65,14 @@ public class MCSpecificBlock implements IBlock { public String getDisplayName() { return block.getLocalizedName(); } + + @Override + public String toString() { + return ""; + } + + private static String getBlockId(Block block) + { + return block.getUnlocalizedName(); + } } diff --git a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/network/MCPacketHandler.java b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/network/MCPacketHandler.java index 1bd3727..a428b51 100644 --- a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/network/MCPacketHandler.java +++ b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/network/MCPacketHandler.java @@ -11,6 +11,9 @@ import net.minecraft.network.packet.Packet250CustomPayload; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.Player; import java.awt.Desktop; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -26,6 +29,7 @@ public class MCPacketHandler implements IPacketHandler { public static final String CHANNEL_SERVERSCRIPT = "MTServerScript"; public static final String CHANNEL_OPENBROWSER = "MTOpenBrowser"; + public static final String CHANNEL_COPYTOCLIPBOARD = "MTCopyToClipboard"; @Override public void onPacketData(INetworkManager manager, @@ -44,7 +48,8 @@ public class MCPacketHandler implements IPacketHandler { } } else if (packet.channel.equals(CHANNEL_OPENBROWSER)) { String url = UTF8.decode(ByteBuffer.wrap(packet.data)).toString().trim(); - if(Desktop.isDesktopSupported()){ + + if (Desktop.isDesktopSupported()){ Desktop desktop = Desktop.getDesktop(); try { desktop.browse(new URI(url)); @@ -52,6 +57,14 @@ public class MCPacketHandler implements IPacketHandler { } catch (URISyntaxException e) { } } + } else if (packet.channel.equals(CHANNEL_COPYTOCLIPBOARD)) { + String message = UTF8.decode(ByteBuffer.wrap(packet.data)).toString().trim(); + + if (Desktop.isDesktopSupported()) { + StringSelection stringSelection = new StringSelection(message); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } } } } diff --git a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/player/MCPlayer.java b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/player/MCPlayer.java index f8fa9a9..7dd7642 100644 --- a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/player/MCPlayer.java +++ b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/player/MCPlayer.java @@ -111,6 +111,13 @@ public class MCPlayer implements IPlayer { } } + @Override + public void copyToClipboard(String value) { + if (player instanceof EntityPlayerMP) { + MineTweakerMod.INSTANCE.copyToClipboard(player.username, value); + } + } + @Override public void give(IItemStack stack) { player.inventory.addItemStackToInventory(MineTweakerMC.getItemStack(stack).copy()); diff --git a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/server/ServerPlayer.java b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/server/ServerPlayer.java index 04b0c73..15337f5 100644 --- a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/server/ServerPlayer.java +++ b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/server/ServerPlayer.java @@ -7,6 +7,9 @@ package minetweaker.mc164.server; import java.awt.Desktop; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.io.IOException; import java.net.URI; import java.util.logging.Level; @@ -105,6 +108,15 @@ public class ServerPlayer implements IPlayer { } } } + + @Override + public void copyToClipboard(String value) { + if (Desktop.isDesktopSupported()) { + StringSelection stringSelection = new StringSelection(value); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + } @Override public void give(IItemStack stack) { diff --git a/MineTweaker3-MC164-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java b/MineTweaker3-MC164-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java index 6dddc09..d474a16 100644 --- a/MineTweaker3-MC164-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java +++ b/MineTweaker3-MC164-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java @@ -134,18 +134,16 @@ public class Planter { return false; for (TweakerPlantable plantable : plantables) { - if (!plantable.seed.matches(MineTweakerMC.getIItemStack(seed))) { - //System.out.println("Cannot plant (seed doesn't match)"); - return false; - } + if (!plantable.seed.matches(MineTweakerMC.getIItemStack(seed))) + continue; - if (!plantable.canPlantOn.matches(MineTweakerMC.getBlock(world, x, y - 1, z))) { - //System.out.println("Cannot plant (not on the right block"); - return false; - } + if (!plantable.canPlantOn.matches(MineTweakerMC.getBlock(world, x, y - 1, z))) + continue; + + return true; } - return true; + return false; } @Override diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java index 9c22807..cfe2f9e 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java @@ -9,6 +9,7 @@ import minetweaker.api.block.IBlockDefinition; import minetweaker.api.data.IData; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; +import minetweaker.api.item.IngredientUnknown; import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.oredict.IOreDictEntry; import minetweaker.api.player.IPlayer; @@ -442,7 +443,7 @@ public class MineTweakerMC { IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient); if (entry == null) { - throw new IllegalArgumentException("No matching oredict entry: " + ingredient); + return IngredientUnknown.INSTANCE; } return entry; diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java index 6166f9f..57b6da8 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java @@ -28,6 +28,8 @@ import minetweaker.mc1710.furnace.FuelTweaker; import minetweaker.mc1710.furnace.MCFurnaceManager; import minetweaker.mc1710.game.MCGame; import minetweaker.mc1710.mods.MCLoadedMods; +import minetweaker.mc1710.network.MineTweakerCopyClipboardHandler; +import minetweaker.mc1710.network.MineTweakerCopyClipboardPacket; import minetweaker.mc1710.network.MineTweakerLoadScriptsHandler; import minetweaker.mc1710.network.MineTweakerLoadScriptsPacket; import minetweaker.mc1710.network.MineTweakerOpenBrowserHandler; @@ -76,6 +78,7 @@ public class MineTweakerMod { static { NETWORK.registerMessage(MineTweakerLoadScriptsHandler.class, MineTweakerLoadScriptsPacket.class, 0, Side.CLIENT); NETWORK.registerMessage(MineTweakerOpenBrowserHandler.class, MineTweakerOpenBrowserPacket.class, 1, Side.CLIENT); + NETWORK.registerMessage(MineTweakerCopyClipboardHandler.class, MineTweakerCopyClipboardPacket.class, 2, Side.CLIENT); } @Mod.Instance(MODID) @@ -99,16 +102,8 @@ public class MineTweakerMod { MineTweakerImplementationAPI.platform = MCPlatformFunctions.INSTANCE; File globalDir = new File("scripts"); - if (!globalDir.exists()) { + if (!globalDir.exists()) globalDir.mkdirs(); - } - - /*try { - String data = Resources.toString(Resources.getResource(MineTweakerMod.class, "/minetweaker/myscript.zs"), Charsets.UTF_8); - - } catch (IOException ex) { - ex.printStackTrace(); - }*/ scriptsIMC = new ScriptProviderCustom("intermod"); scriptsGlobal = new ScriptProviderDirectory(globalDir); diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/block/MCSpecificBlock.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/block/MCSpecificBlock.java index 800d755..d7895c2 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/block/MCSpecificBlock.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/block/MCSpecificBlock.java @@ -65,4 +65,14 @@ public class MCSpecificBlock implements IBlock { public String getDisplayName() { return block.getLocalizedName(); } + + @Override + public String toString() { + return ""; + } + + private static String getBlockId(Block block) + { + return Block.blockRegistry.getNameForObject(block); + } } diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/network/MineTweakerCopyClipboardHandler.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/network/MineTweakerCopyClipboardHandler.java new file mode 100644 index 0000000..0a7bda2 --- /dev/null +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/network/MineTweakerCopyClipboardHandler.java @@ -0,0 +1,32 @@ +/* + * 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 java.awt.Desktop; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; + +/** + * + * @author Stan + */ +public class MineTweakerCopyClipboardHandler implements IMessageHandler { + @Override + public IMessage onMessage(MineTweakerCopyClipboardPacket message, MessageContext ctx) { + if (Desktop.isDesktopSupported()) { + StringSelection stringSelection = new StringSelection(message.getData()); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + + return null; + } +} \ No newline at end of file diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/network/MineTweakerCopyClipboardPacket.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/network/MineTweakerCopyClipboardPacket.java new file mode 100644 index 0000000..3bff5f8 --- /dev/null +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/network/MineTweakerCopyClipboardPacket.java @@ -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.network; + +import static com.google.common.base.Charsets.UTF_8; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import io.netty.buffer.ByteBuf; +import java.nio.ByteBuffer; + +/** + * + * @author Stan + */ +public class MineTweakerCopyClipboardPacket implements IMessage +{ + private String data; + + public MineTweakerCopyClipboardPacket() { + } + + public MineTweakerCopyClipboardPacket(String data) { + this.data = data; + } + + public String getData() { + return data; + } + + @Override + public void fromBytes(ByteBuf buf) { + data = UTF_8.decode(ByteBuffer.wrap(buf.array())).toString().trim(); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeBytes(UTF_8.encode(data).array()); + } +} diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/player/MCPlayer.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/player/MCPlayer.java index 45f8261..50767ea 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/player/MCPlayer.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/player/MCPlayer.java @@ -14,6 +14,7 @@ import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.player.IPlayer; import minetweaker.mc1710.MineTweakerMod; import minetweaker.mc1710.data.NBTConverter; +import minetweaker.mc1710.network.MineTweakerCopyClipboardPacket; import minetweaker.mc1710.network.MineTweakerOpenBrowserPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -114,6 +115,15 @@ public class MCPlayer implements IPlayer { } } + @Override + public void copyToClipboard(String value) { + if (player instanceof EntityPlayerMP) { + MineTweakerMod.NETWORK.sendTo( + new MineTweakerCopyClipboardPacket(value), + (EntityPlayerMP) player); + } + } + @Override public boolean equals(Object other) { if (other.getClass() != this.getClass()) diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/server/ServerPlayer.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/server/ServerPlayer.java index 0865db2..68b1834 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/server/ServerPlayer.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/server/ServerPlayer.java @@ -7,6 +7,9 @@ package minetweaker.mc1710.server; import java.awt.Desktop; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.io.IOException; import java.net.URI; import java.util.logging.Level; @@ -106,6 +109,15 @@ public class ServerPlayer implements IPlayer { } } } + + @Override + public void copyToClipboard(String value) { + if (Desktop.isDesktopSupported()) { + StringSelection stringSelection = new StringSelection(value); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + } @Override public void give(IItemStack stack) { diff --git a/MineTweaker3-MC1710-Mod-GregTech/build.gradle b/MineTweaker3-MC1710-Mod-GregTech/build.gradle index b0663f7..747fbd1 100644 --- a/MineTweaker3-MC1710-Mod-GregTech/build.gradle +++ b/MineTweaker3-MC1710-Mod-GregTech/build.gradle @@ -30,7 +30,7 @@ dependencies { compile project(':ZenScript') compile project(':MineTweaker3-API') compile project(':MineTweaker3-MC1710-Main') - compile files('libs/gregtech-1.7.10-dev.jar') + compile files('libs/gregtech_1.7.10-5.05.11-dev.jar') } task makeRegistry(type: RegisterZenClassesTask) { diff --git a/MineTweaker3-MC1710-Mod-GregTech/libs/gregtech_1.7.10-5.05.11-dev.jar b/MineTweaker3-MC1710-Mod-GregTech/libs/gregtech_1.7.10-5.05.11-dev.jar new file mode 100644 index 0000000..69a048b Binary files /dev/null and b/MineTweaker3-MC1710-Mod-GregTech/libs/gregtech_1.7.10-5.05.11-dev.jar differ diff --git a/MineTweaker3-MC1710-Mod-GregTech/libs/industrialcraft-2-2.2.491-experimental-api.jar b/MineTweaker3-MC1710-Mod-GregTech/libs/industrialcraft-2-2.2.491-experimental-api.jar deleted file mode 100644 index e638b56..0000000 Binary files a/MineTweaker3-MC1710-Mod-GregTech/libs/industrialcraft-2-2.2.491-experimental-api.jar and /dev/null differ diff --git a/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Harvester.java b/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Harvester.java index ab33b94..295bac8 100644 --- a/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Harvester.java +++ b/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Harvester.java @@ -117,7 +117,8 @@ public class Harvester { public HarvestType getHarvestType() { // WARNING: first type will be used // Also, take into account the possibility of having no harvestable yet - return harvestables.isEmpty() ? HarvestType.Normal : harvestables.get(0).type; + HarvestType result = harvestables.isEmpty() ? HarvestType.Normal : harvestables.get(0).type; + return result; } @Override @@ -127,8 +128,10 @@ public class Harvester { @Override public boolean canBeHarvested(World world, Map map, int x, int y, int z) { + IBlock block = MineTweakerMC.getBlock(world, x, y, z); + for (TweakerHarvestable harvestable : harvestables) { - if (harvestable.block.matches(MineTweakerMC.getBlock(world, x, y, z))) + if (harvestable.block.matches(block)) return true; } diff --git a/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java b/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java index c2b386a..a9e7ab4 100644 --- a/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java +++ b/MineTweaker3-MC1710-Mod-MFR/src/main/java/minetweaker/mods/mfr/machines/Planter.java @@ -135,18 +135,16 @@ public class Planter { return false; for (TweakerPlantable plantable : plantables) { - if (!plantable.seed.matches(MineTweakerMC.getIItemStack(seed))) { - //System.out.println("Cannot plant (seed doesn't match)"); - return false; - } + if (!plantable.seed.matches(MineTweakerMC.getIItemStack(seed))) + continue; - if (!plantable.canPlantOn.matches(MineTweakerMC.getBlock(world, x, y - 1, z))) { - //System.out.println("Cannot plant (not on the right block"); - return false; - } + if (!plantable.canPlantOn.matches(MineTweakerMC.getBlock(world, x, y - 1, z))) + continue; + + return true; } - return true; + return false; } @Override diff --git a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java index a10a3b6..c00d733 100644 --- a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java +++ b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java @@ -27,6 +27,8 @@ import minetweaker.mc172.furnace.FuelTweaker; import minetweaker.mc172.furnace.MCFurnaceManager; import minetweaker.mc172.game.MCGame; import minetweaker.mc172.mods.MCLoadedMods; +import minetweaker.mc172.network.MineTweakerCopyClipboardHandler; +import minetweaker.mc172.network.MineTweakerCopyClipboardPacket; import minetweaker.mc172.network.MineTweakerLoadScriptsHandler; import minetweaker.mc172.network.MineTweakerLoadScriptsPacket; import minetweaker.mc172.network.MineTweakerOpenBrowserHandler; @@ -72,6 +74,7 @@ public class MineTweakerMod { static { NETWORK.registerMessage(MineTweakerLoadScriptsHandler.class, MineTweakerLoadScriptsPacket.class, 0, Side.CLIENT); NETWORK.registerMessage(MineTweakerOpenBrowserHandler.class, MineTweakerOpenBrowserPacket.class, 1, Side.CLIENT); + NETWORK.registerMessage(MineTweakerCopyClipboardHandler.class, MineTweakerCopyClipboardPacket.class, 2, Side.CLIENT); } @Mod.Instance(MODID) diff --git a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/block/MCSpecificBlock.java b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/block/MCSpecificBlock.java index 03bcbba..eb7ce8f 100644 --- a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/block/MCSpecificBlock.java +++ b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/block/MCSpecificBlock.java @@ -65,4 +65,14 @@ public class MCSpecificBlock implements IBlock { public String getDisplayName() { return block.getLocalizedName(); } + + @Override + public String toString() { + return ""; + } + + private static String getBlockId(Block block) + { + return Block.blockRegistry.getNameForObject(block); + } } diff --git a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/network/MineTweakerCopyClipboardHandler.java b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/network/MineTweakerCopyClipboardHandler.java new file mode 100644 index 0000000..512696d --- /dev/null +++ b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/network/MineTweakerCopyClipboardHandler.java @@ -0,0 +1,32 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package minetweaker.mc172.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 java.awt.Desktop; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; + +/** + * + * @author Stan + */ +public class MineTweakerCopyClipboardHandler implements IMessageHandler { + @Override + public IMessage onMessage(MineTweakerCopyClipboardPacket message, MessageContext ctx) { + if (Desktop.isDesktopSupported()) { + StringSelection stringSelection = new StringSelection(message.getData()); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + + return null; + } +} \ No newline at end of file diff --git a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/network/MineTweakerCopyClipboardPacket.java b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/network/MineTweakerCopyClipboardPacket.java new file mode 100644 index 0000000..f8b3aab --- /dev/null +++ b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/network/MineTweakerCopyClipboardPacket.java @@ -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.mc172.network; + +import static com.google.common.base.Charsets.UTF_8; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import io.netty.buffer.ByteBuf; +import java.nio.ByteBuffer; + +/** + * + * @author Stan + */ +public class MineTweakerCopyClipboardPacket implements IMessage +{ + private String data; + + public MineTweakerCopyClipboardPacket() { + } + + public MineTweakerCopyClipboardPacket(String data) { + this.data = data; + } + + public String getData() { + return data; + } + + @Override + public void fromBytes(ByteBuf buf) { + data = UTF_8.decode(ByteBuffer.wrap(buf.array())).toString().trim(); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeBytes(UTF_8.encode(data).array()); + } +} diff --git a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/player/MCPlayer.java b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/player/MCPlayer.java index 7884623..847ee5b 100644 --- a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/player/MCPlayer.java +++ b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/player/MCPlayer.java @@ -14,6 +14,7 @@ import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.player.IPlayer; import minetweaker.mc172.MineTweakerMod; import minetweaker.mc172.data.NBTConverter; +import minetweaker.mc172.network.MineTweakerCopyClipboardPacket; import minetweaker.mc172.network.MineTweakerOpenBrowserPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -114,6 +115,15 @@ public class MCPlayer implements IPlayer { (EntityPlayerMP) player); } } + + @Override + public void copyToClipboard(String value) { + if (player instanceof EntityPlayerMP) { + MineTweakerMod.NETWORK.sendTo( + new MineTweakerCopyClipboardPacket(value), + (EntityPlayerMP) player); + } + } @Override public void give(IItemStack stack) { diff --git a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/server/ServerPlayer.java b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/server/ServerPlayer.java index 124bd82..2d51aeb 100644 --- a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/server/ServerPlayer.java +++ b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/server/ServerPlayer.java @@ -7,6 +7,9 @@ package minetweaker.mc172.server; import java.awt.Desktop; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.io.IOException; import java.net.URI; import java.util.logging.Level; @@ -106,6 +109,15 @@ public class ServerPlayer implements IPlayer { } } } + + @Override + public void copyToClipboard(String value) { + if (Desktop.isDesktopSupported()) { + StringSelection stringSelection = new StringSelection(value); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + } @Override public void give(IItemStack stack) {