package wtf.kity.uncrackable.mixin; import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.EntityCollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import org.spongepowered.asm.mixin.Mixin; @Mixin(BlockBehaviour.class) public class BlockBehaviourMixin { /// If checking collision for a dragon egg, non-piston-destructible blocks should act /// as full blocks so the egg lands on top of them. @WrapMethod(method = "getCollisionShape") VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context, Operation original) { VoxelShape shape = original.call(state, level, pos, context); if (!shape.isEmpty() && context instanceof EntityCollisionContext entityContext && entityContext.getEntity() instanceof FallingBlockEntity fallingBlock && fallingBlock.getBlockState().is(Blocks.DRAGON_EGG) && state.getPistonPushReaction() != PushReaction.DESTROY ) { return Shapes.block(); } return shape; } }