use of net.minecraft.server.level.ServerPlayer in project MyPet by xXKeyleXx.
the class ControlTarget method shouldStart.
@Override
public boolean shouldStart() {
if (controlPathfinderGoal == null) {
if (petEntity.getPathfinder().hasGoal("Control")) {
controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
}
}
if (controlPathfinderGoal == null) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
}
for (net.minecraft.world.entity.LivingEntity entityLiving : this.petEntity.level.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, this.petEntity.getBoundingBox().inflate(this.range, 4.0D, this.range))) {
if (entityLiving != petEntity && !(entityLiving instanceof ArmorStand)) {
if (entityLiving instanceof ServerPlayer) {
Player targetPlayer = (Player) entityLiving.getBukkitEntity();
if (myPet.getOwner().equals(targetPlayer)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
continue;
}
} else if (entityLiving instanceof TamableAnimal) {
TamableAnimal tameable = (TamableAnimal) entityLiving;
if (tameable.isTame() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
continue;
}
}
} else if (entityLiving instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
continue;
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
continue;
}
if (behaviorSkill != null) {
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (entityLiving instanceof TamableAnimal) {
continue;
} else if (entityLiving instanceof EntityMyPet) {
continue;
} else if (entityLiving instanceof ServerPlayer) {
continue;
}
}
}
controlPathfinderGoal.stopControl();
this.target = entityLiving;
return true;
}
}
}
return false;
}
use of net.minecraft.server.level.ServerPlayer in project MyPet by xXKeyleXx.
the class OwnerHurtByTarget method shouldStart.
@Override
public boolean shouldStart() {
if (!petEntity.canMove()) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
this.lastDamager = owner.getLastHurtByMob();
if (this.lastDamager == null || !lastDamager.isAlive()) {
return false;
}
if (lastDamager instanceof ArmorStand) {
return false;
}
if (lastDamager == petEntity) {
return false;
}
if (lastDamager instanceof ServerPlayer) {
if (owner == lastDamager) {
return false;
}
Player targetPlayer = (Player) lastDamager.getBukkitEntity();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
return false;
}
} else if (lastDamager instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) lastDamager).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
return false;
}
} else if (lastDamager instanceof TamableAnimal) {
TamableAnimal tameable = (TamableAnimal) lastDamager;
if (tameable.isTame() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
return false;
}
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), lastDamager.getBukkitEntity())) {
return false;
}
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill != null && behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (lastDamager instanceof TamableAnimal && ((TamableAnimal) lastDamager).isTame()) {
return false;
}
if (lastDamager instanceof EntityMyPet) {
return false;
}
return !(lastDamager instanceof ServerPlayer);
}
}
return true;
}
use of net.minecraft.server.level.ServerPlayer in project MyPet by xXKeyleXx.
the class CustomInventory method open.
@Override
public void open(Player player) {
ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
if (container != null) {
MenuType<?> customSize = MenuType.GENERIC_9x1;
switch(this.getContainerSize()) {
case 18:
customSize = MenuType.GENERIC_9x2;
break;
case 27:
customSize = MenuType.GENERIC_9x3;
break;
case 36:
customSize = MenuType.GENERIC_9x4;
break;
case 45:
customSize = MenuType.GENERIC_9x5;
break;
case 54:
customSize = MenuType.GENERIC_9x6;
break;
}
entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
entityPlayer.containerMenu = container;
entityPlayer.initMenu(container);
}
}
use of net.minecraft.server.level.ServerPlayer in project SpongeCommon by SpongePowered.
the class EntityMixin method impl$updateVanishState.
@SuppressWarnings({ "ConstantConditions", "RedundantCast" })
@Inject(method = "tick", at = @At("RETURN"))
private void impl$updateVanishState(final CallbackInfo callbackInfo) {
if (this.impl$pendingVisibilityUpdate && !this.level.isClientSide) {
final ChunkMap_TrackedEntityAccessor trackerAccessor = ((ChunkMapAccessor) ((ServerWorld) this.level).chunkManager()).accessor$entityMap().get(this.shadow$getId());
if (trackerAccessor != null && this.impl$visibilityTicks % 4 == 0) {
if (this.bridge$vanishState().invisible()) {
for (final ServerPlayer entityPlayerMP : trackerAccessor.accessor$seenBy()) {
entityPlayerMP.connection.send(new ClientboundRemoveEntitiesPacket(this.shadow$getId()));
if ((Entity) (Object) this instanceof ServerPlayer) {
entityPlayerMP.connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, (ServerPlayer) (Object) this));
}
}
} else {
this.impl$visibilityTicks = 1;
this.impl$pendingVisibilityUpdate = false;
for (final ServerPlayer entityPlayerMP : SpongeCommon.server().getPlayerList().getPlayers()) {
if ((Entity) (Object) this == entityPlayerMP) {
continue;
}
if ((Entity) (Object) this instanceof ServerPlayer) {
final Packet<?> packet = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, (ServerPlayer) (Object) this);
entityPlayerMP.connection.send(packet);
}
trackerAccessor.accessor$updatePlayer(entityPlayerMP);
}
}
}
if (this.impl$visibilityTicks > 0) {
this.impl$visibilityTicks--;
} else {
this.impl$pendingVisibilityUpdate = false;
}
}
}
use of net.minecraft.server.level.ServerPlayer in project SpongeCommon by SpongePowered.
the class IndirectEntityDamageSourceMixin method onConstruct.
@Inject(method = "<init>", at = @At("RETURN"))
private void onConstruct(final CallbackInfo callbackInfo) {
if (this.entity != null) {
// sources can be null
final Entity mcEntity = this.shadow$getEntity();
this.impl$creatorUUID = mcEntity instanceof CreatorTrackedBridge ? ((CreatorTrackedBridge) mcEntity).tracker$getCreatorUUID().orElse(null) : null;
if (this.owner == null && this.impl$creatorUUID != null) {
final ServerPlayer player = SpongeCommon.server().getPlayerList().getPlayer(this.impl$creatorUUID);
if (player != null) {
this.owner = player;
}
}
}
}
Aggregations