mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
some hasty refactoring
This commit is contained in:
@ -86,7 +86,7 @@ public class Rollback extends FaweCommand {
|
||||
int id = entry.getKey();
|
||||
BlockStateHolder state = null;
|
||||
try {
|
||||
state = BlockState.get(id);
|
||||
state = BlockState.getFromInternalId(id);
|
||||
} catch (Throwable ignore) {};
|
||||
String itemName = state == null ? "#" + id : state.getAsString();
|
||||
percentString.append(prefix).append(entry.getValue()).append("% ").append(itemName);
|
||||
|
@ -2,7 +2,6 @@ package com.boydti.fawe.example;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
@ -17,11 +16,10 @@ import com.boydti.fawe.util.SetQueue;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -17,7 +17,6 @@ import com.boydti.fawe.util.image.ImageViewer;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
@ -32,7 +31,6 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
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;
|
||||
@ -74,7 +72,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
protected boolean randomVariation = true;
|
||||
protected int biomePriority = 0;
|
||||
protected int waterId = BlockTypes.WATER.getInternalId();
|
||||
protected byte bedrockId = 7;
|
||||
protected int bedrockId = 7;
|
||||
protected boolean modifiedMain = false;
|
||||
|
||||
@Override
|
||||
@ -338,7 +336,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
}
|
||||
|
||||
public void setBedrockId(int bedrockId) {
|
||||
this.primtives.bedrockId = (byte) bedrockId;
|
||||
this.primtives.bedrockId = bedrockId;
|
||||
}
|
||||
|
||||
public void setFloorThickness(int floorThickness) {
|
||||
@ -354,7 +352,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
}
|
||||
|
||||
public void setWaterId(int waterId) {
|
||||
this.primtives.waterId = (byte) waterId;
|
||||
this.primtives.waterId = waterId;
|
||||
}
|
||||
|
||||
public void setTextureRandomVariation(boolean randomVariation) {
|
||||
@ -1024,7 +1022,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
|
||||
public BlockState getFloor(int x, int z) {
|
||||
int index = z * getWidth() + x;
|
||||
return BlockState.get(floor.getInt(index));
|
||||
return BlockState.getFromInternalId(floor.getInt(index));
|
||||
}
|
||||
|
||||
public int getHeight(int x, int z) {
|
||||
@ -1048,7 +1046,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(int x, int y, int z) {
|
||||
return BlockState.get(getCombinedId4Data(x, y, z));
|
||||
return BlockState.getFromInternalId(getCombinedId4Data(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.object.visitor.FaweChunkVisitor;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -126,7 +125,7 @@ public abstract class FaweChunk<T> implements Callable<FaweChunk> {
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
}
|
||||
return BlockState.get(combined);
|
||||
return BlockState.getFromInternalId(combined);
|
||||
}
|
||||
|
||||
public int[][] getCombinedIdArrays() {
|
||||
|
@ -22,9 +22,7 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
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.io.File;
|
||||
@ -75,14 +73,15 @@ public interface FaweQueue extends HasFaweQueue, Extent {
|
||||
@Override
|
||||
default BlockState getLazyBlock(int x, int y, int z) {
|
||||
int combinedId4Data = getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId());
|
||||
// TODO FIXME optimize get block tiles
|
||||
try {
|
||||
CompoundTag tile = getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
return BaseBlock.getFromInternalId(combinedId4Data, tile);
|
||||
} else {
|
||||
return BlockState.get(combinedId4Data);
|
||||
BlockState state = BlockState.getFromInternalId(combinedId4Data);
|
||||
if (state.getMaterial().hasContainer()) {
|
||||
CompoundTag tile = getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
return BaseBlock.getFromInternalId(combinedId4Data, tile);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
} catch (Throwable e) {
|
||||
MainUtil.handleError(e);
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
@ -275,7 +274,8 @@ public interface FaweQueue extends HasFaweQueue, Extent {
|
||||
mutable.mutZ(zz);
|
||||
for (int y = 0; y <= getMaxY(); y++) {
|
||||
int combined = getCombinedId4Data(xx, y, zz);
|
||||
BlockType type = BlockTypes.getFromStateId(combined);
|
||||
BlockState state = BlockState.getFromInternalId(combined);
|
||||
BlockTypes type = state.getBlockType();
|
||||
switch (type.getTypeEnum()) {
|
||||
case AIR:
|
||||
case VOID_AIR:
|
||||
@ -288,7 +288,6 @@ public interface FaweQueue extends HasFaweQueue, Extent {
|
||||
BaseBlock block = BaseBlock.getFromInternalId(combined, tile);
|
||||
onEach.run(mutable, block);
|
||||
} else {
|
||||
BlockState state = type.withPropertyId(combined >> BlockTypes.BIT_OFFSET);
|
||||
onEach.run(mutable, state);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.boydti.fawe.object.brush;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.database.DBHandler;
|
||||
@ -23,7 +22,6 @@ import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
@ -95,7 +93,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool {
|
||||
int index = value.getIndex();
|
||||
long age = System.currentTimeMillis() - value.getBDFile().lastModified();
|
||||
String ageFormatted = MainUtil.secToTime(age / 1000);
|
||||
BBC.TOOL_INSPECT_INFO.send(fp, name, BlockState.get(from).getAsString(), BlockState.get(to).getAsString(), ageFormatted);
|
||||
BBC.TOOL_INSPECT_INFO.send(fp, name, BlockState.getFromInternalId(from).getAsString(), BlockState.getFromInternalId(to).getAsString(), ageFormatted);
|
||||
count.incrementAndGet();
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.boydti.fawe.object.change;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.HasFaweQueue;
|
||||
import com.boydti.fawe.util.ExtentTraverser;
|
||||
@ -12,7 +11,6 @@ import com.sk89q.worldedit.extent.inventory.BlockBagException;
|
||||
import com.sk89q.worldedit.history.UndoContext;
|
||||
import com.sk89q.worldedit.history.change.Change;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public class MutableFullBlockChange implements Change {
|
||||
@ -68,14 +66,14 @@ public class MutableFullBlockChange implements Change {
|
||||
if (idFrom != idTo) {
|
||||
if (allowFetch && from != 0) {
|
||||
try {
|
||||
blockBag.fetchPlacedBlock(BlockState.get(from));
|
||||
blockBag.fetchPlacedBlock(BlockState.getFromInternalId(from));
|
||||
} catch (BlockBagException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (allowStore && to != 0) {
|
||||
try {
|
||||
blockBag.storeDroppedBlock(BlockState.get(to));
|
||||
blockBag.storeDroppedBlock(BlockState.getFromInternalId(to));
|
||||
} catch (BlockBagException ignored) {
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@ -392,7 +391,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
|
||||
for (int z = 0; z < length; z++) {
|
||||
for (int x = 0; x < width; x++, pos += 4) {
|
||||
int combinedId = mbb.getInt(pos);
|
||||
BlockState state = BlockState.get(combinedId);
|
||||
BlockState state = BlockState.getFromInternalId(combinedId);
|
||||
task.run(x, y, z, state);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import net.jpountz.util.SafeUtils;
|
||||
|
@ -1,21 +1,17 @@
|
||||
package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.object.change.MutableBlockChange;
|
||||
import com.boydti.fawe.object.change.MutableTileChange;
|
||||
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.history.change.Change;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@ -74,7 +70,7 @@ public class ResizableClipboardBuilder extends MemoryOptimizedHistory {
|
||||
Change change = iter.next();
|
||||
if (change instanceof MutableBlockChange) {
|
||||
MutableBlockChange blockChange = (MutableBlockChange) change;
|
||||
BlockStateHolder block = BlockState.get(blockChange.combinedId);
|
||||
BlockStateHolder block = BlockState.getFromInternalId(blockChange.combinedId);
|
||||
clipboard.setBlock(blockChange.x, blockChange.y, blockChange.z, block);
|
||||
} else if (change instanceof MutableTileChange) {
|
||||
MutableTileChange tileChange = (MutableTileChange) change;
|
||||
|
@ -1,18 +1,14 @@
|
||||
package com.boydti.fawe.object.pattern;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -59,7 +55,7 @@ public class ExpressionPattern extends AbstractPattern {
|
||||
((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector);
|
||||
}
|
||||
double combined = expression.evaluate(vector.getX(), vector.getY(), vector.getZ());
|
||||
return BlockState.get((int) combined);
|
||||
return BlockState.getFromInternalId((int) combined);
|
||||
} catch (EvaluationException e) {
|
||||
e.printStackTrace();
|
||||
return EditSession.nullBlock;
|
||||
|
@ -14,23 +14,28 @@ import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PropertyPattern extends AbstractExtentPattern {
|
||||
private final int[] transformed;
|
||||
|
||||
public PropertyPattern(Extent extent, String[] properties) {
|
||||
super(extent);
|
||||
this(extent);
|
||||
addRegex(".*[" + StringMan.join(properties, ",") + "]");
|
||||
}
|
||||
|
||||
public PropertyPattern(Extent extent) {
|
||||
super(extent);
|
||||
this.transformed = new int[BlockTypes.states.length];
|
||||
for (int i = 0; i < transformed.length; i++) {
|
||||
transformed[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
private int[][] intSets = new int[BlockTypes.size()][];
|
||||
|
||||
private static final Operator EQUAL = (length, value, index) -> value;
|
||||
private static final Operator PLUS = (length, value, index) -> index + value;
|
||||
private static final Operator MINUS = (length, value, index) -> index - value;
|
||||
@ -71,20 +76,14 @@ public class PropertyPattern extends AbstractExtentPattern {
|
||||
List values = property.getValues();
|
||||
int length = values.size();
|
||||
|
||||
int[] states = null;
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
int result = operator.apply(length, valueInt, i);
|
||||
if (wrap) result = MathMan.wrap(result, 0, length - 1);
|
||||
else result = Math.max(Math.min(result, length - 1), 0);
|
||||
if (result == i) continue;
|
||||
|
||||
if (states == null) {
|
||||
states = intSets[type.getInternalId()];
|
||||
if (states == null) {
|
||||
intSets[type.getInternalId()] = states = new int[type.getMaxStateId() + 1];
|
||||
for (int j = 0; j < states.length; j++) states[j] = j;
|
||||
}
|
||||
}
|
||||
int internalId = valueInt + i;
|
||||
|
||||
int state = property.modifyIndex(0, i);
|
||||
if (type.getProperties().size() > 1) {
|
||||
ArrayList<Property> properties = new ArrayList<>(type.getProperties().size() - 1);
|
||||
@ -92,27 +91,30 @@ public class PropertyPattern extends AbstractExtentPattern {
|
||||
if (current == property) continue;
|
||||
properties.add(current);
|
||||
}
|
||||
applyRecursive(property, properties, 0, state, result, states);
|
||||
applyRecursive(type, property, properties, 0, state, result);
|
||||
} else {
|
||||
states[i] = result;
|
||||
int ordinal = type.withStateId(internalId).getOrdinal();
|
||||
transformed[ordinal] = type.withStateId(result).getOrdinal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyRecursive(AbstractProperty property, List<Property> properties, int propertiesIndex, int state, int index, int[] states) {
|
||||
private void applyRecursive(BlockType type, AbstractProperty property, List<Property> properties, int propertiesIndex, int stateId, int index) {
|
||||
AbstractProperty current = (AbstractProperty) properties.get(propertiesIndex);
|
||||
List values = current.getValues();
|
||||
if (propertiesIndex + 1 < properties.size()) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
int newState = current.modifyIndex(state, i);
|
||||
applyRecursive(property, properties, propertiesIndex + 1, newState, index, states);
|
||||
int newState = current.modifyIndex(stateId, i);
|
||||
applyRecursive(type, property, properties, propertiesIndex + 1, newState, index);
|
||||
}
|
||||
} else {
|
||||
//set chest[waterlogged=north]
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
int statesIndex = current.modifyIndex(state, i) >> BlockTypes.BIT_OFFSET;
|
||||
int existing = states[statesIndex] << BlockTypes.BIT_OFFSET;
|
||||
states[statesIndex] = property.modifyIndex(existing, index) >> BlockTypes.BIT_OFFSET;
|
||||
int statesIndex = current.modifyIndex(stateId, i) >> BlockTypes.BIT_OFFSET;
|
||||
BlockState state = BlockState.getFromInternalId(statesIndex);
|
||||
int existingOrdinal = transformed[state.getOrdinal()];
|
||||
int existing = BlockTypes.states[existingOrdinal].getInternalId();
|
||||
//states[statesIndex] << BlockTypes.BIT_OFFSET;
|
||||
transformed[state.getOrdinal()] = property.modifyIndex(existing, index) >> BlockTypes.BIT_OFFSET;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -195,16 +197,14 @@ public class PropertyPattern extends AbstractExtentPattern {
|
||||
}
|
||||
|
||||
public BlockState apply(BlockState block, BlockState orDefault) {
|
||||
int typeId = block.getInternalBlockTypeId();
|
||||
int[] states = intSets[typeId];
|
||||
if (states == null) return orDefault;
|
||||
int propertyId = block.getInternalPropertiesId();
|
||||
int newPropertyId = states[propertyId];
|
||||
if (newPropertyId == propertyId) return orDefault;
|
||||
BlockState newState = block.withPropertyId(newPropertyId);
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
if (nbt == null) return newState;
|
||||
return new BaseBlock(newState, nbt);
|
||||
int ordinal = block.getOrdinal();
|
||||
int newOrdinal = transformed[ordinal];
|
||||
if (newOrdinal != ordinal) {
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
BlockState newState = BlockState.getFromOrdinal(newOrdinal);
|
||||
return nbt != null ? new BaseBlock(newState, nbt) : newState;
|
||||
}
|
||||
return orDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.boydti.fawe.object.queue;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.object.FaweQueue;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -31,7 +30,7 @@ public class FaweQueueDelegateExtent extends DelegateFaweQueue {
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, int combinedId) {
|
||||
return setBlock(x, y, z, BlockState.get(combinedId));
|
||||
return setBlock(x, y, z, BlockState.getFromInternalId(combinedId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,7 +38,7 @@ public class FaweQueueDelegateExtent extends DelegateFaweQueue {
|
||||
if (nbt != null) {
|
||||
return setBlock(x, y, z, BaseBlock.getFromInternalId(combinedId, nbt));
|
||||
}
|
||||
return setBlock(x, y, z, BlockState.get(combinedId));
|
||||
return setBlock(x, y, z, BlockState.getFromInternalId(combinedId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,24 +19,17 @@
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.boydti.fawe.object.string.MutableCharSequence;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.world.block.*;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a "snapshot" of a block with NBT Data.
|
||||
@ -48,7 +41,7 @@ import javax.annotation.Nullable;
|
||||
* may be missing.</p>
|
||||
*/
|
||||
public class BaseBlock extends BlockState {
|
||||
private BlockState blockState;
|
||||
private final BlockState blockState;
|
||||
|
||||
@Nullable
|
||||
protected CompoundTag nbtData;
|
||||
@ -90,7 +83,7 @@ public class BaseBlock extends BlockState {
|
||||
* @param nbtData NBT data, which may be null
|
||||
*/
|
||||
public BaseBlock(BlockStateHolder state, @Nullable CompoundTag nbtData) {
|
||||
super(0);
|
||||
super();
|
||||
this.blockState = state.toImmutableState();
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
@ -115,7 +108,7 @@ public class BaseBlock extends BlockState {
|
||||
}
|
||||
|
||||
protected BaseBlock(int internalId, CompoundTag nbtData) {
|
||||
this(BlockState.get(internalId), nbtData);
|
||||
this(BlockState.getFromInternalId(internalId), nbtData);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ -138,18 +131,6 @@ public class BaseBlock extends BlockState {
|
||||
return blockState;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the block's data value.
|
||||
// *
|
||||
// * Broken - do not use
|
||||
// *
|
||||
// * @return data value (0-15)
|
||||
// */
|
||||
// @Deprecated
|
||||
// public int getData() {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getNbtId() {
|
||||
CompoundTag nbtData = getNbtData();
|
||||
@ -199,9 +180,24 @@ public class BaseBlock extends BlockState {
|
||||
return blockState.getInternalId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockMaterial getMaterial() {
|
||||
return blockState.getMaterial();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTypes getBlockType() {
|
||||
return blockState.getBlockType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
return blockState.getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getInternalId();
|
||||
return getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -240,7 +240,7 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
|
||||
if (nbt == null) nbt = state.getNbtData();
|
||||
|
||||
if (stateString != null) {
|
||||
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state.getInternalPropertiesId());
|
||||
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,23 +306,6 @@ public enum ClipboardFormat {
|
||||
map.put("height", dimensions.getY());
|
||||
map.put("length", dimensions.getZ());
|
||||
map.put("creator", user);
|
||||
if (clipboard instanceof BlockArrayClipboard) {
|
||||
FaweClipboard fc = ((BlockArrayClipboard) clipboard).IMP;
|
||||
final int[] ids = new int[BlockTypes.size()];
|
||||
fc.streamCombinedIds(new NBTStreamer.ByteReader() {
|
||||
@Override
|
||||
public void run(int index, int byteValue) {
|
||||
ids[byteValue & BlockTypes.BIT_MASK]++;
|
||||
}
|
||||
});
|
||||
Map<String, Integer> blocks = new HashMap<String, Integer>();
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
if (ids[i] != 0) {
|
||||
blocks.put(BlockTypes.get(i).getId(), ids[i]);
|
||||
}
|
||||
}
|
||||
map.put("blocks", blocks);
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(map);
|
||||
return MainUtil.upload(Settings.IMP.WEB.ASSETS, false, json, category, null, new RunnableVal<OutputStream>() {
|
||||
|
@ -154,7 +154,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
int maskedId = internalId & mask;
|
||||
int newMaskedId = arr[maskedId];
|
||||
if (newMaskedId != -1) {
|
||||
return BlockState.get(newMaskedId | (internalId & (~mask)));
|
||||
return BlockState.getFromInternalId(newMaskedId | (internalId & (~mask)));
|
||||
}
|
||||
newMaskedId = state.getInternalId();
|
||||
|
||||
@ -169,7 +169,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
}
|
||||
}
|
||||
arr[maskedId] = newMaskedId & mask;
|
||||
return BlockState.get(newMaskedId);
|
||||
return BlockState.getFromInternalId(newMaskedId);
|
||||
}
|
||||
|
||||
public final BlockState transformFast(BlockState block) {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.object.collection.FastBitSet;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
@ -147,7 +145,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
single = single && numSet == 1;
|
||||
}
|
||||
if (single)
|
||||
return new SingleBlockStateMask(getExtent(), BlockState.get(and));
|
||||
return new SingleBlockStateMask(getExtent(), BlockState.getFromInternalId(and));
|
||||
return new SingleBlockStateBitMask(getExtent(), and);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.sk89q.worldedit.registry.state;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.sk89q.util.ReflectionUtil;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -64,6 +66,7 @@ public enum PropertyKey {
|
||||
UP,
|
||||
WATERLOGGED,
|
||||
WEST,
|
||||
UNSTABLE,
|
||||
|
||||
;
|
||||
|
||||
@ -94,12 +97,18 @@ public enum PropertyKey {
|
||||
* @return PropertyKey enum
|
||||
*/
|
||||
public static final PropertyKey getOrCreate(String id) {
|
||||
String name = id.toUpperCase();
|
||||
PropertyKey property;
|
||||
try {
|
||||
property = PropertyKey.valueOf(name);
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
property = ReflectionUtils.addEnum(PropertyKey.class, name);
|
||||
PropertyKey property = PropertyKey.get(id);
|
||||
if (property == null) {
|
||||
Fawe.debug("Registering property " + id);
|
||||
property = ReflectionUtils.addEnum(PropertyKey.class, id.toUpperCase());
|
||||
if (property.getId() == null) {
|
||||
try {
|
||||
ReflectionUtils.setFailsafeFieldValue(PropertyKey.class.getDeclaredField("id"), property, property.name().toLowerCase());
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
keys.put(property.name().toLowerCase(), property);
|
||||
}
|
||||
return property;
|
||||
}
|
||||
|
@ -28,8 +28,11 @@ import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
|
||||
@ -46,15 +49,7 @@ import java.util.stream.Stream;
|
||||
* An immutable class that represents the state a block can be in.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class BlockState implements BlockStateHolder<BlockState> {
|
||||
|
||||
private final int internalId;
|
||||
|
||||
// TODO FIXME have field for BlockType & propertyId (to avoid all the bit shifting / masking)
|
||||
protected BlockState(int internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
public abstract class BlockState implements BlockStateHolder<BlockState> {
|
||||
/**
|
||||
* Returns a temporary BlockState for a given internal id
|
||||
* @param combinedId
|
||||
@ -62,10 +57,15 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
* @return BlockState
|
||||
*/
|
||||
@Deprecated
|
||||
public static BlockState get(int combinedId) throws InputParseException {
|
||||
public static BlockState getFromInternalId(int combinedId) throws InputParseException {
|
||||
return BlockTypes.getFromStateId(combinedId).withStateId(combinedId);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static BlockState getFromOrdinal(int ordinal) {
|
||||
return BlockTypes.states[ordinal];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a temporary BlockState for a given type and string
|
||||
* @param state String e.g. minecraft:water[level=4]
|
||||
@ -83,7 +83,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
* @return BlockState
|
||||
*/
|
||||
public static BlockState get(@Nullable BlockType type, String state) throws InputParseException {
|
||||
return get(type, state, 0);
|
||||
return get(type, state, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
* @param state String e.g. minecraft:water[level=4]
|
||||
* @return BlockState
|
||||
*/
|
||||
public static BlockState get(@Nullable BlockType type, String state, int propId) throws InputParseException {
|
||||
public static BlockState get(@Nullable BlockType type, String state, BlockState defaultState) throws InputParseException {
|
||||
int propStrStart = state.indexOf('[');
|
||||
if (type == null) {
|
||||
CharSequence key;
|
||||
@ -133,8 +133,12 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
|
||||
return type.withPropertyId(property.getIndexFor(charSequence));
|
||||
}
|
||||
|
||||
int stateId = type.getInternalId() + (propId << BlockTypes.BIT_OFFSET);
|
||||
int stateId;
|
||||
if (defaultState != null) {
|
||||
stateId = defaultState.getInternalId();
|
||||
} else {
|
||||
stateId = type.getInternalId();
|
||||
}
|
||||
int length = state.length();
|
||||
AbstractProperty property = null;
|
||||
|
||||
@ -210,11 +214,6 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getInternalId() {
|
||||
return this.internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return getNbtData() != null;
|
||||
@ -246,11 +245,6 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
return this.getInternalId() >> BlockTypes.BIT_OFFSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockTypes getBlockType() {
|
||||
return BlockTypes.get(this.getInternalId() & BlockTypes.BIT_MASK);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public final int getInternalBlockTypeId() {
|
||||
@ -260,8 +254,9 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
@Override
|
||||
public <V> BlockState with(final Property<V> property, final V value) {
|
||||
try {
|
||||
BlockTypes type = getBlockType();
|
||||
int newState = ((AbstractProperty) property).modify(this.getInternalId(), value);
|
||||
return newState != this.getInternalId() ? new BlockState(newState) : this;
|
||||
return newState != this.getInternalId() ? type.withStateId(newState) : this;
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException("Property not found: " + property);
|
||||
}
|
||||
@ -270,8 +265,9 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
@Override
|
||||
public <V> BlockState with(final PropertyKey property, final V value) {
|
||||
try {
|
||||
int newState = ((AbstractProperty) getBlockType().getProperty(property)).modify(this.getInternalId(), value);
|
||||
return newState != this.getInternalId() ? new BlockState(newState) : this;
|
||||
BlockTypes type = getBlockType();
|
||||
int newState = ((AbstractProperty) type.getProperty(property)).modify(this.getInternalId(), value);
|
||||
return newState != this.getInternalId() ? type.withStateId(newState) : this;
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException("Property not found: " + property);
|
||||
}
|
||||
@ -313,7 +309,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getInternalId();
|
||||
return getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -324,38 +320,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean equalsFuzzy(BlockStateHolder o) {
|
||||
try {
|
||||
return o.getInternalId() == this.getInternalId();
|
||||
} catch (ClassCastException e) {
|
||||
// Shouldn't happen unless something modifies WorldEdit
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!getBlockType().equals(o.getBlockType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<Property> differingProperties = new HashSet<>();
|
||||
for (Object state : o.getStates().keySet()) {
|
||||
if (getState((Property) state) == null) {
|
||||
differingProperties.add((Property) state);
|
||||
}
|
||||
}
|
||||
for (Property property : getStates().keySet()) {
|
||||
if (o.getState(property) == null) {
|
||||
differingProperties.add(property);
|
||||
}
|
||||
}
|
||||
|
||||
for (Property property : getStates().keySet()) {
|
||||
if (differingProperties.contains(property)) {
|
||||
continue;
|
||||
}
|
||||
if (!Objects.equals(getState(property), o.getState(property))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return o.getOrdinal() == this.getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -368,32 +333,3 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
return getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world.block;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
@ -44,7 +45,9 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
BlockStateHolder withPropertyId(int propertyId);
|
||||
default BlockStateHolder withPropertyId(int propertyId) {
|
||||
return getBlockType().withPropertyId(propertyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get combined id (legacy uses)
|
||||
@ -53,12 +56,21 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
@Deprecated
|
||||
int getInternalId();
|
||||
|
||||
@Deprecated
|
||||
int getOrdinal();
|
||||
|
||||
default BlockMaterial getMaterial() {
|
||||
return getBlockType().getMaterial();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type id (legacy uses)
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
int getInternalBlockTypeId();
|
||||
default int getInternalBlockTypeId() {
|
||||
return getBlockType().getInternalId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block data (legacy uses)
|
||||
@ -129,9 +141,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
if (getStates().isEmpty()) {
|
||||
return this.getBlockType().getId();
|
||||
} else {
|
||||
String properties =
|
||||
getStates().entrySet().stream().map(entry -> entry.getKey().getName() + "=" + entry.getValue().toString().toLowerCase()).collect(Collectors.joining(
|
||||
","));
|
||||
String properties = getStates().entrySet().stream().map(entry -> entry.getKey().getName() + "=" + entry.getValue().toString().toLowerCase()).collect(Collectors.joining(","));
|
||||
return this.getBlockType().getId() + "[" + properties + "]";
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.sk89q.worldedit.world.block;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
|
||||
public class BlockStateImpl extends BlockState {
|
||||
private final int internalId;
|
||||
private final int ordinal;
|
||||
private final BlockTypes type;
|
||||
private BlockMaterial material;
|
||||
|
||||
protected BlockStateImpl(BlockTypes type, int internalId, int ordinal) {
|
||||
this.type = type;
|
||||
this.internalId = internalId;
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
public BlockMaterial getMaterial() {
|
||||
if (this.material == null) {
|
||||
synchronized (this) {
|
||||
if (this.material == null) {
|
||||
this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getInternalId() {
|
||||
return this.internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockTypes getBlockType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -29,13 +29,12 @@ import com.sk89q.worldedit.function.pattern.FawePattern;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
|
||||
@ -67,6 +66,17 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
*/
|
||||
String getId();
|
||||
|
||||
default String getNamespace() {
|
||||
String id = getId();
|
||||
int i = id.indexOf(':');
|
||||
return i == -1 ? "minecraft" : id.substring(0, i);
|
||||
}
|
||||
|
||||
default String getResource() {
|
||||
String id = getId();
|
||||
return id.substring(id.indexOf(':') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this block, or the ID if the name cannot be found.
|
||||
*
|
||||
@ -84,7 +94,7 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
@Deprecated
|
||||
default BlockState withPropertyId(int internalPropertiesId) {
|
||||
if (internalPropertiesId == 0) return getDefaultState();
|
||||
return BlockState.get(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET));
|
||||
return BlockState.getFromInternalId(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +103,18 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
* @return The properties map
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, ? extends Property> getPropertyMap();
|
||||
default Map<String, ? extends Property> getPropertyMap() {
|
||||
List<? extends Property> properties = getProperties();
|
||||
if (properties.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<String, Property> map = new HashMap<>(properties.size());
|
||||
for (Property property : properties) {
|
||||
map.put(property.getName(), property);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the properties of this BlockType.
|
||||
@ -104,7 +125,9 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
List<? extends Property> getProperties();
|
||||
|
||||
@Deprecated
|
||||
Set<? extends Property> getPropertiesSet();
|
||||
default Set<? extends Property> getPropertiesSet() {
|
||||
return new HashSet<>(getProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property by name.
|
||||
@ -113,11 +136,17 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
* @return The property
|
||||
*/
|
||||
@Deprecated
|
||||
<V> Property<V> getProperty(String name);
|
||||
default <V> Property<V> getProperty(String name) {
|
||||
return getPropertyMap().get(name);
|
||||
}
|
||||
|
||||
boolean hasProperty(PropertyKey key);
|
||||
default boolean hasProperty(PropertyKey key) {
|
||||
return getPropertyMap().containsKey(key.getId());
|
||||
}
|
||||
|
||||
<V> Property<V> getProperty(PropertyKey key);
|
||||
default <V> Property<V> getProperty(PropertyKey key) {
|
||||
return getPropertyMap().get(key.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default state of this block type.
|
||||
@ -141,7 +170,9 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
|
||||
* @return The item representation
|
||||
*/
|
||||
@Nullable
|
||||
ItemType getItemType();
|
||||
default ItemType getItemType() {
|
||||
return ItemTypes.get(this.getTypeEnum());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the material for this BlockType.
|
||||
|
@ -19,9 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.world.block;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.command.SuggestInputParseException;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
@ -38,10 +42,13 @@ import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import it.unimi.dsi.fastutil.ints.IntCollections;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.IntPredicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -647,6 +654,11 @@ public enum BlockTypes implements BlockType {
|
||||
YELLOW_WOOL,
|
||||
ZOMBIE_HEAD,
|
||||
ZOMBIE_WALL_HEAD,
|
||||
DEAD_BRAIN_CORAL,
|
||||
DEAD_BUBBLE_CORAL,
|
||||
DEAD_FIRE_CORAL,
|
||||
DEAD_HORN_CORAL,
|
||||
DEAD_TUBE_CORAL,
|
||||
|
||||
;
|
||||
|
||||
@ -666,9 +678,9 @@ public enum BlockTypes implements BlockType {
|
||||
private final Set<AbstractProperty> propertiesSet;
|
||||
private final BlockMaterial blockMaterial;
|
||||
private final int permutations;
|
||||
private BlockState[] states;
|
||||
private int[] stateOrdinals;
|
||||
|
||||
Settings(BlockTypes type, String id, int internalId) {
|
||||
Settings(BlockTypes type, String id, int internalId, List<BlockState> states) {
|
||||
this.internalId = internalId;
|
||||
String propertyString = null;
|
||||
int propI = id.indexOf('[');
|
||||
@ -715,10 +727,20 @@ public enum BlockTypes implements BlockType {
|
||||
this.blockMaterial = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(type);
|
||||
this.itemType = ItemTypes.get(type);
|
||||
|
||||
if (propertyString != null) {
|
||||
this.defaultState = new BlockState(parseProperties(propertyString, propertiesMap));
|
||||
if (!propertiesList.isEmpty()) {
|
||||
this.stateOrdinals = generateStateOrdinals(internalId, states.size(), maxInternalStateId, propertiesList);
|
||||
for (int propId = 0; propId < this.stateOrdinals.length; propId++) {
|
||||
int ordinal = this.stateOrdinals[propId];
|
||||
if (ordinal != -1) {
|
||||
int stateId = internalId + (propId << BlockTypes.BIT_OFFSET);
|
||||
states.add(new BlockStateImpl(type, stateId, ordinal));
|
||||
}
|
||||
}
|
||||
int defaultPropId = parseProperties(propertyString, propertiesMap) >> BlockTypes.BIT_OFFSET;
|
||||
this.defaultState = states.get(this.stateOrdinals[defaultPropId]);
|
||||
} else {
|
||||
this.defaultState = new BlockState(internalId);
|
||||
this.defaultState = new BlockStateImpl(type, internalId, states.size());
|
||||
states.add(this.defaultState);
|
||||
}
|
||||
}
|
||||
|
||||
@ -744,9 +766,14 @@ public enum BlockTypes implements BlockType {
|
||||
settings = null;
|
||||
}
|
||||
|
||||
private void init(String id, int internalId) {
|
||||
private void init(String id, int internalId, List<BlockState> states) {
|
||||
try {
|
||||
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("settings"), this, new Settings(this, id, internalId));
|
||||
if (getId() == null) {
|
||||
String name = (name().indexOf(':') == -1 ? "minecraft:" : "") + name().toLowerCase();
|
||||
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("id"), this, name);
|
||||
}
|
||||
Settings settings = new Settings(this, id, internalId, states);
|
||||
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("settings"), this, settings);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
@ -754,25 +781,38 @@ public enum BlockTypes implements BlockType {
|
||||
}
|
||||
|
||||
public BlockState withPropertyId(int propertyId) {
|
||||
if (settings.propertiesArr.length == 0) return settings.defaultState;
|
||||
BlockState[] tmp = settings.states;
|
||||
if (tmp == null) {
|
||||
synchronized (this) {
|
||||
if ((tmp = settings.states) == null) {
|
||||
tmp = settings.states = new BlockState[getMaxStateId() + 1];
|
||||
tmp[settings.defaultState.getInternalPropertiesId()] = settings.defaultState;
|
||||
}
|
||||
}
|
||||
if (settings.stateOrdinals == null) return settings.defaultState;
|
||||
return states[settings.stateOrdinals[propertyId]];
|
||||
}
|
||||
|
||||
private static int[] generateStateOrdinals(int internalId, int ordinal, int maxStateId, List<AbstractProperty> props) {
|
||||
if (props.isEmpty()) return null;
|
||||
int[] result = new int[maxStateId + 1];
|
||||
Arrays.fill(result, -1);
|
||||
int[] state = new int[props.size()];
|
||||
int[] sizes = new int[props.size()];
|
||||
for (int i = 0; i < props.size(); i++) {
|
||||
sizes[i] = props.get(i).getValues().size();
|
||||
}
|
||||
BlockState state = tmp[propertyId];
|
||||
if (state == null) {
|
||||
synchronized (this) {
|
||||
if ((state = tmp[propertyId]) == null) {
|
||||
state = tmp[propertyId] = new BlockState(getInternalId() + (propertyId << BIT_OFFSET));
|
||||
}
|
||||
int index = 0;
|
||||
outer:
|
||||
while (true) {
|
||||
// Create the state
|
||||
int stateId = internalId;
|
||||
for (int i = 0; i < state.length; i++) {
|
||||
stateId = props.get(i).modifyIndex(stateId, state[i]);
|
||||
}
|
||||
// Map it to the ordinal
|
||||
result[stateId >> BlockTypes.BIT_OFFSET] = ordinal++;
|
||||
// Increment the state
|
||||
while (++state[index] == sizes[index]) {
|
||||
state[index] = 0;
|
||||
index++;
|
||||
if (index == state.length) break outer;
|
||||
}
|
||||
index = 0;
|
||||
}
|
||||
return state;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -781,16 +821,8 @@ public enum BlockTypes implements BlockType {
|
||||
*/
|
||||
@Deprecated
|
||||
public Collection<BlockState> getStates() {
|
||||
if (this.settings.states == null || this.settings.states.length <= 1) {
|
||||
return Collections.singletonList(getDefaultState());
|
||||
}
|
||||
ArrayList<BlockState> states = new ArrayList<>();
|
||||
for (BlockState state : settings.states) {
|
||||
if (state != null) {
|
||||
states.add(state);
|
||||
}
|
||||
}
|
||||
return states;
|
||||
if (settings.stateOrdinals == null) return Collections.singletonList(getDefaultState());
|
||||
return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> states[i]).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ -965,7 +997,11 @@ public enum BlockTypes implements BlockType {
|
||||
|
||||
private static final Map<String, BlockTypes> $REGISTRY = new HashMap<>();
|
||||
private static int $LENGTH;
|
||||
private static int $STATE_INDEX;
|
||||
|
||||
public static final BlockTypes[] values;
|
||||
public static final BlockState[] states;
|
||||
|
||||
private static final Set<String> $NAMESPACES = new LinkedHashSet<String>();
|
||||
|
||||
static {
|
||||
@ -977,7 +1013,10 @@ public enum BlockTypes implements BlockType {
|
||||
$LENGTH = oldValues.length;
|
||||
int size = blockMap.size();
|
||||
for (BlockTypes type : oldValues) {
|
||||
if (!blockMap.containsKey(type.getId())) size++;
|
||||
if (!blockMap.containsKey(type.getId())) {
|
||||
Fawe.debug("Invalid block registered " + type.getId());
|
||||
size++;
|
||||
}
|
||||
if (type != __RESERVED__) {
|
||||
$REGISTRY.put(type.name().toLowerCase(), type);
|
||||
}
|
||||
@ -987,13 +1026,14 @@ public enum BlockTypes implements BlockType {
|
||||
BIT_MASK = ((1 << BIT_OFFSET) - 1);
|
||||
|
||||
LinkedHashSet<BlockTypes> newValues = new LinkedHashSet<>(Arrays.asList(oldValues));
|
||||
for (BlockTypes type : oldValues) {
|
||||
String block = blockMap.getOrDefault(type.getId(), type.getId());
|
||||
BlockTypes registered = register(block);
|
||||
ArrayList<BlockState> stateList = new ArrayList<>();
|
||||
for (String block : blocks) {
|
||||
BlockTypes registered = register(block, stateList);
|
||||
if (!newValues.contains(registered)) newValues.add(registered);
|
||||
}
|
||||
// Cache the values
|
||||
values = newValues.toArray(new BlockTypes[newValues.size()]);
|
||||
states = stateList.toArray(new BlockState[stateList.size()]);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
@ -1021,7 +1061,7 @@ public enum BlockTypes implements BlockType {
|
||||
);
|
||||
}
|
||||
|
||||
private static BlockTypes register(final String id) {
|
||||
private static BlockTypes register(final String id, List<BlockState> states) {
|
||||
// Get the enum name (remove namespace if minecraft:)
|
||||
int propStart = id.indexOf('[');
|
||||
String typeName = id.substring(0, propStart == -1 ? id.length() : propStart);
|
||||
@ -1032,13 +1072,15 @@ public enum BlockTypes implements BlockType {
|
||||
existing = valueOf(enumName.toUpperCase());
|
||||
} catch (IllegalArgumentException ignore) {}
|
||||
if (existing == null) {
|
||||
Fawe.debug("Registering block " + enumName);
|
||||
existing = ReflectionUtils.addEnum(BlockTypes.class, enumName);
|
||||
}
|
||||
int internalId = existing.ordinal();
|
||||
if (internalId == 0 && existing != __RESERVED__) {
|
||||
internalId = $LENGTH++;
|
||||
}
|
||||
existing.init(id, internalId);
|
||||
existing.init(id, internalId, states);
|
||||
// register states
|
||||
if (typeName.startsWith("minecraft:")) $REGISTRY.put(typeName.substring(10), existing);
|
||||
$REGISTRY.put(typeName, existing);
|
||||
String nameSpace = typeName.substring(0, typeName.indexOf(':'));
|
||||
@ -1068,6 +1110,11 @@ public enum BlockTypes implements BlockType {
|
||||
return values[internalStateId & BIT_MASK];
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static final BlockTypes getFromStateOrdinal(final int internalStateOrdinal) {
|
||||
return states[internalStateOrdinal].getBlockType();
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return values.length;
|
||||
}
|
||||
|
@ -145,6 +145,10 @@ public enum EntityTypes implements EntityType {
|
||||
}
|
||||
|
||||
EntityTypes(String id) {
|
||||
init(id);
|
||||
}
|
||||
|
||||
private void init(String id) {
|
||||
if (id == null) id = "minecraft:" + name().toLowerCase();
|
||||
// If it has no namespace, assume minecraft.
|
||||
else if (!id.contains(":")) {
|
||||
@ -278,6 +282,9 @@ public enum EntityTypes implements EntityType {
|
||||
existing = ReflectionUtils.addEnum(EntityTypes.class, enumName);
|
||||
}
|
||||
int internalId = existing.ordinal();
|
||||
if (existing.id == null) {
|
||||
existing.init(null);
|
||||
}
|
||||
if (internalId == 0 && existing != __RESERVED__) {
|
||||
existing.internalId = $LENGTH++;
|
||||
}
|
||||
|
@ -839,8 +839,8 @@ public enum ItemTypes implements ItemType {
|
||||
*/
|
||||
|
||||
private BlockTypes blockType;
|
||||
private final String id;
|
||||
private final BaseItem defaultState;
|
||||
private String id;
|
||||
private BaseItem defaultState;
|
||||
private int internalId;
|
||||
|
||||
ItemTypes() {
|
||||
@ -848,8 +848,12 @@ public enum ItemTypes implements ItemType {
|
||||
}
|
||||
|
||||
ItemTypes(String id) {
|
||||
init(id);
|
||||
}
|
||||
|
||||
private void init(String id) {
|
||||
if (id == null) id = "minecraft:" + name().toLowerCase();
|
||||
// If it has no namespace, assume minecraft.
|
||||
// If it has no namespace, assume minecraft.
|
||||
else if (!id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
@ -973,6 +977,9 @@ public enum ItemTypes implements ItemType {
|
||||
existing = ReflectionUtils.addEnum(ItemTypes.class, enumName);
|
||||
}
|
||||
int internalId = existing.ordinal();
|
||||
if (existing.id == null) {
|
||||
existing.init(null);
|
||||
}
|
||||
if (internalId == 0 && existing != __RESERVED__) {
|
||||
existing.internalId = $LENGTH++;
|
||||
}
|
||||
|
@ -54,5 +54,4 @@ public interface BiomeRegistry {
|
||||
*/
|
||||
@Nullable
|
||||
BiomeData getData(BaseBiome biome);
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ 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.BlockType;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -44,6 +45,11 @@ public interface BlockRegistry {
|
||||
@Nullable
|
||||
BlockMaterial getMaterial(BlockType blockType);
|
||||
|
||||
@Nullable
|
||||
default BlockMaterial getMaterial(BlockState state) {
|
||||
return getMaterial(state.getBlockType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an unmodifiable map of states for this block.
|
||||
*
|
||||
|
@ -26,7 +26,6 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -142,7 +141,7 @@ public class LegacyMapper {
|
||||
|
||||
public BlockState getBlockFromLegacy(String input) {
|
||||
if (input.startsWith("minecraft:")) input = input.substring(10);
|
||||
return BlockState.get(blockArr[getCombinedId(input)]);
|
||||
return BlockState.getFromInternalId(blockArr[getCombinedId(input)]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -181,7 +180,7 @@ public class LegacyMapper {
|
||||
try {
|
||||
int internalId = blockArr[combinedId];
|
||||
if (internalId == 0) return null;
|
||||
return BlockState.get(internalId);
|
||||
return BlockState.getFromInternalId(internalId);
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
return null;
|
||||
}
|
||||
@ -191,7 +190,7 @@ public class LegacyMapper {
|
||||
extra = extraId4DataToStateId.get(combinedId & 0xFF0);
|
||||
}
|
||||
if (extra != null) {
|
||||
return BlockState.get(extra);
|
||||
return BlockState.getFromInternalId(extra);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -311,8 +311,8 @@
|
||||
"44:14": "minecraft:nether_brick_slab[type=top]",
|
||||
"44:15": "minecraft:quartz_slab[type=top]",
|
||||
"45:0": "minecraft:bricks",
|
||||
"46:0": "minecraft:tnt",
|
||||
"46:1": "minecraft:tnt",
|
||||
"46:0": "minecraft:tnt[unstable=false]",
|
||||
"46:1": "minecraft:tnt[unstable=true]",
|
||||
"47:0": "minecraft:bookshelf",
|
||||
"48:0": "minecraft:mossy_cobblestone",
|
||||
"49:0": "minecraft:obsidian",
|
||||
|
Reference in New Issue
Block a user