mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:34:03 +00:00
Further work on BlockState transition
This commit is contained in:
@@ -28,12 +28,10 @@ import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.blocks.type.BlockType;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
import com.sk89q.worldedit.world.registry.state.value.StateValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -69,6 +67,13 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock(int id) {
|
||||
try {
|
||||
this.blockState = BlockTypes.getBlockType(BundledBlockData.getInstance().fromLegacyId(id)).getDefaultState();
|
||||
} catch (Exception e) {
|
||||
System.out.println(id);
|
||||
System.out.println(BundledBlockData.getInstance().fromLegacyId(id));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,6 +113,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock(int id, int data) {
|
||||
this(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,6 +125,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock(int id, int data, @Nullable CompoundTag nbtData) {
|
||||
this(id);
|
||||
setNbtData(nbtData);
|
||||
}
|
||||
|
||||
@@ -325,51 +332,9 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
* @param o other block
|
||||
* @return true if equal
|
||||
*/
|
||||
public boolean equalsFuzzy(BaseBlock o) {
|
||||
if (!getBlockType().equals(o.getBlockType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<State> differingStates = new ArrayList<>();
|
||||
for (State state : o.getStates().keySet()) {
|
||||
if (getState(state) == null) {
|
||||
differingStates.add(state);
|
||||
}
|
||||
}
|
||||
for (State state : getStates().keySet()) {
|
||||
if (o.getState(state) == null) {
|
||||
differingStates.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
for (State state : differingStates) {
|
||||
if (!getState(state).equals(o.getState(state))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method is silly, use {@link #containsFuzzy(java.util.Collection, BaseBlock)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean inIterable(Iterable<BaseBlock> iter) {
|
||||
for (BaseBlock block : iter) {
|
||||
if (block.equalsFuzzy(this)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Blocks#containsFuzzy(Collection, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean containsFuzzy(Collection<BaseBlock> collection, BaseBlock o) {
|
||||
return Blocks.containsFuzzy(collection, o);
|
||||
@Override
|
||||
public boolean equalsFuzzy(BlockStateHolder o) {
|
||||
return this.getState().equalsFuzzy(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,7 +21,9 @@ package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.world.NbtValued;
|
||||
import com.sk89q.worldedit.world.registry.BundledItemData;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -44,6 +46,7 @@ public class BaseItem implements NbtValued {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseItem(int id) {
|
||||
this(ItemTypes.getItemType(BundledItemData.getInstance().fromLegacyId(id)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,6 +21,7 @@ package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.PlayerDirection;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -671,9 +672,9 @@ public enum BlockType {
|
||||
* @param block the block
|
||||
* @return true if the block can be passed through
|
||||
*/
|
||||
public static boolean canPassThrough(BaseBlock block) {
|
||||
public static boolean canPassThrough(BlockStateHolder block) {
|
||||
checkNotNull(block);
|
||||
return canPassThrough(block.getId(), block.getData());
|
||||
return canPassThrough(block.getBlockType().getLegacyId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -769,9 +770,9 @@ public enum BlockType {
|
||||
* @param block the block
|
||||
* @return the y offset
|
||||
*/
|
||||
public static double centralTopLimit(BaseBlock block) {
|
||||
public static double centralTopLimit(BlockStateHolder block) {
|
||||
checkNotNull(block);
|
||||
return centralTopLimit(block.getId(), block.getData());
|
||||
return centralTopLimit(block.getBlockType().getLegacyId(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -36,9 +38,9 @@ public final class Blocks {
|
||||
* @param o the block
|
||||
* @return true if the collection contains the given block
|
||||
*/
|
||||
public static boolean containsFuzzy(Collection<? extends BaseBlock> collection, BaseBlock o) {
|
||||
public static boolean containsFuzzy(Collection<? extends BlockStateHolder> collection, BlockStateHolder o) {
|
||||
// Allow masked data in the searchBlocks to match various types
|
||||
for (BaseBlock b : collection) {
|
||||
for (BlockStateHolder b : collection) {
|
||||
if (b.equalsFuzzy(o)) {
|
||||
return true;
|
||||
}
|
||||
|
@@ -26,8 +26,10 @@ import com.google.common.collect.Table;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
import com.sk89q.worldedit.world.registry.state.value.StateValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -108,6 +110,33 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
return Collections.unmodifiableMap(this.values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsFuzzy(BlockStateHolder o) {
|
||||
if (!getBlockType().equals(o.getBlockType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<State> differingStates = new ArrayList<>();
|
||||
for (Object state : o.getStates().keySet()) {
|
||||
if (getState((State) state) == null) {
|
||||
differingStates.add((State) state);
|
||||
}
|
||||
}
|
||||
for (State state : getStates().keySet()) {
|
||||
if (o.getState(state) == null) {
|
||||
differingStates.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
for (State state : differingStates) {
|
||||
if (!getState(state).equals(o.getState(state))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method used for creating the initial BlockState.
|
||||
*
|
||||
|
@@ -56,4 +56,12 @@ public interface BlockStateHolder<T extends BlockStateHolder> {
|
||||
* @return The states
|
||||
*/
|
||||
Map<State, StateValue> getStates();
|
||||
|
||||
/**
|
||||
* Checks if the type is the same, and if the matched states are the same.
|
||||
*
|
||||
* @param o other block
|
||||
* @return true if equal
|
||||
*/
|
||||
boolean equalsFuzzy(BlockStateHolder o);
|
||||
}
|
||||
|
Reference in New Issue
Block a user