Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-09-06 16:12:51 +02:00
Further BaseBlock modernisation
Dieser Commit ist enthalten in:
Ursprung
811f1d4433
Commit
e99190225e
@ -48,7 +48,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
|
||||
public List<BaseBiome> getBiomes() {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
List<BaseBiome> biomes = new ArrayList<BaseBiome>();
|
||||
List<BaseBiome> biomes = new ArrayList<>();
|
||||
for (Biome biome : Biome.values()) {
|
||||
int biomeId = adapter.getBiomeId(biome);
|
||||
biomes.add(new BaseBiome(biomeId));
|
||||
@ -65,12 +65,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
final Biome bukkitBiome = adapter.getBiome(biome.getId());
|
||||
return new BiomeData() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return bukkitBiome.name();
|
||||
}
|
||||
};
|
||||
return bukkitBiome::name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class BukkitEntity implements Entity {
|
||||
*/
|
||||
BukkitEntity(org.bukkit.entity.Entity entity) {
|
||||
checkNotNull(entity);
|
||||
this.entityRef = new WeakReference<org.bukkit.entity.Entity>(entity);
|
||||
this.entityRef = new WeakReference<>(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,8 +78,8 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(int type, int amt) {
|
||||
player.getInventory().addItem(new ItemStack(type, amt));
|
||||
public void giveItem(BaseItemStack itemStack) {
|
||||
player.getInventory().addItem(new ItemStack(itemStack.getLegacyId(), itemStack.getAmount()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,8 @@ package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBagException;
|
||||
import com.sk89q.worldedit.extent.inventory.OutOfBlocksException;
|
||||
@ -64,13 +65,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
|
||||
@Override
|
||||
public void fetchItem(BaseItem item) throws BlockBagException {
|
||||
final int id = item.getLegacyId();
|
||||
final int damage = item.getData();
|
||||
final ItemType id = item.getType();
|
||||
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
|
||||
assert(amount == 1);
|
||||
boolean usesDamageValue = true;// TODO ItemType.usesDamageValue(id);
|
||||
|
||||
if (id == BlockID.AIR) {
|
||||
if (id == ItemTypes.AIR) {
|
||||
throw new IllegalArgumentException("Can't fetch air block");
|
||||
}
|
||||
|
||||
@ -85,16 +84,12 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bukkitItem.getTypeId() != id) {
|
||||
if (bukkitItem.getTypeId() != id.getLegacyId()) {
|
||||
// TODO Fix when bukkit gets not awful
|
||||
// Type id doesn't fit
|
||||
continue;
|
||||
}
|
||||
|
||||
if (usesDamageValue && bukkitItem.getDurability() != damage) {
|
||||
// Damage value doesn't fit.
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentAmount = bukkitItem.getAmount();
|
||||
if (currentAmount < 0) {
|
||||
// Unlimited
|
||||
@ -119,13 +114,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
|
||||
@Override
|
||||
public void storeItem(BaseItem item) throws BlockBagException {
|
||||
final int id = item.getLegacyId();
|
||||
final int damage = item.getData();
|
||||
final ItemType id = item.getType();
|
||||
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
|
||||
assert(amount <= 64);
|
||||
boolean usesDamageValue = true; //TODO ItemType.usesDamageValue(id);
|
||||
|
||||
if (id == BlockID.AIR) {
|
||||
if (id == ItemTypes.AIR) {
|
||||
throw new IllegalArgumentException("Can't store air block");
|
||||
}
|
||||
|
||||
@ -146,16 +139,12 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bukkitItem.getTypeId() != id) {
|
||||
if (bukkitItem.getTypeId() != id.getLegacyId()) {
|
||||
// TODO Fix when bukkit gets not terrible
|
||||
// Type id doesn't fit
|
||||
continue;
|
||||
}
|
||||
|
||||
if (usesDamageValue && bukkitItem.getDurability() != damage) {
|
||||
// Damage value doesn't fit.
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentAmount = bukkitItem.getAmount();
|
||||
if (currentAmount < 0) {
|
||||
// Unlimited
|
||||
@ -177,7 +166,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
}
|
||||
|
||||
if (freeSlot > -1) {
|
||||
items[freeSlot] = new ItemStack(id, amount);
|
||||
items[freeSlot] = new ItemStack(id.getLegacyId(), amount); // TODO Ditto
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,13 @@
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.NotABlockException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import org.bukkit.DyeColor;
|
||||
@ -131,7 +130,7 @@ public final class BukkitUtil {
|
||||
case ItemID.INK_SACK:
|
||||
final Dye materialData = (Dye) itemStack.getData();
|
||||
if (materialData.getColor() == DyeColor.BROWN) {
|
||||
return new BaseBlock(BlockID.COCOA_PLANT, -1);
|
||||
return new BaseBlock(BlockTypes.COCOA);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -143,11 +142,7 @@ public final class BukkitUtil {
|
||||
break;
|
||||
}
|
||||
|
||||
if (world.isValidBlockType(typeId)) {
|
||||
return new BaseBlock(typeId, -1);
|
||||
}
|
||||
|
||||
throw new NotABlockException(typeId);
|
||||
return new BaseBlock(typeId, -1);
|
||||
}
|
||||
|
||||
public static BaseItemStack toBaseItemStack(ItemStack itemStack) {
|
||||
|
@ -248,36 +248,6 @@ public class BukkitWorld extends AbstractWorld {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateBigTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateBirchTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.TALL_REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
|
||||
*/
|
||||
@ -323,16 +293,10 @@ public class BukkitWorld extends AbstractWorld {
|
||||
@Override
|
||||
public void dropItem(Vector pt, BaseItemStack item) {
|
||||
World world = getWorld();
|
||||
ItemStack bukkitItem = new ItemStack(item.getLegacyId(), item.getAmount(),
|
||||
item.getData());
|
||||
ItemStack bukkitItem = new ItemStack(item.getLegacyId(), item.getAmount()); // TODO Add data.
|
||||
world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int type) {
|
||||
return Material.getMaterial(type) != null && Material.getMaterial(type).isBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(Vector pt) {
|
||||
World world = getWorld();
|
||||
@ -415,7 +379,7 @@ public class BukkitWorld extends AbstractWorld {
|
||||
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
|
||||
} else {
|
||||
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
return bukkitBlock.setTypeIdAndData(block.getType().getLegacyId(), (byte) block.getData(), notifyAndLight);
|
||||
return bukkitBlock.setTypeIdAndData(block.getBlockType().getLegacyId(), (byte) block.getData(), notifyAndLight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.type.BlockType;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
import com.sk89q.worldedit.world.registry.state.value.StateValue;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
import com.sk89q.worldedit.blocks.type.BlockType;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
/**
|
||||
* A implementation of a lazy block for {@link Extent#getLazyBlock(Vector)}
|
||||
@ -65,14 +62,13 @@ public class LazyBlock extends BaseBlock {
|
||||
/**
|
||||
* Create a new lazy block.
|
||||
*
|
||||
* @param type the block type
|
||||
* @param states the block states
|
||||
* @param state the block state
|
||||
* @param extent the extent to later load the full block data from
|
||||
* @param position the position to later load the full block data from
|
||||
*/
|
||||
@Deprecated
|
||||
public LazyBlock(BlockType type, Map<State, StateValue> states, Extent extent, Vector position) {
|
||||
super(type, states);
|
||||
public LazyBlock(BlockState state, Extent extent, Vector position) {
|
||||
super(state);
|
||||
checkNotNull(extent);
|
||||
checkNotNull(position);
|
||||
this.extent = extent;
|
||||
@ -96,31 +92,12 @@ public class LazyBlock extends BaseBlock {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(int id) {
|
||||
throw new UnsupportedOperationException("This object is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(int data) {
|
||||
throw new UnsupportedOperationException("This object is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(BlockType type) {
|
||||
throw new UnsupportedOperationException("This object is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state, StateValue stateValue) {
|
||||
throw new UnsupportedOperationException("This object is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
if (!loaded) {
|
||||
BaseBlock loadedBlock = extent.getBlock(position);
|
||||
super.setNbtData(loadedBlock.getNbtData());
|
||||
loaded = true;
|
||||
}
|
||||
return super.getNbtData();
|
||||
}
|
||||
|
@ -1063,7 +1063,7 @@ public class EditSession implements Extent {
|
||||
// Remove the original blocks
|
||||
com.sk89q.worldedit.function.pattern.Pattern pattern = replacement != null ?
|
||||
new BlockPattern(replacement) :
|
||||
new BlockPattern(new BaseBlock(BlockID.AIR));
|
||||
new BlockPattern(new BaseBlock(BlockTypes.AIR));
|
||||
BlockReplace remove = new BlockReplace(this, pattern);
|
||||
|
||||
// Copy to a buffer so we don't destroy our original before we can copy all the blocks from it
|
||||
@ -1143,22 +1143,22 @@ public class EditSession implements Extent {
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int fixLiquid(Vector origin, double radius, int moving, int stationary) throws MaxChangedBlocksException {
|
||||
public int fixLiquid(Vector origin, double radius, com.sk89q.worldedit.blocks.type.BlockType moving, com.sk89q.worldedit.blocks.type.BlockType stationary) throws MaxChangedBlocksException {
|
||||
checkNotNull(origin);
|
||||
checkArgument(radius >= 0, "radius >= 0 required");
|
||||
|
||||
// Our origins can only be liquids
|
||||
BlockMask liquidMask = new BlockMask(
|
||||
this,
|
||||
new BaseBlock(moving, -1),
|
||||
new BaseBlock(stationary, -1));
|
||||
new BaseBlock(moving),
|
||||
new BaseBlock(stationary));
|
||||
|
||||
// But we will also visit air blocks
|
||||
MaskIntersection blockMask =
|
||||
new MaskUnion(liquidMask,
|
||||
new BlockMask(
|
||||
this,
|
||||
new BaseBlock(BlockID.AIR)));
|
||||
new BaseBlock(BlockTypes.AIR)));
|
||||
|
||||
// There are boundaries that the routine needs to stay in
|
||||
MaskIntersection mask = new MaskIntersection(
|
||||
@ -1449,7 +1449,7 @@ public class EditSession implements Extent {
|
||||
|
||||
for (int y = world.getMaxY(); y >= 1; --y) {
|
||||
Vector pt = new Vector(x, y, z);
|
||||
com.sk89q.worldedit.blocks.type.BlockType id = getLazyBlock(pt).getType();
|
||||
com.sk89q.worldedit.blocks.type.BlockType id = getLazyBlock(pt).getBlockType();
|
||||
|
||||
if (id == BlockTypes.ICE) {
|
||||
if (setBlock(pt, water)) {
|
||||
@ -1657,14 +1657,14 @@ public class EditSession implements Extent {
|
||||
|
||||
for (int y = basePosition.getBlockY(); y >= basePosition.getBlockY() - 10; --y) {
|
||||
// Check if we hit the ground
|
||||
int t = getBlock(new Vector(x, y, z)).getType().getLegacyId();
|
||||
if (t == BlockID.GRASS || t == BlockID.DIRT) {
|
||||
com.sk89q.worldedit.blocks.type.BlockType t = getBlock(new Vector(x, y, z)).getBlockType();
|
||||
if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) {
|
||||
treeGenerator.generate(this, new Vector(x, y + 1, z));
|
||||
++affected;
|
||||
break;
|
||||
} else if (t == BlockID.SNOW) {
|
||||
setBlock(new Vector(x, y, z), new BaseBlock(BlockID.AIR));
|
||||
} else if (t != BlockID.AIR) { // Trees won't grow on this!
|
||||
} else if (t == BlockTypes.SNOW) {
|
||||
setBlock(new Vector(x, y, z), new BaseBlock(BlockTypes.AIR));
|
||||
} else if (t != BlockTypes.AIR) { // Trees won't grow on this!
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1680,9 +1680,9 @@ public class EditSession implements Extent {
|
||||
* @param region a region
|
||||
* @return the results
|
||||
*/
|
||||
public List<Countable<Integer>> getBlockDistribution(Region region) {
|
||||
List<Countable<Integer>> distribution = new ArrayList<>();
|
||||
Map<Integer, Countable<Integer>> map = new HashMap<>();
|
||||
public List<Countable<com.sk89q.worldedit.blocks.type.BlockType>> getBlockDistribution(Region region) {
|
||||
List<Countable<com.sk89q.worldedit.blocks.type.BlockType>> distribution = new ArrayList<>();
|
||||
Map<com.sk89q.worldedit.blocks.type.BlockType, Countable<com.sk89q.worldedit.blocks.type.BlockType>> map = new HashMap<>();
|
||||
|
||||
if (region instanceof CuboidRegion) {
|
||||
// Doing this for speed
|
||||
@ -1701,13 +1701,13 @@ public class EditSession implements Extent {
|
||||
for (int z = minZ; z <= maxZ; ++z) {
|
||||
Vector pt = new Vector(x, y, z);
|
||||
|
||||
int id = getLazyBlock(pt).getId();
|
||||
com.sk89q.worldedit.blocks.type.BlockType type = getLazyBlock(pt).getBlockType();
|
||||
|
||||
if (map.containsKey(id)) {
|
||||
map.get(id).increment();
|
||||
if (map.containsKey(type)) {
|
||||
map.get(type).increment();
|
||||
} else {
|
||||
Countable<Integer> c = new Countable<>(id, 1);
|
||||
map.put(id, c);
|
||||
Countable<com.sk89q.worldedit.blocks.type.BlockType> c = new Countable<>(type, 1);
|
||||
map.put(type, c);
|
||||
distribution.add(c);
|
||||
}
|
||||
}
|
||||
@ -1715,13 +1715,13 @@ public class EditSession implements Extent {
|
||||
}
|
||||
} else {
|
||||
for (Vector pt : region) {
|
||||
int id = getLazyBlock(pt).getId();
|
||||
com.sk89q.worldedit.blocks.type.BlockType type = getLazyBlock(pt).getBlockType();
|
||||
|
||||
if (map.containsKey(id)) {
|
||||
map.get(id).increment();
|
||||
if (map.containsKey(type)) {
|
||||
map.get(type).increment();
|
||||
} else {
|
||||
Countable<Integer> c = new Countable<>(id, 1);
|
||||
map.put(id, c);
|
||||
Countable<com.sk89q.worldedit.blocks.type.BlockType> c = new Countable<>(type, 1);
|
||||
map.put(type, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1809,7 +1809,7 @@ public class EditSession implements Extent {
|
||||
final Vector scaled = current.subtract(zero).divide(unit);
|
||||
|
||||
try {
|
||||
if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ(), defaultMaterial.getType().getLegacyId(), defaultMaterial.getData()) <= 0) {
|
||||
if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ(), defaultMaterial.getBlockType().getLegacyId(), defaultMaterial.getData()) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -24,19 +24,18 @@ import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.blocks.type.BlockType;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
import com.sk89q.worldedit.world.registry.state.value.StateValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -54,13 +53,12 @@ import javax.annotation.Nullable;
|
||||
* as a "wildcard" block value, even though a {@link Mask} would be
|
||||
* more appropriate.</p>
|
||||
*/
|
||||
public class BaseBlock implements TileEntityBlock {
|
||||
public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
|
||||
// Instances of this class should be _as small as possible_ because there will
|
||||
// be millions of instances of this object.
|
||||
|
||||
private BlockType blockType;
|
||||
private Map<State, StateValue> states;
|
||||
private BlockState blockState;
|
||||
@Nullable
|
||||
private CompoundTag nbtData;
|
||||
|
||||
@ -68,18 +66,18 @@ public class BaseBlock implements TileEntityBlock {
|
||||
* Construct a block with the given ID and a data value of 0.
|
||||
*
|
||||
* @param id ID value
|
||||
* @see #setId(int)
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock(int id) {
|
||||
internalSetId(id);
|
||||
internalSetData(0);
|
||||
this.states = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a block with a state.
|
||||
*
|
||||
* @param blockState The blockstate
|
||||
*/
|
||||
public BaseBlock(BlockState blockState) {
|
||||
this.blockType = blockState.getBlockType();
|
||||
this.states = blockState.getStates();
|
||||
this.blockState = blockState;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,8 +86,18 @@ public class BaseBlock implements TileEntityBlock {
|
||||
* @param blockType The block type
|
||||
*/
|
||||
public BaseBlock(BlockType blockType) {
|
||||
internalSetType(blockType);
|
||||
this.states = new HashMap<>();
|
||||
this.blockState = blockType.getDefaultState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a block with the given ID, data value and NBT data structure.
|
||||
*
|
||||
* @param state The block state
|
||||
* @param nbtData NBT data, which may be null
|
||||
*/
|
||||
public BaseBlock(BlockState state, @Nullable CompoundTag nbtData) {
|
||||
this.blockState = state;
|
||||
setNbtData(nbtData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,27 +105,9 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*
|
||||
* @param id ID value
|
||||
* @param data data value
|
||||
* @see #setId(int)
|
||||
* @see #setData(int)
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock(int id, int data) {
|
||||
internalSetId(id);
|
||||
internalSetData(data);
|
||||
this.states = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a block with the given ID and data value.
|
||||
*
|
||||
* @param blockType The block type
|
||||
* @param states The states
|
||||
* @see #setId(int)
|
||||
* @see #setData(int)
|
||||
*/
|
||||
public BaseBlock(BlockType blockType, Map<State, StateValue> states) {
|
||||
internalSetType(blockType);
|
||||
setStates(states);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,22 +119,6 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock(int id, int data, @Nullable CompoundTag nbtData) {
|
||||
internalSetId(id);
|
||||
setData(data);
|
||||
setNbtData(nbtData);
|
||||
this.states = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a block with the given ID, data value and NBT data structure.
|
||||
*
|
||||
* @param blockType The block type
|
||||
* @param states The states
|
||||
* @param nbtData NBT data, which may be null
|
||||
*/
|
||||
public BaseBlock(BlockType blockType, Map<State, StateValue> states, @Nullable CompoundTag nbtData) {
|
||||
setType(blockType);
|
||||
setStates(states);
|
||||
setNbtData(nbtData);
|
||||
}
|
||||
|
||||
@ -154,7 +128,16 @@ public class BaseBlock implements TileEntityBlock {
|
||||
* @param other the other block
|
||||
*/
|
||||
public BaseBlock(BaseBlock other) {
|
||||
this(other.getType(), other.getStates(), other.getNbtData());
|
||||
this(other.getState(), other.getNbtData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block state
|
||||
*
|
||||
* @return The block state
|
||||
*/
|
||||
public BlockState getState() {
|
||||
return this.blockState;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,45 +147,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public int getId() {
|
||||
return this.blockType.getLegacyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block ID.
|
||||
*
|
||||
* @param type block type
|
||||
*/
|
||||
protected final void internalSetType(BlockType type) {
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("You must provide a BlockType");
|
||||
}
|
||||
|
||||
this.blockType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block ID.
|
||||
*
|
||||
* @param id block id
|
||||
*/
|
||||
@Deprecated
|
||||
public void setId(int id) {
|
||||
internalSetId(id);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void internalSetId(int id) {
|
||||
BlockType type = BlockTypes.getBlockType(BundledBlockData.getInstance().fromLegacyId(id));
|
||||
internalSetType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block type.
|
||||
*
|
||||
* @param type block type
|
||||
*/
|
||||
public void setType(BlockType type) {
|
||||
internalSetType(type);
|
||||
return this.blockState.getBlockType().getLegacyId();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,16 +168,17 @@ public class BaseBlock implements TileEntityBlock {
|
||||
* @return The state map
|
||||
*/
|
||||
public Map<State, StateValue> getStates() {
|
||||
return Collections.unmodifiableMap(states);
|
||||
return this.blockState.getStates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the states of this block.
|
||||
*
|
||||
* @param states The states
|
||||
*/
|
||||
private void setStates(Map<State, StateValue> states) {
|
||||
this.states = states;
|
||||
@Override
|
||||
public BlockType getBlockType() {
|
||||
return this.blockState.getBlockType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock with(State state, StateValue value) {
|
||||
return new BaseBlock(this.blockState.with(state, value), getNbtData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,26 +188,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
* @return The state value
|
||||
*/
|
||||
public StateValue getState(State state) {
|
||||
return states.get(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a state to a specific value
|
||||
*
|
||||
* @param state The state
|
||||
* @param stateValue The value
|
||||
*/
|
||||
public void setState(State state, StateValue stateValue) {
|
||||
this.states.put(state, stateValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block's data value.
|
||||
*
|
||||
* @param data block data value
|
||||
*/
|
||||
@Deprecated
|
||||
protected final void internalSetData(int data) {
|
||||
return this.blockState.getState(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,34 +198,6 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public void setData(int data) {
|
||||
internalSetData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set both the block's ID and data value.
|
||||
*
|
||||
* @param id ID value
|
||||
* @param data data value
|
||||
* @see #setId(int)
|
||||
* @see #setData(int)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setIdAndData(int id, int data) {
|
||||
setId(id);
|
||||
setData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether there are no matched states.
|
||||
*
|
||||
* @return true if there are no matched states
|
||||
*/
|
||||
public boolean hasWildcardData() {
|
||||
return getStates().isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasWildcardDataFor(State state) {
|
||||
return getState(state) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -323,21 +222,12 @@ public class BaseBlock implements TileEntityBlock {
|
||||
@Nullable
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
return nbtData;
|
||||
return this.nbtData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of block.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
public BlockType getType() {
|
||||
return this.blockType;
|
||||
throw new UnsupportedOperationException("This class is immutable.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -346,7 +236,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
* @return if air
|
||||
*/
|
||||
public boolean isAir() {
|
||||
return getType() == BlockTypes.AIR;
|
||||
return getBlockType() == BlockTypes.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -357,7 +247,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public int rotate90() {
|
||||
int newData = BlockData.rotate90(getType().getLegacyId(), getData());
|
||||
int newData = BlockData.rotate90(getBlockType().getLegacyId(), getData());
|
||||
setData(newData);
|
||||
return newData;
|
||||
}
|
||||
@ -370,7 +260,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public int rotate90Reverse() {
|
||||
int newData = BlockData.rotate90Reverse(getType().getLegacyId(), getData());
|
||||
int newData = BlockData.rotate90Reverse(getBlockType().getLegacyId(), getData());
|
||||
setData((short) newData);
|
||||
return newData;
|
||||
}
|
||||
@ -384,7 +274,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public int cycleData(int increment) {
|
||||
int newData = BlockData.cycle(getType().getLegacyId(), getData(), increment);
|
||||
int newData = BlockData.cycle(getBlockType().getLegacyId(), getData(), increment);
|
||||
setData((short) newData);
|
||||
return newData;
|
||||
}
|
||||
@ -397,7 +287,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock flip() {
|
||||
setData((short) BlockData.flip(getType().getLegacyId(), getData()));
|
||||
setData((short) BlockData.flip(getBlockType().getLegacyId(), getData()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -410,7 +300,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock flip(FlipDirection direction) {
|
||||
setData((short) BlockData.flip(getType().getLegacyId(), getData(), direction));
|
||||
setData((short) BlockData.flip(getBlockType().getLegacyId(), getData(), direction));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -425,7 +315,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
|
||||
final BaseBlock otherBlock = (BaseBlock) o;
|
||||
|
||||
return getType() == otherBlock.getType() && getData() == otherBlock.getData();
|
||||
return this.getState().equals(otherBlock.getState()) && Objects.equals(getNbtData(), otherBlock.getNbtData());
|
||||
|
||||
}
|
||||
|
||||
@ -436,7 +326,7 @@ public class BaseBlock implements TileEntityBlock {
|
||||
* @return true if equal
|
||||
*/
|
||||
public boolean equalsFuzzy(BaseBlock o) {
|
||||
if (!getType().equals(o.getType())) {
|
||||
if (!getBlockType().equals(o.getBlockType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -484,14 +374,16 @@ public class BaseBlock implements TileEntityBlock {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int ret = getType().hashCode() << 3;
|
||||
ret += getStates().hashCode();
|
||||
int ret = getState().hashCode() << 3;
|
||||
if (hasNbtData()) {
|
||||
ret += getNbtData().hashCode();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Block{Type:" + getType().getId() + ", States: " + getStates().toString() + "}";
|
||||
return "Block{State: " + this.getState().toString() + ", NBT: " + String.valueOf(getNbtData()) + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,12 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledItemData;
|
||||
import com.sk89q.worldedit.world.NbtValued;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Represents an item, without an amount value. See {@link BaseItemStack}
|
||||
@ -32,11 +31,11 @@ import java.util.Map;
|
||||
*
|
||||
* <p>This class may be removed in the future.</p>
|
||||
*/
|
||||
public class BaseItem {
|
||||
public class BaseItem implements NbtValued {
|
||||
|
||||
private ItemType itemType;
|
||||
private short damage;
|
||||
private final Map<Integer, Integer> enchantments = new HashMap<>();
|
||||
@Nullable
|
||||
private CompoundTag nbtData;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
@ -45,7 +44,6 @@ public class BaseItem {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseItem(int id) {
|
||||
this(id, (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,27 +55,15 @@ public class BaseItem {
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id ID of the item
|
||||
* @param data data value of the item
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseItem(int id, short data) {
|
||||
setLegacyId(id);
|
||||
this.damage = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param itemType Type of the item
|
||||
* @param damage Damage value of the item
|
||||
* @param tag NBT Compound tag
|
||||
*/
|
||||
public BaseItem(ItemType itemType, short damage) {
|
||||
public BaseItem(ItemType itemType, CompoundTag tag) {
|
||||
this.itemType = itemType;
|
||||
this.damage = damage;
|
||||
this.nbtData = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,17 +76,6 @@ public class BaseItem {
|
||||
return this.itemType.getLegacyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of item.
|
||||
*
|
||||
* @param id the id to set
|
||||
*/
|
||||
@Deprecated
|
||||
public void setLegacyId(int id) {
|
||||
ItemType type = ItemTypes.getItemType(BundledItemData.getInstance().fromLegacyId(id));
|
||||
setType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of item.
|
||||
*
|
||||
@ -119,50 +94,19 @@ public class BaseItem {
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the damage value.
|
||||
*
|
||||
* @return the damage
|
||||
*/
|
||||
public short getDamage() {
|
||||
return this.damage;
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return this.nbtData != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data value.
|
||||
*
|
||||
* @return the data
|
||||
*/
|
||||
@Deprecated
|
||||
public short getData() {
|
||||
return this.damage;
|
||||
@Nullable
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
return this.nbtData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data value.
|
||||
*
|
||||
* @param damage the damage to set
|
||||
*/
|
||||
public void setDamage(short damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data value.
|
||||
*
|
||||
* @param data the damage to set
|
||||
*/
|
||||
@Deprecated
|
||||
public void setData(short data) {
|
||||
this.damage = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map of enchantments.
|
||||
*
|
||||
* @return map of enchantments
|
||||
*/
|
||||
public Map<Integer, Integer> getEnchantments() {
|
||||
return enchantments;
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
|
||||
/**
|
||||
@ -81,7 +82,7 @@ public class BaseItemStack extends BaseItem {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseItemStack(int id, int amount, short data) {
|
||||
super(id, data);
|
||||
super(id);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@ -89,11 +90,11 @@ public class BaseItemStack extends BaseItem {
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id The item type
|
||||
* @param tag Tag value
|
||||
* @param amount amount in the stack
|
||||
* @param damage Damage value
|
||||
*/
|
||||
public BaseItemStack(ItemType id, int amount, short damage) {
|
||||
super(id, damage);
|
||||
public BaseItemStack(ItemType id, CompoundTag tag, int amount) {
|
||||
super(id, tag);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
|
@ -1540,7 +1540,7 @@ public enum BlockType {
|
||||
|
||||
addIdentities(BlockID.DOUBLE_WOODEN_STEP, 7); // rule 3
|
||||
addIdentities(BlockID.WOODEN_STEP, 7); // rule 1
|
||||
nonDataBlockBagItems.put(BlockID.COCOA_PLANT, new BaseItem(ItemID.INK_SACK, (short) (15 - ClothColor.ID.BROWN))); // rule 3
|
||||
nonDataBlockBagItems.put(BlockID.COCOA_PLANT, new BaseItem(ItemID.INK_SACK)); // rule 3 TODO data removed
|
||||
addIdentity(BlockID.SANDSTONE_STAIRS); // rule 1
|
||||
nonDataBlockBagItems.put(BlockID.EMERALD_ORE, new BaseItem(ItemID.EMERALD)); // rule 5
|
||||
addIdentity(BlockID.ENDER_CHEST); // rule 3
|
||||
@ -1569,7 +1569,8 @@ public enum BlockType {
|
||||
addIdentity(BlockID.HOPPER); // rule 1
|
||||
addIdentities(BlockID.QUARTZ_BLOCK, 1); // rule 4
|
||||
for (int i = 2; i <= 4; i++) {
|
||||
dataBlockBagItems.put(typeDataKey(BlockID.QUARTZ_BLOCK, i), new BaseItem(BlockID.QUARTZ_BLOCK, (short) 2)); // rule 4, quartz pillars
|
||||
dataBlockBagItems.put(typeDataKey(BlockID.QUARTZ_BLOCK, i), new BaseItem(BlockID.QUARTZ_BLOCK)); // rule 4, quartz pillars TODO data
|
||||
// removed
|
||||
}
|
||||
addIdentity(BlockID.QUARTZ_STAIRS); // rule 1
|
||||
addIdentity(BlockID.ACTIVATOR_RAIL); // rule 1
|
||||
@ -1629,7 +1630,7 @@ public enum BlockType {
|
||||
|
||||
private static void addIdentities(int type, int maxData) {
|
||||
for (int data = 0; data < maxData; ++data) {
|
||||
dataBlockBagItems.put(typeDataKey(type, data), new BaseItem(type, (short) data));
|
||||
dataBlockBagItems.put(typeDataKey(type, data), new BaseItem(type)); // TODO data removed
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ import java.util.Map;
|
||||
* An immutable class that represents the state a block can be in.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class BlockState {
|
||||
public class BlockState implements BlockStateHolder<BlockState> {
|
||||
|
||||
private final BlockType blockType;
|
||||
private final Map<State, StateValue> values;
|
||||
@ -67,7 +67,7 @@ public class BlockState {
|
||||
for(final Map.Entry<State, StateValue> entry : this.values.entrySet()) {
|
||||
final State state = entry.getKey();
|
||||
|
||||
state.getValues().stream().forEach(value -> {
|
||||
state.getValues().forEach(value -> {
|
||||
if(value != entry.getValue()) {
|
||||
states.put(state, (StateValue) value, stateMap.get(this.withValue(state, (StateValue) value)));
|
||||
}
|
||||
@ -83,22 +83,12 @@ public class BlockState {
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block type
|
||||
*
|
||||
* @return The type
|
||||
*/
|
||||
@Override
|
||||
public BlockType getBlockType() {
|
||||
return this.blockType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a BlockState with the given state and value applied.
|
||||
*
|
||||
* @param state The state
|
||||
* @param value The value
|
||||
* @return The modified state, or same if could not be applied
|
||||
*/
|
||||
@Override
|
||||
public BlockState with(State state, StateValue value) {
|
||||
if (fuzzy) {
|
||||
return setState(state, value);
|
||||
@ -108,21 +98,12 @@ public class BlockState {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value at the given state
|
||||
*
|
||||
* @param state The state
|
||||
* @return The value
|
||||
*/
|
||||
@Override
|
||||
public StateValue getState(State state) {
|
||||
return this.values.get(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an immutable collection of the states.
|
||||
*
|
||||
* @return The states
|
||||
*/
|
||||
@Override
|
||||
public Map<State, StateValue> getStates() {
|
||||
return Collections.unmodifiableMap(this.values);
|
||||
}
|
||||
@ -136,7 +117,7 @@ public class BlockState {
|
||||
* @param value The value
|
||||
* @return The blockstate, for chaining
|
||||
*/
|
||||
BlockState setState(State state, StateValue value) {
|
||||
private BlockState setState(State state, StateValue value) {
|
||||
this.values.put(state, value);
|
||||
return this;
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks.type;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
import com.sk89q.worldedit.world.registry.state.value.StateValue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface BlockStateHolder<T extends BlockStateHolder> {
|
||||
|
||||
/**
|
||||
* Get the block type
|
||||
*
|
||||
* @return The type
|
||||
*/
|
||||
BlockType getBlockType();
|
||||
|
||||
/**
|
||||
* Returns a BlockState with the given state and value applied.
|
||||
*
|
||||
* @param state The state
|
||||
* @param value The value
|
||||
* @return The modified state, or same if could not be applied
|
||||
*/
|
||||
T with(State state, StateValue value);
|
||||
|
||||
/**
|
||||
* Gets the value at the given state
|
||||
*
|
||||
* @param state The state
|
||||
* @return The value
|
||||
*/
|
||||
StateValue getState(State state);
|
||||
|
||||
/**
|
||||
* Gets an immutable collection of the states.
|
||||
*
|
||||
* @return The states
|
||||
*/
|
||||
Map<State, StateValue> getStates();
|
||||
}
|
@ -34,6 +34,7 @@ import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -277,7 +278,7 @@ public class SelectionCommands {
|
||||
@CommandPermissions("worldedit.wand")
|
||||
public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
player.giveItem(ItemTypes.getItemType(we.getConfiguration().wandItem).getLegacyId(), 1);
|
||||
player.giveItem(new BaseItemStack(ItemTypes.getItemType(we.getConfiguration().wandItem), 1));
|
||||
player.print("Left click: select pos #1; Right click: select pos #2");
|
||||
}
|
||||
|
||||
@ -677,12 +678,12 @@ public class SelectionCommands {
|
||||
player.print("# total blocks: " + size);
|
||||
|
||||
for (Countable<BaseBlock> c : distributionData) {
|
||||
String name = c.getID().getType().getName();
|
||||
String name = c.getID().getBlockType().getName();
|
||||
String str = String.format("%-7s (%.3f%%) %s #%s%s",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
name,
|
||||
c.getID().getType().getId(),
|
||||
c.getID().getBlockType().getId(),
|
||||
c.getID().getStates());
|
||||
player.print(str);
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ public class ToolCommands {
|
||||
|
||||
session.setTool(itemStack.getType(), new LongRangeBuildTool(primary, secondary));
|
||||
player.print("Long-range building tool bound to " + itemStack.getType().getName() + ".");
|
||||
player.print("Left-click set to " + secondary.getType().getName() + "; right-click set to "
|
||||
+ primary.getType().getName() + ".");
|
||||
player.print("Left-click set to " + secondary.getBlockType().getName() + "; right-click set to "
|
||||
+ primary.getBlockType().getName() + ".");
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.command.util.CreatureButcher;
|
||||
import com.sk89q.worldedit.command.util.EntityRemover;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
@ -65,7 +66,6 @@ import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -176,7 +176,7 @@ public class UtilityCommands {
|
||||
double radius = Math.max(0, args.getDouble(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.fixLiquid(
|
||||
session.getPlacementPosition(player), radius, 10, 11);
|
||||
session.getPlacementPosition(player), radius, BlockTypes.FLOWING_LAVA, BlockTypes.LAVA);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ public class UtilityCommands {
|
||||
double radius = Math.max(0, args.getDouble(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.fixLiquid(
|
||||
session.getPlacementPosition(player), radius, 8, 9);
|
||||
session.getPlacementPosition(player), radius, BlockTypes.FLOWING_WATER, BlockTypes.WATER);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ public class UtilityCommands {
|
||||
int size = Math.max(1, args.getInteger(1, 50));
|
||||
we.checkMaxRadius(size);
|
||||
|
||||
int affected = editSession.removeNear(session.getPlacementPosition(player), block.getType().getLegacyId(), size);
|
||||
int affected = editSession.removeNear(session.getPlacementPosition(player), block.getBlockType().getLegacyId(), size);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ItemUseParser extends SimpleCommand<Contextual<RegionFunction>> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "application of the item " + item.getType() + ":" + item.getData();
|
||||
return "application of the item " + item.getType() + ":" + item.getNbtData();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class AreaPickaxe implements BlockTool {
|
||||
int ox = clicked.getBlockX();
|
||||
int oy = clicked.getBlockY();
|
||||
int oz = clicked.getBlockZ();
|
||||
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector()).getType();
|
||||
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector()).getBlockType();
|
||||
|
||||
if (initialType == BlockTypes.AIR) {
|
||||
return true;
|
||||
@ -68,7 +68,7 @@ public class AreaPickaxe implements BlockTool {
|
||||
for (int y = oy - range; y <= oy + range; ++y) {
|
||||
for (int z = oz - range; z <= oz + range; ++z) {
|
||||
Vector pos = new Vector(x, y, z);
|
||||
if (editSession.getBlock(pos).getType() != initialType) {
|
||||
if (editSession.getBlock(pos).getBlockType() != initialType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
targetBlock = (editSession).getBlock(clicked.toVector());
|
||||
BlockType type = targetBlock.getType().getLegacyType();
|
||||
BlockType type = targetBlock.getBlockType().getLegacyType();
|
||||
|
||||
if (type != null) {
|
||||
player.print("Replacer tool switched to: " + type.getName());
|
||||
|
@ -81,7 +81,7 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
}
|
||||
|
||||
for (Vector blockVector : blockSet) {
|
||||
final int typeId = editSession.getBlock(blockVector).getType().getLegacyId();
|
||||
final int typeId = editSession.getBlock(blockVector).getBlockType().getLegacyId();
|
||||
switch (typeId) {
|
||||
case BlockID.LOG:
|
||||
case BlockID.LOG2:
|
||||
|
@ -54,7 +54,7 @@ public class FloodFillTool implements BlockTool {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
BlockType initialType = world.getLazyBlock(clicked.toVector()).getType();
|
||||
BlockType initialType = world.getLazyBlock(clicked.toVector()).getBlockType();
|
||||
|
||||
if (initialType == BlockTypes.AIR) {
|
||||
return true;
|
||||
@ -87,7 +87,7 @@ public class FloodFillTool implements BlockTool {
|
||||
|
||||
visited.add(pos);
|
||||
|
||||
if (editSession.getBlock(pos).getType() == initialType) {
|
||||
if (editSession.getBlock(pos).getBlockType() == initialType) {
|
||||
editSession.setBlock(pos, pattern.apply(pos));
|
||||
} else {
|
||||
return;
|
||||
|
@ -55,7 +55,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
|
||||
if (pos == null) return false;
|
||||
EditSession eS = session.createEditSession(player);
|
||||
try {
|
||||
if (secondary.getType() == BlockTypes.AIR) {
|
||||
if (secondary.getBlockType() == BlockTypes.AIR) {
|
||||
eS.setBlock(pos.toVector(), secondary);
|
||||
} else {
|
||||
eS.setBlock(pos.getDirection(), secondary);
|
||||
@ -74,7 +74,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
|
||||
if (pos == null) return false;
|
||||
EditSession eS = session.createEditSession(player);
|
||||
try {
|
||||
if (primary.getType() == BlockTypes.AIR) {
|
||||
if (primary.getBlockType() == BlockTypes.AIR) {
|
||||
eS.setBlock(pos.toVector(), primary);
|
||||
} else {
|
||||
eS.setBlock(pos.getDirection(), primary);
|
||||
|
@ -48,8 +48,8 @@ public class QueryTool implements BlockTool {
|
||||
BaseBlock block = editSession.getBlock(clicked.toVector());
|
||||
|
||||
player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e"
|
||||
+ "#" + block.getType() + "\u00A77" + " ("
|
||||
+ block.getType().getId() + ") "
|
||||
+ "#" + block.getBlockType() + "\u00A77" + " ("
|
||||
+ block.getBlockType().getId() + ") "
|
||||
+ "\u00A7f"
|
||||
+ "[" + block.getStates().toString() + "]" + " (" + world.getBlockLightLevel(clicked.toVector()) + "/" + world.getBlockLightLevel(clicked.toVector().add(0, 1, 0)) + ")");
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class RecursivePickaxe implements BlockTool {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
BlockType initialType = world.getBlock(clicked.toVector()).getType();
|
||||
BlockType initialType = world.getBlock(clicked.toVector()).getBlockType();
|
||||
|
||||
if (initialType == BlockTypes.AIR) {
|
||||
return true;
|
||||
@ -89,7 +89,7 @@ public class RecursivePickaxe implements BlockTool {
|
||||
|
||||
visited.add(pos);
|
||||
|
||||
if (editSession.getBlock(pos).getType() != initialType) {
|
||||
if (editSession.getBlock(pos).getBlockType() != initialType) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class SinglePickaxe implements BlockTool {
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
World world = (World) clicked.getExtent();
|
||||
final BlockType blockType = world.getLazyBlock(clicked.toVector()).getType();
|
||||
final BlockType blockType = world.getLazyBlock(clicked.toVector()).getBlockType();
|
||||
if (blockType == BlockTypes.BEDROCK
|
||||
&& !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
|
@ -24,7 +24,6 @@ import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
@ -75,10 +74,9 @@ public interface Player extends Entity, Actor {
|
||||
/**
|
||||
* Gives the player an item.
|
||||
*
|
||||
* @param type The item id of the item to be given to the player
|
||||
* @param amount How many items in the stack
|
||||
* @param itemStack The item to give
|
||||
*/
|
||||
void giveItem(int type, int amount);
|
||||
void giveItem(BaseItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get this actor's block bag.
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -34,7 +34,7 @@ import java.util.Map;
|
||||
public class SignCompatibilityHandler implements NBTCompatibilityHandler {
|
||||
@Override
|
||||
public boolean isAffectedBlock(BaseBlock block) {
|
||||
return block.getType() == BlockTypes.SIGN || block.getType() == BlockTypes.WALL_SIGN;
|
||||
return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,8 +82,8 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
public boolean setBlock(Vector position, BaseBlock block) throws WorldEditException {
|
||||
if (blockBag != null) {
|
||||
BaseBlock lazyBlock = getExtent().getLazyBlock(position);
|
||||
int existing = lazyBlock.getType().getLegacyId();
|
||||
final int type = block.getType().getLegacyId();
|
||||
int existing = lazyBlock.getBlockType().getLegacyId();
|
||||
final int type = block.getBlockType().getLegacyId();
|
||||
|
||||
if (type > 0) {
|
||||
try {
|
||||
|
@ -19,28 +19,30 @@
|
||||
|
||||
package com.sk89q.worldedit.extent.inventory;
|
||||
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
|
||||
/**
|
||||
* Thrown when the target inventory of a block bag is full.
|
||||
*/
|
||||
public class OutOfSpaceException extends BlockBagException {
|
||||
|
||||
private int id;
|
||||
private ItemType type;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id the ID of the block
|
||||
* @param type the type of the block
|
||||
*/
|
||||
public OutOfSpaceException(int id) {
|
||||
this.id = id;
|
||||
public OutOfSpaceException(ItemType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the block
|
||||
* Get the type of the block
|
||||
*
|
||||
* @return the id
|
||||
* @return the type
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
public ItemType getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
@ -94,21 +94,21 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
return super.setBlock(location, block);
|
||||
}
|
||||
|
||||
if (BlockType.shouldPlaceLast(block.getType().getLegacyId())) {
|
||||
if (BlockType.shouldPlaceLast(block.getBlockType().getLegacyId())) {
|
||||
// Place torches, etc. last
|
||||
stage2.put(location.toBlockVector(), block);
|
||||
return !(lazyBlock.getType() == block.getType() && lazyBlock.getData() == block.getData());
|
||||
} else if (BlockType.shouldPlaceFinal(block.getType().getLegacyId())) {
|
||||
return !(lazyBlock.getBlockType() == block.getBlockType() && lazyBlock.getData() == block.getData());
|
||||
} else if (BlockType.shouldPlaceFinal(block.getBlockType().getLegacyId())) {
|
||||
// Place signs, reed, etc even later
|
||||
stage3.put(location.toBlockVector(), block);
|
||||
return !(lazyBlock.getType() == block.getType() && lazyBlock.getData() == block.getData());
|
||||
} else if (BlockType.shouldPlaceLast(lazyBlock.getType().getLegacyId())) {
|
||||
return !(lazyBlock.getBlockType() == block.getBlockType() && lazyBlock.getData() == block.getData());
|
||||
} else if (BlockType.shouldPlaceLast(lazyBlock.getBlockType().getLegacyId())) {
|
||||
// Destroy torches, etc. first
|
||||
super.setBlock(location, new BaseBlock(BlockTypes.AIR));
|
||||
return super.setBlock(location, block);
|
||||
} else {
|
||||
stage1.put(location.toBlockVector(), block);
|
||||
return !(lazyBlock.getType() == block.getType() && lazyBlock.getData() == block.getData());
|
||||
return !(lazyBlock.getBlockType() == block.getBlockType() && lazyBlock.getData() == block.getData());
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
|
||||
final BaseBlock baseBlock = blockTypes.get(current);
|
||||
|
||||
final int type = baseBlock.getType().getLegacyId();
|
||||
final int type = baseBlock.getBlockType().getLegacyId();
|
||||
final int data = baseBlock.getData();
|
||||
|
||||
switch (type) {
|
||||
|
@ -138,7 +138,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
if (value != null && value.getData() != null) {
|
||||
DirectionalStateValue newValue = getNewStateValue((DirectionalState) state, transform, value.getDirection());
|
||||
if (newValue != null) {
|
||||
changedBlock.setState(state, newValue);
|
||||
changedBlock.with(state, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class DataValidatorExtent extends AbstractDelegateExtent {
|
||||
@Override
|
||||
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
|
||||
final int y = location.getBlockY();
|
||||
final BlockType type = block.getType();
|
||||
final BlockType type = block.getBlockType();
|
||||
if (y < 0 || y > world.getMaxY()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class BlockQuirkExtent extends AbstractDelegateExtent {
|
||||
@Override
|
||||
public boolean setBlock(Vector position, BaseBlock block) throws WorldEditException {
|
||||
BaseBlock lazyBlock = getExtent().getLazyBlock(position);
|
||||
int existing = lazyBlock.getType().getLegacyId();
|
||||
int existing = lazyBlock.getBlockType().getLegacyId();
|
||||
|
||||
if (BlockType.isContainerBlock(existing)) {
|
||||
world.clearContainerBlockContents(position); // Clear the container block so that it doesn't drop items
|
||||
|
@ -104,7 +104,7 @@ public class ExtentBlockCopy implements RegionFunction {
|
||||
|
||||
builder.putByte("Rot", (byte) MCDirections.toRotation(newDirection));
|
||||
|
||||
return new BaseBlock(state.getType(), state.getStates(), builder.build());
|
||||
return new BaseBlock(state.getState(), builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,10 +106,10 @@ public class FloraGenerator implements RegionFunction {
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
BaseBlock block = editSession.getBlock(position);
|
||||
|
||||
if (block.getType() == BlockTypes.GRASS) {
|
||||
if (block.getBlockType() == BlockTypes.GRASS) {
|
||||
editSession.setBlock(position.add(0, 1, 0), temperatePattern.apply(position));
|
||||
return true;
|
||||
} else if (block.getType() == BlockTypes.SAND) {
|
||||
} else if (block.getBlockType() == BlockTypes.SAND) {
|
||||
editSession.setBlock(position.add(0, 1, 0), desertPattern.apply(position));
|
||||
return true;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class ForestGenerator implements RegionFunction {
|
||||
@Override
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
BaseBlock block = editSession.getBlock(position);
|
||||
BlockType t = block.getType();
|
||||
BlockType t = block.getBlockType();
|
||||
|
||||
if (t == BlockTypes.GRASS || t == BlockTypes.DIRT) {
|
||||
treeGenerator.generate(editSession, position.add(0, 1, 0));
|
||||
|
@ -163,7 +163,7 @@ public class GardenPatchGenerator implements RegionFunction {
|
||||
position = position.add(0, 1, 0);
|
||||
}
|
||||
|
||||
if (editSession.getBlock(position.add(0, -1, 0)).getType() != BlockTypes.GRASS) {
|
||||
if (editSession.getBlock(position.add(0, -1, 0)).getBlockType() != BlockTypes.GRASS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
BaseBlock block = getExtent().getBlock(vector);
|
||||
return blocks.contains(block) || blocks.contains(new BaseBlock(block.getType()));
|
||||
return blocks.contains(block) || blocks.contains(new BaseBlock(block.getBlockType()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -41,7 +41,7 @@ public class FuzzyBlockMask extends BlockMask {
|
||||
Extent extent = getExtent();
|
||||
Collection<BaseBlock> blocks = getBlocks();
|
||||
BaseBlock lazyBlock = extent.getLazyBlock(vector);
|
||||
BaseBlock compare = new BaseBlock(lazyBlock.getType(), lazyBlock.getStates());
|
||||
BaseBlock compare = new BaseBlock(lazyBlock.getState());
|
||||
return Blocks.containsFuzzy(blocks, compare);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class SolidBlockMask extends AbstractExtentMask {
|
||||
public boolean test(Vector vector) {
|
||||
Extent extent = getExtent();
|
||||
BaseBlock lazyBlock = extent.getLazyBlock(vector);
|
||||
return !BlockType.canPassThrough(lazyBlock.getType().getLegacyId(), lazyBlock.getData());
|
||||
return !BlockType.canPassThrough(lazyBlock.getBlockType().getLegacyId(), lazyBlock.getData());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -148,8 +148,8 @@ public class HeightMap {
|
||||
BaseBlock existing = session.getBlock(new Vector(xr, curHeight, zr));
|
||||
|
||||
// Skip water/lava
|
||||
if (existing.getType() != BlockTypes.WATER && existing.getType() != BlockTypes.FLOWING_WATER
|
||||
&& existing.getType() != BlockTypes.LAVA && existing.getType() != BlockTypes.FLOWING_LAVA) {
|
||||
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.FLOWING_WATER
|
||||
&& existing.getBlockType() != BlockTypes.LAVA && existing.getBlockType() != BlockTypes.FLOWING_LAVA) {
|
||||
session.setBlock(new Vector(xr, newHeight, zr), existing);
|
||||
++blocksChanged;
|
||||
|
||||
|
@ -99,7 +99,7 @@ public abstract class ArbitraryShape {
|
||||
return null;
|
||||
}
|
||||
|
||||
short newCacheEntry = (short) (material.getType().getLegacyId() | ((material.getData() + 1) << 8));
|
||||
short newCacheEntry = (short) (material.getBlockType().getLegacyId() | ((material.getData() + 1) << 8));
|
||||
if (newCacheEntry == 0) {
|
||||
// type and data 0
|
||||
newCacheEntry = -2;
|
||||
|
@ -103,7 +103,7 @@ public class TargetBlock {
|
||||
boolean searchForLastBlock = true;
|
||||
Location lastBlock = null;
|
||||
while (getNextBlock() != null) {
|
||||
if (world.getLazyBlock(getCurrentBlock().toVector()).getType() == BlockTypes.AIR) {
|
||||
if (world.getLazyBlock(getCurrentBlock().toVector()).getBlockType() == BlockTypes.AIR) {
|
||||
if (searchForLastBlock) {
|
||||
lastBlock = getCurrentBlock();
|
||||
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
|
||||
@ -125,7 +125,7 @@ public class TargetBlock {
|
||||
* @return Block
|
||||
*/
|
||||
public Location getTargetBlock() {
|
||||
while (getNextBlock() != null && world.getLazyBlock(getCurrentBlock().toVector()).getType() == BlockTypes.AIR) ;
|
||||
while (getNextBlock() != null && world.getLazyBlock(getCurrentBlock().toVector()).getBlockType() == BlockTypes.AIR) ;
|
||||
return getCurrentBlock();
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
package com.sk89q.worldedit.world;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
@ -34,7 +32,6 @@ import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
@ -53,32 +50,6 @@ public abstract class AbstractWorld implements World {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setBlockType(Vector position, int type) {
|
||||
try {
|
||||
return setBlock(position, new BaseBlock(type));
|
||||
} catch (WorldEditException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setBlockData(Vector position, int data) {
|
||||
try {
|
||||
setBlock(position, new BaseBlock(getLazyBlock(position).getType().getLegacyId(), data));
|
||||
} catch (WorldEditException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setTypeIdAndData(Vector position, int type, int data) {
|
||||
try {
|
||||
return setBlock(position, new BaseBlock(type, data));
|
||||
} catch (WorldEditException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setBlock(Vector pt, BaseBlock block) throws WorldEditException {
|
||||
return setBlock(pt, block, true);
|
||||
@ -89,17 +60,6 @@ public abstract class AbstractWorld implements World {
|
||||
return getMaximumPoint().getBlockY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int type) {
|
||||
return BlockType.fromID(type) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockData(int type) {
|
||||
// We future proof here by assuming all unknown blocks use data
|
||||
return BlockType.usesData(type) || BlockType.fromID(type) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask createLiquidMask() {
|
||||
return new BlockMask(this,
|
||||
@ -124,7 +84,7 @@ public abstract class AbstractWorld implements World {
|
||||
if (stack != null) {
|
||||
final int amount = stack.getAmount();
|
||||
if (amount > 1) {
|
||||
dropItem(pt, new BaseItemStack(stack.getType(), 1, stack.getData()), amount);
|
||||
dropItem(pt, new BaseItemStack(stack.getType(), stack.getNbtData(), 1), amount);
|
||||
} else {
|
||||
dropItem(pt, stack, amount);
|
||||
}
|
||||
@ -137,31 +97,6 @@ public abstract class AbstractWorld implements World {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateBigTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.BIG_TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateBirchTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.BIRCH, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.TALL_REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(Vector pt) {
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.world.registry.WorldData;
|
||||
|
||||
/**
|
||||
@ -56,24 +55,6 @@ public interface World extends Extent {
|
||||
*/
|
||||
int getMaxY();
|
||||
|
||||
/**
|
||||
* Checks whether the given block ID is a valid block ID.
|
||||
*
|
||||
* @param id the block ID
|
||||
* @return true if the block ID is a valid one
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isValidBlockType(int id);
|
||||
|
||||
/**
|
||||
* Checks whether the given block ID uses data values for differentiating
|
||||
* types of blocks.
|
||||
*
|
||||
* @param id the block ID
|
||||
* @return true if the block uses data values
|
||||
*/
|
||||
boolean usesBlockData(int id);
|
||||
|
||||
/**
|
||||
* Create a mask that matches all liquids.
|
||||
*
|
||||
@ -113,24 +94,6 @@ public interface World extends Extent {
|
||||
*/
|
||||
boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setBlockType(Vector position, int type);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setBlockData(Vector position, int data);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setTypeIdAndData(Vector position, int type, int data);
|
||||
|
||||
/**
|
||||
* Get the light level at the given block.
|
||||
*
|
||||
@ -192,36 +155,6 @@ public interface World extends Extent {
|
||||
*/
|
||||
boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateBigTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateBirchTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateRedwoodTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateTallRedwoodTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Load the chunk at the given position if it isn't loaded.
|
||||
*
|
||||
|
@ -118,8 +118,7 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockID(Vector position) throws DataException {
|
||||
private int getBlockID(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
@ -130,9 +129,6 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
|
||||
int yindex = y & 0x0F;
|
||||
if (yindex < 0 || yindex >= 16) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
int index = x + (z * 16 + (yindex * 16 * 16));
|
||||
|
||||
@ -155,8 +151,7 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockData(Vector position) throws DataException {
|
||||
private int getBlockData(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
@ -168,10 +163,6 @@ public class AnvilChunk implements Chunk {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
if (yIndex < 0 || yIndex >= 16) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
int index = x + (z * 16 + (yIndex * 16 * 16));
|
||||
boolean shift = index % 2 == 0;
|
||||
index /= 2;
|
||||
@ -200,8 +191,7 @@ public class AnvilChunk implements Chunk {
|
||||
|
||||
for (Tag tag : tags) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new InvalidFormatException(
|
||||
"CompoundTag expected in TileEntities");
|
||||
throw new InvalidFormatException("CompoundTag expected in TileEntities");
|
||||
}
|
||||
|
||||
CompoundTag t = (CompoundTag) tag;
|
||||
@ -268,21 +258,7 @@ public class AnvilChunk implements Chunk {
|
||||
int data = getBlockData(position);
|
||||
BaseBlock block;
|
||||
|
||||
/*if (id == BlockID.WALL_SIGN || id == BlockID.SIGN_POST) {
|
||||
block = new SignBlock(id, data);
|
||||
} else if (id == BlockID.CHEST) {
|
||||
block = new ChestBlock(data);
|
||||
} else if (id == BlockID.FURNACE || id == BlockID.BURNING_FURNACE) {
|
||||
block = new FurnaceBlock(id, data);
|
||||
} else if (id == BlockID.DISPENSER) {
|
||||
block = new DispenserBlock(data);
|
||||
} else if (id == BlockID.MOB_SPAWNER) {
|
||||
block = new MobSpawnerBlock(data);
|
||||
} else if (id == BlockID.NOTE_BLOCK) {
|
||||
block = new NoteBlock(data);
|
||||
} else {*/
|
||||
block = new BaseBlock(id, data);
|
||||
//}
|
||||
block = new BaseBlock(id, data);
|
||||
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
if (tileEntity != null) {
|
||||
|
@ -28,25 +28,6 @@ import com.sk89q.worldedit.world.DataException;
|
||||
*/
|
||||
public interface Chunk {
|
||||
|
||||
/**
|
||||
* Get the block ID of a block.
|
||||
*
|
||||
* @param position the position of the block
|
||||
* @return the type ID of the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
public int getBlockID(Vector position) throws DataException;
|
||||
|
||||
/**
|
||||
* Get the block data of a block.
|
||||
*
|
||||
* @param position the position of the block
|
||||
* @return the data value of the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
public int getBlockData(Vector position) throws DataException;
|
||||
|
||||
|
||||
/**
|
||||
* Get a block;
|
||||
*
|
||||
@ -54,6 +35,6 @@ public interface Chunk {
|
||||
* @return block the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
public BaseBlock getBlock(Vector position) throws DataException;
|
||||
BaseBlock getBlock(Vector position) throws DataException;
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
@ -76,43 +77,6 @@ public class OldChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockID(Vector position) throws DataException {
|
||||
if(position.getBlockY() >= 128) return 0;
|
||||
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
try {
|
||||
return blocks[index];
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockData(Vector position) throws DataException {
|
||||
if(position.getBlockY() >= 128) return 0;
|
||||
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
boolean shift = index % 2 == 0;
|
||||
index /= 2;
|
||||
|
||||
try {
|
||||
if (!shift) {
|
||||
return (data[index] & 0xF0) >> 4;
|
||||
} else {
|
||||
return data[index] & 0xF;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to load the tile entities.
|
||||
*
|
||||
@ -188,25 +152,33 @@ public class OldChunk implements Chunk {
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) throws DataException {
|
||||
int id = getBlockID(position);
|
||||
int data = getBlockData(position);
|
||||
BaseBlock block;
|
||||
if(position.getBlockY() >= 128) new BaseBlock(BlockTypes.AIR);
|
||||
int id, dataVal;
|
||||
|
||||
/*if (id == BlockID.WALL_SIGN || id == BlockID.SIGN_POST) {
|
||||
block = new SignBlock(id, data);
|
||||
} else if (id == BlockID.CHEST) {
|
||||
block = new ChestBlock(data);
|
||||
} else if (id == BlockID.FURNACE || id == BlockID.BURNING_FURNACE) {
|
||||
block = new FurnaceBlock(id, data);
|
||||
} else if (id == BlockID.DISPENSER) {
|
||||
block = new DispenserBlock(data);
|
||||
} else if (id == BlockID.MOB_SPAWNER) {
|
||||
block = new MobSpawnerBlock(data);
|
||||
} else if (id == BlockID.NOTE_BLOCK) {
|
||||
block = new NoteBlock(data);
|
||||
} else {*/
|
||||
block = new BaseBlock(id, data);
|
||||
//}
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
try {
|
||||
id = blocks[index];
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
boolean shift = index % 2 == 0;
|
||||
index /= 2;
|
||||
|
||||
try {
|
||||
if (!shift) {
|
||||
dataVal = (data[index] & 0xF0) >> 4;
|
||||
} else {
|
||||
dataVal = data[index] & 0xF;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
BaseBlock block = new BaseBlock(id, dataVal);
|
||||
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
if (tileEntity != null) {
|
||||
|
@ -53,13 +53,13 @@ public class BundledBlockRegistry implements BlockRegistry {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockMaterial getMaterial(BaseBlock block) {
|
||||
return BundledBlockData.getInstance().getMaterialById(block.getType().getId());
|
||||
return BundledBlockData.getInstance().getMaterialById(block.getBlockType().getId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, ? extends State> getStates(BaseBlock block) {
|
||||
return BundledBlockData.getInstance().getStatesById(block.getType().getId());
|
||||
return BundledBlockData.getInstance().getStatesById(block.getBlockType().getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class BlockTransformExtentTest {
|
||||
BaseBlock orig = new BaseBlock(type);
|
||||
for (int i = 1; i < 4; i++) {
|
||||
BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_90, blockRegistry);
|
||||
BaseBlock reference = new BaseBlock(orig.getType().getLegacyId(), BlockData.rotate90(orig.getType().getLegacyId(), orig.getData()));
|
||||
BaseBlock reference = new BaseBlock(orig.getBlockType().getLegacyId(), BlockData.rotate90(orig.getBlockType().getLegacyId(), orig.getData()));
|
||||
assertThat(type + "#" + type.getId() + " rotated " + (90 * i) + " degrees did not match BlockData.rotate90()'s expected result", rotated,
|
||||
equalTo(reference));
|
||||
orig = rotated;
|
||||
@ -81,7 +81,7 @@ public class BlockTransformExtentTest {
|
||||
orig = new BaseBlock(type);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_NEG_90, blockRegistry);
|
||||
BaseBlock reference = new BaseBlock(orig.getType().getLegacyId(), BlockData.rotate90Reverse(orig.getType().getLegacyId(), orig.getData()));
|
||||
BaseBlock reference = new BaseBlock(orig.getBlockType().getLegacyId(), BlockData.rotate90Reverse(orig.getBlockType().getLegacyId(), orig.getData()));
|
||||
assertThat(type + "#" + type.getId() + " rotated " + (-90 * i) + " degrees did not match BlockData.rotate90Reverse()'s expected result", rotated, equalTo(reference));
|
||||
orig = rotated;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.ItemRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@ -31,7 +32,7 @@ public class ForgeItemRegistry implements ItemRegistry {
|
||||
public BaseItem createFromId(String id) {
|
||||
Item match = Item.REGISTRY.getObject(new ResourceLocation(id));
|
||||
if (match != null) {
|
||||
return new BaseItem(Item.REGISTRY.getIDForObject(match), (short) 0);
|
||||
return new BaseItem(ItemTypes.getItemType(id));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -41,7 +42,7 @@ public class ForgeItemRegistry implements ItemRegistry {
|
||||
@Override
|
||||
public BaseItem createFromId(int id) {
|
||||
if (Item.REGISTRY.getObjectById(id) != null) {
|
||||
return new BaseItem(id, (short) 0);
|
||||
return new BaseItem(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -91,8 +91,9 @@ public class ForgePlayer extends AbstractPlayerActor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(int type, int amt) {
|
||||
this.player.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(type), amt, 0));
|
||||
public void giveItem(BaseItemStack itemStack) {
|
||||
this.player.inventory.addItemStackToInventory(
|
||||
new ItemStack(Item.getByNameOrId(itemStack.getType().getId()), itemStack.getAmount(), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,7 +238,12 @@ public class ForgeWorld extends AbstractWorld {
|
||||
@Override
|
||||
public boolean useItem(Vector position, BaseItem item, Direction face) {
|
||||
Item nativeItem = Item.getByNameOrId(item.getType().getId());
|
||||
ItemStack stack = new ItemStack(nativeItem, 1, item.getData());
|
||||
ItemStack stack = null;
|
||||
if (item.getNbtData() == null) {
|
||||
stack = new ItemStack(nativeItem, 1, 0);
|
||||
} else {
|
||||
stack = new ItemStack(nativeItem, 1, 0, NBTConverter.toNative(item.getNbtData()));
|
||||
}
|
||||
World world = getWorld();
|
||||
EnumActionResult used = stack.onItemUse(new WorldEditFakePlayer((WorldServer) world), world, ForgeAdapter.toBlockPos(position),
|
||||
EnumHand.MAIN_HAND, ForgeAdapter.adapt(face), 0, 0, 0);
|
||||
@ -333,7 +338,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
@Override
|
||||
public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException {
|
||||
WorldGenerator generator = createWorldGenerator(type);
|
||||
return generator != null ? generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position)) : false;
|
||||
return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -341,12 +346,6 @@ public class ForgeWorld extends AbstractWorld {
|
||||
return ForgeWorldData.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int id) {
|
||||
Block block = Block.getBlockById(id);
|
||||
return Block.getIdFromBlock(block) == id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) {
|
||||
World world = getWorld();
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.block.Block;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static net.minecraft.block.Block.REGISTRY;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -30,12 +29,12 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.forge.net.LeftClickAirEventMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
@ -54,9 +53,9 @@ import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static net.minecraft.block.Block.REGISTRY;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* The Forge implementation of WorldEdit.
|
||||
@ -214,12 +213,11 @@ public class ForgeWorldEdit {
|
||||
}
|
||||
|
||||
public static ItemStack toForgeItemStack(BaseItemStack item) {
|
||||
ItemStack ret = new ItemStack(Item.getByNameOrId(item.getType().getId()), item.getAmount(), item.getData());
|
||||
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
|
||||
ret.addEnchantment(net.minecraft.enchantment.Enchantment.getEnchantmentByID(entry.getKey()), entry.getValue());
|
||||
NBTTagCompound forgeCompound = null;
|
||||
if (item.getNbtData() != null) {
|
||||
forgeCompound = NBTConverter.toNative(item.getNbtData());
|
||||
}
|
||||
|
||||
return ret;
|
||||
return new ItemStack(Item.getByNameOrId(item.getType().getId()), item.getAmount(), 0, forgeCompound);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,8 +31,10 @@ import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.session.SessionKey;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.data.type.HandTypes;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.ItemType;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.format.TextColor;
|
||||
@ -91,8 +93,11 @@ public class SpongePlayer extends AbstractPlayerActor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(int type, int amt) {
|
||||
this.player.getInventory().offer(ItemStack.of(SpongeWorldEdit.inst().getAdapter().resolveItem(type), amt));
|
||||
public void giveItem(BaseItemStack itemStack) {
|
||||
this.player.getInventory().offer(
|
||||
ItemStack.of(Sponge.getGame().getRegistry().getType(ItemType.class, itemStack.getType().getId()).get(),
|
||||
itemStack.getAmount())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -202,11 +202,6 @@ public abstract class SpongeWorld extends AbstractWorld {
|
||||
return SpongeWorldData.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int id) {
|
||||
return id == 0 || SpongeWorldEdit.inst().getAdapter().resolveBlock(id) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getWorld().hashCode();
|
||||
@ -220,7 +215,7 @@ public abstract class SpongeWorld extends AbstractWorld {
|
||||
SpongeWorld other = ((SpongeWorld) o);
|
||||
World otherWorld = other.worldRef.get();
|
||||
World thisWorld = worldRef.get();
|
||||
return otherWorld != null && thisWorld != null && otherWorld.equals(thisWorld);
|
||||
return otherWorld != null && otherWorld.equals(thisWorld);
|
||||
} else {
|
||||
return o instanceof com.sk89q.worldedit.world.World
|
||||
&& ((com.sk89q.worldedit.world.World) o).getName().equals(getName());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren