32
32
import com .laytonsmith .core .constructs .CArray ;
33
33
import com .laytonsmith .core .constructs .CBoolean ;
34
34
import com .laytonsmith .core .constructs .CInt ;
35
+ import com .laytonsmith .core .constructs .CNull ;
35
36
import com .laytonsmith .core .constructs .CString ;
36
37
import com .laytonsmith .core .constructs .Target ;
37
38
import com .laytonsmith .core .events .AbstractEvent ;
41
42
import com .laytonsmith .core .events .Prefilters ;
42
43
import com .laytonsmith .core .events .Prefilters .PrefilterType ;
43
44
import com .laytonsmith .core .exceptions .CRE .CREBindException ;
45
+ import com .laytonsmith .core .exceptions .CRE .CRECastException ;
44
46
import com .laytonsmith .core .exceptions .CRE .CREFormatException ;
45
47
import com .laytonsmith .core .exceptions .ConfigRuntimeException ;
46
48
import com .laytonsmith .core .exceptions .EventException ;
@@ -903,7 +905,7 @@ public String docs() {
903
905
+ " {viewers: all humanentities viewing the screen this event takes place in | matrix | result"
904
906
+ " | isRepair: true if this event was triggered by a repair operation (different than normal crafting)"
905
907
+ " | 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. }"
907
909
+ " {}" ;
908
910
}
909
911
@@ -938,6 +940,7 @@ public Map<String, Mixed> evaluate(BindableEvent event) throws EventException {
938
940
for (int i = 0 ; i < mi .length ; i ++) {
939
941
matrix .set (i , ObjectGenerator .GetGenerator ().item (mi [i ], t ), t );
940
942
}
943
+ ret .put ("inventorytype" , new CString (e .getInventory ().getType ().toString (), t ));
941
944
ret .put ("matrix" , matrix );
942
945
ret .put ("result" , ObjectGenerator .GetGenerator ().item (e .getInventory ().getResult (), t ));
943
946
return ret ;
@@ -953,34 +956,13 @@ public Driver driver() {
953
956
954
957
@ Override
955
958
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 ;
958
961
if ("result" .equals (key )) {
959
- e.getInventory().setResult(ObjectGenerator.GetGenerator().item(value, Target.UNKNOWN ));
962
+ e .getInventory ().setResult (ObjectGenerator .GetGenerator ().item (value , t ));
960
963
return true ;
961
964
}
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
+ }
984
966
return false ;
985
967
}
986
968
0 commit comments