Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 11:00:05 +01:00
Use fuzzy blocks in default block parser
Dieser Commit ist enthalten in:
Ursprung
55b02e1b1f
Commit
113aeb1689
@ -47,6 +47,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
|
|||||||
import com.sk89q.worldedit.extent.inventory.SlottableBlockBag;
|
import com.sk89q.worldedit.extent.inventory.SlottableBlockBag;
|
||||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.registry.state.Property;
|
||||||
import com.sk89q.worldedit.util.HandSide;
|
import com.sk89q.worldedit.util.HandSide;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
@ -54,9 +55,11 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@ -249,10 +252,28 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
throw new NoMatchException(BBC.getPrefix() + "Does not match a valid block type: '" + input + "'");
|
throw new NoMatchException(BBC.getPrefix() + "Does not match a valid block type: '" + input + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (nbt == null) nbt = state.getNbtData();
|
if (nbt == null) nbt = state.getNbtData();
|
||||||
|
|
||||||
if (stateString != null) {
|
if (stateString != null) {
|
||||||
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state);
|
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state);
|
||||||
|
if (context.isPreferringWildcard()) {
|
||||||
|
if (stateString.isEmpty()) {
|
||||||
|
state = new FuzzyBlockState(state);
|
||||||
|
} else {
|
||||||
|
BlockType type = state.getBlockType();
|
||||||
|
FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder();
|
||||||
|
fuzzyBuilder.type(type);
|
||||||
|
String[] entries = stateString.split(",");
|
||||||
|
for (String entry : entries) {
|
||||||
|
String[] split = entry.split("=");
|
||||||
|
String key = split[0];
|
||||||
|
String val = split[1];
|
||||||
|
Property<Object> prop = type.getProperty(key);
|
||||||
|
fuzzyBuilder.withProperty(prop, prop.getValueFor(val));
|
||||||
|
}
|
||||||
|
state = fuzzyBuilder.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ public class DefaultMaskParser extends FaweParser<Mask> {
|
|||||||
} catch (InputParseException ignore) {}
|
} catch (InputParseException ignore) {}
|
||||||
}
|
}
|
||||||
if (mask == null) {
|
if (mask == null) {
|
||||||
context.setPreferringWildcard(true);
|
context.setPreferringWildcard(false);
|
||||||
context.setRestricted(false);
|
context.setRestricted(false);
|
||||||
BlockStateHolder block = worldEdit.getBlockFactory().parseFromInput(full, context);
|
BlockStateHolder block = worldEdit.getBlockFactory().parseFromInput(full, context);
|
||||||
builder.add(block);
|
builder.add(block);
|
||||||
|
@ -37,20 +37,24 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public class FuzzyBlockState extends BlockState {
|
public class FuzzyBlockState extends BlockState {
|
||||||
|
|
||||||
private final Map<PropertyKey, Object> state;
|
private final Map<PropertyKey, Object> props;
|
||||||
|
|
||||||
FuzzyBlockState(BlockType blockType) {
|
public FuzzyBlockState(BlockType blockType) {
|
||||||
this(blockType, null);
|
this(blockType.getDefaultState(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FuzzyBlockState(BlockType blockType, Map<Property<?>, Object> values) {
|
public FuzzyBlockState(BlockState state) {
|
||||||
super(blockType, blockType.getDefaultState().getInternalId(), blockType.getDefaultState().getOrdinal());
|
this(state, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) {
|
||||||
|
super(state.getBlockType(), state.getInternalId(), state.getOrdinal());
|
||||||
if (values == null || values.isEmpty()) {
|
if (values == null || values.isEmpty()) {
|
||||||
state = Collections.emptyMap();
|
props = Collections.emptyMap();
|
||||||
} else {
|
} else {
|
||||||
state = new HashMap<>(values.size());
|
props = new HashMap<>(values.size());
|
||||||
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
|
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
|
||||||
state.put(entry.getKey().getKey(), entry.getValue());
|
props.put(entry.getKey().getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,8 +80,8 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
if (!getBlockType().equals(o.getBlockType())) {
|
if (!getBlockType().equals(o.getBlockType())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!state.isEmpty()) {
|
if (!props.isEmpty()) {
|
||||||
for (Map.Entry<PropertyKey, Object> entry : state.entrySet()) {
|
for (Map.Entry<PropertyKey, Object> entry : props.entrySet()) {
|
||||||
if (!Objects.equals(o.getState(entry.getKey()), entry.getValue())) {
|
if (!Objects.equals(o.getState(entry.getKey()), entry.getValue())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -86,6 +90,11 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock toBaseBlock() {
|
||||||
|
return new BaseBlock();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState toImmutableState() {
|
public BlockState toImmutableState() {
|
||||||
return getFullState();
|
return getFullState();
|
||||||
@ -158,7 +167,7 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
if (values.isEmpty()) {
|
if (values.isEmpty()) {
|
||||||
return type.getFuzzyMatcher();
|
return type.getFuzzyMatcher();
|
||||||
}
|
}
|
||||||
return new FuzzyBlockState(type, values);
|
return new FuzzyBlockState(type.getDefaultState(), values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren