1515import com .laytonsmith .abstraction .StaticLayer ;
1616import com .laytonsmith .abstraction .blocks .MCBlockData ;
1717import com .laytonsmith .abstraction .blocks .MCBlockFace ;
18+ import com .laytonsmith .abstraction .blocks .MCBlockState ;
1819import com .laytonsmith .abstraction .blocks .MCMaterial ;
1920import com .laytonsmith .abstraction .enums .MCEffect ;
2021import com .laytonsmith .abstraction .enums .MCEntityType ;
@@ -888,15 +889,15 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
888889 w = p .getWorld ();
889890 }
890891 MCLocation location = ObjectGenerator .GetGenerator ().location (args [0 ], w , t );
891- if (location .getBlock ().getState () instanceof MCCreatureSpawner ) {
892- MCEntityType entityType = ((MCCreatureSpawner ) location .getBlock ().getState ()).getSpawnedType ();
893- if (entityType == null ) {
894- return CNull .NULL ;
895- }
896- return new CString (entityType .name (), t );
897- } else {
898- throw new CREFormatException ("The block at " + location .toString () + " is not a spawner block" , t );
892+ MCBlockState state = location .getBlock ().getState ();
893+ if (!(state instanceof MCCreatureSpawner )) {
894+ throw new CREFormatException ("The block at " + location + " is not a spawner block" , t );
895+ }
896+ MCEntityType entityType = ((MCCreatureSpawner ) state ).getSpawnedType ();
897+ if (entityType == null ) {
898+ return CNull .NULL ;
899899 }
900+ return new CString (entityType .name (), t );
900901 }
901902
902903 @ Override
@@ -911,7 +912,8 @@ public Integer[] numArgs() {
911912
912913 @ Override
913914 public String docs () {
914- return "string {locationArray} Gets the entity type that will spawn from the specified mob spawner." ;
915+ return "string {locationArray} Gets the entity type that will spawn from the specified mob spawner."
916+ + " May be null." ;
915917 }
916918
917919 @ Override
@@ -947,18 +949,21 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
947949 w = p .getWorld ();
948950 }
949951 MCLocation location = ObjectGenerator .GetGenerator ().location (args [0 ], w , t );
950- MCEntityType type ;
951- try {
952- type = MCEntityType .valueOf (args [1 ].val ().toUpperCase ());
953- } catch (IllegalArgumentException iae ) {
954- throw new CREBadEntityException ("Not a registered entity type: " + args [1 ].val (), t );
952+ MCBlockState state = location .getBlock ().getState ();
953+ if (!(state instanceof MCCreatureSpawner )) {
954+ throw new CREFormatException ("The block at " + location + " is not a spawner block" , t );
955955 }
956- if (location . getBlock (). getState () instanceof MCCreatureSpawner ) {
957- ((MCCreatureSpawner ) location . getBlock (). getState ()). setSpawnedType (type );
956+ if (args [ 1 ] instanceof CNull ) {
957+ ((MCCreatureSpawner ) state ). setSpawnedType (null );
958958 return CVoid .VOID ;
959- } else {
960- throw new CREFormatException ("The block at " + location .toString () + " is not a spawner block" , t );
961959 }
960+ try {
961+ MCEntityType type = MCEntityType .valueOf (args [1 ].val ().toUpperCase ());
962+ ((MCCreatureSpawner ) state ).setSpawnedType (type );
963+ } catch (IllegalArgumentException iae ) {
964+ throw new CREBadEntityException ("Not a valid entity type: " + args [1 ].val (), t );
965+ }
966+ return CVoid .VOID ;
962967 }
963968
964969 @ Override
@@ -974,7 +979,8 @@ public Integer[] numArgs() {
974979 @ Override
975980 public String docs () {
976981 return "void {locationArray, type} Sets the mob spawner's entity type at the location specified."
977- + " If the location is not a mob spawner, or if the type is invalid, a FormatException is thrown."
982+ + " If the location is not a mob spawner, a FormatException is thrown."
983+ + " Entity type may be set to null. If the entity type is invalid, a BadEntityException is thrown."
978984 + " ---- The type may be one of either "
979985 + StringUtils .Join (MCEntityType .MCVanillaEntityType .values (), ", " , ", or " );
980986 }
0 commit comments