Skip to content

Commit dc3e60e

Browse files
committed
fixing modify_event for item_pre_craft result
1 parent ace9b67 commit dc3e60e

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.laytonsmith.core.constructs.CArray;
3333
import com.laytonsmith.core.constructs.CBoolean;
3434
import com.laytonsmith.core.constructs.CInt;
35+
import com.laytonsmith.core.constructs.CNull;
3536
import com.laytonsmith.core.constructs.CString;
3637
import com.laytonsmith.core.constructs.Target;
3738
import com.laytonsmith.core.events.AbstractEvent;
@@ -41,6 +42,7 @@
4142
import com.laytonsmith.core.events.Prefilters;
4243
import com.laytonsmith.core.events.Prefilters.PrefilterType;
4344
import com.laytonsmith.core.exceptions.CRE.CREBindException;
45+
import com.laytonsmith.core.exceptions.CRE.CRECastException;
4446
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
4547
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
4648
import com.laytonsmith.core.exceptions.EventException;
@@ -903,7 +905,7 @@ public String docs() {
903905
+ " {viewers: all humanentities viewing the screen this event takes place in | matrix | result"
904906
+ " | isRepair: true if this event was triggered by a repair operation (different than normal crafting)"
905907
+ " | recipe: information about the formed recipe, or null if there is not one}"
906-
+ " {}"/*" {matrix: the slots that make up the crafting grid | result: the result slot of crafting}"*/
908+
+ " { result: the product of the recipe. }"
907909
+ " {}";
908910
}
909911

@@ -938,6 +940,7 @@ public Map<String, Mixed> evaluate(BindableEvent event) throws EventException {
938940
for(int i = 0; i < mi.length; i++) {
939941
matrix.set(i, ObjectGenerator.GetGenerator().item(mi[i], t), t);
940942
}
943+
ret.put("inventorytype", new CString(e.getInventory().getType().toString(), t));
941944
ret.put("matrix", matrix);
942945
ret.put("result", ObjectGenerator.GetGenerator().item(e.getInventory().getResult(), t));
943946
return ret;
@@ -953,34 +956,13 @@ public Driver driver() {
953956

954957
@Override
955958
public boolean modifyEvent(String key, Mixed value, BindableEvent event) {
956-
/*if(event instanceof MCPrepareItemCraftEvent) {
957-
MCPrepareItemCraftEvent e = (MCPrepareItemCraftEvent) event;
959+
if(event instanceof MCPrepareItemCraftEvent e) {
960+
Target t = Target.UNKNOWN;
958961
if("result".equals(key)) {
959-
e.getInventory().setResult(ObjectGenerator.GetGenerator().item(value, Target.UNKNOWN));
962+
e.getInventory().setResult(ObjectGenerator.GetGenerator().item(value, t));
960963
return true;
961964
}
962-
if("matrix".equals(key)) {
963-
if(value.isInstanceOf(CArray.TYPE)) {
964-
CArray va = (CArray) value;
965-
MCItemStack[] old = e.getInventory().getMatrix();
966-
MCItemStack[] repl = new MCItemStack[old.length];
967-
for(int i=0; i<repl.length; i++) {
968-
if(va.containsKey(i)) {
969-
repl[i] = ObjectGenerator.GetGenerator().item(va, Target.UNKNOWN);
970-
}
971-
}
972-
e.getInventory().setMatrix(repl);
973-
return true;
974-
} else if(value instanceof CNull) {
975-
MCItemStack[] old = e.getInventory().getMatrix();
976-
MCItemStack[] repl = new MCItemStack[old.length];
977-
e.getInventory().setMatrix(repl);
978-
return true;
979-
} else {
980-
throw new CRECastException("Expected an array but received " + value, Target.UNKNOWN);
981-
}
982-
}
983-
} */
965+
}
984966
return false;
985967
}
986968

0 commit comments

Comments
 (0)