Permalink
Browse files

state stuff

  • Loading branch information...
kashike committed Jul 5, 2018
1 parent b8214b7 commit 4ba6a36f8ed0638e155f6c5465b00228aba511a0
Showing with 97 additions and 216 deletions.
  1. +7 −8 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
  2. +6 −7 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java
  3. +10 −10 worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java
  4. +15 −20 ...ain/java/com/sk89q/worldedit/registry/state/{value/SimpleStateValue.java → AbstractProperty.java}
  5. +11 −3 ...c/main/java/com/sk89q/worldedit/registry/state/{DirectionalState.java → DirectionalProperty.java}
  6. +1 −3 worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/{State.java → Property.java}
  7. +0 −66 worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/SimpleState.java
  8. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/value/DirectionalStateValue.java
  9. +0 −49 worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/value/StateValue.java
  10. +29 −30 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java
  11. +6 −7 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java
  12. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java
  13. +5 −5 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java
  14. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java
  15. +2 −3 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java
@@ -22,14 +22,13 @@
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
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 com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.registry.state.State;
import com.sk89q.worldedit.registry.state.value.StateValue;
import java.util.Map;
import java.util.Objects;
@@ -131,7 +130,7 @@ public int getData() {
* @return The state map
*/
@Override
public Map<State, StateValue> getStates() {
public Map<Property<?>, Object> getStates() {
return this.blockState.getStates();
}
@@ -141,19 +140,19 @@ public BlockType getBlockType() {
}
@Override
public BaseBlock with(State state, StateValue value) {
return new BaseBlock(this.blockState.with(state, value), getNbtData());
public <V> BaseBlock with(Property<V> property, V value) {
return new BaseBlock(this.blockState.with(property, value), getNbtData());
}
/**
* Gets the State for this Block.
*
* @param state The state to get the value for
* @param property The state to get the value for
* @return The state value
*/
@Override
public StateValue getState(State state) {
return this.blockState.getState(state);
public <V> V getState(Property<V> property) {
return this.blockState.getState(property);
}
@Override
@@ -44,8 +44,7 @@
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.State;
import com.sk89q.worldedit.registry.state.value.StateValue;
import com.sk89q.worldedit.registry.state.Property;
import java.util.HashMap;
import java.util.Map;
@@ -163,16 +162,16 @@ private static BlockState applyProperties(BlockState state, String[] stateProper
throw new NoMatchException("Bad state format in " + parseableData);
}
State stateKey = BundledBlockData.getInstance().findById(state.getBlockType().getId()).states.get(parts[0]);
if (stateKey == null) {
Property propertyKey = BundledBlockData.getInstance().findById(state.getBlockType().getId()).states.get(parts[0]);
if (propertyKey == null) {
throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName());
}
StateValue value = stateKey.getValueFor(parts[1]);
Object value = propertyKey.getValueFor(parts[1]);
if (value == null) {
throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]);
}
state = state.with(stateKey, value);
state = state.with(propertyKey, value);
} catch (NoMatchException e) {
throw e; // Pass-through
} catch (Exception e) {
@@ -186,7 +185,7 @@ private static BlockState applyProperties(BlockState state, String[] stateProper
private BlockStateHolder parseLogic(String input, ParserContext context) throws InputParseException {
BlockType blockType;
Map<State, StateValue> blockStates = new HashMap<>();
Map<Property<?>, Object> blockStates = new HashMap<>();
String[] blockAndExtraData = input.trim().split("\\|");
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
Matcher matcher = blockStatePattern.matcher(blockAndExtraData[0]);
@@ -32,8 +32,8 @@
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.registry.state.DirectionalState;
import com.sk89q.worldedit.registry.state.State;
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;
@@ -128,20 +128,20 @@ public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEdi
checkNotNull(block);
checkNotNull(transform);
Map<String, ? extends State> states = WorldEdit.getInstance().getPlatformManager()
Map<String, ? extends Property> states = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getStates(block);
if (states == null) {
return changedBlock;
}
for (State state : states.values()) {
if (state instanceof DirectionalState) {
DirectionalStateValue value = (DirectionalStateValue) block.getState(state);
if (value != null && value.getData() != null) {
DirectionalStateValue newValue = getNewStateValue((DirectionalState) state, transform, value.getDirection());
for (Property property : states.values()) {
if (property instanceof DirectionalProperty) {
DirectionalStateValue value = (DirectionalStateValue) block.getState(property);
if (value != null) {
DirectionalStateValue newValue = getNewStateValue((DirectionalProperty) property, transform, value.getDirection());
if (newValue != null) {
changedBlock.with(state, newValue);
changedBlock.with(property, newValue);
}
}
}
@@ -159,7 +159,7 @@ public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEdi
* @return a new state or null if none could be found
*/
@Nullable
private static DirectionalStateValue getNewStateValue(DirectionalState state, Transform transform, Vector oldDirection) {
private static DirectionalStateValue getNewStateValue(DirectionalProperty state, Transform transform, Vector oldDirection) {
Vector newDirection = transform.apply(oldDirection).subtract(transform.apply(Vector.ZERO)).normalize();
DirectionalStateValue newValue = null;
double closest = -2;
@@ -17,36 +17,31 @@
* 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 java.util.Objects;
import static com.google.common.base.Preconditions.checkState;
public class SimpleStateValue implements StateValue {
public abstract class AbstractProperty<T> implements Property<T> {
private String data;
private String name;
@Override
public boolean isSet() {
return data != null;
}
@Override
public void set(String data) {
this.data = data;
public AbstractProperty() {
}
@Override
public String getData() {
return this.data;
public AbstractProperty(final String name) {
this.name = name;
}
@Override
public boolean equals(Object obj) {
return obj instanceof StateValue && Objects.equals(((StateValue) obj).getData(), getData());
public String getName() {
return this.name;
}
@Override
public int hashCode() {
return this.data.hashCode();
/**
* Internal method for name setting post-deserialise. Do not use.
*/
public void setName(final String name) {
checkState(this.name == null, "name already set");
this.name = name;
}
}
@@ -23,9 +23,17 @@
import java.util.List;
public class DirectionalState extends SimpleState<DirectionalStateValue> {
import javax.annotation.Nullable;
public DirectionalState(List<DirectionalStateValue> values) {
super(values);
public class DirectionalProperty extends AbstractProperty<DirectionalStateValue> {
@Override
public List<DirectionalStateValue> getValues() {
return null;
}
@Nullable
@Override
public DirectionalStateValue getValueFor(final String string) {
return null;
}
}
@@ -19,8 +19,6 @@
package com.sk89q.worldedit.registry.state;
import com.sk89q.worldedit.registry.state.value.SimpleStateValue;
import java.util.List;
import javax.annotation.Nullable;
@@ -31,7 +29,7 @@
* <p>Example states include "variant" (indicating material or type) and
* "facing" (indicating orientation).</p>
*/
public interface State<T extends SimpleStateValue> {
public interface Property<T> {
/**
* Returns the name of this state.

This file was deleted.

Oops, something went wrong.
@@ -21,7 +21,7 @@
import com.sk89q.worldedit.Vector;
public class DirectionalStateValue extends SimpleStateValue {
public class DirectionalStateValue {
public Vector getDirection() {
return new Vector(); // TODO

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 4ba6a36

Please sign in to comment.