-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e07654c
commit f626dc4
Showing
1 changed file
with
23 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
package net.rpgz.mixin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
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.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import com.mojang.datafixers.util.Either; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.util.Unit; | ||
import net.minecraft.world.entity.monster.Monster; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
@Mixin(ServerPlayer.class) | ||
public class ServerPlayerMixin { | ||
@Redirect(method = "startSleepInBed", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getEntitiesOfClass(Ljava/lang/Class;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;")) | ||
public List<Monster> isPreventingPlayerRestAndIsAlive(Level level, Class<Monster> pClazz, AABB pArea, Predicate<Monster> pFilter) { | ||
return level.getEntitiesOfClass(pClazz, pArea, (p_9062_) -> { | ||
return !p_9062_.isDeadOrDying() && p_9062_.isPreventingPlayerRest((ServerPlayer)(Object)this); | ||
}); | ||
@Inject(method = "startSleepInBed", at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"), locals = LocalCapture.CAPTURE_FAILSOFT) | ||
public void isPreventingPlayerRestAndIsAlive(BlockPos pos, CallbackInfoReturnable<Either<Player.BedSleepingProblem, Unit>> info, Direction direction, double d, double e, Vec3 vec3d, List<Monster> list) { | ||
if (!list.isEmpty()) { | ||
List<Monster> removeList = new ArrayList<Monster>(); | ||
for (int o = 0; o < list.size(); ++o) { | ||
Monster entityFromList = (Monster) list.get(o); | ||
if (entityFromList.isDeadOrDying()) { | ||
removeList.add(entityFromList); | ||
} | ||
} | ||
list.removeAll(removeList); | ||
} | ||
} | ||
} |