Skip to content

Commit ec919a8

Browse files
committed
Reimplement IOverrideCollisions collide mixin
1 parent 19759c2 commit ec919a8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.itsmeow.whisperwoods.mixin;
2+
3+
import dev.itsmeow.whisperwoods.util.IOverrideCollisions;
4+
import net.minecraft.world.level.BlockCollisions;
5+
import net.minecraft.world.level.BlockGetter;
6+
import net.minecraft.world.level.block.state.BlockState;
7+
import net.minecraft.world.phys.shapes.CollisionContext;
8+
import net.minecraft.world.phys.shapes.EntityCollisionContext;
9+
import net.minecraft.world.phys.shapes.Shapes;
10+
import net.minecraft.world.phys.shapes.VoxelShape;
11+
import org.spongepowered.asm.mixin.Final;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Shadow;
14+
import org.spongepowered.asm.mixin.injection.At;
15+
import org.spongepowered.asm.mixin.injection.Inject;
16+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
17+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
18+
19+
@Mixin(BlockCollisions.class)
20+
public class BlockCollisionsMixin {
21+
22+
@Shadow
23+
@Final
24+
private CollisionContext context;
25+
26+
@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/BlockGetter;getBlockState(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;"), method = "computeNext()Lnet/minecraft/world/phys/shapes/VoxelShape;", cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT)
27+
private void computeNext(CallbackInfoReturnable<VoxelShape> cir, int i, int j, int k, int l, BlockGetter blockGetter, BlockState blockState) {
28+
if(this.context instanceof EntityCollisionContext eContext) {
29+
if(eContext.getEntity() instanceof IOverrideCollisions o) {
30+
if(o.canPassThrough(blockState)) {
31+
cir.setReturnValue(Shapes.empty());
32+
}
33+
}
34+
}
35+
}
36+
37+
}

common/src/main/resources/whisperwoods.mixins.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"compatibilityLevel": "JAVA_17",
55
"minVersion": "0.8",
66
"mixins": [
7-
"LivingEntityMixin"
7+
"LivingEntityMixin",
8+
"BlockCollisionsMixin"
89
],
910
"client": [
1011
"LayerDefinitionsMixin"

0 commit comments

Comments
 (0)