Skip to content

Commit

Permalink
Made changes to ServerPlayerMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
Stereowalker committed Nov 23, 2024
1 parent e07654c commit f626dc4
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/main/java/net/rpgz/mixin/ServerPlayerMixin.java
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);
}
}
}

0 comments on commit f626dc4

Please sign in to comment.