Search in sources :

Example 1 with BlockStateListPopulator

use of org.bukkit.craftbukkit.v.util.BlockStateListPopulator in project Arclight by IzzelAliz.

the class SpongeBlockMixin method absorb.

/**
 * @author IzzelAliz
 * @reason
 */
@SuppressWarnings("unchecked")
@Overwrite
private boolean absorb(World worldIn, BlockPos pos) {
    Queue<Tuple<BlockPos, Integer>> queue = Lists.newLinkedList();
    queue.add(new Tuple<>(pos, 0));
    int i = 0;
    BlockStateListPopulator blockList = new BlockStateListPopulator(worldIn);
    while (!queue.isEmpty()) {
        Tuple<BlockPos, Integer> tuple = queue.poll();
        BlockPos blockpos = tuple.getA();
        int j = tuple.getB();
        for (Direction direction : Direction.values()) {
            BlockPos blockpos1 = blockpos.offset(direction);
            BlockState blockstate = blockList.getBlockState(blockpos1);
            IFluidState ifluidstate = blockList.getFluidState(blockpos1);
            Material material = blockstate.getMaterial();
            if (ifluidstate.isTagged(FluidTags.WATER)) {
                if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) {
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (blockstate.getBlock() instanceof FlowingFluidBlock) {
                    worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    // TileEntity tileentity = blockstate.getBlock().hasTileEntity() ? worldIn.getTileEntity(blockpos1) : null;
                    // Block.spawnDrops(blockstate, worldIn, blockpos1, tileentity);
                    blockList.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                }
            }
        }
        if (i > 64) {
            break;
        }
    }
    // Is a clone
    List<CraftBlockState> blocks = blockList.getList();
    if (!blocks.isEmpty()) {
        final org.bukkit.block.Block bblock = CraftBlock.at(worldIn, pos);
        SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List<org.bukkit.block.BlockState>) (List) blocks);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        for (CraftBlockState block : blocks) {
            BlockPos blockposition2 = block.getPosition();
            BlockState iblockdata = worldIn.getBlockState(blockposition2);
            IFluidState fluid = worldIn.getFluidState(blockposition2);
            Material material = iblockdata.getMaterial();
            if (fluid.isTagged(FluidTags.WATER)) {
                if (iblockdata.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) iblockdata.getBlock()).pickupFluid(blockList, blockposition2, iblockdata) != Fluids.EMPTY) {
                // NOP
                } else if (iblockdata.getBlock() instanceof FlowingFluidBlock) {
                // NOP
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    TileEntity tileentity = iblockdata.getBlock().hasTileEntity(iblockdata) ? worldIn.getTileEntity(blockposition2) : null;
                    Block.spawnDrops(iblockdata, worldIn, blockposition2, tileentity);
                }
            }
            worldIn.setBlockState(blockposition2, block.getHandle(), block.getFlag());
        }
    }
    return i > 0;
}
Also used : IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) SpongeAbsorbEvent(org.bukkit.event.block.SpongeAbsorbEvent) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Material(net.minecraft.block.material.Material) Direction(net.minecraft.util.Direction) TileEntity(net.minecraft.tileentity.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) Tuple(net.minecraft.util.Tuple) IFluidState(net.minecraft.fluid.IFluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with BlockStateListPopulator

use of org.bukkit.craftbukkit.v.util.BlockStateListPopulator in project Arclight by IzzelAliz.

the class ServerPlayerEntityMixin_1_14 method changeDimension.

/**
 * @author IzzelAliz
 * @reason
 */
@Nullable
@Overwrite
public Entity changeDimension(DimensionType dimensionmanager) {
    PlayerTeleportEvent.TeleportCause cause = bridge$getTeleportCause().orElse(PlayerTeleportEvent.TeleportCause.UNKNOWN);
    if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension((ServerPlayerEntity) (Object) this, dimensionmanager))
        return null;
    if (this.isSleeping()) {
        return (ServerPlayerEntity) (Object) this;
    }
    DimensionType dimensionmanager2 = this.dimension;
    if (((DimensionTypeBridge) dimensionmanager2).bridge$getType() == DimensionType.THE_END && ((DimensionTypeBridge) dimensionmanager).bridge$getType() == DimensionType.OVERWORLD) {
        this.invulnerableDimensionChange = true;
        this.detach();
        this.func_71121_q().removePlayer((ServerPlayerEntity) (Object) this, true);
        if (!this.queuedEndExit) {
            this.queuedEndExit = true;
            this.connection.sendPacket(new SChangeGameStatePacket(4, this.seenCredits ? 0.0f : 1.0f));
            this.seenCredits = true;
        }
        return (ServerPlayerEntity) (Object) this;
    }
    ServerWorld worldserver = this.server.func_71218_a(dimensionmanager2);
    ServerWorld worldserver2 = this.server.func_71218_a(dimensionmanager);
    WorldInfo worlddata = this.world.getWorldInfo();
    double d0 = this.posX;
    double d2 = this.posY;
    double d3 = this.posZ;
    float f = this.rotationPitch;
    float f2 = this.rotationYaw;
    double d4 = 8.0;
    float f3 = f2;
    worldserver.getProfiler().startSection("moving");
    if (worldserver2 != null) {
        if (dimensionmanager2 == DimensionType.OVERWORLD && dimensionmanager == DimensionType.THE_NETHER) {
            this.enteredNetherPosition = new Vec3d(this.posX, this.posY, this.posZ);
            d0 /= 8.0;
            d3 /= 8.0;
        } else if (dimensionmanager2 == DimensionType.THE_NETHER && dimensionmanager == DimensionType.OVERWORLD) {
            d0 *= 8.0;
            d3 *= 8.0;
        } else if (dimensionmanager2 == DimensionType.OVERWORLD && dimensionmanager == DimensionType.THE_END) {
            BlockPos blockposition = worldserver2.getSpawnCoordinate();
            d0 = blockposition.getX();
            d2 = blockposition.getY();
            d3 = blockposition.getZ();
            f2 = 90.0f;
            f = 0.0f;
        }
    }
    Location enter = this.bridge$getBukkitEntity().getLocation();
    Location exit = (worldserver2 == null) ? null : new Location(((WorldBridge) worldserver2).bridge$getWorld(), d0, d2, d3, f2, f);
    PlayerPortalEvent event = new PlayerPortalEvent((Player) this.bridge$getBukkitEntity(), enter, exit, cause);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled() || event.getTo() == null) {
        return null;
    }
    exit = event.getTo();
    if (exit == null) {
        return null;
    }
    PlayerTeleportEvent tpEvent = new PlayerTeleportEvent((Player) this.bridge$getBukkitEntity(), enter, exit, cause);
    Bukkit.getServer().getPluginManager().callEvent(tpEvent);
    if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
        return null;
    }
    exit = tpEvent.getTo();
    if (exit == null) {
        return null;
    }
    worldserver2 = ((CraftWorld) exit.getWorld()).getHandle();
    d0 = exit.getX();
    d2 = exit.getY();
    d3 = exit.getZ();
    f2 = exit.getYaw();
    f = exit.getPitch();
    this.invulnerableDimensionChange = true;
    dimensionmanager = worldserver2.getDimension().getType();
    this.dimension = dimensionmanager;
    net.minecraftforge.fml.network.NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
    this.connection.sendPacket(new SRespawnPacket(worldserver2.dimension.getType(), this.world.getWorldInfo().getGenerator(), this.interactionManager.getGameType()));
    this.connection.sendPacket(new SServerDifficultyPacket(this.world.getDifficulty(), this.world.getWorldInfo().isDifficultyLocked()));
    PlayerList playerlist = this.server.getPlayerList();
    playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this);
    worldserver.removePlayer((ServerPlayerEntity) (Object) this, true);
    this.removed = false;
    this.setLocationAndAngles(d0, d2, d3, f2, f);
    worldserver.getProfiler().endSection();
    worldserver.getProfiler().startSection("placing");
    double d5 = Math.min(-2.9999872E7, worldserver2.getWorldBorder().minX() + 16.0);
    double d6 = Math.min(-2.9999872E7, worldserver2.getWorldBorder().minZ() + 16.0);
    double d7 = Math.min(2.9999872E7, worldserver2.getWorldBorder().maxX() - 16.0);
    double d8 = Math.min(2.9999872E7, worldserver2.getWorldBorder().maxZ() - 16.0);
    d0 = MathHelper.clamp(d0, d5, d7);
    d3 = MathHelper.clamp(d3, d6, d8);
    this.setLocationAndAngles(d0, d2, d3, f2, f);
    if (((DimensionTypeBridge) dimensionmanager).bridge$getType() == DimensionType.THE_END) {
        int i = MathHelper.floor(this.posX);
        int j = MathHelper.floor(this.posY) - 1;
        int k = MathHelper.floor(this.posZ);
        boolean flag = true;
        boolean flag2 = false;
        BlockStateListPopulator blockList = new BlockStateListPopulator(worldserver2);
        for (int l = -2; l <= 2; ++l) {
            for (int i2 = -2; i2 <= 2; ++i2) {
                for (int j2 = -1; j2 < 3; ++j2) {
                    int k2 = i + i2 * 1 + l * 0;
                    int l2 = j + j2;
                    int i3 = k + i2 * 0 - l * 1;
                    boolean flag3 = j2 < 0;
                    blockList.setBlockState(new BlockPos(k2, l2, i3), flag3 ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
                }
            }
        }
        org.bukkit.World bworld = ((WorldBridge) worldserver2).bridge$getWorld();
        PortalCreateEvent portalEvent = new PortalCreateEvent((List) blockList.getList(), bworld, this.bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.END_PLATFORM);
        Bukkit.getPluginManager().callEvent(portalEvent);
        if (!portalEvent.isCancelled()) {
            blockList.updateList();
        }
        this.setLocationAndAngles(i, j, k, f2, 0.0f);
        this.setMotion(Vec3d.ZERO);
    } else if (!worldserver2.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f3)) {
        worldserver2.getDefaultTeleporter().makePortal((ServerPlayerEntity) (Object) this);
        worldserver2.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f3);
    }
    worldserver.getProfiler().endSection();
    this.setWorld(worldserver2);
    worldserver2.func_217447_b((ServerPlayerEntity) (Object) this);
    this.func_213846_b(worldserver);
    this.connection.setPlayerLocation(this.posX, this.posY, this.posZ, f2, f);
    this.interactionManager.func_73080_a(worldserver2);
    this.connection.sendPacket(new SPlayerAbilitiesPacket(this.abilities));
    playerlist.func_72354_b((ServerPlayerEntity) (Object) this, worldserver2);
    playerlist.sendInventory((ServerPlayerEntity) (Object) this);
    for (EffectInstance mobeffect : this.getActivePotionEffects()) {
        this.connection.sendPacket(new SPlayEntityEffectPacket(this.getEntityId(), mobeffect));
    }
    this.connection.sendPacket(new SPlaySoundEventPacket(1032, BlockPos.ZERO, 0, false));
    this.lastExperience = -1;
    this.lastHealth = -1.0f;
    this.lastFoodLevel = -1;
    PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent((Player) this.bridge$getBukkitEntity(), ((WorldBridge) worldserver).bridge$getWorld());
    Bukkit.getPluginManager().callEvent(changeEvent);
    net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, dimensionmanager2, dimensionmanager);
    return (ServerPlayerEntity) (Object) this;
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) PlayerList(net.minecraft.server.management.PlayerList) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) SPlaySoundEventPacket(net.minecraft.network.play.server.SPlaySoundEventPacket) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) SPlayerAbilitiesPacket(net.minecraft.network.play.server.SPlayerAbilitiesPacket) SRespawnPacket(net.minecraft.network.play.server.SRespawnPacket) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) EffectInstance(net.minecraft.potion.EffectInstance) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite) Nullable(javax.annotation.Nullable)

