Search in sources :

Example 26 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class FishingBobberEntityMixin method handleHookRetraction.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public int handleHookRetraction(ItemStack p_146034_1_) {
    if (!this.world.isRemote && this.angler != null) {
        int i = 0;
        ItemFishedEvent event = null;
        if (this.caughtEntity != null) {
            PlayerFishEvent fishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), ((EntityBridge) this.caughtEntity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
            Bukkit.getPluginManager().callEvent(fishEvent);
            if (fishEvent.isCancelled()) {
                return 0;
            }
            this.bringInHookedEntity();
            CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) this.angler, p_146034_1_, (FishingBobberEntity) (Object) this, Collections.emptyList());
            this.world.setEntityState((FishingBobberEntity) (Object) this, (byte) 31);
            i = this.caughtEntity instanceof ItemEntity ? 3 : 5;
        } else if (this.ticksCatchable > 0) {
            LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.world)).withParameter(LootParameters.POSITION, new BlockPos((FishingBobberEntity) (Object) this)).withParameter(LootParameters.TOOL, p_146034_1_).withRandom(this.rand).withLuck((float) this.luck + this.angler.getLuck());
            lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.angler).withParameter(LootParameters.THIS_ENTITY, (FishingBobberEntity) (Object) this);
            LootTable loottable = this.world.getServer().getLootTableManager().getLootTableFromLocation(LootTables.GAMEPLAY_FISHING);
            List<ItemStack> list = loottable.generate(lootcontext$builder.build(LootParameterSets.FISHING));
            event = new ItemFishedEvent(list, this.inGround ? 2 : 1, (FishingBobberEntity) (Object) this);
            MinecraftForge.EVENT_BUS.post(event);
            if (event.isCanceled()) {
                this.remove();
                return event.getRodDamage();
            }
            CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) this.angler, p_146034_1_, (FishingBobberEntity) (Object) this, list);
            for (ItemStack itemstack : list) {
                ItemEntity itementity = new ItemEntity(this.world, this.posX, this.posY, this.posZ, itemstack);
                PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), ((EntityBridge) itementity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
                playerFishEvent.setExpToDrop(this.rand.nextInt(6) + 1);
                Bukkit.getPluginManager().callEvent(playerFishEvent);
                if (playerFishEvent.isCancelled()) {
                    return 0;
                }
                double d0 = this.angler.posX - this.posX;
                double d1 = this.angler.posY - this.posY;
                double d2 = this.angler.posZ - this.posZ;
                double d3 = 0.1D;
                itementity.setMotion(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
                this.world.addEntity(itementity);
                if (playerFishEvent.getExpToDrop() > 0) {
                    this.angler.world.addEntity(new ExperienceOrbEntity(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, playerFishEvent.getExpToDrop()));
                }
                if (itemstack.getItem().isIn(ItemTags.FISHES)) {
                    this.angler.addStat(Stats.FISH_CAUGHT, 1);
                }
            }
            i = 1;
        }
        if (this.inGround) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
            Bukkit.getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            i = 2;
        }
        if (i == 0) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN);
            Bukkit.getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
        }
        this.remove();
        return event == null ? i : event.getRodDamage();
    } else {
        return 0;
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) FishingBobberEntity(net.minecraft.entity.projectile.FishingBobberEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) FishHook(org.bukkit.entity.FishHook) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) ItemFishedEvent(net.minecraftforge.event.entity.player.ItemFishedEvent) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 27 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class EntityMixin_1_15 method changeDimension.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite(remap = false)
@Nullable
public Entity changeDimension(DimensionType destination, ITeleporter teleporter) {
    BlockPos location = ((InternalEntityBridge) this).internal$capturedPos();
    if (!ForgeHooks.onTravelToDimension((Entity) (Object) this, destination))
        return null;
    if (!this.world.isRemote && !this.removed) {
        this.world.getProfiler().startSection("changeDimension");
        MinecraftServer minecraftserver = this.getServer();
        DimensionType dimensiontype = this.dimension;
        ServerWorld serverworld = minecraftserver.getWorld(dimensiontype);
        ServerWorld[] serverworld1 = new ServerWorld[] { minecraftserver.getWorld(destination) };
        if (serverworld1 == null) {
            return null;
        }
        // this.dimension = destination;
        // this.detach();
        this.world.getProfiler().startSection("reposition");
        Entity transportedEntity = teleporter.placeEntity((Entity) (Object) this, serverworld, serverworld1[0], this.rotationYaw, spawnPortal -> {
            // Forge: Start vanilla logic
            Vec3d vec3d = this.getMotion();
            float f = 0.0F;
            BlockPos blockpos = location;
            if (blockpos == null) {
                if (dimensiontype == DimensionType.THE_END && destination == DimensionType.OVERWORLD) {
                    EntityPortalEvent event = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], serverworld1[0].getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1[0].getSpawnPoint()), 0);
                    if (event == null) {
                        return null;
                    }
                    serverworld1[0] = ((CraftWorld) event.getTo().getWorld()).getHandle();
                    blockpos = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
                // blockpos = serverworld1[0].getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1[0].getSpawnPoint());
                } else if (destination == DimensionType.THE_END) {
                    EntityPortalEvent event = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], (serverworld1[0].getSpawnCoordinate() != null) ? serverworld1[0].getSpawnCoordinate() : serverworld1[0].getSpawnPoint(), 0);
                    if (event == null) {
                        return null;
                    }
                    serverworld1[0] = ((CraftWorld) event.getTo().getWorld()).getHandle();
                    blockpos = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
                // blockpos = serverworld1[0].getSpawnCoordinate();
                } else {
                    double movementFactor = serverworld.getDimension().getMovementFactor() / serverworld1[0].getDimension().getMovementFactor();
                    double d0 = this.getPosX() * movementFactor;
                    double d1 = this.getPosZ() * movementFactor;
                    double d3 = Math.min(-2.9999872E7D, serverworld1[0].getWorldBorder().minX() + 16.0D);
                    double d4 = Math.min(-2.9999872E7D, serverworld1[0].getWorldBorder().minZ() + 16.0D);
                    double d5 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxX() - 16.0D);
                    double d6 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxZ() - 16.0D);
                    d0 = MathHelper.clamp(d0, d3, d5);
                    d1 = MathHelper.clamp(d1, d4, d6);
                    Vec3d vec3d1 = this.getLastPortalVec();
                    blockpos = new BlockPos(d0, this.getPosY(), d1);
                    EntityPortalEvent event2 = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], blockpos, 128);
                    if (event2 == null) {
                        return null;
                    }
                    serverworld1[0] = ((CraftWorld) event2.getTo().getWorld()).getHandle();
                    blockpos = new BlockPos(event2.getTo().getX(), event2.getTo().getY(), event2.getTo().getZ());
                    int searchRadius = event2.getSearchRadius();
                    if (spawnPortal) {
                        BlockPattern.PortalInfo blockpattern$portalinfo = serverworld1[0].getDefaultTeleporter().placeInExistingPortal(blockpos, vec3d, this.getTeleportDirection(), vec3d1.x, vec3d1.y, (Object) this instanceof PlayerEntity);
                        if (blockpattern$portalinfo == null) {
                            return null;
                        }
                        blockpos = new BlockPos(blockpattern$portalinfo.pos);
                        vec3d = blockpattern$portalinfo.motion;
                        f = (float) blockpattern$portalinfo.rotation;
                    }
                }
            }
            this.dimension = destination;
            this.detach();
            this.world.getProfiler().endStartSection("reloading");
            Entity entity = this.getType().create(serverworld1[0]);
            if (entity != null) {
                entity.copyDataFromOld((Entity) (Object) this);
                entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw + f, entity.rotationPitch);
                entity.setMotion(vec3d);
                serverworld1[0].addFromAnotherDimension(entity);
                ((InternalEntityBridge) this).internal$getBukkitEntity().setHandle(entity);
                ((EntityBridge) entity).bridge$setBukkitEntity(((InternalEntityBridge) this).internal$getBukkitEntity());
                if ((Object) this instanceof MobEntity) {
                    ((MobEntity) (Object) this).clearLeashed(true, false);
                }
            }
            return entity;
        });
        // Forge: End vanilla logic
        this.remove(false);
        this.world.getProfiler().endSection();
        serverworld.resetUpdateEntityTick();
        serverworld1[0].resetUpdateEntityTick();
        this.world.getProfiler().endSection();
        return transportedEntity;
    } else {
        return null;
    }
}
Also used : MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) DimensionType(net.minecraft.world.dimension.DimensionType) EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) Vec3d(net.minecraft.util.math.Vec3d) MinecraftServer(net.minecraft.server.MinecraftServer) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite) Nullable(javax.annotation.Nullable)

