Search in sources :

Example 26 with World

use of net.minecraft.server.v1_15_R1.World in project THP-Engine by TheHollowPlanetMC.

the class LightUpdatePacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    World world = EnginePlayer.getBukkitPlayer().getWorld();
    String worldName = world.getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    try {
        int chunkX = a.getInt(packet);
        int chunkZ = b.getInt(packet);
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        Object cachedPacket = parallelChunk.getCachedLightUpdatePacket();
        if (cachedPacket != null)
            return cachedPacket;
        int cValue = c.getInt(packet);
        int dValue = d.getInt(packet);
        int eValue = e.getInt(packet);
        int fValue = f.getInt(packet);
        Deque<byte[]> gValue = new ArrayDeque<>((List<byte[]>) g.get(packet));
        Deque<byte[]> hValue = new ArrayDeque<>((List<byte[]>) h.get(packet));
        int newC = 0;
        int newD = 0;
        int newE = 0;
        int newF = 0;
        List<byte[]> newG = new ArrayList<>();
        List<byte[]> newH = new ArrayList<>();
        boolean edited = false;
        for (int index = 0; index < 18; index++) {
            int sectionIndex = index - 1;
            int cSectionBit = cValue & (1 << index);
            newC |= cSectionBit;
            newE |= eValue & (1 << index);
            int dSectionBit = dValue & (1 << index);
            newD |= dSectionBit;
            newF |= fValue & (1 << index);
            if (index == 0 || index == 17) {
                if (cSectionBit != 0) {
                    newG.add(gValue.removeFirst());
                }
                if (dSectionBit != 0) {
                    newH.add(hValue.removeFirst());
                }
                continue;
            }
            SectionLevelArray skyLevelArray = parallelChunk.getSkyLightSectionLevelArray(sectionIndex);
            SectionLevelArray blockLevelArray = parallelChunk.getBlockLightSectionLevelArray(sectionIndex);
            if (skyLevelArray == null) {
                if (cSectionBit != 0) {
                    newG.add(gValue.removeFirst());
                }
            } else {
                if (cSectionBit == 0) {
                    NibbleArray nibbleArray = new NibbleArray();
                    boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newG.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newC |= 1 << index;
                        newE &= ~(1 << index);
                    } else {
                        newE |= 1 << index;
                    }
                } else {
                    NibbleArray nibbleArray = new NibbleArray(gValue.removeFirst().clone());
                    boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newG.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newE &= ~(1 << index);
                    }
                }
            }
            if (blockLevelArray == null) {
                if (dSectionBit != 0) {
                    newH.add(hValue.removeFirst());
                }
            } else {
                if (dSectionBit == 0) {
                    NibbleArray nibbleArray = new NibbleArray();
                    boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newH.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newD |= 1 << index;
                        newF &= ~(1 << index);
                    } else {
                        newF |= 1 << index;
                    }
                } else {
                    NibbleArray nibbleArray = new NibbleArray(hValue.removeFirst().clone());
                    boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newH.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newF &= ~(1 << index);
                    }
                }
            }
        }
        if (!edited)
            return packet;
        PacketPlayOutLightUpdate newPacket = new PacketPlayOutLightUpdate();
        a.set(newPacket, chunkX);
        b.set(newPacket, chunkZ);
        c.set(newPacket, newC);
        d.set(newPacket, newD);
        e.set(newPacket, newE);
        f.set(newPacket, newF);
        g.set(newPacket, newG);
        h.set(newPacket, newH);
        if (cacheSetting)
            parallelChunk.setLightUpdatePacketCache(newPacket);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) PacketPlayOutLightUpdate(net.minecraft.server.v1_15_R1.PacketPlayOutLightUpdate) World(org.bukkit.World) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) NibbleArray(net.minecraft.server.v1_15_R1.NibbleArray) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) SectionLevelArray(thpmc.engine.util.SectionLevelArray)

Example 27 with World

use of net.minecraft.server.v1_15_R1.World in project Citizens2 by CitizensDev.

the class NMSImpl method sendPacketsNearby.

public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
    radius *= radius;
    final org.bukkit.World world = location.getWorld();
    for (Player ply : Bukkit.getServer().getOnlinePlayers()) {
        if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) {
            continue;
        }
        if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) {
            continue;
        }
        for (Packet<?> packet : packets) {
            NMSImpl.sendPacket(ply, packet);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) AdvancementDataPlayer(net.minecraft.server.v1_15_R1.AdvancementDataPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) World(org.bukkit.World)

Example 28 with World

use of net.minecraft.server.v1_15_R1.World in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method updateTile.

private void updateTile() {
    World level = this.a();
    if (level != null) {
        level.b(this.blockPos, this.blockEntity);
        IBlockData var1 = this.a().getType(this.b());
        this.a().notify(this.blockPos, var1, var1, 3);
    }
}
Also used : IBlockData(net.minecraft.server.v1_16_R2.IBlockData) World(net.minecraft.server.v1_16_R2.World)

Example 29 with World

use of net.minecraft.server.v1_15_R1.World in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method c.

