9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-27 18:59:06 +00:00

Configure players colliding with cobwebs

This commit is contained in:
Samsuik
2025-09-28 16:43:30 +01:00
parent 3efe13eb91
commit 1f7c1af374
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
--- a/net/minecraft/world/level/block/WebBlock.java
+++ b/net/minecraft/world/level/block/WebBlock.java
@@ -10,6 +_,7 @@
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
+import net.minecraft.world.phys.shapes.EntityCollisionContext;
public class WebBlock extends Block {
public static final MapCodec<WebBlock> CODEC = simpleCodec(WebBlock::new);
@@ -22,6 +_,31 @@
public WebBlock(BlockBehaviour.Properties properties) {
super(properties);
}
+
+ // Sakura start - configure players colliding with cobwebs
+ @Override
+ protected final net.minecraft.world.phys.shapes.VoxelShape getCollisionShape(
+ final BlockState state,
+ final net.minecraft.world.level.BlockGetter blockGetter,
+ final BlockPos pos,
+ final net.minecraft.world.phys.shapes.CollisionContext context
+ ) {
+ if (blockGetter instanceof Level level
+ && level.sakuraConfig().players.collideWithCobwebs
+ && context instanceof EntityCollisionContext entityContext
+ && entityContext.getEntity() instanceof net.minecraft.world.entity.player.Player) {
+ final BlockPos blockPosAbove = pos.above();
+ final BlockState stateAbove = level.getBlockState(blockPosAbove);
+
+ // If the block above is a full block then this cobweb should have a solid collision (for players)
+ if (stateAbove.getCollisionShape(level, blockPosAbove, context).moonrise$isFullBlock()) {
+ return net.minecraft.world.phys.shapes.Shapes.block();
+ }
+ }
+
+ return super.getCollisionShape(state, blockGetter, pos, context);
+ }
+ // Sakura end - configure players colliding with cobwebs
@Override
protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity, InsideBlockEffectApplier effectApplier) {

View File

@@ -188,6 +188,7 @@ public final class WorldConfiguration extends ConfigurationPart {
public boolean posesShrinkCollisionBox = true;
public boolean fishingHooksPullEntities = true;
public boolean preventPlacingSpawnEggsInsideBlocks = false;
public boolean collideWithCobwebs = false;
}
public Entity entity;