Example 3 with BlockStateListPopulator

use of org.bukkit.craftbukkit.v.util.BlockStateListPopulator in project Arclight by IzzelAliz.

the class ServerPlayerEntityMixin_1_15 method changeDimension.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite(remap = false)
@Nullable
public Entity changeDimension(DimensionType dim, ITeleporter teleporter) {
    DimensionType[] destination = { dim };
    if (this.isSleeping())
        return (ServerPlayerEntity) (Object) this;
    if (!ForgeHooks.onTravelToDimension((ServerPlayerEntity) (Object) this, destination[0]))
        return null;
    PlayerTeleportEvent.TeleportCause cause = bridge$getTeleportCause().orElse(PlayerTeleportEvent.TeleportCause.UNKNOWN);
    // this.invulnerableDimensionChange = true;
    DimensionType dimensiontype = this.dimension;
    if (((DimensionTypeBridge) dimensiontype).bridge$getType() == DimensionType.THE_END && ((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.OVERWORLD && teleporter instanceof Teleporter) {
        // Forge: Fix non-vanilla teleporters triggering end credits
        this.invulnerableDimensionChange = true;
        this.detach();
        // Forge: The player entity is cloned so keep the data until after cloning calls copyFrom
        this.getServerWorld().removePlayer((ServerPlayerEntity) (Object) this, true);
        if (!this.queuedEndExit) {
            this.queuedEndExit = true;
            this.connection.sendPacket(new SChangeGameStatePacket(4, this.seenCredits ? 0.0F : 1.0F));
            this.seenCredits = true;
        }
        return (ServerPlayerEntity) (Object) this;
    } else {
        ServerWorld serverworld = this.server.getWorld(dimensiontype);
        // this.dimension = destination;
        ServerWorld[] serverworld1 = { this.server.getWorld(destination[0]) };
        /*
            WorldInfo worldinfo = serverworld1.getWorldInfo();
            NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
            this.connection.sendPacket(new SRespawnPacket(destination, WorldInfo.byHashing(worldinfo.getSeed()), worldinfo.getGenerator(), this.interactionManager.getGameType()));
            this.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
            PlayerList playerlist = this.server.getPlayerList();
            playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this);
            serverworld.removeEntity((ServerPlayerEntity) (Object) this, true); //Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call.
            this.revive();
            */
        PlayerList[] playerlist = new PlayerList[1];
        Entity e = teleporter.placeEntity((ServerPlayerEntity) (Object) this, serverworld, serverworld1[0], this.rotationYaw, spawnPortal -> {
            // Forge: Start vanilla logic
            double d0 = this.getPosX();
            double d1 = this.getPosY();
            double d2 = this.getPosZ();
            float f = this.rotationPitch;
            float f1 = this.rotationYaw;
            double d3 = 8.0D;
            float f2 = f1;
            serverworld.getProfiler().startSection("moving");
            if (serverworld1[0] != null) {
                double moveFactor = serverworld.getDimension().getMovementFactor() / serverworld1[0].getDimension().getMovementFactor();
                d0 *= moveFactor;
                d2 *= moveFactor;
                if (dimensiontype == DimensionType.OVERWORLD && destination[0] == DimensionType.THE_NETHER) {
                    this.enteredNetherPosition = this.getPositionVec();
                } else if (dimensiontype == DimensionType.OVERWORLD && destination[0] == DimensionType.THE_END) {
                    BlockPos blockpos = serverworld1[0].getSpawnCoordinate();
                    d0 = blockpos.getX();
                    d1 = blockpos.getY();
                    d2 = blockpos.getZ();
                    f1 = 90.0F;
                    f = 0.0F;
                }
            }
            Location enter = this.bridge$getBukkitEntity().getLocation();
            Location exit = (serverworld1[0] == null) ? null : new Location(((ServerWorldBridge) serverworld1[0]).bridge$getWorld(), d0, d1, d2, f1, f);
            PlayerPortalEvent event = new PlayerPortalEvent(this.bridge$getBukkitEntity(), enter, exit, cause, 128, true, ((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.THE_END ? 0 : 16);
            Bukkit.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled() || event.getTo() == null) {
                return null;
            }
            exit = event.getTo();
            if (exit == null) {
                return null;
            }
            serverworld1[0] = ((CraftWorld) exit.getWorld()).getHandle();
            d0 = exit.getX();
            d1 = exit.getY();
            d2 = exit.getZ();
            // this.setLocationAndAngles(d0, d1, d2, f1, f);
            serverworld.getProfiler().endSection();
            serverworld.getProfiler().startSection("placing");
            double d7 = Math.max(-2.9999872E7D, serverworld1[0].getWorldBorder().minX() + 16.0D);
            double d4 = Math.max(-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, d7, d5);
            d2 = MathHelper.clamp(d2, d4, d6);
            // this.setLocationAndAngles(d0, d1, d2, f1, f);
            Vec3d exitVelocity = Vec3d.ZERO;
            BlockPos exitPosition = new BlockPos(d0, d1, d2);
            if (((DimensionTypeBridge) destination[0]).bridge$getType() == DimensionType.THE_END) {
                int i = exitPosition.getX();
                int j = exitPosition.getY() - 1;
                int k = exitPosition.getZ();
                if (event.getCanCreatePortal()) {
                    BlockStateListPopulator blockList = new BlockStateListPopulator(serverworld1[0]);
                    for (int j1 = -2; j1 <= 2; ++j1) {
                        for (int k1 = -2; k1 <= 2; ++k1) {
                            for (int l1 = -1; l1 < 3; ++l1) {
                                int i2 = i + k1 * 1 + j1 * 0;
                                int j2 = j + l1;
                                int k2 = k + k1 * 0 - j1 * 1;
                                boolean flag = l1 < 0;
                                blockList.setBlockState(new BlockPos(i2, j2, k2), flag ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
                            }
                        }
                    }
                    org.bukkit.World bworld = ((ServerWorldBridge) serverworld1[0]).bridge$getWorld();
                    PortalCreateEvent portalEvent = new PortalCreateEvent((List<BlockState>) (List) blockList.getList(), bworld, this.bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.END_PLATFORM);
                    Bukkit.getPluginManager().callEvent(portalEvent);
                    if (!portalEvent.isCancelled()) {
                        blockList.updateList();
                    }
                }
                // this.setLocationAndAngles(i, j, k, f1, 0.0F);
                exit.setX(i);
                exit.setY(j);
                exit.setZ(k);
                // this.setMotion(Vec3d.ZERO);
                exitVelocity = Vec3d.ZERO;
            } else {
                BlockPattern.PortalInfo portalInfo = ((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$placeInPortal((ServerPlayerEntity) (Object) this, exitPosition, f2, event.getSearchRadius(), true);
                if (spawnPortal && portalInfo == null && event.getCanCreatePortal()) {
                    if (((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$makePortal((ServerPlayerEntity) (Object) this, exitPosition, event.getCreationRadius())) {
                        // serverworld1.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f2);
                        portalInfo = ((TeleporterBridge) serverworld1[0].getDefaultTeleporter()).bridge$placeInPortal((ServerPlayerEntity) (Object) this, exitPosition, f2, event.getSearchRadius(), true);
                    }
                }
                if (portalInfo == null) {
                    return null;
                }
                exitVelocity = portalInfo.motion;
                exit.setX(portalInfo.pos.getX());
                exit.setY(portalInfo.pos.getY());
                exit.setZ(portalInfo.pos.getZ());
                exit.setYaw(f2 + (float) portalInfo.rotation);
            }
            serverworld.getProfiler().endSection();
            PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.bridge$getBukkitEntity(), enter, exit, cause);
            Bukkit.getServer().getPluginManager().callEvent(tpEvent);
            if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
                return null;
            }
            exit = tpEvent.getTo();
            if (exit == null) {
                return null;
            }
            serverworld1[0] = ((CraftWorld) exit.getWorld()).getHandle();
            this.invulnerableDimensionChange = true;
            destination[0] = serverworld1[0].getDimension().getType();
            this.dimension = destination[0];
            WorldInfo worldinfo = serverworld1[0].getWorldInfo();
            NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
            this.connection.sendPacket(new SRespawnPacket(destination[0], WorldInfo.byHashing(worldinfo.getSeed()), worldinfo.getGenerator(), this.interactionManager.getGameType()));
            this.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
            playerlist[0] = this.server.getPlayerList();
            playerlist[0].updatePermissionLevel((ServerPlayerEntity) (Object) this);
            // Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call.
            serverworld.removeEntity((ServerPlayerEntity) (Object) this, true);
            this.revive();
            this.setMotion(exitVelocity);
            this.setWorld(serverworld1[0]);
            serverworld1[0].addDuringPortalTeleport((ServerPlayerEntity) (Object) this);
            this.func_213846_b(serverworld);
            // this.connection.setPlayerLocation(this.getPosX(), this.getPosY(), this.getPosZ(), f1, f);
            ((ServerPlayNetHandlerBridge) this.connection).bridge$teleport(exit);
            this.connection.captureCurrentPosition();
            // forge: this is part of the ITeleporter patch
            return (ServerPlayerEntity) (Object) this;
        });
        // Forge: End vanilla logic
        if (e == null) {
            return (ServerPlayerEntity) (Object) this;
        } else if (e != (Object) this) {
            throw new IllegalArgumentException(String.format("Teleporter %s returned not the player entity but instead %s, expected PlayerEntity %s", teleporter, e, this));
        }
        this.interactionManager.setWorld(serverworld1[0]);
        this.connection.sendPacket(new SPlayerAbilitiesPacket(this.abilities));
        playerlist[0].sendWorldInfo((ServerPlayerEntity) (Object) this, serverworld1[0]);
        playerlist[0].sendInventory((ServerPlayerEntity) (Object) this);
        for (EffectInstance effectinstance : this.getActivePotionEffects()) {
            this.connection.sendPacket(new SPlayEntityEffectPacket(this.getEntityId(), effectinstance));
        }
        this.connection.sendPacket(new SPlaySoundEventPacket(1032, BlockPos.ZERO, 0, false));
        this.lastExperience = -1;
        this.lastHealth = -1.0F;
        this.lastFoodLevel = -1;
        BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, dimensiontype, destination[0]);
        PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.bridge$getBukkitEntity(), ((WorldBridge) serverworld).bridge$getWorld());
        Bukkit.getPluginManager().callEvent(changeEvent);
        return (ServerPlayerEntity) (Object) this;
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Entity(net.minecraft.entity.Entity) PlayerList(net.minecraft.server.management.PlayerList) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) SPlaySoundEventPacket(net.minecraft.network.play.server.SPlaySoundEventPacket) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerWorld(net.minecraft.world.server.ServerWorld) SPlayerAbilitiesPacket(net.minecraft.network.play.server.SPlayerAbilitiesPacket) SRespawnPacket(net.minecraft.network.play.server.SRespawnPacket) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) PlayerList(net.minecraft.server.management.PlayerList) TeleporterBridge(io.izzel.arclight.common.bridge.world.TeleporterBridge) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) Teleporter(net.minecraft.world.Teleporter) ITeleporter(net.minecraftforge.common.util.ITeleporter) BlockPattern(net.minecraft.block.pattern.BlockPattern) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) BlockState(org.bukkit.block.BlockState) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) ServerWorldBridge(io.izzel.arclight.common.bridge.world.server.ServerWorldBridge) EffectInstance(net.minecraft.potion.EffectInstance) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite) Nullable(javax.annotation.Nullable)

