Search in sources :

Example 1 with SSpawnMobPacket

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()));
        }
    }
}
Also used : SEntityPropertiesPacket(net.minecraft.network.play.server.SEntityPropertiesPacket) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) SEntityHeadLookPacket(net.minecraft.network.play.server.SEntityHeadLookPacket) SSetPassengersPacket(net.minecraft.network.play.server.SSetPassengersPacket) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) SMountEntityPacket(net.minecraft.network.play.server.SMountEntityPacket) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) SEntityEquipmentPacket(net.minecraft.network.play.server.SEntityEquipmentPacket) SSpawnMobPacket(net.minecraft.network.play.server.SSpawnMobPacket) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) AttributeMap(net.minecraft.entity.ai.attributes.AttributeMap) SEntityMetadataPacket(net.minecraft.network.play.server.SEntityMetadataPacket) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) MobEntity(net.minecraft.entity.MobEntity)

Example 2 with SSpawnMobPacket

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);
                }
            }
        }
    }
}
Also used : SignTileEntity(net.minecraft.tileentity.SignTileEntity) LivingEntity(net.minecraft.entity.LivingEntity) TileEntity(net.minecraft.tileentity.TileEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.item.ItemEntity) ActionResultType(net.minecraft.util.ActionResultType) SMountEntityPacket(net.minecraft.network.play.server.SMountEntityPacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) SSpawnMobPacket(net.minecraft.network.play.server.SSpawnMobPacket) ServerWorld(net.minecraft.world.server.ServerWorld) LivingEntity(net.minecraft.entity.LivingEntity) WritableBookItem(net.minecraft.item.WritableBookItem) Item(net.minecraft.item.Item) PlayerInteractAtEntityEvent(org.bukkit.event.player.PlayerInteractAtEntityEvent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) SignTileEntityBridge(io.izzel.arclight.common.bridge.tileentity.SignTileEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Vector(org.bukkit.util.Vector) PlayerInteractEntityEvent(org.bukkit.event.player.PlayerInteractEntityEvent) ItemEntity(net.minecraft.entity.item.ItemEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Hand(net.minecraft.util.Hand) Vec3d(net.minecraft.util.math.Vec3d) SEntityMetadataPacket(net.minecraft.network.play.server.SEntityMetadataPacket) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) MobEntity(net.minecraft.entity.MobEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

LivingEntity (net.minecraft.entity.LivingEntity)2 MobEntity (net.minecraft.entity.MobEntity)2 ItemStack (net.minecraft.item.ItemStack)2 SEntityMetadataPacket (net.minecraft.network.play.server.SEntityMetadataPacket)2 SMountEntityPacket (net.minecraft.network.play.server.SMountEntityPacket)2 SSpawnMobPacket (net.minecraft.network.play.server.SSpawnMobPacket)2 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)1 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)1 SignTileEntityBridge (io.izzel.arclight.common.bridge.tileentity.SignTileEntityBridge)1 Entity (net.minecraft.entity.Entity)1 AttributeMap (net.minecraft.entity.ai.attributes.AttributeMap)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1 ExperienceOrbEntity (net.minecraft.entity.item.ExperienceOrbEntity)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 AbstractFishEntity (net.minecraft.entity.passive.fish.AbstractFishEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 EquipmentSlotType (net.minecraft.inventory.EquipmentSlotType)1 Item (net.minecraft.item.Item)1 WritableBookItem (net.minecraft.item.WritableBookItem)1