diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java index e176743c4a..d782f2a8eb 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java @@ -51,6 +51,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.core.WritableRegistry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.resources.ResourceLocation; @@ -92,6 +93,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -219,6 +221,15 @@ private synchronized boolean init() { return true; } + @Override + public Collection getRegisteredDefaultBlockStates() { + ArrayList states = new ArrayList<>(); + for (final Block block : BuiltInRegistries.BLOCK) { + states.add(CraftBlockData.createData(block.defaultBlockState()).getAsString()); + } + return states; + } + @Override public BlockMaterial getMaterial(BlockType blockType) { Block block = getBlock(blockType); diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java index c5f4772a03..1d7bd1eabe 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java @@ -50,6 +50,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.core.WritableRegistry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.resources.ResourceLocation; @@ -91,6 +92,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -218,6 +220,15 @@ private synchronized boolean init() { return true; } + @Override + public Collection getRegisteredDefaultBlockStates() { + ArrayList states = new ArrayList<>(); + for (final Block block : BuiltInRegistries.BLOCK) { + states.add(CraftBlockData.createData(block.defaultBlockState()).getAsString()); + } + return states; + } + @Override public BlockMaterial getMaterial(BlockType blockType) { Block block = getBlock(blockType); diff --git a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java index 6c5a5330ec..64a08ce2a6 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweAdapter.java @@ -55,6 +55,7 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.core.WritableRegistry; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; @@ -98,6 +99,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -228,6 +230,15 @@ private synchronized boolean init() { return true; } + @Override + public Collection getRegisteredDefaultBlockStates() { + ArrayList states = new ArrayList<>(); + for (final Block block : BuiltInRegistries.BLOCK) { + states.add(CraftBlockData.createData(block.defaultBlockState()).getAsString()); + } + return states; + } + @Override public BlockMaterial getMaterial(BlockType blockType) { Block block = getBlock(blockType); diff --git a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java index 415a462c93..df78d214de 100644 --- a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweAdapter.java @@ -55,6 +55,7 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.core.WritableRegistry; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; @@ -98,6 +99,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -228,6 +230,15 @@ private synchronized boolean init() { return true; } + @Override + public Collection getRegisteredDefaultBlockStates() { + ArrayList states = new ArrayList<>(); + for (final Block block : BuiltInRegistries.BLOCK) { + states.add(CraftBlockData.createData(block.defaultBlockState()).getAsString()); + } + return states; + } + @Override public BlockMaterial getMaterial(BlockType blockType) { Block block = getBlock(blockType); diff --git a/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java index 47aba48713..42c4a5517a 100644 --- a/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21_3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_3/PaperweightFaweAdapter.java @@ -55,6 +55,7 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.core.WritableRegistry; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; @@ -97,6 +98,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -214,6 +216,15 @@ private synchronized boolean init() { return true; } + @Override + public Collection getRegisteredDefaultBlockStates() { + ArrayList states = new ArrayList<>(); + for (final Block block : BuiltInRegistries.BLOCK) { + states.add(CraftBlockData.createData(block.defaultBlockState()).getAsString()); + } + return states; + } + @Override public BlockMaterial getMaterial(BlockType blockType) { Block block = getBlock(blockType); diff --git a/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java b/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java index b0ec904cd3..22e3f220cb 100644 --- a/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4/PaperweightFaweAdapter.java @@ -55,6 +55,7 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.core.WritableRegistry; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; @@ -97,6 +98,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -214,6 +216,15 @@ private synchronized boolean init() { return true; } + @Override + public Collection getRegisteredDefaultBlockStates() { + ArrayList states = new ArrayList<>(); + for (final Block block : BuiltInRegistries.BLOCK) { + states.add(CraftBlockData.createData(block.defaultBlockState()).getAsString()); + } + return states; + } + @Override public BlockMaterial getMaterial(BlockType blockType) { Block block = getBlock(blockType); diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java index 14f4bd7942..8e79a08b91 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/FaweAdapter.java @@ -13,6 +13,7 @@ import org.bukkit.World; import org.bukkit.block.BlockState; +import java.util.Collection; import java.util.List; import java.util.Map; diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java index 41c5cbc794..49329f2cca 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IDelegateBukkitImplAdapter.java @@ -35,6 +35,7 @@ import org.enginehub.linbus.tree.LinTag; import javax.annotation.Nullable; +import java.util.Collection; import java.util.Map; import java.util.OptionalInt; @@ -135,6 +136,11 @@ default void sendBiomeUpdates(World world, Iterable chunks) { getParent().sendBiomeUpdates(world, chunks); } + @Override + default Collection getRegisteredDefaultBlockStates() { + return getParent().getRegisteredDefaultBlockStates(); + } + @Override default BlockMaterial getMaterial(BlockType blockType) { return getParent().getMaterial(blockType); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java index 8a84a5b113..a1045ed9e1 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java @@ -150,15 +150,9 @@ public boolean isTranslucent() { //FAWE start @Override - public Collection values() { - ArrayList blocks = new ArrayList<>(); - for (Material m : Material.values()) { - if (!m.isLegacy() && m.isBlock()) { - BlockData blockData = m.createBlockData(); - blocks.add(blockData.getAsString()); - } - } - return blocks; + public Collection getAllDefaultBlockStates() { + BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); + return adapter.getRegisteredDefaultBlockStates(); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java index 7c778b5ce9..42b49c1578 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java @@ -54,6 +54,7 @@ import com.sk89q.worldedit.world.registry.BlockMaterial; import org.bukkit.Keyed; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -66,7 +67,9 @@ import org.enginehub.linbus.tree.LinTag; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -332,6 +335,22 @@ default BlockMaterial getMaterial(BlockState blockState) { return null; } + /** + * Returns an iterable of all blocks in their default state as string representations known to the server. + * + * @return an iterable containing the default state strings of all valid blocks + */ + default Collection getRegisteredDefaultBlockStates() { + ArrayList blocks = new ArrayList<>(); + for (Material m : Material.values()) { + if (!m.isLegacy() && m.isBlock()) { + BlockData blockData = m.createBlockData(); + blocks.add(blockData.getAsString()); + } + } + return blocks; + } + @Deprecated default Tag toNative(T foreign) { return LinBusConverter.toJnbtTag(toNativeLin(foreign)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java index a8ce03effc..b00813f809 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java @@ -214,7 +214,7 @@ private static int[] generateStateOrdinals(int internalId, int ordinal, int maxS Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS); Registries registries = platform.getRegistries(); BlockRegistry blockReg = registries.getBlockRegistry(); - Collection blocks = blockReg.values(); + Collection blocks = blockReg.getAllDefaultBlockStates(); Map blockMap = blocks.stream().collect(Collectors.toMap(item -> item.charAt(item.length() - 1) == ']' ? item.substring(0, item.indexOf('[')) : item, item -> item)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java index 3b782445de..2c62a15db3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java @@ -94,7 +94,7 @@ default BlockMaterial getMaterial(BlockState state) { /** * Register all blocks. */ - default Collection values() { + default Collection getAllDefaultBlockStates() { return Collections.emptyList(); }