use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method getWareHouse.
/**
* Gets the colony's warehouse for the Deliveryman.
*/
public BuildingWareHouse getWareHouse() {
final Map<BlockPos, AbstractBuilding> buildings = job.getColony().getBuildingManager().getBuildings();
for (final AbstractBuilding building : buildings.values()) {
if (building == null) {
continue;
}
final Colony buildingColony = building.getColony();
final Colony ownColony = worker.getColony();
if (building instanceof BuildingWareHouse && ownColony != null && buildingColony != null && buildingColony.getID() == ownColony.getID() && ((BuildingWareHouse) building).registerWithWareHouse((BuildingDeliveryman) this.getOwnBuilding())) {
return (BuildingWareHouse) building;
}
}
return null;
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method searchAndAddFields.
/**
* Searches and adds a field that has not been taken yet for the farmer and then adds it to the list.
*/
private void searchAndAddFields() {
final Colony colony = worker.getColony();
if (colony != null) {
@Nullable final ScarecrowTileEntity newField = colony.getBuildingManager().getFreeField(worker.getCitizenData().getId(), world);
if (newField != null && getOwnBuilding() != null) {
newField.setOwner(worker.getCitizenData().getId());
newField.setTaken(true);
newField.markDirty();
getOwnBuilding().addFarmerFields(newField.getPos());
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ShowColonyInfoCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
int colonyId = getIthArgument(args, 0, -1);
IColony tempColony = ColonyManager.getColony(colonyId);
if (colonyId == -1 && args.length >= 1) {
final GameProfile playerProfile = server.getPlayerProfileCache().getGameProfileForUsername(args[0]);
if (playerProfile != null) {
tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), playerProfile.getId());
}
}
if (sender.getCommandSenderEntity() != null) {
final UUID mayorID = sender.getCommandSenderEntity().getUniqueID();
if (tempColony == null) {
tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
}
if (tempColony != null) {
colonyId = tempColony.getID();
}
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, SHOWCOLONYINFO, colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
if (tempColony == null) {
if (colonyId == -1 && args.length != 0) {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, args[0])));
} else {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
}
return;
}
final Colony colony = ColonyManager.getColony(tempColony.getID());
if (colony == null) {
if (colonyId == -1 && args.length != 0) {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, args[0])));
} else {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
}
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class AbstractBuildingWorker method getHandlers.
/**
* Get all handlers accociated with this building.
* @return the handlers of the building + citizen.
*/
public List<IItemHandler> getHandlers() {
final Colony colony = getColony();
if (this.getWorkerEntities().isEmpty() || colony == null || colony.getWorld() == null) {
return Collections.emptyList();
}
final List<IItemHandler> handlers = new ArrayList<>();
for (final CitizenData workerEntity : this.getWorker()) {
handlers.add(new InvWrapper(workerEntity.getInventory()));
}
handlers.add(new InvWrapper(getTileEntity()));
for (final BlockPos pos : getAdditionalCountainers()) {
final TileEntity entity = colony.getWorld().getTileEntity(pos);
if (entity != null) {
handlers.addAll(InventoryUtils.getItemHandlersFromProvider(entity));
}
}
return handlers;
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class EventHandler method onEnteringChunk.
/**
* Event called when the player enters a new chunk.
* @param event the event.
*/
@SubscribeEvent
public void onEnteringChunk(@NotNull final PlayerEvent.EnteringChunk event) {
final Entity entity = event.getEntity();
// Add nearby players
if (entity instanceof EntityPlayerMP && entity.dimension == 0) {
final World world = entity.getEntityWorld();
final Chunk newChunk = world.getChunkFromChunkCoords(event.getNewChunkX(), event.getNewChunkZ());
ColonyManager.loadChunk(newChunk, entity.world);
final IColonyTagCapability newCloseColonies = newChunk.getCapability(CLOSE_COLONY_CAP, null);
MineColonies.getNetwork().sendToAll(new UpdateChunkCapabilityMessage(newCloseColonies, newChunk.x, newChunk.z));
@NotNull final EntityPlayerMP player = (EntityPlayerMP) entity;
final Chunk oldChunk = world.getChunkFromChunkCoords(event.getOldChunkX(), event.getOldChunkZ());
final IColonyTagCapability oldCloseColonies = oldChunk.getCapability(CLOSE_COLONY_CAP, null);
// Add new subscribers to colony.
for (final int colonyId : newCloseColonies.getAllCloseColonies()) {
final Colony colony = ColonyManager.getColony(colonyId);
if (colony != null) {
colony.getPackageManager().addSubscribers(player);
}
}
// Remove old subscribers from colony.
for (final int colonyId : oldCloseColonies.getAllCloseColonies()) {
if (!newCloseColonies.getAllCloseColonies().contains(colonyId)) {
final Colony colony = ColonyManager.getColony(colonyId);
if (colony != null) {
colony.getPackageManager().removeSubscriber(player);
}
}
}
if (newCloseColonies.getOwningColony() != oldCloseColonies.getOwningColony()) {
if (newCloseColonies.getOwningColony() == 0) {
final Colony colony = ColonyManager.getColony(oldCloseColonies.getOwningColony());
if (colony != null) {
colony.removeVisitingPlayer(player);
}
return;
}
final Colony colony = ColonyManager.getColony(newCloseColonies.getOwningColony());
if (colony != null) {
colony.addVisitingPlayer(player);
}
}
}
}
Aggregations