This commit is contained in:
MattBDev
2019-06-25 13:07:47 -04:00
parent a1c15e1c39
commit a69b239848
143 changed files with 1042 additions and 2405 deletions

View File

@ -36,7 +36,6 @@ import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.util.PriorityQueue;
/**
* An abstract implementation of {@link World}.
@ -143,6 +142,7 @@ public abstract class AbstractWorld implements World {
this.priority = priority;
}
@SuppressWarnings("deprecation")
public void play() {
playEffect(position, 2001, blockType.getLegacyCombinedId() >> 4);
}

View File

@ -19,11 +19,9 @@
package com.sk89q.worldedit.world;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -54,7 +52,7 @@ public class NullWorld extends AbstractWorld {
private static final NullWorld INSTANCE = new NullWorld();
public NullWorld() {
protected NullWorld() {
}
@Override

View File

@ -20,11 +20,7 @@
package com.sk89q.worldedit.world.biome;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* Stores a list of common Biome String IDs.

View File

@ -20,21 +20,18 @@
package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Objects;
@ -48,10 +45,10 @@ import java.util.Objects;
* may be missing.</p>
*/
public class BaseBlock implements BlockStateHolder<BaseBlock> {
private final BlockState blockState;
@Nullable
protected CompoundTag nbtData;
@Nullable protected CompoundTag nbtData;
@Deprecated
public BaseBlock() {
@ -82,9 +79,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
*
* @param blockState The blockstate
*/
public BaseBlock(BlockState blockState) {
// this(blockState, blockState.getNbtData());
this.blockState = blockState;
}
@ -111,7 +106,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
this(getState(id, data));
}
public static final BlockState getState(int id, int data) {
public static BlockState getState(int id, int data) {
BlockState blockState = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
if (blockState == null) {
blockState = BlockTypes.AIR.getDefaultState();
@ -138,6 +133,42 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
this(other.toImmutableState(), other.getNbtData());
}
/**
* Gets a map of state to statevalue
*
* @return The state map
*/
@Override
public Map<Property<?>, Object> getStates() {
return toImmutableState().getStates();
}
@Override
public BlockType getBlockType() {
return this.blockState.getBlockType();
}
@Override
public <V> BaseBlock with(Property<V> property, V value) {
return toImmutableState().with(property, value).toBaseBlock(getNbtData());
}
/**
* Gets the State for this Block.
*
* @param property The state to get the value for
* @return The state value
*/
@Override
public <V> V getState(Property<V> property) {
return toImmutableState().getState(property);
}
@Override
public boolean hasNbtData() {
return getNbtData() != null;
}
@Override
public String getNbtId() {
CompoundTag nbtData = getNbtData();
@ -180,11 +211,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
return this.blockState.equalsFuzzy(otherBlock.blockState) && Objects.equals(getNbtData(), otherBlock.getNbtData());
}
@Override
public final BlockState toImmutableState() {
return blockState;
}
@Override
public int getInternalId() {
return blockState.getInternalId();
@ -196,17 +222,24 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
}
@Override
public BlockType getBlockType() {
return blockState.getBlockType();
public int getOrdinal() {
return blockState.getOrdinal();
}
public BlockType getType() {
return getBlockType();
/**
* Checks if the type is the same, and if the matched states are the same.
*
* @param o other block
* @return true if equal
*/
@Override
public boolean equalsFuzzy(BlockStateHolder<?> o) {
return this.blockState.equalsFuzzy(o);
}
@Override
public int getOrdinal() {
return blockState.getOrdinal();
public BlockState toImmutableState() {
return this.blockState;
}
@Override
@ -227,16 +260,11 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
@Override
public int hashCode() {
return getOrdinal();
}
@Override
public String toString() {
if (this.getNbtData() != null) {
return getAsString() + " {" + String.valueOf(getNbtData()) + "}";
} else {
return getAsString();
int ret = toImmutableState().hashCode() << 3;
if (hasNbtData()) {
ret += getNbtData().hashCode();
}
return ret;
}
@Override
@ -244,11 +272,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
return extent.setBlock(set, this);
}
@Override
public boolean hasNbtData() {
return this.nbtData != null;
}
@Override
public BaseBlock withPropertyId(int propertyId) {
return getBlockType().withPropertyId(propertyId).toBaseBlock(getNbtData());
@ -264,34 +287,23 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
return toImmutableState().getInternalPropertiesId();
}
@Override
public <V> BaseBlock with(Property<V> property, V value) {
return toImmutableState().with(property, value).toBaseBlock(getNbtData());
}
@Override
public <V> BaseBlock with(PropertyKey property, V value) {
return toImmutableState().with(property, value).toBaseBlock(getNbtData());
}
@Override
public <V> V getState(Property<V> property) {
return toImmutableState().getState(property);
}
@Override
public <V> V getState(PropertyKey property) {
return toImmutableState().getState(property);
}
@Override
public Map<Property<?>, Object> getStates() {
return toImmutableState().getStates();
}
@Override
public boolean equalsFuzzy(BlockStateHolder o) {
return toImmutableState().equalsFuzzy(o);
}
@Override
public String toString() {
if (getNbtData() != null) {
return getAsString() + " {" + String.valueOf(getNbtData()) + "}";
} else {
return getAsString();
}
}
}

View File

@ -1,5 +0,0 @@
package com.sk89q.worldedit.world.block;
public enum BlockTypeEnum {
}

View File

@ -20,8 +20,6 @@
package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Maps;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
@ -39,7 +37,7 @@ public class FuzzyBlockState extends BlockState {
private final Map<PropertyKey, Object> props;
public FuzzyBlockState(BlockType blockType) {
FuzzyBlockState(BlockType blockType) {
this(blockType.getDefaultState(), null);
}
@ -181,4 +179,4 @@ public class FuzzyBlockState extends BlockState {
return this;
}
}
}
}

View File

@ -28,7 +28,6 @@ import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -55,7 +54,7 @@ public class AnvilChunk implements Chunk {
/**
* Construct the chunk with a compound tag.
*
*
* @param world the world to construct the chunk for
* @param tag the tag to read
* @throws DataException on a data error
@ -69,19 +68,19 @@ public class AnvilChunk implements Chunk {
blocks = new byte[16][16 * 16 * 16];
blocksAdd = new byte[16][16 * 16 * 8];
data = new byte[16][16 * 16 * 8];
List<Tag> sections = NBTUtils.getChildTag(rootTag.getValue(), "Sections", ListTag.class).getValue();
for (Tag rawSectionTag : sections) {
if (!(rawSectionTag instanceof CompoundTag)) {
continue;
}
CompoundTag sectionTag = (CompoundTag) rawSectionTag;
if (!sectionTag.getValue().containsKey("Y")) {
continue; // Empty section.
}
int y = NBTUtils.getChildTag(sectionTag.getValue(), "Y", ByteTag.class).getValue();
if (y < 0 || y >= 16) {
continue;
@ -117,7 +116,7 @@ public class AnvilChunk implements Chunk {
}
}
}
private int getBlockID(BlockVector3 position) throws DataException {
int x = position.getX() - rootX * 16;
int y = position.getY();
@ -127,14 +126,14 @@ public class AnvilChunk implements Chunk {
if (section < 0 || section >= blocks.length) {
throw new DataException("Chunk does not contain position " + position);
}
int yindex = y & 0x0F;
int index = x + (z * 16 + (yindex * 16 * 16));
try {
int addId = 0;
// The block ID is the combination of the Blocks byte array with the
// Add byte array. 'Blocks' stores the lowest 8 bits of a block's ID, and
// 'Add' stores the highest 4 bits of the ID. The first block is stored
@ -144,7 +143,7 @@ public class AnvilChunk implements Chunk {
} else {
addId = (blocksAdd[section][index >> 1] & 0xF0) << 4;
}
return (blocks[section][index] & 0xFF) + addId;
} catch (IndexOutOfBoundsException e) {
throw new DataException("Chunk does not contain position " + position);
@ -158,7 +157,7 @@ public class AnvilChunk implements Chunk {
int section = y >> 4;
int yIndex = y & 0x0F;
if (section < 0 || section >= blocks.length) {
throw new DataException("Chunk does not contain position " + position);
}
@ -264,10 +263,12 @@ public class AnvilChunk implements Chunk {
}
if (state.getMaterial().hasContainer()) {
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) {
return state.toBaseBlock(tileEntity);
}
}
return state.toBaseBlock();
}

View File

@ -54,7 +54,7 @@ public class AnvilChunk13 implements Chunk {
/**
* Construct the chunk with a compound tag.
*
*
* @param tag the tag to read
* @throws DataException on a data error
*/
@ -159,13 +159,14 @@ public class AnvilChunk13 implements Chunk {
* @throws DataException
*/
private void populateTileEntities() throws DataException {
tileEntities = new HashMap<>();
if (!rootTag.getValue().containsKey("TileEntities")) {
return;
}
List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(),
"TileEntities", ListTag.class).getValue();
tileEntities = new HashMap<>();
for (Tag tag : tags) {
if (!(tag instanceof CompoundTag)) {
throw new InvalidFormatException("CompoundTag expected in TileEntities");
@ -221,6 +222,7 @@ public class AnvilChunk13 implements Chunk {
BlockState[] sectionBlocks = blocks[section];
BlockState state = sectionBlocks != null ? sectionBlocks[(yIndex << 8) | (z << 4) | x] : BlockTypes.AIR.getDefaultState();
if (state.getMaterial().hasContainer()) {
CompoundTag tileEntity = getBlockTileEntity(position);
return state.toBaseBlock(tileEntity);

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.world.chunk;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.block.BaseBlock;

View File

@ -61,7 +61,7 @@ public class OldChunk implements Chunk {
*/
public OldChunk(World world, CompoundTag tag) throws DataException {
rootTag = tag;
blocks = NBTUtils.getChildTag(rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue();
data = NBTUtils.getChildTag(rootTag.getValue(), "Data", ByteArrayTag.class).getValue();
rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue();
@ -191,6 +191,7 @@ public class OldChunk implements Chunk {
return state.toBaseBlock(tileEntity);
}
}
return state.toBaseBlock();
}

View File

@ -34,7 +34,6 @@ import java.util.Set;
public class ItemCategory extends Category<ItemType> {
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>("item tag");
private int internalId;
public ItemCategory(final String id) {
super(id);
@ -57,5 +56,4 @@ public class ItemCategory extends Category<ItemType> {
public boolean contains(BaseItem baseItem) {
return this.getAll().contains(baseItem.getType());
}
}

View File

@ -100,21 +100,17 @@ public class ItemType implements RegistryItem {
}
return this.blockType;
}
public void setBlockType(BlockType blockType) {
this.blockType = blockType;
}
public BaseItem getDefaultState() {
if (defaultState == null) {
this.defaultState = new BaseItemStack(this);
}
return this.defaultState;
}
public void setDefaultState(BaseItem defaultState) {
this.defaultState = defaultState;
}
@Override
public String toString() {
@ -130,4 +126,4 @@ public class ItemType implements RegistryItem {
public boolean equals(Object obj) {
return obj instanceof ItemType && this.id.equals(((ItemType) obj).id);
}
}
}

View File

@ -834,24 +834,16 @@ public final class ItemTypes {
}
if (!input.split("\\[", 2)[0].contains(":")) input = "minecraft:" + input;
ItemType result = get(input);
return result;
return get(input);
}
public static final @Nullable ItemType get(String id) {
public static @Nullable ItemType get(final String id) {
return ItemType.REGISTRY.get(id);
}
@Deprecated
public static final ItemType get(final int ordinal) {
public static ItemType get(final int ordinal) {
return ItemType.REGISTRY.getByInternalId(ordinal);
}
public static int size() {
return ItemType.REGISTRY.size();
}
public static Collection<ItemType> values() {
return ItemType.REGISTRY.values();
}
}

View File

@ -73,17 +73,14 @@ public class BundledBlockData {
private void loadFromResource() throws IOException {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
gsonBuilder.registerTypeAdapter(int.class, new JsonDeserializer<Integer>() {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonPrimitive primitive = (JsonPrimitive) json;
if (primitive.isString()) {
String value = primitive.getAsString();
if (value.charAt(0) == '#') return Integer.parseInt(value.substring(1), 16);
return Integer.parseInt(value);
}
return primitive.getAsInt();
gsonBuilder.registerTypeAdapter(int.class, (JsonDeserializer<Integer>) (json, typeOfT, context) -> {
JsonPrimitive primitive = (JsonPrimitive) json;
if (primitive.isString()) {
String value = primitive.getAsString();
if (value.charAt(0) == '#') return Integer.parseInt(value.substring(1), 16);
return Integer.parseInt(value);
}
return primitive.getAsInt();
});
Gson gson = gsonBuilder.create();
URL url = BundledBlockData.class.getResource("blocks.json");

View File

@ -22,8 +22,6 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
/**
* A item registry that uses {@link BundledItemRegistry} to serve information
@ -46,9 +44,4 @@ public class BundledItemRegistry implements ItemRegistry {
}
return null;
}
@Override
public Collection<String> registerItems() {
return Collections.emptyList();
}
}

View File

@ -22,18 +22,9 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
public interface ItemRegistry {
/**
* Register all items
*/
default Collection<String> registerItems() {
return Collections.emptyList();
}
/**
* Gets the name for the given item.
*

View File

@ -94,7 +94,6 @@ public class LegacyMapper {
for (Map.Entry<String, String> blockEntry : dataFile.blocks.entrySet()) {
try {
BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue());
// BlockState blockState = WorldEdit.getInstance().getBlockFactory().parseFromInput(blockEntry.getValue(), parserContext).toImmutableState();
BlockType type = blockState.getBlockType();
if (type.hasProperty(PropertyKey.WATERLOGGED)) {
blockState = blockState.with(PropertyKey.WATERLOGGED, false);
@ -160,7 +159,11 @@ public class LegacyMapper {
@Nullable
public int[] getLegacyFromItem(ItemType itemType) {
Integer combinedId = getLegacyCombined(itemType);
return combinedId == null ? null : new int[] { combinedId >> 4, combinedId & 0xF };
if (combinedId == null) {
return null;
} else {
return new int[]{combinedId >> 4, combinedId & 0xF};
}
}
@Nullable

View File

@ -114,7 +114,6 @@ public abstract class ChunkStore implements Closeable {
return new OldChunk(world, tag);
}
@Override
public void close() throws IOException {
}

View File

@ -37,7 +37,6 @@ public class WeatherTypes {
private WeatherTypes() {
}
public static @Nullable WeatherType get(final String id) {
return WeatherType.REGISTRY.get(id);
}