use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class AbstractBuilding method requestUpgrade.
/**
* Requests an upgrade for the current building.
*
* @param player the requesting player.
* @param builder the assigned builder.
*/
@Override
public void requestUpgrade(final PlayerEntity player, final BlockPos builder) {
final ResourceLocation hutResearch = colony.getResearchManager().getResearchEffectIdFrom(this.getBuildingType().getBuildingBlock());
if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearchEffect(hutResearch) && colony.getResearchManager().getResearchEffects().getEffectStrength(hutResearch) < 1) {
player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.research.havetounlock"), player.getUUID());
return;
}
if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearchEffect(hutResearch) && (colony.getResearchManager().getResearchEffects().getEffectStrength(hutResearch) <= getBuildingLevel())) {
player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.research.unlocktoupgrade"), player.getUUID());
return;
}
final IBuilding parentBuilding = colony.getBuildingManager().getBuilding(getParent());
if (getBuildingLevel() < getMaxBuildingLevel() && (parentBuilding == null || getBuildingLevel() < parentBuilding.getBuildingLevel())) {
requestWorkOrder(getBuildingLevel() + 1, builder, false);
} else {
player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.worker.noupgrade"), player.getUUID());
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class AbstractBuilding method destroy.
/**
* Destroys the block. Calls {@link #onDestroyed()}.
*/
@Override
public final void destroy() {
onDestroyed();
colony.getBuildingManager().removeBuilding(this, colony.getPackageManager().getCloseSubscribers());
colony.getRequestManager().getDataStoreManager().remove(this.rsDataStoreToken);
for (final BlockPos childpos : getChildren()) {
final IBuilding building = colony.getBuildingManager().getBuilding(childpos);
if (building != null) {
building.destroy();
}
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class ColonyManager method deleteColony.
/**
* Delete a colony and purge all buildings and citizens.
*
* @param iColony the colony to destroy.
* @param canDestroy if the building outlines should be destroyed as well.
*/
private void deleteColony(@Nullable final IColony iColony, final boolean canDestroy) {
if (!(iColony instanceof Colony)) {
return;
}
final Colony colony = (Colony) iColony;
final int id = colony.getID();
final World world = colony.getWorld();
if (world == null) {
Log.getLogger().warn("Deleting Colony " + id + " errored: World is Null");
return;
}
try {
ChunkDataHelper.claimColonyChunks(world, false, id, colony.getCenter(), colony.getDimension());
Log.getLogger().info("Removing citizens for " + id);
for (final ICitizenData citizenData : new ArrayList<>(colony.getCitizenManager().getCitizens())) {
Log.getLogger().info("Kill Citizen " + citizenData.getName());
citizenData.getEntity().ifPresent(entityCitizen -> entityCitizen.die(CONSOLE_DAMAGE_SOURCE));
}
Log.getLogger().info("Removing buildings for " + id);
for (final IBuilding building : new ArrayList<>(colony.getBuildingManager().getBuildings().values())) {
try {
final BlockPos location = building.getPosition();
Log.getLogger().info("Delete Building at " + location);
if (canDestroy) {
building.deconstruct();
}
building.destroy();
if (world.getBlockState(location).getBlock() instanceof AbstractBlockHut) {
Log.getLogger().info("Found Block, deleting " + world.getBlockState(location).getBlock());
world.removeBlock(location, false);
}
} catch (final Exception ex) {
Log.getLogger().warn("Something went wrong deleting a building while deleting the colony!", ex);
}
}
try {
MinecraftForge.EVENT_BUS.unregister(colony.getEventHandler());
} catch (final NullPointerException e) {
Log.getLogger().warn("Can't unregister the event handler twice");
}
Log.getLogger().info("Deleting colony: " + colony.getID());
final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).resolve().orElse(null);
if (cap == null) {
Log.getLogger().warn(MISSING_WORLD_CAP_MESSAGE);
return;
}
cap.deleteColony(id);
BackUpHelper.markColonyDeleted(colony.getID(), colony.getDimension());
colony.getImportantMessageEntityPlayers().forEach(player -> Network.getNetwork().sendToPlayer(new ColonyViewRemoveMessage(colony.getID(), colony.getDimension()), (ServerPlayerEntity) player));
Log.getLogger().info("Successfully deleted colony: " + id);
} catch (final RuntimeException e) {
Log.getLogger().warn("Deleting Colony " + id + " errored:", e);
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class DirectPlaceMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final ServerPlayerEntity player = ctxIn.getSender();
final World world = player.getCommandSenderWorld();
final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, pos);
if ((colony == null && state.getBlock() == ModBlocks.blockHutTownHall) || (colony != null && colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS))) {
final CompoundNBT compound = stack.getTag();
if (colony != null && compound != null && compound.contains(TAG_COLONY_ID) && colony.getID() != compound.getInt(TAG_COLONY_ID)) {
LanguageHandler.sendPlayerMessage(player, WRONG_COLONY, compound.getInt(TAG_COLONY_ID));
return;
}
player.getCommandSenderWorld().setBlockAndUpdate(pos, state);
InventoryUtils.reduceStackInItemHandler(new InvWrapper(player.inventory), stack);
state.getBlock().setPlacedBy(world, pos, state, player, stack);
if (compound != null && compound.contains(TAG_OTHER_LEVEL)) {
final IBuilding building = colony.getBuildingManager().getBuilding(pos);
if (building != null) {
building.setBuildingLevel(compound.getInt(TAG_OTHER_LEVEL));
building.setDeconstructed();
}
}
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class HireFireMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final ICitizenData citizen = colony.getCitizenManager().getCivilian(citizenID);
citizen.setPaused(false);
if (hire) {
building.getModuleMatching(IAssignsJob.class, m -> m.getJobEntry() == entry).assignCitizen(citizen);
} else {
building.getModuleMatching(IAssignsJob.class, m -> m.getJobEntry() == entry).removeCitizen(citizen);
}
}
Aggregations