Java Code Examples for com.flowpowered.math.vector.Vector3i#getY()

The following examples show how to use com.flowpowered.math.vector.Vector3i#getY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCAWorld.java    From BlueMap with MIT License 6 votes vote down vote up
@Override
public Block getBlock(Vector3i pos) {
	if (pos.getY() < getMinY()) {
		return new Block(this, BlockState.AIR, LightData.ZERO, Biome.DEFAULT, BlockProperties.TRANSPARENT, pos);
	}
	
	if (pos.getY() > getMaxY()) {
		return new Block(this, BlockState.AIR, LightData.SKY, Biome.DEFAULT, BlockProperties.TRANSPARENT, pos);
	}
	
	try {
		
		Vector2i chunkPos = blockToChunk(pos);
		Chunk chunk = getChunk(chunkPos);
		BlockState blockState = getExtendedBlockState(chunk, pos);
		LightData lightData = chunk.getLightData(pos);
		Biome biome = chunk.getBiome(pos);
		BlockProperties properties = blockPropertiesMapper.get(blockState);
		return new Block(this, blockState, lightData, biome, properties, pos);
		
	} catch (IOException ex) {
		throw new RuntimeException("Unexpected IO-Exception trying to read world-data!", ex);
	}
}
 
Example 2
Source File: BlockUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
public boolean clickedClaimCorner(GDClaim claim, Vector3i clickedPos) {
    int clickedX = clickedPos.getX();
    int clickedY = clickedPos.getY();
    int clickedZ = clickedPos.getZ();
    int lesserX = claim.getLesserBoundaryCorner().getX();
    int lesserY = claim.getLesserBoundaryCorner().getY();
    int lesserZ = claim.getLesserBoundaryCorner().getZ();
    int greaterX = claim.getGreaterBoundaryCorner().getX();
    int greaterY = claim.getGreaterBoundaryCorner().getY();
    int greaterZ = claim.getGreaterBoundaryCorner().getZ();
    if ((clickedX == lesserX || clickedX == greaterX) && (clickedZ == lesserZ || clickedZ == greaterZ)
            && (!claim.isCuboid() || (clickedY == lesserY || clickedY == greaterY))) {
        return true;
    }

    return false;
}
 
Example 3
Source File: ChunkAnvil112.java    From BlueMap with MIT License 6 votes vote down vote up
public String getBlockIdMeta(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0
	
	int blockId = this.blocks[blockByteIndex] & 0xFF;
	
	if (this.add.length > 0) {
		blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8);
	}
	
	int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf);
	String forgeIdMapping = getWorld().getForgeBlockIdMapping(blockId);
	
	return blockId + ":" + blockData + " " + forgeIdMapping;
}
 
Example 4
Source File: ChunkAnvil112.java    From BlueMap with MIT License 6 votes vote down vote up
public BlockState getBlockState(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0
	
	int blockId = this.blocks[blockByteIndex] & 0xFF;
	
	if (this.add.length > 0) {
		blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8);
	}
	
	int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf);
	
	String forgeIdMapping = getWorld().getForgeBlockIdMapping(blockId);
	if (forgeIdMapping != null) {
		return blockIdMapper.get(forgeIdMapping, blockId, blockData);
	} else {
		return blockIdMapper.get(blockId, blockData);
	}
}
 
Example 5
Source File: BlockUtils.java    From GriefPrevention with MIT License 6 votes vote down vote up
public static boolean clickedClaimCorner(GPClaim claim, Vector3i clickedPos) {
    int clickedX = clickedPos.getX();
    int clickedY = clickedPos.getY();
    int clickedZ = clickedPos.getZ();
    int lesserX = claim.getLesserBoundaryCorner().getBlockX();
    int lesserY = claim.getLesserBoundaryCorner().getBlockY();
    int lesserZ = claim.getLesserBoundaryCorner().getBlockZ();
    int greaterX = claim.getGreaterBoundaryCorner().getBlockX();
    int greaterY = claim.getGreaterBoundaryCorner().getBlockY();
    int greaterZ = claim.getGreaterBoundaryCorner().getBlockZ();
    if ((clickedX == lesserX || clickedX == greaterX) && (clickedZ == lesserZ || clickedZ == greaterZ)
            && (!claim.isCuboid() || (clickedY == lesserY || clickedY == greaterY))) {
        return true;
    }

    return false;
}
 
