wip upstream merge

This commit is contained in:
Jesse Boyd
2019-04-04 00:25:16 +11:00
parent 7086eb8b3e
commit 8897109dc4
52 changed files with 236 additions and 209 deletions

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.world.biome;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Set;
/**
* Stores a list of common Biome String IDs.
@ -121,4 +123,8 @@ public class BiomeTypes {
public static BiomeType get(int parseInt) {
// TODO
}
public static List<BiomeType> values() {
}
}

View File

@ -29,6 +29,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.FawePattern;
import com.sk89q.worldedit.math.BlockVector3;
@ -52,31 +53,17 @@ import java.util.Set;
*/
@SuppressWarnings("unchecked")
public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
private final BlockType blockType;
private BlockMaterial material;
private BlockType blockType;
private int internalId, ordinal;
private BaseBlock emptyBaseBlock;
BlockState(BlockType blockType) {
BlockState(BlockType blockType, int internalId, int ordinal) {
this.blockType = blockType;
this.emptyBaseBlock = new BaseBlock(this);
this.internalId = internalId;
this.ordinal = ordinal;
}
BlockState(BlockType blockType, BaseBlock baseBlock){
this.blockType = blockType;
this.emptyBaseBlock = baseBlock;
}
/**
* Creates a fuzzy BlockState. This can be used for partial matching.
*
* @param blockType The block type
* @param values The block state values
*/
private BlockState(BlockType blockType, Map<Property<?>, Object> values) {
this.blockType = blockType;
// this.values = values;
// this.fuzzy = true;
}
/**
* Returns a temporary BlockState for a given internal id
* @param combinedId
@ -364,13 +351,22 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
@Override
public BlockMaterial getMaterial() {
return blockType.getMaterial();
if (this.material == null) {
if (blockType == BlockTypes.__RESERVED__) {
return this.material = blockType.getMaterial();
}
if (this.material == null) {
this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this);
}
}
return material;
}
@Override
public int getOrdinal() {
get ordinal
return this.ordinal;
}
/**
* Internal method used for creating the initial BlockState.
*
@ -399,8 +395,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return equalsFuzzy((BlockState) obj);
}
private Integer hashCodeCache = null;
@Override
public int hashCode() {
return getOrdinal();

View File

@ -21,14 +21,13 @@ package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.ImmutableList;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.function.pattern.FawePattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.google.common.collect.ImmutableMap;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.extension.platform.Capability;
@ -37,16 +36,11 @@ 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;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ -55,33 +49,50 @@ 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;
private final BlockTypeEnum typeEnum;
private BlockTypes.Settings settings;
public BlockType(@Nonnull String id) {
this(id, null);
// private ArrayList<BlockState> states;
// public final Function<BlockState, BlockState> defaultValue;
//
// private BlockMaterial material;
public BlockType(@Nonnull BlockTypeEnum typeEnum) {
this.typeEnum = typeEnum;
}
public BlockType(@Nonnull String id, Function<BlockState, BlockState> defaultValue) {
this.id = id;
this.defaultValue = defaultValue;
}
public void setStates(ArrayList<BlockState> states) {
public BlockTypeEnum getTypeEnum() {
return typeEnum;
}
private void init(String id, int internalId, List<BlockState> states) {
try {
if (getId() == null) {
String name = (name().indexOf(':') == -1 ? "minecraft:" : "") + name().toLowerCase();
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("id"), this, name);
}
Settings settings = new Settings(this, id, internalId, states);
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("settings"), this, settings);
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public void setStates(ArrayList<BlockState> states) { //
this.states = states;
}
public void setSettings(BlockTypes.Settings settings) {
public void setSettings(BlockTypes.Settings settings) { //
this.settings = settings;
}
public BlockTypes.Settings getSettings(){
public BlockTypes.Settings getSettings(){ //
return settings;
}
public ArrayList<BlockState> updateStates(){
public ArrayList<BlockState> updateStates(){ //
if(settings != null) {
return settings.localStates = new ArrayList<>(settings.localStates.stream()
.map(state -> new BlockStateImpl(this, state.getInternalId(), state.getOrdinal())).collect(Collectors.toList()));
@ -130,13 +141,13 @@ public class BlockType implements FawePattern {
}
@Deprecated
public BlockState withPropertyId(int propertyId) {
if (settings.stateOrdinals == null) return settings.defaultState;
return states.get(settings.stateOrdinals[propertyId]);
public BlockState withPropertyId(int internalPropertiesId) {
if (internalPropertiesId == 0) return getDefaultState();
return BlockState.getFromInternalId(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET));
}
@Deprecated
public BlockState withStateId(int internalStateId) {
public BlockState withStateId(int internalStateId) { //
return this.withPropertyId(internalStateId >> BlockTypes.BIT_OFFSET);
}
@ -145,7 +156,7 @@ public class BlockType implements FawePattern {
* @param properties
* @return
*/
public BlockState withProperties(String properties) {
public BlockState withProperties(String properties) { //
int id = getInternalId();
for (String keyPair : properties.split(",")) {
String[] split = keyPair.split("=");
@ -190,7 +201,6 @@ public class BlockType implements FawePattern {
*/
@Deprecated
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);
}
@ -213,18 +223,14 @@ public class BlockType implements FawePattern {
* @return The default state
*/
public BlockState getDefaultState() {
BlockState defaultState = this.settings.defaultState;
if (defaultValue != null) {
defaultState = defaultValue.apply(defaultState);
}
return defaultState;
return this.settings.defaultState;
}
public FuzzyBlockState getFuzzyMatcher() {
public FuzzyBlockState getFuzzyMatcher() { //
return new FuzzyBlockState(this);
}
public FuzzyBlockState getFuzzyMatcher() {
public FuzzyBlockState getFuzzyMatcher() { //
return updateField(emptyFuzzy, () -> new FuzzyBlockState(this));
}
@ -235,7 +241,7 @@ public class BlockType implements FawePattern {
@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());
return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> BlockTypes.states[i]).collect(Collectors.toList());
}
/**
@ -243,7 +249,7 @@ public class BlockType implements FawePattern {
*
* @return The state, if it exists
*/
public 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();
@ -278,7 +284,7 @@ public class BlockType implements FawePattern {
*/
@Nullable
public ItemType getItemType() {
return ItemTypes.get(this);
return settings.itemType;
}
/**
@ -287,9 +293,7 @@ public class BlockType implements FawePattern {
* @return The material
*/
public BlockMaterial getMaterial() {
return this.material == null ?
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this)
: this.material;
return this.settings.blockMaterial;
}
/**
@ -317,12 +321,12 @@ public class BlockType implements FawePattern {
@Override
public int hashCode() {
return this.getSettings().defaultState.ordinal();
return settings.internalId;
}
@Override
public boolean equals(Object obj) {
return obj instanceof BlockType && this.id.equals(((BlockType) obj).id);
return obj == this;
}
@Override
@ -347,7 +351,7 @@ public class BlockType implements FawePattern {
@Deprecated
public int getLegacyId() {
public int getLegacyId() { //
Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
if (id != null) {
return id >> 4;

View File

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

View File

@ -20,6 +20,7 @@
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;

View File

@ -872,6 +872,10 @@ public final class ItemTypes {
return ItemType.REGISTRY.register(type.getId(), type);
}
public static final @Nullable ItemType get(String id) {
}
public static final @Nullable ItemType get(BlockType type) {
ItemType item = get(type.getId());
if (item != null && item.getBlockType() == null) {

View File

@ -51,11 +51,4 @@ 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;
}
}

View File

@ -233,7 +233,7 @@ public class LegacyMapper {
try {
return BlockTypes.get(plotBlock.toString()).getDefaultState().toBaseBlock();
}catch(Throwable failed) {
log.severe("Unable to convert StringPlotBlock " + plotBlock + " to BaseBlock!");
log.error("Unable to convert StringPlotBlock " + plotBlock + " to BaseBlock!");
failed.printStackTrace();
return null;
}
@ -241,12 +241,12 @@ public class LegacyMapper {
try {
return new BaseBlock(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData());
}catch(Throwable failed) {
log.severe("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
failed.printStackTrace();
return null;
}
}else {
log.severe("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
return null;
}
}