Search in sources :

Example 1 with EntityLocation

use of com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation in project minecolonies by ldtteam.

the class AbstractBuildingGuards method getRallyLocation.

@Override
@Nullable
public ILocation getRallyLocation() {
    if (rallyLocation == null) {
        return null;
    }
    boolean outOfRange = false;
    final IColony colonyAtPosition = IColonyManager.getInstance().getColonyByPosFromDim(rallyLocation.getDimension(), rallyLocation.getInDimensionLocation());
    if (colonyAtPosition == null || colonyAtPosition.getID() != colony.getID()) {
        outOfRange = true;
    }
    if (rallyLocation instanceof EntityLocation) {
        final PlayerEntity player = ((EntityLocation) rallyLocation).getPlayerEntity();
        if (player == null) {
            setRallyLocation(null);
            return null;
        }
        if (outOfRange) {
            LanguageHandler.sendPlayerMessage(player, "item.minecolonies.banner_rally_guards.outofrange");
            setRallyLocation(null);
            return null;
        }
        final int size = player.inventory.getContainerSize();
        for (int i = 0; i < size; i++) {
            final ItemStack stack = player.inventory.getItem(i);
            if (stack.getItem() instanceof ItemBannerRallyGuards) {
                if (((ItemBannerRallyGuards) (stack.getItem())).isActiveForGuardTower(stack, this)) {
                    return rallyLocation;
                }
            }
        }
        // if the user moves the banner around in the inventory.
        return null;
    }
    return rallyLocation;
}
Also used : EntityLocation(com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation) IColony(com.minecolonies.api.colony.IColony) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ItemBannerRallyGuards(com.minecolonies.coremod.items.ItemBannerRallyGuards) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with EntityLocation

use of com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation in project minecolonies by ldtteam.

the class ItemBannerRallyGuards method broadcastPlayerToRally.

/**
 * Broadcasts the player all the guardtowers rallied by the item are supposed to follow.
 *
 * @param banner   The banner that should broadcast
 * @param playerIn The player to follow. Can be null, if the towers should revert to "normal" mode
 * @return The number of guards rallied
 */
public static int broadcastPlayerToRally(final ItemStack banner, final World worldIn, @Nullable final PlayerEntity playerIn) {
    if (worldIn.isClientSide()) {
        Log.getLogger().error("Tried to run server-side function #broadcastPlayerToRally() on the client-side!");
        return 0;
    }
    @Nullable ILocation rallyTarget = null;
    if (!isActive(banner) || playerIn == null) {
        rallyTarget = null;
    } else {
        rallyTarget = new EntityLocation(playerIn.getUUID());
    }
    int numGuards = 0;
    for (final ILocation guardTowerLocation : getGuardTowerLocations(banner)) {
        // Note: getCurrentServer().getWorld() must be used here because MineColonies.proxy.getWorld() fails on single player worlds
        // We are sure we are on the server-side in this function though, so it's fine.
        final IGuardBuilding building = getGuardBuilding(ServerLifecycleHooks.getCurrentServer().getLevel(guardTowerLocation.getDimension()), guardTowerLocation.getInDimensionLocation());
        // Safely ignore this case, the player must remove the tower from the rallying list manually.
        if (building != null && (playerIn == null || building.getColony().getPermissions().hasPermission(playerIn, Action.RALLY_GUARDS))) {
            building.setRallyLocation(rallyTarget);
            numGuards += building.getAllAssignedCitizen().size();
        }
    }
    return numGuards;
}
Also used : IGuardBuilding(com.minecolonies.api.colony.buildings.IGuardBuilding) EntityLocation(com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) Nullable(javax.annotation.Nullable)

Example 3 with EntityLocation

use of com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation in project minecolonies by Minecolonies.

the class ItemBannerRallyGuards method broadcastPlayerToRally.

/**
 * Broadcasts the player all the guardtowers rallied by the item are supposed to follow.
 *
 * @param banner   The banner that should broadcast
 * @param playerIn The player to follow. Can be null, if the towers should revert to "normal" mode
 * @return The number of guards rallied
 */
public static int broadcastPlayerToRally(final ItemStack banner, final World worldIn, @Nullable final PlayerEntity playerIn) {
    if (worldIn.isClientSide()) {
        Log.getLogger().error("Tried to run server-side function #broadcastPlayerToRally() on the client-side!");
        return 0;
    }
    @Nullable ILocation rallyTarget = null;
    if (!isActive(banner) || playerIn == null) {
        rallyTarget = null;
    } else {
        rallyTarget = new EntityLocation(playerIn.getUUID());
    }
    int numGuards = 0;
    for (final ILocation guardTowerLocation : getGuardTowerLocations(banner)) {
        // Note: getCurrentServer().getWorld() must be used here because MineColonies.proxy.getWorld() fails on single player worlds
        // We are sure we are on the server-side in this function though, so it's fine.
        final IGuardBuilding building = getGuardBuilding(ServerLifecycleHooks.getCurrentServer().getLevel(guardTowerLocation.getDimension()), guardTowerLocation.getInDimensionLocation());
        // Safely ignore this case, the player must remove the tower from the rallying list manually.
        if (building != null && (playerIn == null || building.getColony().getPermissions().hasPermission(playerIn, Action.RALLY_GUARDS))) {
            building.setRallyLocation(rallyTarget);
            numGuards += building.getAllAssignedCitizen().size();
        }
    }
    return numGuards;
}
Also used : IGuardBuilding(com.minecolonies.api.colony.buildings.IGuardBuilding) EntityLocation(com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) Nullable(javax.annotation.Nullable)

Example 4 with EntityLocation

use of com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation in project minecolonies by Minecolonies.

the class AbstractBuildingGuards method getRallyLocation.

@Override
@Nullable
public ILocation getRallyLocation() {
    if (rallyLocation == null) {
        return null;
    }
    boolean outOfRange = false;
    final IColony colonyAtPosition = IColonyManager.getInstance().getColonyByPosFromDim(rallyLocation.getDimension(), rallyLocation.getInDimensionLocation());
    if (colonyAtPosition == null || colonyAtPosition.getID() != colony.getID()) {
        outOfRange = true;
    }
    if (rallyLocation instanceof EntityLocation) {
        final PlayerEntity player = ((EntityLocation) rallyLocation).getPlayerEntity();
        if (player == null) {
            setRallyLocation(null);
            return null;
        }
        if (outOfRange) {
            MessageUtils.format(WARNING_RALLYING_POINT_OUT_OF_RANGE).sendTo(player);
            setRallyLocation(null);
            return null;
        }
        final int size = player.inventory.getContainerSize();
        for (int i = 0; i < size; i++) {
            final ItemStack stack = player.inventory.getItem(i);
            if (stack.getItem() instanceof ItemBannerRallyGuards) {
                if (((ItemBannerRallyGuards) (stack.getItem())).isActiveForGuardTower(stack, this)) {
                    return rallyLocation;
                }
            }
        }
        // if the user moves the banner around in the inventory.
        return null;
    }
    return rallyLocation;
}
Also used : EntityLocation(com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation) IColony(com.minecolonies.api.colony.IColony) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ItemBannerRallyGuards(com.minecolonies.coremod.items.ItemBannerRallyGuards) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

EntityLocation (com.minecolonies.coremod.colony.requestsystem.locations.EntityLocation)4 IColony (com.minecolonies.api.colony.IColony)2 IGuardBuilding (com.minecolonies.api.colony.buildings.IGuardBuilding)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 ItemBannerRallyGuards (com.minecolonies.coremod.items.ItemBannerRallyGuards)2 Nullable (javax.annotation.Nullable)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 Nullable (org.jetbrains.annotations.Nullable)2