Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-03 01:50:07 +01:00
Potential minor performance improvements when checking fuzzy equality.
Dieser Commit ist enthalten in:
Ursprung
6a71cd2155
Commit
4969dac39c
@ -134,12 +134,15 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof BaseBlock)) {
|
||||
if (!hasNbtData() && o instanceof BlockStateHolder) {
|
||||
return Objects.equals(toImmutableState(), ((BlockStateHolder) o).toImmutableState());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final BaseBlock otherBlock = (BaseBlock) o;
|
||||
|
||||
return this.toImmutableState().equals(otherBlock.toImmutableState()) && Objects.equals(getNbtData(), otherBlock.getNbtData());
|
||||
return Objects.equals(this.toImmutableState(), otherBlock.toImmutableState()) && Objects.equals(getNbtData(), otherBlock.getNbtData());
|
||||
|
||||
}
|
||||
|
||||
|
@ -168,6 +168,10 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
|
||||
@Override
|
||||
public boolean equalsFuzzy(BlockStateHolder o) {
|
||||
if (this == o) {
|
||||
// Added a reference equality check for
|
||||
return true;
|
||||
}
|
||||
if (!getBlockType().equals(o.getBlockType())) {
|
||||
return false;
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ package com.sk89q.worldedit.world.block;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
@ -46,6 +46,7 @@ public class BlockType {
|
||||
private BlockState defaultState;
|
||||
private Map<String, ? extends Property> properties;
|
||||
private BlockMaterial blockMaterial;
|
||||
private Map<Map<Property<?>, Object>, BlockState> blockStatesMap;
|
||||
|
||||
public BlockType(String id) {
|
||||
this(id, null);
|
||||
@ -57,7 +58,8 @@ public class BlockType {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
this.id = id;
|
||||
this.defaultState = new ArrayList<>(BlockState.generateStateMap(this).values()).get(0);
|
||||
this.blockStatesMap = BlockState.generateStateMap(this);
|
||||
this.defaultState = new ArrayList<>(this.blockStatesMap.values()).get(0);
|
||||
if (values != null) {
|
||||
this.defaultState = values.apply(this.defaultState);
|
||||
}
|
||||
@ -127,6 +129,15 @@ public class BlockType {
|
||||
return this.defaultState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all possible states for this BlockType.
|
||||
*
|
||||
* @return All possible states
|
||||
*/
|
||||
public List<BlockState> getAllStates() {
|
||||
return ImmutableList.copyOf(this.blockStatesMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this block type has an item representation.
|
||||
*
|
||||
|
@ -28,10 +28,12 @@ import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
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 com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
|
||||
@ -51,8 +53,6 @@ public class AnvilChunk implements Chunk {
|
||||
private int rootZ;
|
||||
|
||||
private Map<BlockVector, Map<String,Tag>> tileEntities;
|
||||
@SuppressWarnings("unused")
|
||||
private World world; // TODO: remove if stays unused.
|
||||
|
||||
/**
|
||||
* Construct the chunk with a compound tag.
|
||||
@ -63,7 +63,6 @@ public class AnvilChunk implements Chunk {
|
||||
*/
|
||||
public AnvilChunk(World world, CompoundTag tag) throws DataException {
|
||||
rootTag = tag;
|
||||
this.world = world;
|
||||
|
||||
rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue();
|
||||
rootZ = NBTUtils.getChildTag(rootTag.getValue(), "zPos", IntTag.class).getValue();
|
||||
@ -255,14 +254,22 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) throws DataException {
|
||||
public BlockStateHolder getBlock(Vector position) throws DataException {
|
||||
int id = getBlockID(position);
|
||||
int data = getBlockData(position);
|
||||
|
||||
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
|
||||
if (state == null) {
|
||||
WorldEdit.logger.warning("Unknown legacy block " + id + ":" + data + " found when loading legacy anvil chunk.");
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
|
||||
return state.toBaseBlock(tileEntity);
|
||||
if (tileEntity != null) {
|
||||
return state.toBaseBlock(tileEntity);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
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.world.storage.InvalidFormatException;
|
||||
@ -230,7 +230,7 @@ public class AnvilChunk13 implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) throws DataException {
|
||||
public BlockStateHolder getBlock(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
@ -247,7 +247,11 @@ public class AnvilChunk13 implements Chunk {
|
||||
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
|
||||
return state.toBaseBlock(tileEntity);
|
||||
if (tileEntity != null) {
|
||||
return state.toBaseBlock(tileEntity);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,8 @@
|
||||
package com.sk89q.worldedit.world.chunk;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* A 16 by 16 block chunk.
|
||||
@ -35,6 +35,6 @@ public interface Chunk {
|
||||
* @return block the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
BaseBlock getBlock(Vector position) throws DataException;
|
||||
BlockStateHolder getBlock(Vector position) throws DataException;
|
||||
|
||||
}
|
||||
|
@ -27,10 +27,11 @@ import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
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 com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
@ -153,7 +154,7 @@ public class OldChunk implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) throws DataException {
|
||||
public BlockStateHolder getBlock(Vector position) throws DataException {
|
||||
if(position.getBlockY() >= 128) BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
|
||||
int id, dataVal;
|
||||
|
||||
@ -181,9 +182,18 @@ public class OldChunk implements Chunk {
|
||||
}
|
||||
|
||||
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, dataVal);
|
||||
if (state == null) {
|
||||
WorldEdit.logger.warning("Unknown legacy block " + id + ":" + dataVal + " found when loading legacy anvil chunk.");
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
|
||||
return state.toBaseBlock(tileEntity);
|
||||
if (tileEntity != null) {
|
||||
return state.toBaseBlock(tileEntity);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -147,8 +147,7 @@ public class SnapshotRestore {
|
||||
// Now just copy blocks!
|
||||
for (Vector pos : entry.getValue()) {
|
||||
try {
|
||||
BaseBlock block = chunk.getBlock(pos);
|
||||
editSession.setBlock(pos, block);
|
||||
editSession.setBlock(pos, chunk.getBlock(pos));
|
||||
} catch (DataException e) {
|
||||
// this is a workaround: just ignore for now
|
||||
}
|
||||
|
@ -26,8 +26,6 @@ import org.spongepowered.api.service.permission.PermissionDescription;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.SubjectReference;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpongePermissionsProvider {
|
||||
|
||||
public boolean hasPermission(Player player, String permission) {
|
||||
@ -44,6 +42,6 @@ public class SpongePermissionsProvider {
|
||||
public String[] getGroups(Player player) {
|
||||
return player.getParents().stream()
|
||||
.map(SubjectReference::getSubjectIdentifier)
|
||||
.collect(Collectors.toList()).toArray(new String[0]);
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren