Search in sources :

Example 16 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 in project BKCommonLib by bergerhealer.

the class CommonHumanEntity method getSpawnPoint.

/**
 * Gets the block location of the respawn point for the human entity.
 * If none is available, null is returned instead.
 *
 * @return spawn point coordinates, or null if none are available
 */
public BlockLocation getSpawnPoint() {
    Object handle = getHandle();
    String world = EntityHumanHandle.T.spawnWorld.get(handle);
    IntVector3 coords = EntityHumanHandle.T.spawnCoord.get(handle);
    if (world != null && coords != null && !world.isEmpty()) {
        return new BlockLocation(world, coords);
    } else {
        return null;
    }
}
Also used : BlockLocation(com.bergerkiller.bukkit.common.BlockLocation) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

Example 17 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 in project BKCommonLib by bergerhealer.

the class CommonHumanEntity method setSpawnPoint.

/**
 * Sets the block location of the respawn point for the human entity.
 * To clear the respawn point and set it to 'none', set it to null.
 *
 * @param spawnPoint to set to
 */
public void setSpawnPoint(BlockLocation spawnPoint) {
    Object handle = getHandle();
    IntVector3 coord = null;
    String world = "";
    if (spawnPoint != null) {
        world = spawnPoint.world;
        coord = spawnPoint.getCoordinates();
    }
    EntityHumanHandle.T.spawnWorld.set(handle, world);
    EntityHumanHandle.T.spawnCoord.set(handle, coord);
}
Also used : IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

Example 18 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 in project BKCommonLib by bergerhealer.

the class BlockDataImpl method ignite.

@Override
public final void ignite(org.bukkit.World world, int x, int y, int z) {
    ExplosionHandle ex = ExplosionHandle.createNew(world, null, x, y, z, 4.0f, true, true);
    this.block.ignite(world, new IntVector3(x, y, z), ex);
}
Also used : ExplosionHandle(com.bergerkiller.generated.net.minecraft.server.ExplosionHandle) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

Example 19 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 in project BKCommonLib by bergerhealer.

the class ItemFrameInfo method recalculateUUID.

void recalculateUUID() {
    // Find out the tile information of this item frame
    // This is a slow and lengthy procedure; hopefully it does not happen too often
    // What we do is: we add all neighbours, then find the most top-left item frame
    // Subtracting coordinates will give us the tile x/y of this item frame
    IntVector3 itemFramePosition = this.coordinates;
    ItemFrameCluster cluster = this.controller.findCluster(itemFrameHandle, itemFramePosition);
    // If not fully loaded, 'park' this item frame until surrounding chunks are loaded too
    World world = this.getWorld();
    boolean fullyLoaded = true;
    for (ItemFrameCluster.ChunkDependency dependency : cluster.chunk_dependencies) {
        fullyLoaded &= this.controller.checkClusterChunkDependency(world, dependency);
    }
    if (!fullyLoaded) {
        this.requiresFurtherLoading = true;
        return;
    }
    // Calculate UUID of this item frame
    this.recalculateUUIDInCluster(cluster);
    // as otherwise there is a tick delay until these other item frames initialize.
    if (cluster.hasMultipleTiles()) {
        for (ItemFrameInfo itemFrame : this.controller.findClusterItemFrames(cluster)) {
            if (itemFrame == this) {
                continue;
            }
            if ((itemFrame.lastFrameItemUpdateNeeded && itemFrame.checkItemChanged()) || itemFrame.requiresFurtherLoading) {
                itemFrame.recalculateUUIDInCluster(cluster);
            }
        }
    }
}
Also used : ItemFrameCluster(com.bergerkiller.bukkit.common.internal.map.ItemFrameCluster) World(org.bukkit.World) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3)

Example 20 with IntVector3

use of com.bergerkiller.bukkit.common.bases.IntVector3 in project BKCommonLib by bergerhealer.

the class ItemFrameInfo method recalculateUUIDInCluster.