Example 6
Source File: ChunkAnvil116.java    From BlueMap with MIT License 6 votes vote down vote up
public BlockState getBlockState(Vector3i pos) {
	if (blocks.length == 0) return BlockState.AIR;
	
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockIndex = y * 256 + z * 16 + x;
	int longIndex = blockIndex / blocksPerLong;
	int bitIndex = (blockIndex % blocksPerLong) * bitsPerBlock;
	
	long value = blocks[longIndex] >>> bitIndex;

	value = value & (0xFFFFFFFFFFFFFFFFL >>> -bitsPerBlock);
	
	if (value >= palette.length) {
		Logger.global.noFloodWarning("palettewarning", "Got palette value " + value + " but palette has size of " + palette.length + "! (Future occasions of this error will not be logged)");
		return BlockState.MISSING;
	}
	
	return palette[(int) value];
}
 
Example 7
Source File: ChunkAnvil116.java    From BlueMap with MIT License 5 votes vote down vote up
public LightData getLightData(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0

	int blockLight = getByteHalf(this.blockLight[blockHalfByteIndex], largeHalf);
	int skyLight = getByteHalf(this.skyLight[blockHalfByteIndex], largeHalf);
	
	return new LightData(skyLight, blockLight);
}
 
Example 8
Source File: ChunkAnvil116.java    From BlueMap with MIT License 5 votes vote down vote up
@Override
public Biome getBiome(Vector3i pos) {
	int x = (pos.getX() & 0xF) / 4; // Math.floorMod(pos.getX(), 16)
	int z = (pos.getZ() & 0xF) / 4;
	int y = pos.getY() / 4;
	int biomeIntIndex = y * 16 + z * 4 + x;
	
	return biomeIdMapper.get(biomes[biomeIntIndex]);
}
 
Example 9
Source File: ChunkAnvil115.java    From BlueMap with MIT License 5 votes vote down vote up
public BlockState getBlockState(Vector3i pos) {
	if (blocks.length == 0) return BlockState.AIR;
	
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockIndex = y * 256 + z * 16 + x;
	int index = blockIndex * bitsPerBlock;
	int firstLong = index >> 6; // index / 64
	int bitoffset = index & 0x3F; // Math.floorMod(index, 64)
	
	long value = blocks[firstLong] >>> bitoffset;
	
	if (bitoffset > 0 && firstLong + 1 < blocks.length) {
		long value2 = blocks[firstLong + 1];
		value2 = value2 << -bitoffset;
		value = value | value2;
	}
	
	value = value & (0xFFFFFFFFFFFFFFFFL >>> -bitsPerBlock);
	
	if (value >= palette.length) {
		Logger.global.noFloodWarning("palettewarning", "Got palette value " + value + " but palette has size of " + palette.length + " (Future occasions of this error will not be logged)");
		return BlockState.MISSING;
	}
	
	return palette[(int) value];
}
 
Example 10
Source File: BlockGetOperation.java    From Web-API with MIT License 5 votes vote down vote up
@Override
protected void processBlock(World world, Vector3i pos) {
    int x = pos.getX() - min.getX();
    int y = pos.getY() - min.getY();
    int z = pos.getZ() - min.getZ();
    blockStates[x][y][z] = world.getBlock(pos).copy();
}
 
Example 11
Source File: ChunkAnvil113.java    From BlueMap with MIT License 5 votes vote down vote up
public LightData getLightData(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0

	int blockLight = getByteHalf(this.blockLight[blockHalfByteIndex], largeHalf);
	int skyLight = getByteHalf(this.skyLight[blockHalfByteIndex], largeHalf);
	
	return new LightData(skyLight, blockLight);
}
 
Example 12
Source File: ChunkAnvil113.java    From BlueMap with MIT License 5 votes vote down vote up
public BlockState getBlockState(Vector3i pos) {
	if (blocks.length == 0) return BlockState.AIR;
	
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockIndex = y * 256 + z * 16 + x;
	int bitsPerBlock = blocks.length * 64 / 4096; //64 bits per long and 4096 blocks per section
	int index = blockIndex * bitsPerBlock;
	int firstLong = index >> 6; // index / 64
	int bitoffset = index & 0x3F; // Math.floorMod(index, 64)
	
	long value = blocks[firstLong] >>> bitoffset;
	
	if (bitoffset > 0 && firstLong + 1 < blocks.length) {
		long value2 = blocks[firstLong + 1];
		value2 = value2 << -bitoffset;
		value = value | value2;
	}
	
	value = value & (0xFFFFFFFFFFFFFFFFL >>> -bitsPerBlock);
	
	if (value >= palette.length) {
		Logger.global.noFloodWarning("palettewarning", "Got palette value " + value + " but palette has size of " + palette.length + " (Future occasions of this error will not be logged)");
		return BlockState.MISSING;
	}
	
	return palette[(int) value];
}
 
Example 13
Source File: BlockUtils.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static int getClaimBlockCost(World world, Vector3i lesser, Vector3i greater, boolean cuboid) {
    final int claimWidth = greater.getX() - lesser.getX() + 1;
    final int claimHeight = greater.getY() - lesser.getY() + 1;
    final int claimLength = greater.getZ() - lesser.getZ() + 1;
    if (GriefPreventionPlugin.CLAIM_BLOCK_SYSTEM == ClaimBlockSystem.AREA) {
        return claimWidth * claimLength;
    }

    return claimLength * claimWidth * claimHeight;
}
 
Example 14
Source File: MapUpdateHandler.java    From BlueMap with MIT License 5 votes vote down vote up
private void updateChunk(UUID world, Vector2i chunkPos) {
	Vector3i min = new Vector3i(chunkPos.getX() * 16, 0, chunkPos.getY() * 16);
	Vector3i max = min.add(15, 255, 15);
	
	Vector3i xmin = new Vector3i(min.getX(), 0, max.getY());
	Vector3i xmax = new Vector3i(max.getX(), 255, min.getY());
	
	//update all corners so we always update all tiles containing this chunk
	synchronized (updateBuffer) {
		updateBlock(world, min);
		updateBlock(world, max);
		updateBlock(world, xmin);
		updateBlock(world, xmax);
	}
}
 
Example 15
Source File: Vector3iView.java    From Web-API with MIT License 5 votes vote down vote up
public Vector3iView(Vector3i value) {
    super(value);

    this.x = value.getX();
    this.y = value.getY();
    this.z = value.getZ();
}
 
Example 16
Source File: GPClaim.java    From GriefPrevention with MIT License 4 votes vote down vote up
public GPClaim(World world, Vector3i point1, Vector3i point2, ClaimType type, UUID ownerUniqueId, boolean cuboid, GPClaim parent) {
    int smallx, bigx, smally, bigy, smallz, bigz;
    int x1 = point1.getX();
    int x2 = point2.getX();
    int y1 = point1.getY();
    int y2 = point2.getY();
    int z1 = point1.getZ();
    int z2 = point2.getZ();
    // determine small versus big inputs
    if (x1 < x2) {
        smallx = x1;
        bigx = x2;
    } else {
        smallx = x2;
        bigx = x1;
    }

    if (y1 < y2) {
        smally = y1;
        bigy = y2;
    } else {
        smally = y2;
        bigy = y1;
    }

    if (z1 < z2) {
        smallz = z1;
        bigz = z2;
    } else {
        smallz = z2;
        bigz = z1;
    }

    // creative mode claims always go to bedrock
    if (GriefPreventionPlugin.instance.claimModeIsActive(world.getProperties(), ClaimsMode.Creative)) {
        smally = 2;
    }

    this.world = world;
    this.lesserBoundaryCorner = new Location<World>(world, smallx, smally, smallz);
    this.greaterBoundaryCorner = new Location<World>(world, bigx, bigy, bigz);
    if (ownerUniqueId != null) {
        this.ownerUniqueId = ownerUniqueId;
        this.ownerPlayerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(this.world, this.ownerUniqueId);
    }
    this.type = type;
    this.id = UUID.randomUUID();
    this.context = new Context("gp_claim", this.id.toString());
    this.cuboid = cuboid;
    this.parent = parent;
    this.hashCode = this.id.hashCode();
    this.worldClaimManager = GriefPreventionPlugin.instance.dataStore.getClaimWorldManager(this.world.getProperties());
    if (this.type == ClaimType.WILDERNESS) {
        this.wildernessClaim = this;
    } else {
        this.wildernessClaim = this.worldClaimManager.getWildernessClaim();
    }
}
 
