Skip to content

Commit

Permalink
Adjustment for tall flowers - add capability to forcefully override b…
Browse files Browse the repository at this point in the history
…lock updates
  • Loading branch information
dordsor21 committed Sep 17, 2024
1 parent a8e70bb commit 164e5c6
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

public class PaperweightLevelProxy extends ServerLevel {

protected ServerLevel serverLevel;
private PaperweightFaweAdapter adapter;
private PaperweightPlacementStateProcessor processor;

Expand All @@ -28,7 +29,7 @@ private PaperweightLevelProxy() {
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;
Expand All @@ -39,6 +40,7 @@ public static PaperweightLevelProxy getInstance(PaperweightPlacementStateProcess
}
newLevel.processor = processor;
newLevel.adapter = ((PaperweightFaweAdapter) WorldEditPlugin.getInstance().getBukkitImplAdapter());
newLevel.serverLevel = serverLevel;
return newLevel;
}

Expand Down Expand Up @@ -94,4 +96,14 @@ public boolean isWaterAt(@Nonnull BlockPos pos) {
return getBlockState(pos).getFluidState().is(FluidTags.WATER);
}

@Override
public int getHeight() {
return serverLevel.getHeight();
}

@Override
public int getMinBuildHeight() {
return serverLevel.getMinBuildHeight();
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
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;
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;
Expand All @@ -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);
}

Expand All @@ -42,7 +58,18 @@ private PaperweightPlacementStateProcessor(
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

public class PaperweightLevelProxy extends ServerLevel {

protected ServerLevel serverLevel;
private PaperweightFaweAdapter adapter;
private PaperweightPlacementStateProcessor processor;

Expand All @@ -28,7 +29,7 @@ private PaperweightLevelProxy() {
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;
Expand All @@ -39,6 +40,7 @@ public static PaperweightLevelProxy getInstance(PaperweightPlacementStateProcess
}
newLevel.processor = processor;
newLevel.adapter = ((PaperweightFaweAdapter) WorldEditPlugin.getInstance().getBukkitImplAdapter());
newLevel.serverLevel = serverLevel;
return newLevel;
}

Expand Down Expand Up @@ -94,4 +96,14 @@ public boolean isWaterAt(@Nonnull BlockPos pos) {
return getBlockState(pos).getFluidState().is(FluidTags.WATER);
}

@Override
public int getHeight() {
return serverLevel.getHeight();
}

@Override
public int getMinBuildHeight() {
return serverLevel.getMinBuildHeight();
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
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;
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;
Expand All @@ -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);
}

Expand All @@ -42,7 +58,18 @@ private PaperweightPlacementStateProcessor(
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ public boolean isWaterAt(@Nonnull BlockPos pos) {
return getBlockState(pos).getFluidState().is(FluidTags.WATER);
}

@Override
public int getHeight() {
return serverLevel.getHeight();
}

@Override
public int getMinBuildHeight() {
return serverLevel.getMinBuildHeight();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ public boolean isWaterAt(@Nonnull BlockPos pos) {
return getBlockState(pos).getFluidState().is(FluidTags.WATER);
}

@Override
public int getHeight() {
return serverLevel.getHeight();
}

@Override
public int getMinBuildHeight() {
return serverLevel.getMinBuildHeight();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ public CompoundTag getTileAt(int x, int y, int z) {
}

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<Direction> dirs = Direction.getDirections(state);
Direction clickedFaceDirection = null; // This should be always be set by the below.
Set<String> states = state.getStates().keySet().stream().map(Property::getName).collect(Collectors.toSet());
Expand Down Expand Up @@ -436,6 +440,17 @@ private char getBlockOrdinal(int blockX, int blockY, int blockZ, BlockState stat
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()) {
Expand Down

0 comments on commit 164e5c6

Please sign in to comment.