Search in sources :

Example 1 with IBuilding

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());
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ResourceLocation(net.minecraft.util.ResourceLocation) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 2 with IBuilding

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();
        }
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with IBuilding

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);
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ColonyViewRemoveMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveMessage) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) World(net.minecraft.world.World) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with IBuilding

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();
            }
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IColony(com.minecolonies.api.colony.IColony) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) World(net.minecraft.world.World)

Example 5 with IBuilding

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);
    }
}
Also used : AbstractBuildingServerMessage(com.minecolonies.coremod.network.messages.server.AbstractBuildingServerMessage) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) IColony(com.minecolonies.api.colony.IColony) IAssignsJob(com.minecolonies.api.colony.buildings.modules.IAssignsJob) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) IAssignsJob(com.minecolonies.api.colony.buildings.modules.IAssignsJob) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)168 BlockPos (net.minecraft.util.math.BlockPos)62 NotNull (org.jetbrains.annotations.NotNull)38 IColony (com.minecolonies.api.colony.IColony)34 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)22 Nullable (org.jetbrains.annotations.Nullable)22 ICitizenData (com.minecolonies.api.colony.ICitizenData)20 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)20 ItemStack (net.minecraft.item.ItemStack)18 World (net.minecraft.world.World)18 TileEntity (net.minecraft.tileentity.TileEntity)14 ArrayList (java.util.ArrayList)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)12 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)10 ItemStorage (com.minecolonies.api.crafting.ItemStorage)8 InventoryUtils (com.minecolonies.api.util.InventoryUtils)8 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)8 ResourceLocation (net.minecraft.util.ResourceLocation)8 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)8 IItemHandler (net.minecraftforge.items.IItemHandler)8