Example 17
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onExplosionPrimeEvent(ExplosionPrimeEvent event) {
    final World world = event.getEntity().getLocation().getWorld();
    final Entity source = event.getEntity();
    if (!GDFlags.EXPLOSION_BLOCK && !GDFlags.EXPLOSION_ENTITY) {
        return;
    }
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }
    if (source instanceof Creeper || source instanceof EnderCrystal) {
        return;
    }

    GDCauseStackManager.getInstance().pushCause(source);
    GDTimings.ENTITY_EXPLOSION_PRE_EVENT.startTiming();
    final GDEntity gdEntity = EntityTracker.getCachedEntity(source.getEntityId());
    GDPermissionUser user = null;
    if (gdEntity != null) {
        user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
    }

    final Location location = event.getEntity().getLocation();
    final GDClaim radiusClaim = NMSUtil.getInstance().createClaimFromCenter(location, event.getRadius());
    final GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID());
    final Set<Claim> surroundingClaims = claimManager.findOverlappingClaims(radiusClaim);
    if (surroundingClaims.size() == 0) {
        GDTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTiming();
        return;
    }
    for (Claim claim : surroundingClaims) {
        // Use any location for permission check
        final Vector3i pos = claim.getLesserBoundaryCorner();
        Location targetLocation = new Location(location.getWorld(), pos.getX(), pos.getY(), pos.getZ());
        Tristate blockResult = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.EXPLOSION_BLOCK, source, targetLocation, user, true);
        if (blockResult == Tristate.FALSE) {
            // Check explosion entity
            if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.EXPLOSION_ENTITY, source, targetLocation, user, true) == Tristate.FALSE) {
                event.setCancelled(true);
                break;
            }
        }
    }
    GDTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTiming();
}
 
Example 18
Source File: Vector3iParamConverter.java    From Web-API with MIT License 4 votes vote down vote up
@Override
public String toString(Vector3i value) {
    return value.getX() + "|" + value.getY() + "|" + value.getZ();
}
 
