Start work on the new BaseBlock/BlockState split

This commit is contained in:
Matthew Miller
2018-06-17 15:42:47 +10:00
parent aaaf2d5678
commit c43109bde5
20 changed files with 273 additions and 268 deletions

View File

@ -180,7 +180,7 @@ public abstract class AbstractWorld implements World {
}
@Override
public boolean queueBlockBreakEffect(Platform server, Vector position, int blockId, double priority) {
public boolean queueBlockBreakEffect(Platform server, Vector position, com.sk89q.worldedit.blocks.type.BlockType blockType, double priority) {
if (taskId == -1) {
taskId = server.schedule(0, 1, () -> {
int max = Math.max(1, Math.min(30, effectQueue.size() / 3));
@ -196,7 +196,7 @@ public abstract class AbstractWorld implements World {
return false;
}
effectQueue.offer(new QueuedEffect(position, blockId, priority));
effectQueue.offer(new QueuedEffect(position, blockType, priority));
return true;
}
@ -218,17 +218,17 @@ public abstract class AbstractWorld implements World {
private class QueuedEffect implements Comparable<QueuedEffect> {
private final Vector position;
private final int blockId;
private final com.sk89q.worldedit.blocks.type.BlockType blockType;
private final double priority;
private QueuedEffect(Vector position, int blockId, double priority) {
private QueuedEffect(Vector position, com.sk89q.worldedit.blocks.type.BlockType blockType, double priority) {
this.position = position;
this.blockId = blockId;
this.blockType = blockType;
this.priority = priority;
}
public void play() {
playEffect(position, 2001, blockId);
playEffect(position, 2001, blockType.getLegacyId());
}
@Override

View File

@ -27,6 +27,7 @@ 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.type.BlockType;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
@ -262,11 +263,11 @@ public interface World extends Extent {
*
* @param server the server
* @param position the position
* @param blockId the block ID
* @param blockType the block type
* @param priority the priority
* @return true if the effect was played
*/
boolean queueBlockBreakEffect(Platform server, Vector position, int blockId, double priority);
boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority);
/**
* Get the data for blocks and so on for this world.

View File

@ -98,7 +98,7 @@ public class BundledBlockData {
* @return the entry, or null
*/
@Nullable
private BlockEntry findById(String id) {
public BlockEntry findById(String id) {
// If it has no namespace, assume minecraft.
if (!id.contains(":")) {
id = "minecraft:" + id;
@ -190,10 +190,11 @@ public class BundledBlockData {
return INSTANCE;
}
private static class BlockEntry {
public static class BlockEntry {
private int legacyId;
private String id;
private String unlocalizedName;
public String localizedName;
private List<String> aliases;
private Map<String, SimpleState> states = new HashMap<>();
private SimpleBlockMaterial material = new SimpleBlockMaterial();

View File

@ -21,6 +21,11 @@ package com.sk89q.worldedit.world.registry.state;
import com.sk89q.worldedit.world.registry.state.value.DirectionalStateValue;
import java.util.List;
public class DirectionalState extends SimpleState<DirectionalStateValue> {
public DirectionalState(List<DirectionalStateValue> values) {
super(values);
}
}

View File

@ -21,17 +21,24 @@ 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<>();
private List<T> values;
/**
* Creates a state with values
*
* @param values The values
*/
public SimpleState(List<T> values) {
this.values = values;
}
@Override
public List<T> getValues() {
return Collections.unmodifiableList(values);
}
}