From f451a4b868fe6abb8c1fb337f3149ca4737fe1f5 Mon Sep 17 00:00:00 2001 From: xtex Date: Mon, 3 Jul 2023 09:49:47 +0800 Subject: [PATCH] feat: kick projected people from bed https://todo.projectsegfau.lt/tasks/748 --- .../java/quaedam/mixin/MixinBedBlock.java | 30 +++++++++++++++++++ .../main/resources/quaedam-common.mixins.json | 1 + 2 files changed, 31 insertions(+) create mode 100644 common/src/main/java/quaedam/mixin/MixinBedBlock.java 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": {