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:
Ursprung
2571efb5c3
Commit
dc21b4df58
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||||
import com.sk89q.worldedit.registry.state.Property;
|
import com.sk89q.worldedit.registry.state.Property;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
@ -34,8 +35,8 @@ import java.util.OptionalInt;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class BukkitBlockRegistry extends BundledBlockRegistry {
|
public class BukkitBlockRegistry extends BundledBlockRegistry {
|
||||||
|
|
||||||
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
|
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
|
||||||
|
private BlockState[] statesById = new BlockState[2 << 14];
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@ -58,10 +59,32 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OptionalInt getInternalBlockStateId(BlockState state) {
|
public OptionalInt getInternalBlockStateId(BlockState state) {
|
||||||
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
|
if (state.getBlockType() == BlockTypes.AIR) {
|
||||||
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state);
|
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 {
|
public static class BukkitBlockMaterial extends PassthroughBlockMaterial {
|
||||||
|
@ -415,8 +415,18 @@ public class BukkitWorld extends AbstractWorld {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public com.sk89q.worldedit.world.block.BlockState getBlock(BlockVector3 position) {
|
public com.sk89q.worldedit.world.block.BlockState getBlock(BlockVector3 position) {
|
||||||
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||||
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
|
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
|
@Override
|
||||||
|
@ -345,9 +345,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
|||||||
BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);
|
BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);
|
||||||
if (++nextX > max.getBlockX()) {
|
if (++nextX > max.getBlockX()) {
|
||||||
nextX = min.getBlockX();
|
nextX = min.getBlockX();
|
||||||
if (++nextY > max.getBlockY()) {
|
if (++nextZ > max.getBlockZ()) {
|
||||||
nextY = min.getBlockY();
|
nextZ = min.getBlockZ();
|
||||||
if (++nextZ > max.getBlockZ()) {
|
if (++nextY > max.getBlockY()) {
|
||||||
nextX = Integer.MIN_VALUE;
|
nextX = Integer.MIN_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class BlockState implements BlockStateHolder<BlockState> {
|
public class BlockState implements BlockStateHolder<BlockState> {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
BlockStateIdAccess.setBlockStateStateId(x -> x.internalId);
|
BlockStateIdAccess.setBlockStateStateId(x -> x.internalId);
|
||||||
}
|
}
|
||||||
@ -86,13 +86,14 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
|||||||
List<List<Object>> valueLists = Lists.cartesianProduct(separatedValues);
|
List<List<Object>> valueLists = Lists.cartesianProduct(separatedValues);
|
||||||
for (List<Object> valueList : valueLists) {
|
for (List<Object> valueList : valueLists) {
|
||||||
Map<Property<?>, Object> valueMap = Maps.newTreeMap(Comparator.comparing(Property::getName));
|
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++) {
|
for (int i = 0; i < valueList.size(); i++) {
|
||||||
Property<?> property = properties.get(i);
|
Property<?> property = properties.get(i);
|
||||||
Object value = valueList.get(i);
|
Object value = valueList.get(i);
|
||||||
valueMap.put(property, value);
|
valueMap.put(property, value);
|
||||||
stateMaker.setState(property, value);
|
stateMaker.setState(property, value);
|
||||||
}
|
}
|
||||||
|
stateMaker.initializeId(registry);
|
||||||
stateMap.put(valueMap, stateMaker);
|
stateMap.put(valueMap, stateMaker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,4 +67,11 @@ public interface BlockRegistry {
|
|||||||
*/
|
*/
|
||||||
OptionalInt getInternalBlockStateId(BlockState state);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,9 @@ public class BundledBlockRegistry implements BlockRegistry {
|
|||||||
return OptionalInt.empty();
|
return OptionalInt.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockStateByInternalId(int id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren