use of net.minecraft.network.play.server.SSpawnMobPacket in project Arclight by IzzelAliz.
the class TrackedEntityMixin method a.
public void a(final Consumer<IPacket<?>> consumer, final ServerPlayerEntity entityplayer) {
if (this.trackedEntity.removed) {
return;
}
final IPacket<?> packet = this.trackedEntity.createSpawnPacket();
this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
consumer.accept(packet);
if (!this.trackedEntity.getDataManager().isEmpty()) {
consumer.accept(new SEntityMetadataPacket(this.trackedEntity.getEntityId(), this.trackedEntity.getDataManager(), true));
}
boolean flag = this.sendVelocityUpdates;
if (this.trackedEntity instanceof LivingEntity) {
final AttributeMap attributemapserver = (AttributeMap) ((LivingEntity) this.trackedEntity).getAttributes();
final Collection<IAttributeInstance> collection = attributemapserver.getWatchedAttributes();
if (this.trackedEntity.getEntityId() == entityplayer.getEntityId()) {
((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false);
}
if (!collection.isEmpty()) {
consumer.accept(new SEntityPropertiesPacket(this.trackedEntity.getEntityId(), collection));
}
if (((LivingEntity) this.trackedEntity).isElytraFlying()) {
flag = true;
}
}
this.velocity = this.trackedEntity.getMotion();
if (flag && !(packet instanceof SSpawnMobPacket)) {
consumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
}
if (this.trackedEntity instanceof LivingEntity) {
for (final EquipmentSlotType enumitemslot : EquipmentSlotType.values()) {
final ItemStack itemstack = ((LivingEntity) this.trackedEntity).getItemStackFromSlot(enumitemslot);
if (!itemstack.isEmpty()) {
consumer.accept(new SEntityEquipmentPacket(this.trackedEntity.getEntityId(), enumitemslot, itemstack));
}
}
}
this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
consumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) this.encodedRotationYawHead));
if (this.trackedEntity instanceof LivingEntity) {
final LivingEntity entityliving = (LivingEntity) this.trackedEntity;
for (final EffectInstance mobeffect : entityliving.getActivePotionEffects()) {
consumer.accept(new SPlayEntityEffectPacket(this.trackedEntity.getEntityId(), mobeffect));
}
}
if (!this.trackedEntity.getPassengers().isEmpty()) {
consumer.accept(new SSetPassengersPacket(this.trackedEntity));
}
if (this.trackedEntity.isPassenger()) {
consumer.accept(new SSetPassengersPacket(this.trackedEntity.getRidingEntity()));
}
if (this.trackedEntity instanceof MobEntity) {
MobEntity mobentity = (MobEntity) this.trackedEntity;
if (mobentity.getLeashed()) {
consumer.accept(new SMountEntityPacket(mobentity, mobentity.getLeashHolder()));
}
}
}
use of net.minecraft.network.play.server.SSpawnMobPacket in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method processUseEntity.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void processUseEntity(final CUseEntityPacket packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
return;
}
final ServerWorld world = this.minecraftServer.getWorld(this.player.dimension);
final Entity entity = packetIn.getEntityFromWorld(world);
this.player.markPlayerActive();
if (entity != null) {
final boolean flag = this.player.canEntityBeSeen(entity);
double d0 = 36.0;
if (!flag) {
d0 = 9.0;
}
if (this.player.getDistanceSq(entity) < d0) {
final ItemStack itemInHand = this.player.getHeldItem((packetIn.getHand() == null) ? Hand.MAIN_HAND : packetIn.getHand());
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT || packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof MobEntity;
final Item origItem = (this.player.inventory.getCurrentItem() == null) ? null : this.player.inventory.getCurrentItem().getItem();
PlayerInteractEntityEvent event;
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
event = new PlayerInteractEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
} else {
final Vec3d target = packetIn.getHitVec();
event = new PlayerInteractAtEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), new Vector(target.x, target.y, target.z), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
}
this.server.getPluginManager().callEvent(event);
if (entity instanceof AbstractFishEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SSpawnMobPacket((LivingEntity) entity));
this.player.sendContainerToPlayer(this.player.openContainer);
}
if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
this.sendPacket(new SMountEntityPacket(entity, ((MobEntity) entity).getLeashHolder()));
}
if (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem) {
this.sendPacket(new SEntityMetadataPacket(entity.getEntityId(), entity.getDataManager(), true));
}
if (event.isCancelled()) {
return;
}
}
if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
final Hand hand = packetIn.getHand();
this.player.interactOn(entity, hand);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
final Hand hand = packetIn.getHand();
if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, packetIn.getHitVec(), hand) != null)
return;
ActionResultType result = entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand);
if (result == ActionResultType.SUCCESS) {
this.player.swingArm(hand);
}
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
} else if (packetIn.getAction() == CUseEntityPacket.Action.ATTACK) {
if (entity instanceof ItemEntity || entity instanceof ExperienceOrbEntity || entity instanceof AbstractArrowEntity || (entity == this.player && !this.player.isSpectator())) {
this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_entity_attacked"));
this.minecraftServer.logWarning("Player " + this.player.getName().getString() + " tried to attack an invalid entity");
return;
}
this.player.attackTargetEntityWithCurrentItem(entity);
if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
}
}
}
}
Aggregations