mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
This does something idk.
This commit is contained in:
parent
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,9 +415,19 @@ 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) {
|
||||||
|
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());
|
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||||
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
|
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||||
|
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
|
||||||
|
@ -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()) {
|
|
||||||
nextY = min.getBlockY();
|
|
||||||
if (++nextZ > max.getBlockZ()) {
|
if (++nextZ > max.getBlockZ()) {
|
||||||
|
nextZ = min.getBlockZ();
|
||||||
|
if (++nextY > max.getBlockY()) {
|
||||||
nextX = Integer.MIN_VALUE;
|
nextX = Integer.MIN_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user