Search in sources :

Example 1 with AbstractFishEntity

use of net.minecraft.entity.passive.fish.AbstractFishEntity 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

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 LivingEntity (net.minecraft.entity.LivingEntity)1 MobEntity (net.minecraft.entity.MobEntity)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 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 WritableBookItem (net.minecraft.item.WritableBookItem)1 SEntityMetadataPacket (net.minecraft.network.play.server.SEntityMetadataPacket)1 SMountEntityPacket (net.minecraft.network.play.server.SMountEntityPacket)1 SSpawnMobPacket (net.minecraft.network.play.server.SSpawnMobPacket)1 SignTileEntity (net.minecraft.tileentity.SignTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ActionResultType (net.minecraft.util.ActionResultType)1