mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Convert the data system to a state system. This doesn't work, needs new data
This commit is contained in:
@ -27,7 +27,6 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
@ -37,15 +36,16 @@ import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link World}.
|
||||
*/
|
||||
public abstract class AbstractWorld implements World {
|
||||
|
||||
private final PriorityQueue<QueuedEffect> effectQueue = new PriorityQueue<QueuedEffect>();
|
||||
private final PriorityQueue<QueuedEffect> effectQueue = new PriorityQueue<>();
|
||||
private int taskId = -1;
|
||||
|
||||
@Override
|
||||
@ -65,7 +65,7 @@ public abstract class AbstractWorld implements World {
|
||||
@Override
|
||||
public final void setBlockData(Vector position, int data) {
|
||||
try {
|
||||
setBlock(position, new BaseBlock(getLazyBlock(position).getType(), data));
|
||||
setBlock(position, new BaseBlock(getLazyBlock(position).getType().getLegacyId(), data));
|
||||
} catch (WorldEditException ignored) {
|
||||
}
|
||||
}
|
||||
@ -103,10 +103,10 @@ public abstract class AbstractWorld implements World {
|
||||
@Override
|
||||
public Mask createLiquidMask() {
|
||||
return new BlockMask(this,
|
||||
new BaseBlock(BlockTypes.LAVA, -1),
|
||||
new BaseBlock(BlockTypes.FLOWING_LAVA, -1),
|
||||
new BaseBlock(BlockTypes.WATER, -1),
|
||||
new BaseBlock(BlockTypes.FLOWING_WATER, -1));
|
||||
new BaseBlock(BlockTypes.LAVA),
|
||||
new BaseBlock(BlockTypes.FLOWING_LAVA),
|
||||
new BaseBlock(BlockTypes.WATER),
|
||||
new BaseBlock(BlockTypes.FLOWING_WATER));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
@ -26,6 +26,8 @@ import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.world.registry.state.SimpleState;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
@ -53,8 +55,8 @@ public class BundledBlockData {
|
||||
private static final Logger log = Logger.getLogger(BundledBlockData.class.getCanonicalName());
|
||||
private static final BundledBlockData INSTANCE = new BundledBlockData();
|
||||
|
||||
private final Map<String, BlockEntry> idMap = new HashMap<String, BlockEntry>();
|
||||
private final Map<Integer, BlockEntry> legacyMap = new HashMap<Integer, BlockEntry>(); // Trove usage removed temporarily
|
||||
private final Map<String, BlockEntry> idMap = new HashMap<>();
|
||||
private final Map<Integer, BlockEntry> legacyMap = new HashMap<>(); // Trove usage removed temporarily
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -84,7 +86,6 @@ public class BundledBlockData {
|
||||
List<BlockEntry> entries = gson.fromJson(data, new TypeToken<List<BlockEntry>>() {}.getType());
|
||||
|
||||
for (BlockEntry entry : entries) {
|
||||
entry.postDeserialization();
|
||||
idMap.put(entry.id, entry);
|
||||
legacyMap.put(entry.legacyId, entry);
|
||||
}
|
||||
@ -196,12 +197,6 @@ public class BundledBlockData {
|
||||
private List<String> aliases;
|
||||
private Map<String, SimpleState> states = new HashMap<>();
|
||||
private SimpleBlockMaterial material = new SimpleBlockMaterial();
|
||||
|
||||
void postDeserialization() {
|
||||
for (SimpleState state : states.values()) {
|
||||
state.postDeserialization();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.registry;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleState implements State {
|
||||
|
||||
private Byte dataMask;
|
||||
private Map<String, SimpleStateValue> values;
|
||||
|
||||
@Override
|
||||
public Map<String, SimpleStateValue> valueMap() {
|
||||
return Collections.unmodifiableMap(values);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public StateValue getValue(BaseBlock block) {
|
||||
for (StateValue value : values.values()) {
|
||||
if (value.isSet(block)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte getDataMask() {
|
||||
return dataMask != null ? dataMask : 0xF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDirection() {
|
||||
for (SimpleStateValue value : values.values()) {
|
||||
if (value.getDirection() != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void postDeserialization() {
|
||||
for (SimpleStateValue v : values.values()) {
|
||||
v.setState(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.world.registry.state;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.state.value.DirectionalStateValue;
|
||||
|
||||
public class DirectionalState extends SimpleState<DirectionalStateValue> {
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.world.registry.state;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.state.value.SimpleStateValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleState<T extends SimpleStateValue> implements State<T> {
|
||||
|
||||
private List<T> values = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public List<T> getValues() {
|
||||
return Collections.unmodifiableList(values);
|
||||
}
|
||||
|
||||
}
|
@ -17,12 +17,11 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
package com.sk89q.worldedit.world.registry.state;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.registry.state.value.SimpleStateValue;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes a state property of a block.
|
||||
@ -30,32 +29,13 @@ import java.util.Map;
|
||||
* <p>Example states include "variant" (indicating material or type) and
|
||||
* "facing" (indicating orientation).</p>
|
||||
*/
|
||||
public interface State {
|
||||
public interface State<T extends SimpleStateValue> {
|
||||
|
||||
/**
|
||||
* Return a map of available values for this state.
|
||||
* Return a list of available values for this state.
|
||||
*
|
||||
* <p>Keys are the value of state and map values describe that
|
||||
* particular state value.</p>
|
||||
*
|
||||
* @return the map of state values
|
||||
* @return the list of state values
|
||||
*/
|
||||
Map<String, ? extends StateValue> valueMap();
|
||||
|
||||
/**
|
||||
* Get the value that the block is set to.
|
||||
*
|
||||
* @param block the block
|
||||
* @return the state, otherwise null if the block isn't set to any of the values
|
||||
*/
|
||||
@Nullable
|
||||
StateValue getValue(BaseBlock block);
|
||||
|
||||
/**
|
||||
* Returns whether this state contains directional data.
|
||||
*
|
||||
* @return true if directional data is available
|
||||
*/
|
||||
boolean hasDirection();
|
||||
List<T> getValues();
|
||||
|
||||
}
|
@ -17,39 +17,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
package com.sk89q.worldedit.world.registry.state.value;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
class SimpleStateValue implements StateValue {
|
||||
public class DirectionalStateValue extends SimpleStateValue {
|
||||
|
||||
private SimpleState state;
|
||||
private Byte data;
|
||||
private Vector direction;
|
||||
|
||||
void setState(SimpleState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSet(BaseBlock block) {
|
||||
return data != null && (block.getData() & state.getDataMask()) == data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(BaseBlock block) {
|
||||
if (data != null) {
|
||||
block.setData((block.getData() & ~state.getDataMask()) | data);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getDirection() {
|
||||
return direction;
|
||||
return new Vector(); // TODO
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.world.registry.state.value;
|
||||
|
||||
public class SimpleStateValue implements StateValue {
|
||||
|
||||
private String data;
|
||||
|
||||
@Override
|
||||
public boolean isSet() {
|
||||
return data != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
}
|
@ -17,10 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
package com.sk89q.worldedit.world.registry.state.value;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -32,25 +29,21 @@ public interface StateValue {
|
||||
/**
|
||||
* Return whether this state is set on the given block.
|
||||
*
|
||||
* @param block the block
|
||||
* @return true if this value is set
|
||||
*/
|
||||
boolean isSet(BaseBlock block);
|
||||
boolean isSet();
|
||||
|
||||
/**
|
||||
* Set the state to this value on the given block.
|
||||
*
|
||||
* @param block the block to change
|
||||
* @return true if the value was set successfully
|
||||
* Set the state to the given value.
|
||||
*/
|
||||
boolean set(BaseBlock block);
|
||||
void set(String data);
|
||||
|
||||
/**
|
||||
* Return the direction associated with this value.
|
||||
* Returns the data associated with this value.
|
||||
*
|
||||
* @return the direction, otherwise null
|
||||
* @return The data, otherwise null
|
||||
*/
|
||||
@Nullable
|
||||
Vector getDirection();
|
||||
String getData();
|
||||
|
||||
}
|
Reference in New Issue
Block a user