@Override
public void c() {
    World level = this.a();
    if (level == null)
        return;
    // Only tick the spawner if a player is nearby
    this.playersTimeSinceLastCheck = (this.playersTimeSinceLastCheck + 1) % Setting.SPAWNER_PLAYER_CHECK_FREQUENCY.getInt();
    if (this.playersTimeSinceLastCheck == 0)
        this.playersNearby = this.isNearPlayer(level, this.blockPos);
    if (!this.playersNearby)
        return;
    SpawnerStackSettings stackSettings = this.stackedSpawner.getStackSettings();
    // Handle redstone deactivation if enabled
    if (Setting.SPAWNER_DEACTIVATE_WHEN_POWERED.getBoolean()) {
        if (this.redstoneTimeSinceLastCheck == 0) {
            boolean hasSignal = level.isBlockIndirectlyPowered(this.blockPos);
            if (this.redstoneDeactivated && !hasSignal) {
                this.redstoneDeactivated = false;
                this.requiredPlayerRange = stackSettings.getPlayerActivationRange();
                this.updateTile();
            } else if (!this.redstoneDeactivated && hasSignal) {
                this.redstoneDeactivated = true;
                this.requiredPlayerRange = 0;
                this.updateTile();
            }
            if (this.redstoneDeactivated)
                return;
        }
        this.redstoneTimeSinceLastCheck = (this.redstoneTimeSinceLastCheck + 1) % Setting.SPAWNER_POWERED_CHECK_FREQUENCY.getInt();
    }
    // Count down spawn timer unless we are ready to spawn
    if (this.spawnDelay > 0) {
        this.spawnDelay--;
        return;
    }
    // Reset spawn delay
    this.spawnDelay = level.getRandom().nextInt(this.maxSpawnDelay - this.minSpawnDelay + 1) + this.minSpawnDelay;
    this.updateTile();
    // Execute spawning method
    if (this.spawnData != null) {
        MinecraftKey resourceLocation = MinecraftKey.a(this.spawnData.getEntity().getString("id"));
        if (resourceLocation != null) {
            NamespacedKey namespacedKey = CraftNamespacedKey.fromMinecraft(resourceLocation);
            EntityType entityType = this.fromKey(namespacedKey);
            if (entityType != null)
                new MobSpawningMethod(entityType).spawn(this.stackedSpawner);
        }
    }
    // Randomize spawn potentials
    if (!this.mobs.isEmpty())
        this.setSpawnData(WeightedRandom.a(this.a().random, this.mobs));
}
Also used : EntityType(org.bukkit.entity.EntityType) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) MobSpawningMethod(dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R2.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) World(net.minecraft.server.v1_16_R2.World) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 30 with World

use of net.minecraft.server.v1_15_R1.World in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method c.

@Override
public void c() {
    World level = this.a();
    if (level == null)
        return;
    // Only tick the spawner if a player is nearby
    this.playersTimeSinceLastCheck = (this.playersTimeSinceLastCheck + 1) % Setting.SPAWNER_PLAYER_CHECK_FREQUENCY.getInt();
    if (this.playersTimeSinceLastCheck == 0)
        this.playersNearby = this.isNearPlayer(level, this.blockPos);
    if (!this.playersNearby)
        return;
    SpawnerStackSettings stackSettings = this.stackedSpawner.getStackSettings();
    // Handle redstone deactivation if enabled
    if (Setting.SPAWNER_DEACTIVATE_WHEN_POWERED.getBoolean()) {
        if (this.redstoneTimeSinceLastCheck == 0) {
            boolean hasSignal = level.isBlockIndirectlyPowered(this.blockPos);
            if (this.redstoneDeactivated && !hasSignal) {
                this.redstoneDeactivated = false;
                this.requiredPlayerRange = stackSettings.getPlayerActivationRange();
                this.updateTile();
            } else if (!this.redstoneDeactivated && hasSignal) {
                this.redstoneDeactivated = true;
                this.requiredPlayerRange = 0;
                this.updateTile();
            }
            if (this.redstoneDeactivated)
                return;
        }
        this.redstoneTimeSinceLastCheck = (this.redstoneTimeSinceLastCheck + 1) % Setting.SPAWNER_POWERED_CHECK_FREQUENCY.getInt();
    }
    // Count down spawn timer unless we are ready to spawn
    if (this.spawnDelay > 0) {
        this.spawnDelay--;
        return;
    }
    // Reset spawn delay
    this.spawnDelay = level.getRandom().nextInt(this.maxSpawnDelay - this.minSpawnDelay + 1) + this.minSpawnDelay;
    this.updateTile();
    // Execute spawning method
    if (this.spawnData != null) {
        MinecraftKey resourceLocation = MinecraftKey.a(this.spawnData.getEntity().getString("id"));
        if (resourceLocation != null) {
            NamespacedKey namespacedKey = CraftNamespacedKey.fromMinecraft(resourceLocation);
            EntityType entityType = this.fromKey(namespacedKey);
            if (entityType != null)
                new MobSpawningMethod(entityType).spawn(this.stackedSpawner);
        }
    }
    // Randomize spawn potentials
    if (!this.mobs.isEmpty())
        this.setSpawnData(WeightedRandom.a(this.a().random, this.mobs));
}
Also used : EntityType(org.bukkit.entity.EntityType) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) MobSpawningMethod(dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod) NamespacedKey(org.bukkit.NamespacedKey) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey) World(net.minecraft.server.v1_16_R3.World) MinecraftKey(net.minecraft.server.v1_16_R3.MinecraftKey)

Aggregations

Location (org.bukkit.Location)27 World (net.minecraft.server.v1_16_R3.World)16 World (net.minecraft.server.v1_12_R1.World)14 World (net.minecraft.server.v1_8_R3.World)14 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)14 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)14 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)14 ArrayList (java.util.ArrayList)12 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)11 List (java.util.List)10 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)10 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)10 CraftWorld (org.bukkit.craftbukkit.v1_15_R1.CraftWorld)10 WildLoadersPlugin (com.bgsoftware.wildloaders.WildLoadersPlugin)8 Hologram (com.bgsoftware.wildloaders.api.holograms.Hologram)8 ChunkLoader (com.bgsoftware.wildloaders.api.loaders.ChunkLoader)8 ChunkLoaderNPC (com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC)8 ITileEntityChunkLoader (com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader)8 WChunkLoader (com.bgsoftware.wildloaders.loaders.WChunkLoader)8 Collection (java.util.Collection)8