Example 19
Source File: CommandClaimSpawn.java    From GriefDefender with MIT License 4 votes vote down vote up
@CommandAlias("claimspawn")
@Description("Teleports you to claim spawn if available.")
@Syntax("[name] [user]")
@Subcommand("claim spawn")
public void execute(Player player, @Optional String claimName, @Optional OfflinePlayer targetPlayer) {
    final GDPlayerData srcPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GDPlayerData targetPlayerData = null;
    if (targetPlayer != null) {
        targetPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), targetPlayer.getUniqueId());
    } else {
        targetPlayerData = srcPlayerData;
    }

    GDClaim claim = null;
    if (claimName != null) {
        for (Claim playerClaim : targetPlayerData.getInternalClaims()) {
            String name = null;
            Component component = playerClaim.getName().orElse(null);
            if (component != null) {
                name = PlainComponentSerializer.INSTANCE.serialize(component);
                if (claimName.equalsIgnoreCase(name)) {
                    claim = (GDClaim) playerClaim;
                    break;
                }
            }
        }
        if (claim == null) {
            GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_CLAIMNAME_NOT_FOUND,
                    ImmutableMap.of("name", claimName)));
            return;
        }
    } else {
        claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(targetPlayerData, player.getLocation());
    }

    if (!srcPlayerData.canIgnoreClaim(claim) && !claim.isUserTrusted(player, TrustTypes.ACCESSOR) && !player.hasPermission(GDPermissions.COMMAND_DELETE_CLAIMS)) {
        GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ACCESS,
                ImmutableMap.of("player", claim.getOwnerDisplayName())));
        return;
    }

    final Vector3i spawnPos = claim.getData().getSpawnPos().orElse(null);
    if (spawnPos == null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().SPAWN_NOT_SET);
        return;
    }

    final Location spawnLocation = new Location(claim.getWorld(), spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
    int teleportDelay = 0;
    if (GDOptions.isOptionEnabled(Options.PLAYER_TELEPORT_DELAY)) {
        teleportDelay = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.PLAYER_TELEPORT_DELAY, claim);
    }
    if (teleportDelay > 0) {
        srcPlayerData.teleportDelay = teleportDelay + 1;
        srcPlayerData.teleportLocation = spawnLocation;
        return;
    }
    player.teleport(spawnLocation);
    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.SPAWN_TELEPORT,
            ImmutableMap.of(
            "location", spawnPos));
    GriefDefenderPlugin.sendMessage(player, message);
}
 
Example 20
Source File: CommandClaimSpawn.java    From GriefDefender with MIT License 4 votes vote down vote up
@CommandAlias("claimspawn")
@Description("Teleports you to claim spawn if available.")
@Syntax("[name] [user]")
@Subcommand("claim spawn")
public void execute(Player player, @Optional String claimName, @Optional User targetPlayer) {
    final GDPlayerData srcPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GDPlayerData targetPlayerData = null;
    if (targetPlayer != null) {
        targetPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), targetPlayer.getUniqueId());
    } else {
        targetPlayerData = srcPlayerData;
    }

    GDClaim claim = null;
    if (claimName != null) {
        for (Claim playerClaim : targetPlayerData.getInternalClaims()) {
            String name = null;
            Component component = playerClaim.getName().orElse(null);
            if (component != null) {
                name = PlainComponentSerializer.INSTANCE.serialize(component);
                if (claimName.equalsIgnoreCase(name)) {
                    claim = (GDClaim) playerClaim;
                    break;
                }
            }
        }
        if (claim == null) {
            GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_CLAIMNAME_NOT_FOUND,
                    ImmutableMap.of("name", claimName)));
            return;
        }
    } else {
        claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(targetPlayerData, player.getLocation());
    }

    if (!srcPlayerData.canIgnoreClaim(claim) && !claim.isUserTrusted(player, TrustTypes.ACCESSOR) && !player.hasPermission(GDPermissions.COMMAND_DELETE_CLAIMS)) {
        GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ACCESS,
                ImmutableMap.of("player", claim.getOwnerDisplayName())));
        return;
    }

    final Vector3i spawnPos = claim.getData().getSpawnPos().orElse(null);
    if (spawnPos == null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().SPAWN_NOT_SET);
        return;
    }

    final Location<World> spawnLocation = new Location<>(claim.getWorld(), spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
    int teleportDelay = 0;
    if (GDOptions.isOptionEnabled(Options.PLAYER_TELEPORT_DELAY)) {
        teleportDelay = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.PLAYER_TELEPORT_DELAY, claim);
    }
    if (teleportDelay > 0) {
        srcPlayerData.teleportDelay = teleportDelay + 1;
        srcPlayerData.teleportLocation = spawnLocation;
        return;
    }
    player.setLocation(spawnLocation);
    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.SPAWN_TELEPORT,
            ImmutableMap.of(
            "location", spawnPos));
    GriefDefenderPlugin.sendMessage(player, message);
}