Properly check empty context-sensitive collision shape
The emptyCollisionShape() function only checks whether the cached collision shape (not the context-sensitive collision shape) is empty. In places where we use the context-sensitive collision, we need to check the context-sensitive shape instead.
This commit is contained in:
@@ -59,10 +59,10 @@ abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState> implem
|
|||||||
private boolean emptyCollisionShape;
|
private boolean emptyCollisionShape;
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private VoxelShape constantCollisionShape;
|
private boolean emptyConstantCollisionShape;
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private AABB constantAABBCollision;
|
private VoxelShape constantCollisionShape;
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private static void initCaches(final VoxelShape shape, final boolean neighbours) {
|
private static void initCaches(final VoxelShape shape, final boolean neighbours) {
|
||||||
@@ -95,14 +95,13 @@ abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState> implem
|
|||||||
final VoxelShape collisionShape = this.cache.collisionShape;
|
final VoxelShape collisionShape = this.cache.collisionShape;
|
||||||
try {
|
try {
|
||||||
this.constantCollisionShape = this.getCollisionShape(null, null, null);
|
this.constantCollisionShape = this.getCollisionShape(null, null, null);
|
||||||
this.constantAABBCollision = this.constantCollisionShape == null ? null : ((CollisionVoxelShape)this.constantCollisionShape).moonrise$getSingleAABBRepresentation();
|
|
||||||
} catch (final Throwable throwable) {
|
} catch (final Throwable throwable) {
|
||||||
// :(
|
// :(
|
||||||
this.constantCollisionShape = null;
|
this.constantCollisionShape = null;
|
||||||
this.constantAABBCollision = null;
|
|
||||||
}
|
}
|
||||||
this.occludesFullBlock = ((CollisionVoxelShape)collisionShape).moonrise$occludesFullBlock();
|
this.occludesFullBlock = ((CollisionVoxelShape)collisionShape).moonrise$occludesFullBlock();
|
||||||
this.emptyCollisionShape = collisionShape.isEmpty();
|
this.emptyCollisionShape = collisionShape.isEmpty();
|
||||||
|
this.emptyConstantCollisionShape = this.constantCollisionShape != null && this.constantCollisionShape.isEmpty();
|
||||||
// init caches
|
// init caches
|
||||||
initCaches(collisionShape, true);
|
initCaches(collisionShape, true);
|
||||||
if (this.constantCollisionShape != null) {
|
if (this.constantCollisionShape != null) {
|
||||||
@@ -116,8 +115,8 @@ abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState> implem
|
|||||||
} else {
|
} else {
|
||||||
this.occludesFullBlock = false;
|
this.occludesFullBlock = false;
|
||||||
this.emptyCollisionShape = false;
|
this.emptyCollisionShape = false;
|
||||||
|
this.emptyConstantCollisionShape = false;
|
||||||
this.constantCollisionShape = null;
|
this.constantCollisionShape = null;
|
||||||
this.constantAABBCollision = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +135,11 @@ abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState> implem
|
|||||||
return this.emptyCollisionShape;
|
return this.emptyCollisionShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean moonrise$emptyContextCollisionShape() {
|
||||||
|
return this.emptyConstantCollisionShape;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int moonrise$uniqueId1() {
|
public final int moonrise$uniqueId1() {
|
||||||
return this.id1;
|
return this.id1;
|
||||||
@@ -147,12 +151,7 @@ abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final VoxelShape moonrise$getConstantCollisionShape() {
|
public final VoxelShape moonrise$getConstantContextCollisionShape() {
|
||||||
return this.constantCollisionShape;
|
return this.constantCollisionShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public final AABB moonrise$getConstantCollisionAABB() {
|
|
||||||
return this.constantAABBCollision;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,10 +246,10 @@ abstract class ExplosionMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final BlockState blockState = cachedBlock.blockState;
|
final BlockState blockState = cachedBlock.blockState;
|
||||||
if (blockState != null && !((CollisionBlockState)blockState).moonrise$emptyCollisionShape()) {
|
if (blockState != null && !((CollisionBlockState)blockState).moonrise$emptyContextCollisionShape()) {
|
||||||
VoxelShape collision = cachedBlock.cachedCollisionShape;
|
VoxelShape collision = cachedBlock.cachedCollisionShape;
|
||||||
if (collision == null) {
|
if (collision == null) {
|
||||||
collision = ((CollisionBlockState)blockState).moonrise$getConstantCollisionShape();
|
collision = ((CollisionBlockState)blockState).moonrise$getConstantContextCollisionShape();
|
||||||
if (collision == null) {
|
if (collision == null) {
|
||||||
collision = blockState.getCollisionShape(this.level, currPos, context);
|
collision = blockState.getCollisionShape(this.level, currPos, context);
|
||||||
if (!context.isDelegated()) {
|
if (!context.isDelegated()) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import ca.spottedleaf.moonrise.patches.collisions.world.CollisionLevel;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.profiling.ProfilerFiller;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.level.ClipContext;
|
import net.minecraft.world.level.ClipContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
@@ -425,11 +424,11 @@ abstract class LevelMixin implements CollisionLevel, LevelAccessor, AutoCloseabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
final BlockState state = ((GetBlockChunk)lastChunk).moonrise$getBlock(currX, currY, currZ);
|
final BlockState state = ((GetBlockChunk)lastChunk).moonrise$getBlock(currX, currY, currZ);
|
||||||
if (((CollisionBlockState)state).moonrise$emptyCollisionShape()) {
|
if (((CollisionBlockState)state).moonrise$emptyContextCollisionShape()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShape blockCollision = ((CollisionBlockState)state).moonrise$getConstantCollisionShape();
|
VoxelShape blockCollision = ((CollisionBlockState)state).moonrise$getConstantContextCollisionShape();
|
||||||
|
|
||||||
if ((edgeCount != 1 || state.hasLargeCollisionShape()) && (edgeCount != 2 || state.getBlock() == Blocks.MOVING_PISTON)) {
|
if ((edgeCount != 1 || state.hasLargeCollisionShape()) && (edgeCount != 2 || state.getBlock() == Blocks.MOVING_PISTON)) {
|
||||||
if (collisionContext == null) {
|
if (collisionContext == null) {
|
||||||
|
|||||||
@@ -69,8 +69,7 @@ abstract class ThreadedLevelLightEngineMixin extends LevelLightEngine implements
|
|||||||
|
|
||||||
final ChunkAccess center = this.starlight$getLightEngine().getAnyChunkNow(chunkX, chunkZ);
|
final ChunkAccess center = this.starlight$getLightEngine().getAnyChunkNow(chunkX, chunkZ);
|
||||||
if (center == null || !center.getPersistedStatus().isOrAfter(ChunkStatus.LIGHT)) {
|
if (center == null || !center.getPersistedStatus().isOrAfter(ChunkStatus.LIGHT)) {
|
||||||
// do not accept updates in unlit chunks, unless we might be generating a chunk. thanks to the amazing
|
// do not accept updates in unlit chunks, unless we might be generating a chunk
|
||||||
// chunk scheduling, we could be lighting and generating a chunk at the same time
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +96,8 @@ abstract class ThreadedLevelLightEngineMixin extends LevelLightEngine implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int starlight$serverRelightChunks(final Collection<ChunkPos> chunks0,
|
public final int starlight$serverRelightChunks(final Collection<ChunkPos> chunks0,
|
||||||
final Consumer<ChunkPos> chunkLightCallback,
|
final Consumer<ChunkPos> chunkLightCallback,
|
||||||
final IntConsumer onComplete) {
|
final IntConsumer onComplete) {
|
||||||
final Set<ChunkPos> chunks = new LinkedHashSet<>(chunks0);
|
final Set<ChunkPos> chunks = new LinkedHashSet<>(chunks0);
|
||||||
final Map<ChunkPos, Long> ticketIds = new HashMap<>();
|
final Map<ChunkPos, Long> ticketIds = new HashMap<>();
|
||||||
final ServerLevel world = (ServerLevel)this.starlight$getLightEngine().getWorld();
|
final ServerLevel world = (ServerLevel)this.starlight$getLightEngine().getWorld();
|
||||||
|
|||||||
@@ -2023,11 +2023,11 @@ public final class CollisionUtil {
|
|||||||
|
|
||||||
final BlockState blockData = blocks.get(localBlockIndex);
|
final BlockState blockData = blocks.get(localBlockIndex);
|
||||||
|
|
||||||
if (((CollisionBlockState)blockData).moonrise$emptyCollisionShape()) {
|
if (((CollisionBlockState)blockData).moonrise$emptyContextCollisionShape()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShape blockCollision = ((CollisionBlockState)blockData).moonrise$getConstantCollisionShape();
|
VoxelShape blockCollision = ((CollisionBlockState)blockData).moonrise$getConstantContextCollisionShape();
|
||||||
|
|
||||||
if (edgeCount == 0 || ((edgeCount != 1 || blockData.hasLargeCollisionShape()) && (edgeCount != 2 || blockData.getBlock() == Blocks.MOVING_PISTON))) {
|
if (edgeCount == 0 || ((edgeCount != 1 || blockData.hasLargeCollisionShape()) && (edgeCount != 2 || blockData.getBlock() == Blocks.MOVING_PISTON))) {
|
||||||
if (blockCollision == null) {
|
if (blockCollision == null) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ca.spottedleaf.moonrise.patches.collisions.block;
|
package ca.spottedleaf.moonrise.patches.collisions.block;
|
||||||
|
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
|
||||||
public interface CollisionBlockState {
|
public interface CollisionBlockState {
|
||||||
@@ -12,6 +11,9 @@ public interface CollisionBlockState {
|
|||||||
// whether the cached collision shape exists and is empty
|
// whether the cached collision shape exists and is empty
|
||||||
public boolean moonrise$emptyCollisionShape();
|
public boolean moonrise$emptyCollisionShape();
|
||||||
|
|
||||||
|
// whether the context-sensitive shape is constant and is empty
|
||||||
|
public boolean moonrise$emptyContextCollisionShape();
|
||||||
|
|
||||||
// indicates that occludesFullBlock is cached for the collision shape
|
// indicates that occludesFullBlock is cached for the collision shape
|
||||||
public boolean moonrise$hasCache();
|
public boolean moonrise$hasCache();
|
||||||
|
|
||||||
@@ -23,7 +25,5 @@ public interface CollisionBlockState {
|
|||||||
// value is still unique
|
// value is still unique
|
||||||
public int moonrise$uniqueId2();
|
public int moonrise$uniqueId2();
|
||||||
|
|
||||||
public VoxelShape moonrise$getConstantCollisionShape();
|
public VoxelShape moonrise$getConstantContextCollisionShape();
|
||||||
|
|
||||||
public AABB moonrise$getConstantCollisionAABB();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user