3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-03 01:50:07 +01:00

This does something idk.

Dieser Commit ist enthalten in:
wizjany 2019-05-12 14:19:46 -04:00 committet von Matthew Miller
Ursprung 2571efb5c3
Commit dc21b4df58
6 geänderte Dateien mit 57 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState;
@ -34,8 +35,8 @@ import java.util.OptionalInt;
import javax.annotation.Nullable;
public class BukkitBlockRegistry extends BundledBlockRegistry {
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
private BlockState[] statesById = new BlockState[2 << 14];
@Nullable
@Override
@ -58,10 +59,32 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
@Override
public OptionalInt getInternalBlockStateId(BlockState state) {
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state);
if (state.getBlockType() == BlockTypes.AIR) {
statesById[0] = state;
return OptionalInt.of(0);
}
return super.getInternalBlockStateId(state);
final OptionalInt id;
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
id = WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state);
} else {
id = super.getInternalBlockStateId(state);
}
if (id.isPresent()) {
final int idx = id.getAsInt();
if (statesById.length <= idx) {
BlockState[] newArr = new BlockState[statesById.length * 2];
System.arraycopy(statesById, 0, newArr, 0, statesById.length);
statesById = newArr;
}
statesById[idx] = state;
}
return id;
}
@Nullable
@Override
public BlockState getBlockStateByInternalId(int id) {
return id >= statesById.length ? null : statesById[id];
}
public static class BukkitBlockMaterial extends PassthroughBlockMaterial {

Datei anzeigen

@ -415,8 +415,18 @@ public class BukkitWorld extends AbstractWorld {
@Override
public com.sk89q.worldedit.world.block.BlockState getBlock(BlockVector3 position) {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
try {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)).toImmutableState();
} catch (Exception e) {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
} else {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
}
@Override

Datei anzeigen

@ -345,9 +345,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
if (++nextY > max.getBlockY()) {
nextY = min.getBlockY();
if (++nextZ > max.getBlockZ()) {
if (++nextZ > max.getBlockZ()) {
nextZ = min.getBlockZ();
if (++nextY > max.getBlockY()) {
nextX = Integer.MIN_VALUE;
}
}

Datei anzeigen

@ -46,7 +46,7 @@ import java.util.Set;
*/
@SuppressWarnings("unchecked")
public class BlockState implements BlockStateHolder<BlockState> {
static {
BlockStateIdAccess.setBlockStateStateId(x -> x.internalId);
}
@ -86,13 +86,14 @@ public class BlockState implements BlockStateHolder<BlockState> {
List<List<Object>> valueLists = Lists.cartesianProduct(separatedValues);
for (List<Object> valueList : valueLists) {
Map<Property<?>, Object> valueMap = Maps.newTreeMap(Comparator.comparing(Property::getName));
BlockState stateMaker = new BlockState(blockType).initializeId(registry);
BlockState stateMaker = new BlockState(blockType);
for (int i = 0; i < valueList.size(); i++) {
Property<?> property = properties.get(i);
Object value = valueList.get(i);
valueMap.put(property, value);
stateMaker.setState(property, value);
}
stateMaker.initializeId(registry);
stateMap.put(valueMap, stateMaker);
}
}

Datei anzeigen

@ -67,4 +67,11 @@ public interface BlockRegistry {
*/
OptionalInt getInternalBlockStateId(BlockState state);
/**
* Retrieve a block state by its internal ID, if possible.
*
* @param id The internal ID
* @return the block state, if available
*/
BlockState getBlockStateByInternalId(int id);
}

Datei anzeigen

@ -59,4 +59,9 @@ public class BundledBlockRegistry implements BlockRegistry {
return OptionalInt.empty();
}
@Override
public BlockState getBlockStateByInternalId(int id) {
return null;
}
}