Example 4 with BlockStateListPopulator

use of org.bukkit.craftbukkit.v.util.BlockStateListPopulator in project Arclight by IzzelAliz.

the class TeleporterMixin_1_15 method createPortal.

public boolean createPortal(Entity entity, BlockPos createPosition, int createRadius) {
    boolean flag = true;
    double d0 = -1.0;
    int i = createPosition.getX();
    int j = createPosition.getY();
    int k = createPosition.getZ();
    int l = i;
    int i2 = j;
    int j2 = k;
    int k2 = 0;
    int l2 = this.random.nextInt(4);
    BlockPos.Mutable blockposition_mutableblockposition = new BlockPos.Mutable();
    for (int i3 = i - createRadius; i3 <= i + createRadius; ++i3) {
        double d2 = i3 + 0.5 - createPosition.getX();
        for (int j3 = k - createRadius; j3 <= k + createRadius; ++j3) {
            double d3 = j3 + 0.5 - createPosition.getZ();
            Label_0439: for (int k3 = this.world.getActualHeight() - 1; k3 >= 0; --k3) {
                if (this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3, j3))) {
                    while (k3 > 0 && this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3 - 1, j3))) {
                        --k3;
                    }
                    for (int i4 = l2; i4 < l2 + 4; ++i4) {
                        int l3 = i4 % 2;
                        int j4 = 1 - l3;
                        if (i4 % 4 >= 2) {
                            l3 = -l3;
                            j4 = -j4;
                        }
                        for (int l4 = 0; l4 < 3; ++l4) {
                            for (int i5 = 0; i5 < 4; ++i5) {
                                for (int k4 = -1; k4 < 4; ++k4) {
                                    int k5 = i3 + (i5 - 1) * l3 + l4 * j4;
                                    int j5 = k3 + k4;
                                    int l5 = j3 + (i5 - 1) * j4 - l4 * l3;
                                    blockposition_mutableblockposition.setPos(k5, j5, l5);
                                    if (k4 < 0 && !this.world.getBlockState(blockposition_mutableblockposition).getMaterial().isSolid()) {
                                        continue Label_0439;
                                    }
                                    if (k4 >= 0 && !this.world.isAirBlock(blockposition_mutableblockposition)) {
                                        continue Label_0439;
                                    }
                                }
                            }
                        }
                        double d4 = k3 + 0.5 - entity.getPosY();
                        double d5 = d2 * d2 + d4 * d4 + d3 * d3;
                        if (d0 < 0.0 || d5 < d0) {
                            d0 = d5;
                            l = i3;
                            i2 = k3;
                            j2 = j3;
                            k2 = i4 % 4;
                        }
                    }
                }
            }
        }
    }
    if (d0 < 0.0) {
        for (int i3 = i - createRadius; i3 <= i + createRadius; ++i3) {
            double d2 = i3 + 0.5 - createPosition.getX();
            for (int j3 = k - createRadius; j3 <= k + createRadius; ++j3) {
                double d3 = j3 + 0.5 - createPosition.getZ();
                Label_0812: for (int k3 = this.world.getActualHeight() - 1; k3 >= 0; --k3) {
                    if (this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3, j3))) {
                        while (k3 > 0 && this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3 - 1, j3))) {
                            --k3;
                        }
                        for (int i4 = l2; i4 < l2 + 2; ++i4) {
                            int l3 = i4 % 2;
                            int j4 = 1 - l3;
                            for (int l4 = 0; l4 < 4; ++l4) {
                                for (int i5 = -1; i5 < 4; ++i5) {
                                    int k4 = i3 + (l4 - 1) * l3;
                                    int k5 = k3 + i5;
                                    int j5 = j3 + (l4 - 1) * j4;
                                    blockposition_mutableblockposition.setPos(k4, k5, j5);
                                    if (i5 < 0 && !this.world.getBlockState(blockposition_mutableblockposition).getMaterial().isSolid()) {
                                        continue Label_0812;
                                    }
                                    if (i5 >= 0 && !this.world.isAirBlock(blockposition_mutableblockposition)) {
                                        continue Label_0812;
                                    }
                                }
                            }
                            double d4 = k3 + 0.5 - entity.getPosY();
                            double d5 = d2 * d2 + d4 * d4 + d3 * d3;
                            if (d0 < 0.0 || d5 < d0) {
                                d0 = d5;
                                l = i3;
                                i2 = k3;
                                j2 = j3;
                                k2 = i4 % 2;
                            }
                        }
                    }
                }
            }
        }
    }
    int i6 = l;
    int j6 = i2;
    int j3 = j2;
    int k6 = k2 % 2;
    int l6 = 1 - k6;
    if (k2 % 4 >= 2) {
        k6 = -k6;
        l6 = -l6;
    }
    BlockStateListPopulator blockList = new BlockStateListPopulator(this.world);
    if (d0 < 0.0) {
        i2 = (j6 = MathHelper.clamp(i2, 70, this.world.getActualHeight() - 10));
        for (int k3 = -1; k3 <= 1; ++k3) {
            for (int i4 = 1; i4 < 3; ++i4) {
                for (int l3 = -1; l3 < 3; ++l3) {
                    int j4 = i6 + (i4 - 1) * k6 + k3 * l6;
                    int l4 = j6 + l3;
                    int i5 = j3 + (i4 - 1) * l6 - k3 * k6;
                    boolean flag2 = l3 < 0;
                    blockposition_mutableblockposition.setPos(j4, l4, i5);
                    blockList.setBlockState(blockposition_mutableblockposition, flag2 ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
                }
            }
        }
    }
    for (int k3 = -1; k3 < 3; ++k3) {
        for (int i4 = -1; i4 < 4; ++i4) {
            if (k3 == -1 || k3 == 2 || i4 == -1 || i4 == 3) {
                blockposition_mutableblockposition.setPos(i6 + k3 * k6, j6 + i4, j3 + k3 * l6);
                blockList.setBlockState(blockposition_mutableblockposition, Blocks.OBSIDIAN.getDefaultState(), 3);
            }
        }
    }
    BlockState iblockdata = (Blocks.NETHER_PORTAL.getDefaultState()).with(NetherPortalBlock.AXIS, (k6 == 0) ? Direction.Axis.Z : Direction.Axis.X);
    for (int i4 = 0; i4 < 2; ++i4) {
        for (int l3 = 0; l3 < 3; ++l3) {
            blockposition_mutableblockposition.setPos(i6 + i4 * k6, j6 + l3, j3 + i4 * l6);
            blockList.setBlockState(blockposition_mutableblockposition, iblockdata, 18);
        }
    }
    org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld();
    PortalCreateEvent event = new PortalCreateEvent((List) blockList.getList(), bworld, ((EntityBridge) entity).bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.NETHER_PAIR);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        blockList.updateList();
    }
    return true;
}
Also used : BlockState(net.minecraft.block.BlockState) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) BlockPos(net.minecraft.util.math.BlockPos) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)4 BlockStateListPopulator (org.bukkit.craftbukkit.v.util.BlockStateListPopulator)4 PortalCreateEvent (org.bukkit.event.world.PortalCreateEvent)3 Overwrite (org.spongepowered.asm.mixin.Overwrite)3 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 BlockState (net.minecraft.block.BlockState)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 SChangeGameStatePacket (net.minecraft.network.play.server.SChangeGameStatePacket)2 SPlayEntityEffectPacket (net.minecraft.network.play.server.SPlayEntityEffectPacket)2 SPlaySoundEventPacket (net.minecraft.network.play.server.SPlaySoundEventPacket)2 SPlayerAbilitiesPacket (net.minecraft.network.play.server.SPlayerAbilitiesPacket)2 SRespawnPacket (net.minecraft.network.play.server.SRespawnPacket)2 SServerDifficultyPacket (net.minecraft.network.play.server.SServerDifficultyPacket)2 EffectInstance (net.minecraft.potion.EffectInstance)2 PlayerList (net.minecraft.server.management.PlayerList)2 Vec3d (net.minecraft.util.math.Vec3d)2 DimensionType (net.minecraft.world.dimension.DimensionType)2 ServerWorld (net.minecraft.world.server.ServerWorld)2