Example 28 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class FollowOwnerGoalMixin_1_15 method arclight$teleport.

@Redirect(method = "tryToTeleportToLocation", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/TameableEntity;setLocationAndAngles(DDDFF)V"))
public void arclight$teleport(TameableEntity tameableEntity, double x, double y, double z, float yaw, float pitch) {
    CraftEntity craftEntity = ((EntityBridge) this.tameable).bridge$getBukkitEntity();
    Location location = new Location(craftEntity.getWorld(), x, y, z, yaw, pitch);
    EntityTeleportEvent event = new EntityTeleportEvent(craftEntity, craftEntity.getLocation(), location);
    Bukkit.getPluginManager().callEvent(event);
    if (!(arclight$cancelled = event.isCancelled())) {
        tameableEntity.setLocationAndAngles(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Location(org.bukkit.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 29 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class PlayerListMixin method recreatePlayerEntity.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ServerPlayerEntity recreatePlayerEntity(ServerPlayerEntity playerIn, DimensionType dimension, boolean conqueredEnd) {
    Location location = arclight$loc;
    arclight$loc = null;
    boolean avoidSuffocation = arclight$suffo == null ? true : arclight$suffo;
    arclight$suffo = null;
    playerIn.stopRiding();
    org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
    ServerWorld world = server.getWorld(dimension);
    if (world == null)
        dimension = playerIn.getSpawnDimension();
    else if (!world.getDimension().canRespawnHere())
        dimension = world.getDimension().getRespawnDimension(playerIn);
    if (server.getWorld(dimension) == null)
        dimension = DimensionType.OVERWORLD;
    this.removePlayer(playerIn);
    // Forge: keep data until copyFrom called
    playerIn.getServerWorld().removePlayer(playerIn, true);
    BlockPos blockpos = playerIn.getBedLocation(dimension);
    boolean flag = playerIn.isSpawnForced(dimension);
    // playerIn.dimension = dimension;
    PlayerInteractionManager playerinteractionmanager;
    if (this.server.isDemo()) {
        playerinteractionmanager = new DemoPlayerInteractionManager(this.server.getWorld(playerIn.dimension));
    } else {
        playerinteractionmanager = new PlayerInteractionManager(this.server.getWorld(playerIn.dimension));
    }
    playerIn.queuedEndExit = false;
    if (location == null) {
        boolean isBedSpawn = false;
        CraftWorld cworld = (CraftWorld) Bukkit.getWorld(((PlayerEntityBridge) playerIn).bridge$getSpawnWorld());
        if (cworld != null && blockpos != null) {
            Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), blockpos, flag);
            if (optional.isPresent()) {
                Vec3d vec3d = optional.get();
                isBedSpawn = true;
                location = new Location(cworld, vec3d.x, vec3d.y, vec3d.z);
            } else {
                this.bridge$setSpawnPoint(playerIn, null, true, playerIn.dimension, false);
                playerIn.connection.sendPacket(new SChangeGameStatePacket(0, 0.0f));
            }
        }
        if (location == null) {
            cworld = (CraftWorld) Bukkit.getWorlds().get(0);
            blockpos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
            location = new Location(cworld, blockpos.getX() + 0.5f, blockpos.getY() + 0.1f, blockpos.getZ() + 0.5f);
        }
        Player respawnPlayer = this.cserver.getPlayer(playerIn);
        PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
        this.cserver.getPluginManager().callEvent(respawnEvent);
        if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
            return playerIn;
        }
        location = respawnEvent.getRespawnLocation();
        if (location.getWorld() == null) {
            location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
        }
        dimension = ((CraftWorld) location.getWorld()).getHandle().dimension.getType();
        if (!flag) {
            ((ServerPlayerEntityBridge) playerIn).bridge$reset();
        }
    } else {
        location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
    }
    playerIn.dimension = dimension;
    ServerPlayerEntity serverplayerentity = new ServerPlayerEntity(this.server, this.server.getWorld(playerIn.dimension), playerIn.getGameProfile(), playerinteractionmanager);
    // Forward to new player instance
    ((InternalEntityBridge) playerIn).internal$getBukkitEntity().setHandle(serverplayerentity);
    ((EntityBridge) serverplayerentity).bridge$setBukkitEntity(((InternalEntityBridge) playerIn).internal$getBukkitEntity());
    if ((Object) serverplayerentity instanceof MobEntity) {
        ((MobEntity) (Object) serverplayerentity).clearLeashed(true, false);
    }
    serverplayerentity.connection = playerIn.connection;
    serverplayerentity.copyFrom(playerIn, conqueredEnd);
    // Forge: clone event had a chance to see old data, now discard it
    playerIn.remove(false);
    serverplayerentity.dimension = dimension;
    serverplayerentity.setEntityId(playerIn.getEntityId());
    serverplayerentity.setPrimaryHand(playerIn.getPrimaryHand());
    for (String s : playerIn.getTags()) {
        serverplayerentity.addTag(s);
    }
    ServerWorld serverworld = ((CraftWorld) location.getWorld()).getHandle();
    serverplayerentity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    serverplayerentity.connection.captureCurrentPosition();
    this.setPlayerGameTypeBasedOnOther(serverplayerentity, playerIn, serverworld);
    while (avoidSuffocation && !this.bridge$worldNoCollision(serverworld, serverplayerentity) && serverplayerentity.posY < 256.0D) {
        serverplayerentity.setPosition(serverplayerentity.posX, serverplayerentity.posY + 1.0D, serverplayerentity.posZ);
    }
    if (fromWorld.getEnvironment() == ((WorldBridge) serverworld).bridge$getWorld().getEnvironment()) {
        serverplayerentity.connection.sendPacket(this.bridge$respawnPacket((((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverworld.getWorldInfo().getSeed(), serverworld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
    }
    WorldInfo worldinfo = serverplayerentity.world.getWorldInfo();
    NetworkHooks.sendDimensionDataPacket(serverplayerentity.connection.netManager, serverplayerentity);
    serverplayerentity.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType(), worldinfo.getSeed(), worldinfo.getGenerator(), serverplayerentity.interactionManager.getGameType()));
    serverplayerentity.connection.sendPacket(new SUpdateViewDistancePacket(((WorldBridge) serverworld).bridge$spigotConfig().viewDistance));
    BlockPos blockpos1 = serverworld.getSpawnPoint();
    serverplayerentity.connection.setPlayerLocation(serverplayerentity.posX, serverplayerentity.posY, serverplayerentity.posZ, serverplayerentity.rotationYaw, serverplayerentity.rotationPitch);
    serverplayerentity.connection.sendPacket(new SSpawnPositionPacket(blockpos1));
    serverplayerentity.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
    serverplayerentity.connection.sendPacket(new SSetExperiencePacket(serverplayerentity.experience, serverplayerentity.experienceTotal, serverplayerentity.experienceLevel));
    this.sendWorldInfo(serverplayerentity, serverworld);
    this.updatePermissionLevel(serverplayerentity);
    if (!((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$isDisconnected()) {
        serverworld.addRespawnedPlayer(serverplayerentity);
        this.addPlayer(serverplayerentity);
        this.uuidToPlayerMap.put(serverplayerentity.getUniqueID(), serverplayerentity);
    }
    serverplayerentity.addSelfToInternalCraftingInventory();
    serverplayerentity.setHealth(serverplayerentity.getHealth());
    this.sendInventory(serverplayerentity);
    serverplayerentity.sendPlayerAbilities();
    serverplayerentity.func_213846_b(((CraftWorld) fromWorld).getHandle());
    if (fromWorld != location.getWorld()) {
        PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
        Bukkit.getPluginManager().callEvent(event);
    }
    BasicEventHooks.firePlayerRespawnEvent(serverplayerentity, conqueredEnd);
    System.out.println("pos " + serverplayerentity.getBedLocation());
    return serverplayerentity;
}
Also used : DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ServerWorldBridge(io.izzel.arclight.common.bridge.world.server.ServerWorldBridge) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) SSetExperiencePacket(net.minecraft.network.play.server.SSetExperiencePacket) Player(org.bukkit.entity.Player) SUpdateViewDistancePacket(net.minecraft.network.play.server.SUpdateViewDistancePacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) PlayerInteractionManager(net.minecraft.server.management.PlayerInteractionManager) DemoPlayerInteractionManager(net.minecraft.server.management.DemoPlayerInteractionManager) DemoPlayerInteractionManager(net.minecraft.server.management.DemoPlayerInteractionManager) MobEntity(net.minecraft.entity.MobEntity) SSpawnPositionPacket(net.minecraft.network.play.server.SSpawnPositionPacket) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 30 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge 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)39 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)15 Overwrite (org.spongepowered.asm.mixin.Overwrite)15 Entity (net.minecraft.entity.Entity)13 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 Inject (org.spongepowered.asm.mixin.injection.Inject)10 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)9 LivingEntity (net.minecraft.entity.LivingEntity)9 MobEntity (net.minecraft.entity.MobEntity)9 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)9 BlockPos (net.minecraft.util.math.BlockPos)8 Redirect (org.spongepowered.asm.mixin.injection.Redirect)8 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)7 Location (org.bukkit.Location)7 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)6 Vec3d (net.minecraft.util.math.Vec3d)6 EntityCombustByEntityEvent (org.bukkit.event.entity.EntityCombustByEntityEvent)6 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)5 CraftEntity (org.bukkit.craftbukkit.v.entity.CraftEntity)5 Player (org.bukkit.entity.Player)5