mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Plenty of changes to core block behavior to become more compatible with upstream WorldEdit (still more to be done!)
This commit is contained in:
@ -93,7 +93,7 @@ public abstract class AbstractWorld implements World {
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(BlockVector3 position) {
|
||||
return new BaseBlock(getBlock(position));
|
||||
return new BaseBlock(getBlock(position)).toImmutableState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,8 +59,8 @@ public interface SimpleWorld extends World {
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockState getFullBlock(BlockVector3 position) {
|
||||
return getLazyBlock(position);
|
||||
default BaseBlock getFullBlock(BlockVector3 position) {
|
||||
return getLazyBlock(position).toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,9 +34,15 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -48,7 +54,7 @@ import java.util.Objects;
|
||||
* snapshot of blocks correctly, so, for example, the NBT data for a block
|
||||
* may be missing.</p>
|
||||
*/
|
||||
public class BaseBlock extends BlockState {
|
||||
public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
private final BlockState blockState;
|
||||
|
||||
@Nullable
|
||||
@ -69,11 +75,6 @@ public class BaseBlock extends BlockState {
|
||||
// this(blockState, blockState.getNbtData());
|
||||
// }
|
||||
|
||||
@Deprecated
|
||||
public BaseBlock(BlockTypes id) {
|
||||
this(id.getDefaultState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a block with the given type and default data.
|
||||
* @deprecated Just use the BlockType.getDefaultState()
|
||||
@ -101,7 +102,6 @@ public class BaseBlock extends BlockState {
|
||||
* @param nbtData NBT data, which must be provided
|
||||
*/
|
||||
public BaseBlock(BlockState state, CompoundTag nbtData) {
|
||||
// super(state.getBlockType());
|
||||
checkNotNull(nbtData);
|
||||
this.blockState = state;
|
||||
this.nbtData = nbtData;
|
||||
@ -145,11 +145,6 @@ public class BaseBlock extends BlockState {
|
||||
this(other.toImmutableState(), other.getNbtData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState toFuzzy() {
|
||||
return blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNbtId() {
|
||||
CompoundTag nbtData = getNbtData();
|
||||
@ -181,12 +176,15 @@ public class BaseBlock extends BlockState {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof BaseBlock)) {
|
||||
if (!hasNbtData() && o instanceof BlockStateHolder) {
|
||||
return Objects.equals(toImmutableState(), ((BlockStateHolder<?>) o).toImmutableState());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final BaseBlock otherBlock = (BaseBlock) o;
|
||||
|
||||
return this.equals(otherBlock) && Objects.equals(getNbtData(), otherBlock.getNbtData());
|
||||
return this.blockState.equalsFuzzy(otherBlock.blockState) && Objects.equals(getNbtData(), otherBlock.getNbtData());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -205,7 +203,7 @@ public class BaseBlock extends BlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTypes getBlockType() {
|
||||
public BlockType getBlockType() {
|
||||
return blockState.getBlockType();
|
||||
}
|
||||
|
||||
@ -244,4 +242,65 @@ public class BaseBlock extends BlockState {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return this.nbtData != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder withPropertyId(int propertyId) {
|
||||
return getBlockType().withPropertyId(propertyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalBlockTypeId() {
|
||||
return toImmutableState().getInternalBlockTypeId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalPropertiesId() {
|
||||
return toImmutableState().getInternalPropertiesId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask toMask(Extent extent) {
|
||||
return new SingleBlockStateMask(extent, toImmutableState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> BaseBlock with(Property<V> property, V value) {
|
||||
return toImmutableState().with(property, value).toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> BlockStateHolder with(PropertyKey property, V value) {
|
||||
return toImmutableState().with(property, value);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
@ -49,13 +50,26 @@ import java.util.stream.Stream;
|
||||
* An immutable class that represents the state a block can be in.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
public class BlockState implements BlockStateHolder<BlockState> {
|
||||
private final BlockType blockType;
|
||||
private BaseBlock emptyBaseBlock;
|
||||
BlockState(BlockType blockType) {
|
||||
this.blockType = blockType;
|
||||
this.emptyBaseBlock = new BaseBlock(this);
|
||||
}
|
||||
|
||||
BlockState(BlockType blockType, BaseBlock baseBlock){
|
||||
this.blockType = blockType;
|
||||
this.emptyBaseBlock = baseBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a temporary BlockState for a given internal id
|
||||
* @param combinedId
|
||||
* @deprecated magic number
|
||||
* @return BlockState
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public static BlockState getFromInternalId(int combinedId) throws InputParseException {
|
||||
return BlockTypes.getFromStateId(combinedId).withStateId(combinedId);
|
||||
@ -85,17 +99,6 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
public static BlockState get(@Nullable BlockType type, String state) throws InputParseException {
|
||||
return get(type, state, null);
|
||||
}
|
||||
// private BlockTypes blockType;
|
||||
// private BaseBlock emptyBaseBlock;
|
||||
|
||||
// Neighbouring state table.
|
||||
private Table<Property<?>, Object, BlockState> states;
|
||||
|
||||
// protected BlockState(BlockTypes blockType) {
|
||||
//// protected BlockState() {
|
||||
// this.blockType = blockType;
|
||||
// this.emptyBaseBlock = new BaseBlock(this);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns a temporary BlockState for a given type and string
|
||||
@ -265,7 +268,7 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
@Override
|
||||
public <V> BlockState with(final Property<V> property, final V value) {
|
||||
try {
|
||||
BlockTypes type = getBlockType();
|
||||
BlockType type = getBlockType();
|
||||
int newState = ((AbstractProperty) property).modify(this.getInternalId(), value);
|
||||
return newState != this.getInternalId() ? type.withStateId(newState) : this;
|
||||
} catch (ClassCastException e) {
|
||||
@ -276,7 +279,7 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
@Override
|
||||
public <V> BlockState with(final PropertyKey property, final V value) {
|
||||
try {
|
||||
BlockTypes type = getBlockType();
|
||||
BlockType type = getBlockType();
|
||||
int newState = ((AbstractProperty) type.getProperty(property)).modify(this.getInternalId(), value);
|
||||
return newState != this.getInternalId() ? type.withStateId(newState) : this;
|
||||
} catch (ClassCastException e) {
|
||||
@ -309,13 +312,10 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
return (Map<Property<?>, Object>) map;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public BaseBlock toBaseBlock() {
|
||||
//// if (this.fuzzy) {
|
||||
//// throw new IllegalArgumentException("Can't create a BaseBlock from a fuzzy BlockState!");
|
||||
//// }
|
||||
// return this.emptyBaseBlock;
|
||||
// }
|
||||
@Override
|
||||
public BaseBlock toBaseBlock() {
|
||||
return this.emptyBaseBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock toBaseBlock(CompoundTag compoundTag) {
|
||||
@ -325,10 +325,10 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
return new BaseBlock(this, compoundTag);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public BlockTypes getBlockType() {
|
||||
// return this.blockType;
|
||||
// }
|
||||
@Override
|
||||
public BlockType getBlockType() {
|
||||
return this.blockType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense
|
||||
@ -364,4 +364,20 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
public String toString() {
|
||||
return getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return blockType.getInternalId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockMaterial getMaterial() {
|
||||
return blockType.getMaterial();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
//?
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
*
|
||||
* @return The type
|
||||
*/
|
||||
BlockTypes getBlockType();
|
||||
BlockType getBlockType();
|
||||
|
||||
/**
|
||||
* Magic number (legacy uses)
|
||||
@ -46,9 +46,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
default BlockStateHolder withPropertyId(int propertyId) {
|
||||
return getBlockType().withPropertyId(propertyId);
|
||||
}
|
||||
BlockStateHolder withPropertyId(int propertyId);
|
||||
|
||||
/**
|
||||
* Get combined id (legacy uses)
|
||||
@ -60,18 +58,13 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
@Deprecated
|
||||
int getOrdinal();
|
||||
|
||||
default BlockMaterial getMaterial() {
|
||||
return getBlockType().getMaterial();
|
||||
}
|
||||
|
||||
BlockMaterial getMaterial();
|
||||
/**
|
||||
* Get type id (legacy uses)
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
default int getInternalBlockTypeId() {
|
||||
return getBlockType().getInternalId();
|
||||
}
|
||||
int getInternalBlockTypeId();
|
||||
|
||||
/**
|
||||
* Get the block data (legacy uses)
|
||||
@ -132,11 +125,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
boolean equalsFuzzy(BlockStateHolder o);
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* Returns an immutable BlockStateHolder from this BlockStateHolder.
|
||||
=======
|
||||
* Returns an immutable {@link BlockState} from this BlockStateHolder.
|
||||
>>>>>>> f54d6afb... Make BaseBlock more memory efficient, and make it clear in the API that it's not intended to be used for every single block.
|
||||
*
|
||||
* @return A BlockState
|
||||
*/
|
||||
|
@ -7,12 +7,12 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
public class BlockStateImpl extends BlockState {
|
||||
private final int internalId;
|
||||
private final int ordinal;
|
||||
private final BlockTypes type;
|
||||
private final BlockType type;
|
||||
private BlockMaterial material;
|
||||
private BaseBlock baseBlock;
|
||||
|
||||
protected BlockStateImpl(BlockTypes type, int internalId, int ordinal) {
|
||||
// super(type);
|
||||
protected BlockStateImpl(BlockType type, int internalId, int ordinal) {
|
||||
super(type);
|
||||
this.type = type;
|
||||
this.internalId = internalId;
|
||||
this.ordinal = ordinal;
|
||||
@ -44,7 +44,7 @@ public class BlockStateImpl extends BlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockTypes getBlockType() {
|
||||
public final BlockType getBlockType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
@ -40,30 +41,55 @@ import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
|
||||
default BlockTypes getTypeEnum() {
|
||||
return (BlockTypes) this;
|
||||
}
|
||||
public class BlockType implements FawePattern {
|
||||
|
||||
public static final NamespacedRegistry<BlockType> REGISTRY = new NamespacedRegistry<>("block type");
|
||||
|
||||
private final @Nonnull String id;
|
||||
private ArrayList<BlockState> states;
|
||||
public final Function<BlockState, BlockState> defaultValue;
|
||||
private BlockTypes.Settings settings;
|
||||
private BlockMaterial material;
|
||||
|
||||
public BlockType(@Nonnull String id) {
|
||||
this(id, null);
|
||||
}
|
||||
|
||||
public BlockType(@Nonnull String id, Function<BlockState, BlockState> defaultValue) {
|
||||
this.id = id;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public void setStates(ArrayList<BlockState> states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
public void setSettings(BlockTypes.Settings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public BlockTypes.Settings getSettings(){
|
||||
return settings;
|
||||
}
|
||||
|
||||
public ArrayList<BlockState> updateStates(){
|
||||
if(settings != null) {
|
||||
return settings.localStates = new ArrayList<BlockState>(settings.localStates.stream().map(state -> new BlockStateImpl(this, state.getInternalId(), state.getOrdinal())).collect(Collectors.toList()));
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
int getMaxStateId();
|
||||
|
||||
@Override
|
||||
default boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
return extent.setBlock(set, this.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockStateHolder apply(BlockVector3 position) {
|
||||
return this.getDefaultState();
|
||||
}
|
||||
|
||||
default Mask toMask(Extent extent) {
|
||||
return new SingleBlockTypeMask(extent, this);
|
||||
public int getMaxStateId() {
|
||||
return settings.permutations;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,15 +97,17 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
*
|
||||
* @return The id
|
||||
*/
|
||||
String getId();
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
default String getNamespace() {
|
||||
public String getNamespace() {
|
||||
String id = getId();
|
||||
int i = id.indexOf(':');
|
||||
return i == -1 ? "minecraft" : id.substring(0, i);
|
||||
}
|
||||
|
||||
default String getResource() {
|
||||
public String getResource() {
|
||||
String id = getId();
|
||||
return id.substring(id.indexOf(':') + 1);
|
||||
}
|
||||
@ -89,7 +117,7 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
*
|
||||
* @return The name, or ID
|
||||
*/
|
||||
default String getName() {
|
||||
public String getName() {
|
||||
BundledBlockData.BlockEntry entry = BundledBlockData.getInstance().findById(this.getId());
|
||||
if (entry == null) {
|
||||
return getId();
|
||||
@ -99,28 +127,41 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default BlockState withPropertyId(int internalPropertiesId) {
|
||||
if (internalPropertiesId == 0) return getDefaultState();
|
||||
return BlockState.getFromInternalId(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET));
|
||||
public BlockState withPropertyId(int propertyId) {
|
||||
if (settings.stateOrdinals == null) return settings.defaultState;
|
||||
return states.get(settings.stateOrdinals[propertyId]);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockState withStateId(int internalStateId) {
|
||||
return this.withPropertyId(internalStateId >> BlockTypes.BIT_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the properties of this BlockType in a {@code key->property} mapping.
|
||||
* Properties string in the form property1=foo,prop2=bar
|
||||
* @param properties
|
||||
* @return
|
||||
*/
|
||||
public BlockState withProperties(String properties) {
|
||||
int id = getInternalId();
|
||||
for (String keyPair : properties.split(",")) {
|
||||
String[] split = keyPair.split("=");
|
||||
String name = split[0];
|
||||
String value = split[1];
|
||||
AbstractProperty btp = settings.propertiesMap.get(name);
|
||||
id = btp.modify(id, btp.getValueFor(value));
|
||||
}
|
||||
return withStateId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the properties of this BlockType in a key->property mapping.
|
||||
*
|
||||
* @return The properties map
|
||||
*/
|
||||
@Deprecated
|
||||
default Map<String, ? extends Property> getPropertyMap() {
|
||||
List<? extends Property> properties = getProperties();
|
||||
if (properties.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<String, Property> map = new HashMap<>(properties.size());
|
||||
for (Property property : properties) {
|
||||
map.put(property.getName(), property);
|
||||
}
|
||||
return map;
|
||||
public Map<String, ? extends Property<?>> getPropertyMap() {
|
||||
return this.settings.propertiesMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,11 +170,13 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
* @return the properties
|
||||
*/
|
||||
@Deprecated
|
||||
List<? extends Property> getProperties();
|
||||
public List<? extends Property<?>> getProperties() {
|
||||
return this.settings.propertiesList;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
default Set<? extends Property> getPropertiesSet() {
|
||||
return new HashSet<>(getProperties());
|
||||
public Set<? extends Property<?>> getPropertiesSet() {
|
||||
return this.settings.propertiesSet;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,20 +186,22 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
* @return The property
|
||||
*/
|
||||
@Deprecated
|
||||
default <V> Property<V> getProperty(String name) {
|
||||
Property<V> property = getPropertyMap().get(name);
|
||||
checkArgument(property != null, "%s has no property named %s", this, name);
|
||||
return property;
|
||||
public <V> Property<V> getProperty(String name) {
|
||||
checkArgument(this.settings.propertiesMap.get(name) != null, "%s has no property named %s", this, name);
|
||||
return (Property<V>) this.settings.propertiesMap.get(name);
|
||||
}
|
||||
|
||||
default boolean hasProperty(PropertyKey key) {
|
||||
return getPropertyMap().containsKey(key.getId());
|
||||
public boolean hasProperty(PropertyKey key) {
|
||||
int ordinal = key.ordinal();
|
||||
return this.settings.propertiesMapArr.length > ordinal ? this.settings.propertiesMapArr[ordinal] != null : false;
|
||||
}
|
||||
|
||||
default <V> Property<V> getProperty(PropertyKey key) {
|
||||
Property<V> property = getPropertyMap().get(key.getId());
|
||||
checkArgument(property != null, "%s has no property named %s", this, key.getId());
|
||||
return property;
|
||||
|
||||
public <V> Property<V> getProperty(PropertyKey key) {
|
||||
try {
|
||||
return (Property<V>) this.settings.propertiesMapArr[key.ordinal()];
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,28 +209,54 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
*
|
||||
* @return The default state
|
||||
*/
|
||||
BlockState getDefaultState();
|
||||
public BlockState getDefaultState() {
|
||||
BlockState defaultState = this.settings.defaultState;
|
||||
if (defaultValue != null) {
|
||||
defaultState = defaultValue.apply(defaultState);
|
||||
}
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all possible states for this BlockType.
|
||||
*
|
||||
* @return All possible states
|
||||
* Slow
|
||||
* @return collection of states
|
||||
*/
|
||||
List<BlockState> getAllStates();
|
||||
@Deprecated
|
||||
public List<BlockState> getAllStates() {
|
||||
if (settings.stateOrdinals == null) return Collections.singletonList(getDefaultState());
|
||||
return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> states.get(i)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a state of this BlockType with the given properties.
|
||||
*
|
||||
* @return The state, if it exists
|
||||
*/
|
||||
BlockState getState(Map<Property<?>, Object> key);
|
||||
public BlockState getState(Map<Property<?>, Object> key) {
|
||||
int id = getInternalId();
|
||||
for (Map.Entry<Property<?>, Object> iter : key.entrySet()) {
|
||||
Property<?> prop = iter.getKey();
|
||||
Object value = iter.getValue();
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* This is likely wrong. The only place this seems to currently (Dec 23 2018)
|
||||
* be invoked is via ForgeWorld, and value is a String when invoked there...
|
||||
*/
|
||||
AbstractProperty btp = this.settings.propertiesMap.get(prop.getName());
|
||||
checkArgument(btp != null, "%s has no property named %s", this, prop.getName());
|
||||
id = btp.modify(id, btp.getValueFor((String)value));
|
||||
}
|
||||
return withStateId(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets whether this block type has an item representation.
|
||||
*
|
||||
* @return If it has an item
|
||||
*/
|
||||
default boolean hasItemType() {
|
||||
public boolean hasItemType() {
|
||||
return getItemType() != null;
|
||||
}
|
||||
|
||||
@ -195,8 +266,8 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
* @return The item representation
|
||||
*/
|
||||
@Nullable
|
||||
default ItemType getItemType() {
|
||||
return ItemTypes.get(this.getTypeEnum());
|
||||
public ItemType getItemType() {
|
||||
return ItemTypes.get(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,7 +275,11 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
*
|
||||
* @return The material
|
||||
*/
|
||||
BlockMaterial getMaterial();
|
||||
public BlockMaterial getMaterial() {
|
||||
return this.material == null ?
|
||||
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this)
|
||||
: this.material;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the legacy ID. Needed for legacy reasons.
|
||||
@ -213,7 +288,7 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
*
|
||||
* @return legacy id or 0, if unknown
|
||||
*/
|
||||
default int getLegacyCombinedId() {
|
||||
public int getLegacyCombinedId() {
|
||||
Integer combinedId = LegacyMapper.getInstance().getLegacyCombined(this);
|
||||
return combinedId == null ? 0 : combinedId;
|
||||
}
|
||||
@ -225,16 +300,43 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
*
|
||||
* @return internal id
|
||||
*/
|
||||
int getInternalId();
|
||||
public int getInternalId() {
|
||||
return this.settings.internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean equals(Object obj);
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
int hashCode();
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof BlockType && this.id.equals(((BlockType) obj).id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
return extent.setBlock(set, this.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 position) {
|
||||
return this.getDefaultState();
|
||||
}
|
||||
|
||||
public Mask toMask(Extent extent) {
|
||||
return new SingleBlockTypeMask(extent, this);
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
default int getLegacyId() {
|
||||
public int getLegacyId() {
|
||||
Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
|
||||
if (id != null) {
|
||||
return id >> 4;
|
||||
|
@ -17,7 +17,7 @@ public class BlockTypeSwitchBuilder<T> {
|
||||
}
|
||||
|
||||
public BlockTypeSwitchBuilder<T> add(Predicate<BlockType> predicate, T task) {
|
||||
for (BlockTypes type : BlockTypes.values) {
|
||||
for (BlockType type : BlockTypes.values) {
|
||||
if (predicate.test(type)) {
|
||||
this.runnables[type.getInternalId()] = task;
|
||||
}
|
||||
|
@ -0,0 +1,214 @@
|
||||
/*
|
||||
* 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.world.block;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.PropertyGroup;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class BlockTypeUtil {
|
||||
|
||||
public static double centralTopLimit(com.sk89q.worldedit.world.block.BlockType type) {
|
||||
checkNotNull(type);
|
||||
return centralTopLimit(type.getDefaultState());
|
||||
}
|
||||
|
||||
public static double centralBottomLimit(BlockStateHolder block) {
|
||||
checkNotNull(block);
|
||||
BlockType type = block.getBlockType();
|
||||
switch (type.getResource().toUpperCase()) {
|
||||
case "CREEPER_WALL_HEAD":
|
||||
case "DRAGON_WALL_HEAD":
|
||||
case "PLAYER_WALL_HEAD":
|
||||
case "ZOMBIE_WALL_HEAD": return 0.25;
|
||||
case "ACACIA_SLAB":
|
||||
case "BIRCH_SLAB":
|
||||
case "BRICK_SLAB":
|
||||
case "COBBLESTONE_SLAB":
|
||||
case "DARK_OAK_SLAB":
|
||||
case "DARK_PRISMARINE_SLAB":
|
||||
case "JUNGLE_SLAB":
|
||||
case "NETHER_BRICK_SLAB":
|
||||
case "OAK_SLAB":
|
||||
case "PETRIFIED_OAK_SLAB":
|
||||
case "PRISMARINE_BRICK_SLAB":
|
||||
case "PRISMARINE_SLAB":
|
||||
case "PURPUR_SLAB":
|
||||
case "QUARTZ_SLAB":
|
||||
case "RED_SANDSTONE_SLAB":
|
||||
case "SANDSTONE_SLAB":
|
||||
case "SPRUCE_SLAB":
|
||||
case "STONE_BRICK_SLAB":
|
||||
case "STONE_SLAB": {
|
||||
String state = (String) block.getState(PropertyKey.TYPE);
|
||||
if (state == null) return 0;
|
||||
switch (state) {
|
||||
case "double":
|
||||
case "bottom":
|
||||
return 0;
|
||||
case "top":
|
||||
return 0.5;
|
||||
}
|
||||
}
|
||||
case "ACACIA_TRAPDOOR":
|
||||
case "BIRCH_TRAPDOOR":
|
||||
case "DARK_OAK_TRAPDOOR":
|
||||
case "IRON_TRAPDOOR":
|
||||
case "JUNGLE_TRAPDOOR":
|
||||
case "OAK_TRAPDOOR":
|
||||
case "SPRUCE_TRAPDOOR":
|
||||
if (block.getState(PropertyKey.OPEN) == Boolean.TRUE) {
|
||||
return 1;
|
||||
} else if ("bottom".equals(block.getState(PropertyKey.HALF))) {
|
||||
return 0.8125;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
case "ACACIA_FENCE_GATE":
|
||||
case "BIRCH_FENCE_GATE":
|
||||
case "DARK_OAK_FENCE_GATE":
|
||||
case "JUNGLE_FENCE_GATE":
|
||||
case "OAK_FENCE_GATE":
|
||||
case "SPRUCE_FENCE_GATE": return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 1 : 0;
|
||||
default:
|
||||
if (type.getMaterial().isMovementBlocker()) return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the y offset a player falls to when falling onto the top of a block at xp+0.5/zp+0.5.
|
||||
*
|
||||
* @param block the block
|
||||
* @return the y offset
|
||||
*/
|
||||
public static double centralTopLimit(BlockStateHolder block) {
|
||||
checkNotNull(block);
|
||||
BlockType type = block.getBlockType();
|
||||
switch (type.getResource().toUpperCase()) {
|
||||
case "BLACK_BED":
|
||||
case "BLUE_BED":
|
||||
case "BROWN_BED":
|
||||
case "CYAN_BED":
|
||||
case "GRAY_BED":
|
||||
case "GREEN_BED":
|
||||
case "LIGHT_BLUE_BED":
|
||||
case "LIGHT_GRAY_BED":
|
||||
case "LIME_BED":
|
||||
case "MAGENTA_BED":
|
||||
case "ORANGE_BED":
|
||||
case "PINK_BED":
|
||||
case "PURPLE_BED":
|
||||
case "RED_BED":
|
||||
case "WHITE_BED":
|
||||
case "YELLOW_BED": return 0.5625;
|
||||
case "BREWING_STAND": return 0.875;
|
||||
case "CAKE": return (block.getState(PropertyKey.BITES) == (Integer) 6) ? 0 : 0.4375;
|
||||
case "CAULDRON": return 0.3125;
|
||||
case "COCOA": return 0.750;
|
||||
case "ENCHANTING_TABLE": return 0.75;
|
||||
case "END_PORTAL_FRAME": return block.getState(PropertyKey.EYE) == Boolean.TRUE ? 1 : 0.8125;
|
||||
case "CREEPER_HEAD":
|
||||
case "DRAGON_HEAD":
|
||||
case "PISTON_HEAD":
|
||||
case "PLAYER_HEAD":
|
||||
case "ZOMBIE_HEAD": return 0.5;
|
||||
case "CREEPER_WALL_HEAD":
|
||||
case "DRAGON_WALL_HEAD":
|
||||
case "PLAYER_WALL_HEAD":
|
||||
case "ZOMBIE_WALL_HEAD": return 0.75;
|
||||
case "ACACIA_FENCE":
|
||||
case "BIRCH_FENCE":
|
||||
case "DARK_OAK_FENCE":
|
||||
case "JUNGLE_FENCE":
|
||||
case "NETHER_BRICK_FENCE":
|
||||
case "OAK_FENCE":
|
||||
case "SPRUCE_FENCE": return 1.5;
|
||||
case "ACACIA_SLAB":
|
||||
case "BIRCH_SLAB":
|
||||
case "BRICK_SLAB":
|
||||
case "COBBLESTONE_SLAB":
|
||||
case "DARK_OAK_SLAB":
|
||||
case "DARK_PRISMARINE_SLAB":
|
||||
case "JUNGLE_SLAB":
|
||||
case "NETHER_BRICK_SLAB":
|
||||
case "OAK_SLAB":
|
||||
case "PETRIFIED_OAK_SLAB":
|
||||
case "PRISMARINE_BRICK_SLAB":
|
||||
case "PRISMARINE_SLAB":
|
||||
case "PURPUR_SLAB":
|
||||
case "QUARTZ_SLAB":
|
||||
case "RED_SANDSTONE_SLAB":
|
||||
case "SANDSTONE_SLAB":
|
||||
case "SPRUCE_SLAB":
|
||||
case "STONE_BRICK_SLAB":
|
||||
case "STONE_SLAB": {
|
||||
String state = (String) block.getState(PropertyKey.TYPE);
|
||||
if (state == null) return 0.5;
|
||||
switch (state) {
|
||||
case "bottom":
|
||||
return 0.5;
|
||||
case "top":
|
||||
case "double":
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
case "LILY_PAD": return 0.015625;
|
||||
case "REPEATER": return 0.125;
|
||||
case "SOUL_SAND": return 0.875;
|
||||
case "COBBLESTONE_WALL":
|
||||
case "MOSSY_COBBLESTONE_WALL": return 1.5;
|
||||
case "FLOWER_POT": return 0.375;
|
||||
case "COMPARATOR": return 0.125;
|
||||
case "DAYLIGHT_DETECTOR": return 0.375;
|
||||
case "HOPPER": return 0.625;
|
||||
case "ACACIA_TRAPDOOR":
|
||||
case "BIRCH_TRAPDOOR":
|
||||
case "DARK_OAK_TRAPDOOR":
|
||||
case "IRON_TRAPDOOR":
|
||||
case "JUNGLE_TRAPDOOR":
|
||||
case "OAK_TRAPDOOR":
|
||||
case "SPRUCE_TRAPDOOR":
|
||||
if (block.getState(PropertyKey.OPEN) == Boolean.TRUE) {
|
||||
return 0;
|
||||
} else if ("top".equals(block.getState(PropertyKey.HALF))) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0.1875;
|
||||
}
|
||||
case "ACACIA_FENCE_GATE":
|
||||
case "BIRCH_FENCE_GATE":
|
||||
case "DARK_OAK_FENCE_GATE":
|
||||
case "JUNGLE_FENCE_GATE":
|
||||
case "OAK_FENCE_GATE":
|
||||
case "SPRUCE_FENCE_GATE": return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 0 : 1.5;
|
||||
default:
|
||||
if (type.hasProperty(PropertyKey.LAYERS)) {
|
||||
return PropertyGroup.LEVEL.get(block) * 0.0625;
|
||||
}
|
||||
if (!type.getMaterial().isMovementBlocker()) return 0;
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -21,18 +21,46 @@ package com.sk89q.worldedit.world.entity;
|
||||
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
|
||||
public interface EntityType {
|
||||
String getId();
|
||||
public class EntityType {
|
||||
|
||||
public static final NamespacedRegistry<EntityType> REGISTRY = new NamespacedRegistry<>("entity type");
|
||||
|
||||
private String id;
|
||||
|
||||
public EntityType(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (!id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this item, or the ID if the name cannot be found.
|
||||
*
|
||||
* @return The name, or ID
|
||||
*/
|
||||
default String getName() {
|
||||
public String getName() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getInternalId();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof EntityType && this.id.equals(((EntityType) obj).id);
|
||||
}
|
||||
|
||||
}
|
@ -19,166 +19,121 @@
|
||||
|
||||
package com.sk89q.worldedit.world.entity;
|
||||
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public enum EntityTypes implements EntityType {
|
||||
/*
|
||||
-----------------------------------------------------
|
||||
Replaced at runtime by the entity registry
|
||||
-----------------------------------------------------
|
||||
*/
|
||||
__RESERVED__,
|
||||
AREA_EFFECT_CLOUD,
|
||||
ARMOR_STAND,
|
||||
ARROW,
|
||||
BAT,
|
||||
BLAZE,
|
||||
BOAT,
|
||||
CAVE_SPIDER,
|
||||
CHEST_MINECART,
|
||||
CHICKEN,
|
||||
COD,
|
||||
COMMAND_BLOCK_MINECART,
|
||||
COW,
|
||||
CREEPER,
|
||||
DOLPHIN,
|
||||
DONKEY,
|
||||
DRAGON_FIREBALL,
|
||||
DROWNED,
|
||||
EGG,
|
||||
ELDER_GUARDIAN,
|
||||
END_CRYSTAL,
|
||||
ENDER_DRAGON,
|
||||
ENDER_PEARL,
|
||||
ENDERMAN,
|
||||
ENDERMITE,
|
||||
EVOKER,
|
||||
EVOKER_FANGS,
|
||||
EXPERIENCE_BOTTLE,
|
||||
EXPERIENCE_ORB,
|
||||
EYE_OF_ENDER,
|
||||
FALLING_BLOCK,
|
||||
FIREBALL,
|
||||
FIREWORK_ROCKET,
|
||||
FISHING_BOBBER,
|
||||
FURNACE_MINECART,
|
||||
GHAST,
|
||||
GIANT,
|
||||
GUARDIAN,
|
||||
HOPPER_MINECART,
|
||||
HORSE,
|
||||
HUSK,
|
||||
ILLUSIONER,
|
||||
IRON_GOLEM,
|
||||
ITEM,
|
||||
ITEM_FRAME,
|
||||
LEASH_KNOT,
|
||||
LIGHTNING_BOLT,
|
||||
LLAMA,
|
||||
LLAMA_SPIT,
|
||||
MAGMA_CUBE,
|
||||
MINECART,
|
||||
MOOSHROOM,
|
||||
MULE,
|
||||
OCELOT,
|
||||
PAINTING,
|
||||
PARROT,
|
||||
PHANTOM,
|
||||
PIG,
|
||||
PLAYER,
|
||||
POLAR_BEAR,
|
||||
POTION,
|
||||
PUFFERFISH,
|
||||
RABBIT,
|
||||
SALMON,
|
||||
SHEEP,
|
||||
SHULKER,
|
||||
SHULKER_BULLET,
|
||||
SILVERFISH,
|
||||
SKELETON,
|
||||
SKELETON_HORSE,
|
||||
SLIME,
|
||||
SMALL_FIREBALL,
|
||||
SNOW_GOLEM,
|
||||
SNOWBALL,
|
||||
SPAWNER_MINECART,
|
||||
SPECTRAL_ARROW,
|
||||
SPIDER,
|
||||
SQUID,
|
||||
STRAY,
|
||||
TNT,
|
||||
TNT_MINECART,
|
||||
TRIDENT,
|
||||
TROPICAL_FISH,
|
||||
TURTLE,
|
||||
VEX,
|
||||
VILLAGER,
|
||||
VINDICATOR,
|
||||
WITCH,
|
||||
WITHER,
|
||||
WITHER_SKELETON,
|
||||
WITHER_SKULL,
|
||||
WOLF,
|
||||
ZOMBIE,
|
||||
ZOMBIE_HORSE,
|
||||
ZOMBIE_PIGMAN,
|
||||
ZOMBIE_VILLAGER,
|
||||
public class EntityTypes {
|
||||
|
||||
;
|
||||
public static final EntityType AREA_EFFECT_CLOUD = register("minecraft:area_effect_cloud");
|
||||
public static final EntityType ARMOR_STAND = register("minecraft:armor_stand");
|
||||
public static final EntityType ARROW = register("minecraft:arrow");
|
||||
public static final EntityType BAT = register("minecraft:bat");
|
||||
public static final EntityType BLAZE = register("minecraft:blaze");
|
||||
public static final EntityType BOAT = register("minecraft:boat");
|
||||
public static final EntityType CAVE_SPIDER = register("minecraft:cave_spider");
|
||||
public static final EntityType CHEST_MINECART = register("minecraft:chest_minecart");
|
||||
public static final EntityType CHICKEN = register("minecraft:chicken");
|
||||
public static final EntityType COD = register("minecraft:cod");
|
||||
public static final EntityType COMMAND_BLOCK_MINECART = register("minecraft:command_block_minecart");
|
||||
public static final EntityType COW = register("minecraft:cow");
|
||||
public static final EntityType CREEPER = register("minecraft:creeper");
|
||||
public static final EntityType DOLPHIN = register("minecraft:dolphin");
|
||||
public static final EntityType DONKEY = register("minecraft:donkey");
|
||||
public static final EntityType DRAGON_FIREBALL = register("minecraft:dragon_fireball");
|
||||
public static final EntityType DROWNED = register("minecraft:drowned");
|
||||
public static final EntityType EGG = register("minecraft:egg");
|
||||
public static final EntityType ELDER_GUARDIAN = register("minecraft:elder_guardian");
|
||||
public static final EntityType END_CRYSTAL = register("minecraft:end_crystal");
|
||||
public static final EntityType ENDER_DRAGON = register("minecraft:ender_dragon");
|
||||
public static final EntityType ENDER_PEARL = register("minecraft:ender_pearl");
|
||||
public static final EntityType ENDERMAN = register("minecraft:enderman");
|
||||
public static final EntityType ENDERMITE = register("minecraft:endermite");
|
||||
public static final EntityType EVOKER = register("minecraft:evoker");
|
||||
public static final EntityType EVOKER_FANGS = register("minecraft:evoker_fangs");
|
||||
public static final EntityType EXPERIENCE_BOTTLE = register("minecraft:experience_bottle");
|
||||
public static final EntityType EXPERIENCE_ORB = register("minecraft:experience_orb");
|
||||
public static final EntityType EYE_OF_ENDER = register("minecraft:eye_of_ender");
|
||||
public static final EntityType FALLING_BLOCK = register("minecraft:falling_block");
|
||||
public static final EntityType FIREBALL = register("minecraft:fireball");
|
||||
public static final EntityType FIREWORK_ROCKET = register("minecraft:firework_rocket");
|
||||
public static final EntityType FISHING_BOBBER = register("minecraft:fishing_bobber");
|
||||
public static final EntityType FURNACE_MINECART = register("minecraft:furnace_minecart");
|
||||
public static final EntityType GHAST = register("minecraft:ghast");
|
||||
public static final EntityType GIANT = register("minecraft:giant");
|
||||
public static final EntityType GUARDIAN = register("minecraft:guardian");
|
||||
public static final EntityType HOPPER_MINECART = register("minecraft:hopper_minecart");
|
||||
public static final EntityType HORSE = register("minecraft:horse");
|
||||
public static final EntityType HUSK = register("minecraft:husk");
|
||||
public static final EntityType ILLUSIONER = register("minecraft:illusioner");
|
||||
public static final EntityType IRON_GOLEM = register("minecraft:iron_golem");
|
||||
public static final EntityType ITEM = register("minecraft:item");
|
||||
public static final EntityType ITEM_FRAME = register("minecraft:item_frame");
|
||||
public static final EntityType LEASH_KNOT = register("minecraft:leash_knot");
|
||||
public static final EntityType LIGHTNING_BOLT = register("minecraft:lightning_bolt");
|
||||
public static final EntityType LLAMA = register("minecraft:llama");
|
||||
public static final EntityType LLAMA_SPIT = register("minecraft:llama_spit");
|
||||
public static final EntityType MAGMA_CUBE = register("minecraft:magma_cube");
|
||||
public static final EntityType MINECART = register("minecraft:minecart");
|
||||
public static final EntityType MOOSHROOM = register("minecraft:mooshroom");
|
||||
public static final EntityType MULE = register("minecraft:mule");
|
||||
public static final EntityType OCELOT = register("minecraft:ocelot");
|
||||
public static final EntityType PAINTING = register("minecraft:painting");
|
||||
public static final EntityType PARROT = register("minecraft:parrot");
|
||||
public static final EntityType PHANTOM = register("minecraft:phantom");
|
||||
public static final EntityType PIG = register("minecraft:pig");
|
||||
public static final EntityType PLAYER = register("minecraft:player");
|
||||
public static final EntityType POLAR_BEAR = register("minecraft:polar_bear");
|
||||
public static final EntityType POTION = register("minecraft:potion");
|
||||
public static final EntityType PUFFERFISH = register("minecraft:pufferfish");
|
||||
public static final EntityType RABBIT = register("minecraft:rabbit");
|
||||
public static final EntityType SALMON = register("minecraft:salmon");
|
||||
public static final EntityType SHEEP = register("minecraft:sheep");
|
||||
public static final EntityType SHULKER = register("minecraft:shulker");
|
||||
public static final EntityType SHULKER_BULLET = register("minecraft:shulker_bullet");
|
||||
public static final EntityType SILVERFISH = register("minecraft:silverfish");
|
||||
public static final EntityType SKELETON = register("minecraft:skeleton");
|
||||
public static final EntityType SKELETON_HORSE = register("minecraft:skeleton_horse");
|
||||
public static final EntityType SLIME = register("minecraft:slime");
|
||||
public static final EntityType SMALL_FIREBALL = register("minecraft:small_fireball");
|
||||
public static final EntityType SNOW_GOLEM = register("minecraft:snow_golem");
|
||||
public static final EntityType SNOWBALL = register("minecraft:snowball");
|
||||
public static final EntityType SPAWNER_MINECART = register("minecraft:spawner_minecart");
|
||||
public static final EntityType SPECTRAL_ARROW = register("minecraft:spectral_arrow");
|
||||
public static final EntityType SPIDER = register("minecraft:spider");
|
||||
public static final EntityType SQUID = register("minecraft:squid");
|
||||
public static final EntityType STRAY = register("minecraft:stray");
|
||||
public static final EntityType TNT = register("minecraft:tnt");
|
||||
public static final EntityType TNT_MINECART = register("minecraft:tnt_minecart");
|
||||
public static final EntityType TRIDENT = register("minecraft:trident");
|
||||
public static final EntityType TROPICAL_FISH = register("minecraft:tropical_fish");
|
||||
public static final EntityType TURTLE = register("minecraft:turtle");
|
||||
public static final EntityType VEX = register("minecraft:vex");
|
||||
public static final EntityType VILLAGER = register("minecraft:villager");
|
||||
public static final EntityType VINDICATOR = register("minecraft:vindicator");
|
||||
public static final EntityType WITCH = register("minecraft:witch");
|
||||
public static final EntityType WITHER = register("minecraft:wither");
|
||||
public static final EntityType WITHER_SKELETON = register("minecraft:wither_skeleton");
|
||||
public static final EntityType WITHER_SKULL = register("minecraft:wither_skull");
|
||||
public static final EntityType WOLF = register("minecraft:wolf");
|
||||
public static final EntityType ZOMBIE = register("minecraft:zombie");
|
||||
public static final EntityType ZOMBIE_HORSE = register("minecraft:zombie_horse");
|
||||
public static final EntityType ZOMBIE_PIGMAN = register("minecraft:zombie_pigman");
|
||||
public static final EntityType ZOMBIE_VILLAGER = register("minecraft:zombie_villager");
|
||||
|
||||
private String id;
|
||||
private int internalId;
|
||||
|
||||
EntityTypes() {
|
||||
this(null);
|
||||
private EntityTypes() {
|
||||
}
|
||||
|
||||
EntityTypes(String id) {
|
||||
init(id);
|
||||
private static EntityType register(final String id) {
|
||||
return register(new EntityType(id));
|
||||
}
|
||||
|
||||
private void init(String id) {
|
||||
if (id == null) id = "minecraft:" + name().toLowerCase();
|
||||
// If it has no namespace, assume minecraft.
|
||||
else if (!id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
this.id = id;
|
||||
this.internalId = ordinal();
|
||||
public static EntityType register(final EntityType entityType) {
|
||||
return EntityType.REGISTRY.register(entityType.getId(), entityType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
public static @Nullable EntityType get(final String id) {
|
||||
return EntityType.REGISTRY.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------
|
||||
Static Initializer
|
||||
-----------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
public static EntityType parse(String id) {
|
||||
if (id.startsWith("minecraft:")) id = id.substring(10);
|
||||
switch (id) {
|
||||
@ -246,64 +201,4 @@ public enum EntityTypes implements EntityType {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String, EntityTypes> $REGISTRY = new HashMap<>();
|
||||
private static int $LENGTH;
|
||||
public static final EntityTypes[] values;
|
||||
|
||||
static {
|
||||
try {
|
||||
Collection<String> ents = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getEntityRegistry().registerEntities();
|
||||
EntityTypes[] oldValues = values();
|
||||
$LENGTH = oldValues.length;
|
||||
LinkedHashSet<EntityTypes> newValues = new LinkedHashSet<>(Arrays.asList(oldValues));
|
||||
if (!ents.isEmpty()) { // No types found - use defaults
|
||||
for (String ent : ents) {
|
||||
EntityTypes registered = register(ent);
|
||||
if (!newValues.contains(registered)) newValues.add(registered);
|
||||
}
|
||||
}
|
||||
// Cache the values
|
||||
values = newValues.toArray(new EntityTypes[newValues.size()]);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static EntityTypes register(final String id) {
|
||||
// Get the enum name (remove namespace if minecraft:)
|
||||
int propStart = id.indexOf('[');
|
||||
String typeName = id.substring(0, propStart == -1 ? id.length() : propStart);
|
||||
String enumName = (typeName.startsWith("minecraft:") ? typeName.substring(10) : typeName).toUpperCase();
|
||||
// Check existing
|
||||
EntityTypes existing = null;
|
||||
try { existing = valueOf(enumName.toUpperCase()); } catch (IllegalArgumentException ignore) {}
|
||||
if (existing == null) {
|
||||
existing = ReflectionUtils.addEnum(EntityTypes.class, enumName);
|
||||
}
|
||||
int internalId = existing.ordinal();
|
||||
if (existing.id == null) {
|
||||
existing.init(null);
|
||||
}
|
||||
if (internalId == 0 && existing != __RESERVED__) {
|
||||
existing.internalId = $LENGTH++;
|
||||
}
|
||||
if (typeName.startsWith("minecraft:")) $REGISTRY.put(typeName.substring(10), existing);
|
||||
$REGISTRY.put(typeName, existing);
|
||||
return existing;
|
||||
}
|
||||
|
||||
public static final @Nullable EntityTypes get(final String id) {
|
||||
return $REGISTRY.get(id);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static final EntityTypes get(final int ordinal) {
|
||||
return values[ordinal];
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return values.length;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -19,29 +19,58 @@
|
||||
|
||||
package com.sk89q.worldedit.world.item;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface ItemType {
|
||||
public class ItemType {
|
||||
|
||||
default ItemTypes toEnum() {
|
||||
return (ItemTypes) this;
|
||||
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type");
|
||||
|
||||
private String id;
|
||||
private BlockType blockType;
|
||||
private int internalId;
|
||||
private BaseItem defaultState;
|
||||
|
||||
public ItemType(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (!id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
this.id = id;
|
||||
this.blockType = BlockTypes.get(this.id);
|
||||
}
|
||||
|
||||
String getId();
|
||||
|
||||
int getInternalId();
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getInternalId() {
|
||||
return this.internalId;
|
||||
}
|
||||
|
||||
public void setInternalId(int internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this item, or the ID if the name cannot be found.
|
||||
*
|
||||
* @return The name, or ID
|
||||
*/
|
||||
String getName();
|
||||
public String getName() {
|
||||
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().getName(this);
|
||||
if (name == null) {
|
||||
return getId();
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -49,7 +78,7 @@ public interface ItemType {
|
||||
*
|
||||
* @return If it has a block
|
||||
*/
|
||||
default boolean hasBlockType() {
|
||||
public boolean hasBlockType() {
|
||||
return getBlockType() != null;
|
||||
}
|
||||
|
||||
@ -59,11 +88,34 @@ public interface ItemType {
|
||||
* @return The block representation
|
||||
*/
|
||||
@Nullable
|
||||
default BlockTypes getBlockType() {
|
||||
return BlockTypes.get(getId());
|
||||
public BlockType getBlockType() {
|
||||
return this.blockType;
|
||||
}
|
||||
|
||||
public void setBlockType(BlockType blockType) {
|
||||
this.blockType = blockType;
|
||||
}
|
||||
|
||||
public BaseItem getDefaultState() {
|
||||
return this.defaultState;
|
||||
}
|
||||
|
||||
public void setDefaultState(BaseItem defaultState) {
|
||||
this.defaultState = defaultState;
|
||||
}
|
||||
|
||||
default BaseItem getDefaultState() {
|
||||
return new BaseItem(this);
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof ItemType && this.id.equals(((ItemType) obj).id);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -55,7 +55,7 @@ public interface BlockRegistry {
|
||||
* @param blockType the block
|
||||
* @return a map of states where the key is the state's ID
|
||||
*/
|
||||
Map<String, ? extends Property> getProperties(BlockType blockType);
|
||||
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public class BundledBlockRegistry implements BlockRegistry {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, ? extends Property> getProperties(BlockType blockType) {
|
||||
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
|
||||
return Collections.emptyMap(); // Oof
|
||||
}
|
||||
|
||||
|
@ -44,4 +44,11 @@ public class BundledItemRegistry implements ItemRegistry {
|
||||
public Collection<String> registerItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(ItemType itemType) {
|
||||
BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId());
|
||||
return itemEntry != null ? itemEntry.localizedName : null;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.registry;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
@ -43,7 +44,7 @@ public interface EntityRegistry {
|
||||
*/
|
||||
@Nullable
|
||||
default BaseEntity createFromId(String id) {
|
||||
EntityTypes entType = EntityTypes.get(id);
|
||||
EntityType entType = EntityTypes.get(id);
|
||||
return entType == null ? null : new BaseEntity(entType);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
@ -42,5 +43,14 @@ public interface ItemRegistry {
|
||||
default Collection<String> registerItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name for the given item.
|
||||
*
|
||||
* @param itemType the item
|
||||
* @return The name, or null if it's unknown
|
||||
*/
|
||||
@Nullable
|
||||
String getName(ItemType itemType);
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class LegacyMapper {
|
||||
private final Int2ObjectArrayMap<Integer> blockStateToLegacyId4Data = new Int2ObjectArrayMap<>();
|
||||
private final Int2ObjectArrayMap<Integer> extraId4DataToStateId = new Int2ObjectArrayMap<>();
|
||||
private final int[] blockArr = new int[4096];
|
||||
private final BiMap<Integer, ItemTypes> itemMap = HashBiMap.create();
|
||||
private final BiMap<Integer, ItemType> itemMap = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -96,7 +96,7 @@ public class LegacyMapper {
|
||||
try {
|
||||
BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue());
|
||||
// BlockState blockState = WorldEdit.getInstance().getBlockFactory().parseFromInput(blockEntry.getValue(), parserContext).toImmutableState();
|
||||
BlockTypes type = blockState.getBlockType();
|
||||
BlockType type = blockState.getBlockType();
|
||||
if (type.hasProperty(PropertyKey.WATERLOGGED)) {
|
||||
blockState = blockState.with(PropertyKey.WATERLOGGED, false);
|
||||
}
|
||||
@ -134,11 +134,11 @@ public class LegacyMapper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemTypes getItemFromLegacy(int legacyId) {
|
||||
public ItemType getItemFromLegacy(int legacyId) {
|
||||
return itemMap.get(legacyId << 4);
|
||||
}
|
||||
|
||||
public ItemTypes getItemFromLegacy(String input) {
|
||||
public ItemType getItemFromLegacy(String input) {
|
||||
if (input.startsWith("minecraft:")) input = input.substring(10);
|
||||
return itemMap.get(getCombinedId(input));
|
||||
}
|
||||
@ -149,7 +149,7 @@ public class LegacyMapper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemTypes getItemFromLegacy(int legacyId, int data) {
|
||||
public ItemType getItemFromLegacy(int legacyId, int data) {
|
||||
return itemMap.get((legacyId << 4) + data);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user