Permalink
Browse files

Simplify item durability

  • Loading branch information...
PseudoKnight committed Dec 31, 2017
1 parent 26ff57c commit a4ffb5f96f4b6c2a6168151b849ee3d317eecfc1
@@ -20,7 +20,6 @@
import com.laytonsmith.abstraction.MCLeatherArmorMeta;
import com.laytonsmith.abstraction.MCLivingEntity;
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.MCMaterialData;
import com.laytonsmith.abstraction.MCMapMeta;
import com.laytonsmith.abstraction.MCMetadataValue;
import com.laytonsmith.abstraction.MCOfflinePlayer;
@@ -231,22 +230,10 @@ public Construct item(MCItemStack is, Target t) {
}
MCMaterial mat = is.getType();
int data = 0;
if(mat.isBlock()){
//Use the data
MCMaterialData md = is.getData();
if(md != null) {
data = md.getData();
}
} else {
//Use the durability
data = is.getDurability();
}
CArray ret = CArray.GetAssociativeArray(t);
ret.set("name", new CString(mat.getName(), t), t);
ret.set("type", new CInt(mat.getType(), t), t);
ret.set("data", new CInt(data, t), t);
ret.set("data", new CInt(is.getDurability(), t), t);
ret.set("qty", new CInt(is.getAmount(), t), t);
ret.set("enchants", enchants(is.getEnchantments(), t), t);
ret.set("meta", itemMeta(is, t), t);
@@ -10,7 +10,6 @@
import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCLivingEntity;
import com.laytonsmith.abstraction.MCMaterialData;
import com.laytonsmith.abstraction.MCMetadatable;
import com.laytonsmith.abstraction.MCOfflinePlayer;
import com.laytonsmith.abstraction.MCPlayer;
@@ -600,27 +599,18 @@ public static MCItemStack ParseItemNotation(String functionName, String notation
return StaticLayer.GetItemStack(type, data, qty);
}
/**
* Works in reverse from the other ParseItemNotation
*
* @param is
* @return
*/
public static String ParseItemNotation(MCItemStack is) {
if (is == null) {
return "0";
}
String append = null;
if (is.getDurability() != 0) {
append = Short.toString(is.getDurability());
} else {
MCMaterialData md = is.getData();
if (md != null) {
append = Integer.toString(md.getData());
}
/**
* Works in reverse from the other ParseItemNotation
*
* @param is
* @return
*/
public static String ParseItemNotation(MCItemStack is) {
if (is == null) {
return "0";
}
return is.getTypeId() + (is.getDurability() == 0 ? "" : ":" + Short.toString(is.getDurability()));
}
return is.getTypeId() + (append == null ? "" : ":" + append);
}
public static String ParseItemNotation(MCBlock b) {
if (b == null || b.isNull()) {
@@ -937,17 +937,7 @@ public Construct exec(Target t, Environment env, Construct... args) throws Cance
if (index == 6 || index == -1) {
//Item in hand
MCItemStack is = p.getItemInHand();
int data;
if (is.getType().isBlock()) {
if (is.getData() != null) {
data = is.getData().getData();
} else {
data = 0;
}
} else {
data = is.getDurability();
}
retVals.add(new CString(is.getTypeId() + ":" + data, t));
retVals.add(new CString(is.getTypeId() + ":" + is.getDurability(), t));
}
if (index == 7 || index == -1) {
//World name

0 comments on commit a4ffb5f

Please sign in to comment.