This commit is contained in:
Jesse Boyd
2020-01-07 00:09:49 +00:00
42 changed files with 1592 additions and 906 deletions

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.WorldEdit;
import com.google.common.collect.Iterables;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.Extent;
@ -33,20 +32,21 @@ 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;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
public class BlockType implements FawePattern, Keyed {
@ -54,7 +54,11 @@ public class BlockType implements FawePattern, Keyed {
private final String id;
private final BlockTypesCache.Settings settings;
/*
private final LazyReference<Integer> legacyId = LazyReference.from(() -> computeLgacy(0));
private final LazyReference<Integer> legacyData = LazyReference.from(() -> computeLegacy(1));
*/
private Integer legacyCombinedId;
private boolean initItemType;
private ItemType itemType;
@ -103,6 +107,7 @@ public class BlockType implements FawePattern, Keyed {
return name;
}
}
/*
private BlockState computeDefaultState() {
@ -212,7 +217,7 @@ public class BlockType implements FawePattern, Keyed {
*/
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));
id = btp.modify(id, btp.getValueFor((String) value));
}
return withStateId(id);
}
@ -233,7 +238,7 @@ public class BlockType implements FawePattern, Keyed {
*/
@Nullable
public ItemType getItemType() {
if(!initItemType) {
if (!initItemType) {
initItemType = true;
itemType = ItemTypes.get(this.id);
}
@ -251,7 +256,7 @@ public class BlockType implements FawePattern, Keyed {
/**
* Gets the legacy ID. Needed for legacy reasons.
*
* <p>
* DO NOT USE THIS.
*
* @return legacy id or 0, if unknown
@ -264,7 +269,7 @@ public class BlockType implements FawePattern, Keyed {
/**
* The internal index of this type.
*
* <p>
* This number is not necessarily consistent across restarts.
*
* @return internal id
@ -288,7 +293,6 @@ public class BlockType implements FawePattern, Keyed {
return obj == this; // stop changing this to a shitty string comparison
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return set.setBlock(extent, getDefaultState());
@ -307,14 +311,27 @@ public class BlockType implements FawePattern, Keyed {
return new SingleBlockTypeMask(extent, this);
}
@Deprecated
public int getLegacyId() {
Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
if (id != null) {
return id >> 4;
} else {
return 0;
return computeLegacy(0);
}
/**
* Gets the legacy data. Needed for legacy reasons.
* <p>
* DO NOT USE THIS.
*
* @return legacy data or 0, if unknown
*/
@Deprecated
public int getLegacyData() {
return computeLegacy(1);
}
private int computeLegacy(int index) {
if (this.legacyCombinedId == null) {
this.legacyCombinedId = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
}
return index == 0 ? legacyCombinedId >> 4 : legacyCombinedId & 15;
}
}