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;
}
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;
}
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;
}
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;
}
Aggregations