Further BaseBlock modernisation

This commit is contained in:
Matthew Miller
2018-06-18 17:53:33 +10:00
parent 811f1d4433
commit e99190225e
61 changed files with 344 additions and 787 deletions

View File

@ -125,7 +125,7 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
return blockInHand;
}
blockType = blockInHand.getType();
blockType = blockInHand.getBlockType();
blockStates = blockInHand.getStates();
} else if ("offhand".equalsIgnoreCase(typeString)) {
// Get the block type from the item in the user's off hand.
@ -134,7 +134,7 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
return blockInHand;
}
blockType = blockInHand.getType();
blockType = blockInHand.getBlockType();
blockStates = blockInHand.getStates();
} else if ("pos1".equalsIgnoreCase(typeString)) {
// Get the block type from the "primary position"
@ -150,7 +150,7 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
return blockInHand;
}
blockType = blockInHand.getType();
blockType = blockInHand.getBlockType();
blockStates = blockInHand.getStates();
} else {
// Attempt to lookup a block from ID or name.

View File

@ -33,45 +33,11 @@ public class DefaultItemParser extends InputParser<BaseItem> {
@Override
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
String[] tokens = input.split(":", 3);
BaseItem item;
short damage = 0;
try {
int id = Integer.parseInt(tokens[0]);
// Parse metadata
if (tokens.length == 2) {
try {
damage = Short.parseShort(tokens[1]);
} catch (NumberFormatException ignored) {
throw new InputParseException("Expected '" + tokens[1] + "' to be a damage value but it's not a number");
}
}
item = context.requireWorld().getWorldData().getItemRegistry().createFromId(id);
} catch (NumberFormatException e) {
String name = tokens[0];
if (input.length() >= 2) {
name += ":" + tokens[1];
}
// Parse metadata
if (tokens.length == 3) {
try {
damage = Short.parseShort(tokens[2]);
} catch (NumberFormatException ignored) {
throw new InputParseException("Expected '" + tokens[2] + "' to be a damage value but it's not a number");
}
}
item = context.requireWorld().getWorldData().getItemRegistry().createFromId(name);
}
BaseItem item = context.requireWorld().getWorldData().getItemRegistry().createFromId(input);
if (item == null) {
throw new InputParseException("'" + input + "' did not match any item");
} else {
item.setDamage(damage);
return item;
}
}

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.PlayerDirection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
@ -366,9 +365,6 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
final ItemType typeId = getItemInHand(handSide).getType();
if (!getWorld().isValidBlockType(typeId.getLegacyId())) {
throw new NotABlockException(typeId.getId());
}
return new BaseBlock(typeId.getLegacyId());
}

View File

@ -65,8 +65,8 @@ class PlayerProxy extends AbstractPlayerActor {
}
@Override
public void giveItem(int type, int amount) {
basePlayer.giveItem(type, amount);
public void giveItem(BaseItemStack itemStack) {
basePlayer.giveItem(itemStack);
}
@Override