mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Almost finished the state system. Just got to have it actually load in the values.
This commit is contained in:
parent
3e1d438565
commit
4938f419ad
@ -20,12 +20,15 @@
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
|
||||
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -41,6 +44,23 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
|
||||
material -> new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(id), material));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getPropertyValues(BlockType blockType, Property<?> property) {
|
||||
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
|
||||
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getPropertyValues(blockType, property);
|
||||
}
|
||||
return super.getPropertyValues(blockType, property);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, ? extends Property> getProperties(BlockType blockType) {
|
||||
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
|
||||
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getProperties(blockType);
|
||||
}
|
||||
return super.getProperties(blockType);
|
||||
}
|
||||
|
||||
public static class BukkitBlockMaterial extends PassthroughBlockMaterial {
|
||||
|
||||
private final Material material;
|
||||
|
@ -20,12 +20,17 @@
|
||||
package com.sk89q.worldedit.bukkit.adapter;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@ -91,4 +96,19 @@ public interface BukkitImplAdapter {
|
||||
Entity createEntity(Location location, BaseEntity state);
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of values for a property.
|
||||
*
|
||||
* @param property The property
|
||||
* @return The list of values
|
||||
*/
|
||||
List<Object> getPropertyValues(BlockType blockType, Property<?> property);
|
||||
|
||||
/**
|
||||
* Get a map of string -> properties
|
||||
*
|
||||
* @param blockType The block type
|
||||
* @return The properties map
|
||||
*/
|
||||
Map<String, ? extends Property> getProperties(BlockType blockType);
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -29,10 +29,6 @@ import com.sk89q.worldedit.blocks.MobSpawnerBlock;
|
||||
import com.sk89q.worldedit.blocks.SignBlock;
|
||||
import com.sk89q.worldedit.blocks.SkullBlock;
|
||||
import com.sk89q.worldedit.blocks.metadata.MobType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
@ -41,11 +37,15 @@ import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@ -162,7 +162,8 @@ class DefaultBlockParser extends InputParser<BlockStateHolder> {
|
||||
throw new NoMatchException("Bad state format in " + parseableData);
|
||||
}
|
||||
|
||||
Property propertyKey = BundledBlockData.getInstance().findById(state.getBlockType().getId()).states.get(parts[0]);
|
||||
Property propertyKey = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
|
||||
.getRegistries().getBlockRegistry().getProperties(state.getBlockType()).get(parts[0]);
|
||||
if (propertyKey == null) {
|
||||
throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName());
|
||||
}
|
||||
@ -194,7 +195,7 @@ class DefaultBlockParser extends InputParser<BlockStateHolder> {
|
||||
}
|
||||
String typeString = matcher.group(1);
|
||||
String[] stateProperties = EMPTY_STRING_ARRAY;
|
||||
if (matcher.groupCount() == 3) {
|
||||
if (matcher.groupCount() >= 2 && matcher.group(2) != null) {
|
||||
stateProperties = matcher.group(2).split(",");
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,6 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.registry.state.DirectionalProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.value.DirectionalStateValue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -129,7 +128,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
checkNotNull(transform);
|
||||
|
||||
Map<String, ? extends Property> states = WorldEdit.getInstance().getPlatformManager()
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getStates(block);
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getProperties(block.getBlockType());
|
||||
|
||||
if (states == null) {
|
||||
return changedBlock;
|
||||
@ -137,9 +136,9 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
|
||||
for (Property property : states.values()) {
|
||||
if (property instanceof DirectionalProperty) {
|
||||
DirectionalStateValue value = (DirectionalStateValue) block.getState(property);
|
||||
Vector value = (Vector) block.getState(property);
|
||||
if (value != null) {
|
||||
DirectionalStateValue newValue = getNewStateValue((DirectionalProperty) property, transform, value.getDirection());
|
||||
Vector newValue = getNewStateValue((DirectionalProperty) property, transform, value);
|
||||
if (newValue != null) {
|
||||
changedBlock.with(property, newValue);
|
||||
}
|
||||
@ -159,20 +158,18 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
* @return a new state or null if none could be found
|
||||
*/
|
||||
@Nullable
|
||||
private static DirectionalStateValue getNewStateValue(DirectionalProperty state, Transform transform, Vector oldDirection) {
|
||||
private static Vector getNewStateValue(DirectionalProperty state, Transform transform, Vector oldDirection) {
|
||||
Vector newDirection = transform.apply(oldDirection).subtract(transform.apply(Vector.ZERO)).normalize();
|
||||
DirectionalStateValue newValue = null;
|
||||
Vector newValue = null;
|
||||
double closest = -2;
|
||||
boolean found = false;
|
||||
|
||||
for (DirectionalStateValue v : state.getValues()) {
|
||||
if (v.getDirection() != null) {
|
||||
double dot = v.getDirection().normalize().dot(newDirection);
|
||||
if (dot >= closest) {
|
||||
closest = dot;
|
||||
newValue = v;
|
||||
found = true;
|
||||
}
|
||||
for (Vector v : state.getValues()) {
|
||||
double dot = v.normalize().dot(newDirection);
|
||||
if (dot >= closest) {
|
||||
closest = dot;
|
||||
newValue = v;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.registry.state;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BooleanProperty extends AbstractProperty<Boolean> {
|
||||
|
||||
@Override
|
||||
public List<Boolean> getValues() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Boolean getValueFor(String string) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -19,21 +19,21 @@
|
||||
|
||||
package com.sk89q.worldedit.registry.state;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.value.DirectionalStateValue;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DirectionalProperty extends AbstractProperty<DirectionalStateValue> {
|
||||
public class DirectionalProperty extends AbstractProperty<Vector> {
|
||||
@Override
|
||||
public List<DirectionalStateValue> getValues() {
|
||||
public List<Vector> getValues() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DirectionalStateValue getValueFor(final String string) {
|
||||
public Vector getValueFor(final String string) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,22 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.registry.state.value;
|
||||
package com.sk89q.worldedit.registry.state;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import java.util.List;
|
||||
|
||||
public class DirectionalStateValue {
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public Vector getDirection() {
|
||||
return new Vector(); // TODO
|
||||
public class EnumProperty extends AbstractProperty<String> {
|
||||
|
||||
@Override
|
||||
public List<String> getValues() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getValueFor(String string) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.registry.state;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class IntegerProperty extends AbstractProperty<Integer> {
|
||||
|
||||
@Override
|
||||
public List<Integer> getValues() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getValueFor(String string) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -20,10 +20,10 @@
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -33,15 +33,6 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public interface BlockRegistry {
|
||||
|
||||
/**
|
||||
* Create a new block using its ID.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the block, which may be null if no block exists
|
||||
*/
|
||||
@Nullable
|
||||
BlockState createFromId(String id);
|
||||
|
||||
/**
|
||||
* Get the material for the given block.
|
||||
*
|
||||
@ -51,13 +42,21 @@ public interface BlockRegistry {
|
||||
@Nullable
|
||||
BlockMaterial getMaterial(String id);
|
||||
|
||||
/**
|
||||
* Get an unmodifiable list of values for this property.
|
||||
*
|
||||
* @param blockType The block
|
||||
* @param property the property
|
||||
* @return the list of values
|
||||
*/
|
||||
List<Object> getPropertyValues(BlockType blockType, Property<?> property);
|
||||
|
||||
/**
|
||||
* Get an unmodifiable map of states for this block.
|
||||
*
|
||||
* @param block the block
|
||||
* @param blockType the block
|
||||
* @return a map of states where the key is the state's ID
|
||||
*/
|
||||
@Nullable
|
||||
Map<String, ? extends Property> getStates(BlockStateHolder block);
|
||||
Map<String, ? extends Property> getProperties(BlockType blockType);
|
||||
|
||||
}
|
||||
|
@ -25,11 +25,8 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
@ -39,6 +36,8 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Provides block data based on the built-in block database that is bundled
|
||||
* with WorldEdit.
|
||||
@ -86,7 +85,6 @@ public class BundledBlockData {
|
||||
|
||||
for (BlockEntry entry : entries) {
|
||||
idMap.put(entry.id, entry);
|
||||
entry.postDeserialization();
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,22 +119,6 @@ public class BundledBlockData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the states for the given block.
|
||||
*
|
||||
* @param id the string ID
|
||||
* @return the block's states, or null if no information is available
|
||||
*/
|
||||
@Nullable
|
||||
public Map<String, ? extends Property> getStatesById(String id) {
|
||||
BlockEntry entry = findById(id);
|
||||
if (entry != null) {
|
||||
return entry.states;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a singleton instance of this object.
|
||||
*
|
||||
@ -151,14 +133,7 @@ public class BundledBlockData {
|
||||
private String unlocalizedName;
|
||||
public String localizedName;
|
||||
private List<String> aliases;
|
||||
public Map<String, AbstractProperty> states = new HashMap<>();
|
||||
private SimpleBlockMaterial material = new SimpleBlockMaterial();
|
||||
|
||||
void postDeserialization() {
|
||||
for (Map.Entry<String, AbstractProperty> state : states.entrySet()) {
|
||||
state.getValue().setName(state.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -35,22 +35,21 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class BundledBlockRegistry implements BlockRegistry {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState createFromId(String id) {
|
||||
return BlockTypes.get(id).getDefaultState();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockMaterial getMaterial(String id) {
|
||||
return new PassthroughBlockMaterial(BundledBlockData.getInstance().getMaterialById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getPropertyValues(BlockType blockType, Property<?> property) {
|
||||
return Collections.emptyList(); // Oof
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, ? extends Property> getStates(BlockStateHolder block) {
|
||||
return BundledBlockData.getInstance().getStatesById(block.getBlockType().getId());
|
||||
public Map<String, ? extends Property> getProperties(BlockType blockType) {
|
||||
return Collections.emptyMap(); // Oof
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user