diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightLevelProxy.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightLevelProxy.java index 2fd9d6f56..33a50aa42 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightLevelProxy.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightLevelProxy.java @@ -19,6 +19,7 @@ import javax.annotation.Nullable; public class PaperweightLevelProxy extends ServerLevel { + protected ServerLevel serverLevel; private PaperweightFaweAdapter adapter; private PaperweightPlacementStateProcessor processor; @@ -28,7 +29,7 @@ public class PaperweightLevelProxy extends ServerLevel { throw new IllegalStateException("Cannot be instantiated"); } - public static PaperweightLevelProxy getInstance(PaperweightPlacementStateProcessor processor) { + public static PaperweightLevelProxy getInstance(ServerLevel serverLevel, PaperweightPlacementStateProcessor processor) { Unsafe unsafe = ReflectionUtils.getUnsafe(); PaperweightLevelProxy newLevel; @@ -39,6 +40,7 @@ public class PaperweightLevelProxy extends ServerLevel { } newLevel.processor = processor; newLevel.adapter = ((PaperweightFaweAdapter) WorldEditPlugin.getInstance().getBukkitImplAdapter()); + newLevel.serverLevel = serverLevel; return newLevel; } @@ -94,4 +96,14 @@ public class PaperweightLevelProxy extends ServerLevel { return getBlockState(pos).getFluidState().is(FluidTags.WATER); } + @Override + public int getHeight() { + return serverLevel.getHeight(); + } + + @Override + public int getMinBuildHeight() { + return serverLevel.getMinBuildHeight(); + } + } diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java index bc09a61a1..24b0fe129 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java @@ -1,6 +1,9 @@ package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2; import com.fastasyncworldedit.core.extent.processor.PlacementStateProcessor; +import com.fastasyncworldedit.core.util.ExtentTraverser; +import com.fastasyncworldedit.core.wrappers.WorldWrapper; +import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BlockTypeMask; @@ -8,12 +11,14 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypesCache; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; +import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; import javax.annotation.Nullable; import java.util.Map; @@ -29,7 +34,18 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor public PaperweightPlacementStateProcessor(Extent extent, BlockTypeMask mask, Region region) { super(extent, mask, region); - this.proxyLevel = PaperweightLevelProxy.getInstance(this); + World world = ExtentTraverser.getWorldFromExtent(extent); + if (world == null) { + throw new UnsupportedOperationException( + "World is required for PlacementStateProcessor but none found in given extent."); + } + BukkitWorld bukkitWorld; + if (world instanceof WorldWrapper wrapper) { + bukkitWorld = (BukkitWorld) wrapper.getParent(); + } else { + bukkitWorld = (BukkitWorld) world; + } + this.proxyLevel = PaperweightLevelProxy.getInstance(((CraftWorld) bukkitWorld.getWorld()).getHandle(), this); this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } @@ -42,7 +58,18 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor AtomicBoolean finished ) { super(extent, mask, crossChunkSecondPasses, threadProcessors, region, finished); - this.proxyLevel = PaperweightLevelProxy.getInstance(this); + World world = ExtentTraverser.getWorldFromExtent(extent); + if (world == null) { + throw new UnsupportedOperationException( + "World is required for PlacementStateProcessor but none found in given extent."); + } + BukkitWorld bukkitWorld; + if (world instanceof WorldWrapper wrapper) { + bukkitWorld = (BukkitWorld) wrapper.getParent(); + } else { + bukkitWorld = (BukkitWorld) world; + } + this.proxyLevel = PaperweightLevelProxy.getInstance(((CraftWorld) bukkitWorld.getWorld()).getHandle(), this); this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightLevelProxy.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightLevelProxy.java index 5e9dbc885..90149f633 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightLevelProxy.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightLevelProxy.java @@ -19,6 +19,7 @@ import javax.annotation.Nullable; public class PaperweightLevelProxy extends ServerLevel { + protected ServerLevel serverLevel; private PaperweightFaweAdapter adapter; private PaperweightPlacementStateProcessor processor; @@ -28,7 +29,7 @@ public class PaperweightLevelProxy extends ServerLevel { throw new IllegalStateException("Cannot be instantiated"); } - public static PaperweightLevelProxy getInstance(PaperweightPlacementStateProcessor processor) { + public static PaperweightLevelProxy getInstance(ServerLevel serverLevel, PaperweightPlacementStateProcessor processor) { Unsafe unsafe = ReflectionUtils.getUnsafe(); PaperweightLevelProxy newLevel; @@ -39,6 +40,7 @@ public class PaperweightLevelProxy extends ServerLevel { } newLevel.processor = processor; newLevel.adapter = ((PaperweightFaweAdapter) WorldEditPlugin.getInstance().getBukkitImplAdapter()); + newLevel.serverLevel = serverLevel; return newLevel; } @@ -94,4 +96,14 @@ public class PaperweightLevelProxy extends ServerLevel { return getBlockState(pos).getFluidState().is(FluidTags.WATER); } + @Override + public int getHeight() { + return serverLevel.getHeight(); + } + + @Override + public int getMinBuildHeight() { + return serverLevel.getMinBuildHeight(); + } + } diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java index f0c2d7223..fd12e5f38 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java @@ -1,6 +1,9 @@ package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3; import com.fastasyncworldedit.core.extent.processor.PlacementStateProcessor; +import com.fastasyncworldedit.core.util.ExtentTraverser; +import com.fastasyncworldedit.core.wrappers.WorldWrapper; +import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BlockTypeMask; @@ -8,12 +11,14 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypesCache; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; +import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; import javax.annotation.Nullable; import java.util.Map; @@ -29,7 +34,18 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor public PaperweightPlacementStateProcessor(Extent extent, BlockTypeMask mask, Region region) { super(extent, mask, region); - this.proxyLevel = PaperweightLevelProxy.getInstance(this); + World world = ExtentTraverser.getWorldFromExtent(extent); + if (world == null) { + throw new UnsupportedOperationException( + "World is required for PlacementStateProcessor but none found in given extent."); + } + BukkitWorld bukkitWorld; + if (world instanceof WorldWrapper wrapper) { + bukkitWorld = (BukkitWorld) wrapper.getParent(); + } else { + bukkitWorld = (BukkitWorld) world; + } + this.proxyLevel = PaperweightLevelProxy.getInstance(((CraftWorld) bukkitWorld.getWorld()).getHandle(), this); this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } @@ -42,7 +58,18 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor AtomicBoolean finished ) { super(extent, mask, crossChunkSecondPasses, threadProcessors, region, finished); - this.proxyLevel = PaperweightLevelProxy.getInstance(this); + World world = ExtentTraverser.getWorldFromExtent(extent); + if (world == null) { + throw new UnsupportedOperationException( + "World is required for PlacementStateProcessor but none found in given extent."); + } + BukkitWorld bukkitWorld; + if (world instanceof WorldWrapper wrapper) { + bukkitWorld = (BukkitWorld) wrapper.getParent(); + } else { + bukkitWorld = (BukkitWorld) world; + } + this.proxyLevel = PaperweightLevelProxy.getInstance(((CraftWorld) bukkitWorld.getWorld()).getHandle(), this); this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } diff --git a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightLevelProxy.java b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightLevelProxy.java index ad916e5a9..3cc3baa2f 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightLevelProxy.java +++ b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightLevelProxy.java @@ -96,4 +96,14 @@ public class PaperweightLevelProxy extends ServerLevel { return getBlockState(pos).getFluidState().is(FluidTags.WATER); } + @Override + public int getHeight() { + return serverLevel.getHeight(); + } + + @Override + public int getMinBuildHeight() { + return serverLevel.getMinBuildHeight(); + } + } diff --git a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightLevelProxy.java b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightLevelProxy.java index cedf5ae20..0676a5fa7 100644 --- a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightLevelProxy.java +++ b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightLevelProxy.java @@ -96,4 +96,14 @@ public class PaperweightLevelProxy extends ServerLevel { return getBlockState(pos).getFluidState().is(FluidTags.WATER); } + @Override + public int getHeight() { + return serverLevel.getHeight(); + } + + @Override + public int getMinBuildHeight() { + return serverLevel.getMinBuildHeight(); + } + } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java index 694a11a5e..a0fec2fee 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java @@ -392,6 +392,10 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp } private char getBlockOrdinal(int blockX, int blockY, int blockZ, BlockState state) { + char override = getOverrideBlockOrdinal(blockX, blockY, blockZ, state); + if (override != BlockTypesCache.ReservedIDs.__RESERVED__) { + return override; + } EnumSet dirs = Direction.getDirections(state); Direction clickedFaceDirection = null; // This should be always be set by the below. Set states = state.getStates().keySet().stream().map(Property::getName).collect(Collectors.toSet()); @@ -436,6 +440,17 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp return getStateAtFor(blockX, blockY, blockZ, state, clickPos, clickedFaceDirection, clickedBlock); } + protected char getOverrideBlockOrdinal(int blockX, int blockY, int blockZ, BlockState state) { + if (BlockCategories.TALL_FLOWERS.contains(state)) { + PropertyKey propertyKey = PropertyKey.HALF; + BlockState plantState = extent.getBlock(blockX, blockY - 1, blockZ).getBlockType().equals(state.getBlockType()) + ? state.with(propertyKey, "upper") + : state.with(propertyKey, "lower"); + return plantState.getOrdinalChar(); + } + return BlockTypesCache.ReservedIDs.__RESERVED__; + } + @Override public void applyBlock(FilterBlock block) { if (finished.get()) {