diff --git a/common/src/main/java/quaedam/mixin/MixinBedBlock.java b/common/src/main/java/quaedam/mixin/MixinBedBlock.java new file mode 100644 index 0000000..9245c48 --- /dev/null +++ b/common/src/main/java/quaedam/mixin/MixinBedBlock.java @@ -0,0 +1,30 @@ +package quaedam.mixin; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BedBlock; +import net.minecraft.world.phys.AABB; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import quaedam.projection.swarm.ProjectedPersonEntity; + +import java.util.List; + +@Mixin(BedBlock.class) +public class MixinBedBlock { + + @Inject(at = @At("RETURN"), method = "kickVillagerOutOfBed(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z", cancellable = true) + private void kickVillagerOutOfBed(Level level, BlockPos blockPos, CallbackInfoReturnable cir) { + if (!cir.getReturnValueZ()) { + List list = level.getEntitiesOfClass(ProjectedPersonEntity.class, new AABB(blockPos), LivingEntity::isSleeping); + if (!list.isEmpty()) { + list.get(0).stopSleeping(); + cir.setReturnValue(true); + } + } + } + +} diff --git a/common/src/main/resources/quaedam-common.mixins.json b/common/src/main/resources/quaedam-common.mixins.json index be9b42f..99e8b24 100644 --- a/common/src/main/resources/quaedam-common.mixins.json +++ b/common/src/main/resources/quaedam-common.mixins.json @@ -7,6 +7,7 @@ "MixinClientLevel" ], "mixins": [ + "MixinBedBlock", "MixinBuiltInRegistries" ], "injectors": {