private void recalculateUUIDInCluster(ItemFrameCluster cluster) {
    this.requiresFurtherLoading = false;
    IntVector3 itemFramePosition = this.coordinates;
    UUID mapUUID = this.itemFrameHandle.getItemMapDisplayDynamicOnlyUUID();
    if (mapUUID == null) {
        return;
    }
    MapUUID newMapUUID;
    if (cluster.hasMultipleTiles()) {
        int tileX = 0;
        int tileY = 0;
        if (cluster.facing.getModY() > 0) {
            // We use rotation of the item frame to decide which side is up
            switch(cluster.rotation) {
                case 90:
                    tileX = (itemFramePosition.z - cluster.min_coord.z);
                    tileY = (cluster.max_coord.x - itemFramePosition.x);
                    break;
                case 180:
                    tileX = (cluster.max_coord.x - itemFramePosition.x);
                    tileY = (cluster.max_coord.z - itemFramePosition.z);
                    break;
                case 270:
                    tileX = (cluster.max_coord.z - itemFramePosition.z);
                    tileY = (itemFramePosition.x - cluster.min_coord.x);
                    break;
                default:
                    tileX = (itemFramePosition.x - cluster.min_coord.x);
                    tileY = (itemFramePosition.z - cluster.min_coord.z);
                    break;
            }
        } else if (cluster.facing.getModY() < 0) {
            // We use rotation of the item frame to decide which side is up
            switch(cluster.rotation) {
                case 90:
                    tileX = (cluster.max_coord.z - itemFramePosition.z);
                    tileY = (cluster.max_coord.x - itemFramePosition.x);
                    break;
                case 180:
                    tileX = (cluster.max_coord.x - itemFramePosition.x);
                    tileY = (itemFramePosition.z - cluster.min_coord.z);
                    break;
                case 270:
                    tileX = (itemFramePosition.z - cluster.min_coord.z);
                    tileY = (itemFramePosition.x - cluster.min_coord.x);
                    break;
                default:
                    tileX = (itemFramePosition.x - cluster.min_coord.x);
                    tileY = (cluster.max_coord.z - itemFramePosition.z);
                    break;
            }
        } else {
            // On the wall
            switch(cluster.facing) {
                case NORTH:
                    tileX = (cluster.max_coord.x - itemFramePosition.x);
                    break;
                case EAST:
                    tileX = (cluster.max_coord.z - itemFramePosition.z);
                    break;
                case SOUTH:
                    tileX = (itemFramePosition.x - cluster.min_coord.x);
                    break;
                case WEST:
                    tileX = (itemFramePosition.z - cluster.min_coord.z);
                    break;
                default:
                    tileX = 0;
                    break;
            }
            tileY = cluster.max_coord.y - itemFramePosition.y;
        }
        newMapUUID = new MapUUID(mapUUID, tileX, tileY);
    } else {
        newMapUUID = new MapUUID(mapUUID, 0, 0);
    }
    if (lastMapUUID == null || !lastMapUUID.getUUID().equals(mapUUID)) {
        // Map item UUID changed entirely. Remove the previous and add the new.
        remove();
        lastMapUUID = newMapUUID;
        needsItemRefresh.set(sentMapInfoToPlayers && !newMapUUID.equals(preReloadMapUUID));
        preReloadMapUUID = null;
        add();
    } else if (newMapUUID.equals(lastMapUUID)) {
    // No change occurred
    } else if (this.displayInfo != null) {
        // Tile coordinates of this map were changed
        // Ensure the new tile coordinates are added
        this.displayInfo.addTileIfMissing(newMapUUID.getTileX(), newMapUUID.getTileY());
        // Refresh state now so that removeTileIfMissing works correctly
        int oldTileX = lastMapUUID.getTileX();
        int oldTileY = lastMapUUID.getTileY();
        lastMapUUID = newMapUUID;
        needsItemRefresh.set(sentMapInfoToPlayers);
        preReloadMapUUID = null;
        // If the previous coordinates are now no longer used, remove the tile
        this.displayInfo.removeTileIfMissing(oldTileX, oldTileY);
    } else {
        // Tile coordinates changed, but we had no previous display info
        // Strange.
        lastMapUUID = newMapUUID;
        needsItemRefresh.set(sentMapInfoToPlayers);
        preReloadMapUUID = null;
    }
}
Also used : MapUUID(com.bergerkiller.bukkit.common.map.util.MapUUID) UUID(java.util.UUID) IntVector3(com.bergerkiller.bukkit.common.bases.IntVector3) MapUUID(com.bergerkiller.bukkit.common.map.util.MapUUID)

Aggregations

IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)27 HashSet (java.util.HashSet)9 IntVector2 (com.bergerkiller.bukkit.common.bases.IntVector2)6 Chunk (org.bukkit.Chunk)5 BlockFace (org.bukkit.block.BlockFace)4 Test (org.junit.Test)4 MapUUID (com.bergerkiller.bukkit.common.map.util.MapUUID)3 WorldHandle (com.bergerkiller.generated.net.minecraft.world.level.WorldHandle)3 File (java.io.File)3 UUID (java.util.UUID)3 World (org.bukkit.World)3 BlockLocation (com.bergerkiller.bukkit.common.BlockLocation)2 Octree (com.bergerkiller.bukkit.common.collections.octree.Octree)2 CommonTagCompound (com.bergerkiller.bukkit.common.nbt.CommonTagCompound)2 BlockData (com.bergerkiller.bukkit.common.wrappers.BlockData)2 EntityPlayerHandle (com.bergerkiller.generated.net.minecraft.server.level.EntityPlayerHandle)2 BitSet (java.util.BitSet)2 Random (java.util.Random)2 Set (java.util.Set)2 ItemFrame (org.bukkit.entity.ItemFrame)2