Skip to content

Commit

Permalink
close #4349
Browse files Browse the repository at this point in the history
  • Loading branch information
yrsegal committed Sep 25, 2023
1 parent 29a6710 commit 0ddeb18
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package vazkii.quark.content.automation.block.be;

import java.util.List;

import com.mojang.math.Vector3f;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.DustParticleOptions;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ClipContext.Block;
import net.minecraft.world.level.ClipContext.Fluid;
import net.minecraft.world.level.Level;
Expand All @@ -25,6 +23,8 @@
import vazkii.quark.content.automation.block.EnderWatcherBlock;
import vazkii.quark.content.automation.module.EnderWatcherModule;

import java.util.List;

public class EnderWatcherBlockEntity extends ARLBlockEntity {

public EnderWatcherBlockEntity(BlockPos pos, BlockState state) {
Expand All @@ -39,10 +39,14 @@ public static void tick(Level level, BlockPos pos, BlockState state, EnderWatche
int newWatch = 0;
List<Player> players = level.getEntitiesOfClass(Player.class, new AABB(be.worldPosition.offset(-range, -range, -range), be.worldPosition.offset(range, range, range)));

EnderMan fakeEnderman = new EnderMan(EntityType.ENDERMAN, level);
fakeEnderman.setPos(pos.getX() + 0.5, pos.getY() + 0.5 - fakeEnderman.getEyeHeight(), pos.getZ() + 0.5);

boolean looking = false;
for(Player player : players) {
ItemStack helm = player.getItemBySlot(EquipmentSlot.HEAD);
if(!helm.isEmpty() && helm.getItem() == Items.PUMPKIN)
fakeEnderman.lookAt(player, 180, 180);
if(!helm.isEmpty() && helm.isEnderMask(player, fakeEnderman))
continue;

HitResult result = RayTraceHandler.rayTrace(player, level, player, Block.OUTLINE, Fluid.NONE, 64);
Expand All @@ -58,10 +62,10 @@ public static void tick(Level level, BlockPos pos, BlockState state, EnderWatche
// 0.7071067811865476 being the hypotenuse of an isosceles triangle with cathetus of length 0.5
double fract = 1 - (Math.sqrt(x*x + y*y + z*z) / 0.7071067811865476);
int playerWatch = (int) Math.ceil(fract * 15);

if(playerWatch == 15 && player instanceof ServerPlayer sp)
EnderWatcherModule.watcherCenterTrigger.trigger(sp);

newWatch = Math.max(newWatch, playerWatch);
}
}
Expand Down

0 comments on commit 0ddeb18

Please sign in to comment.