Search in sources :

Example 1 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

the class AbstractBuilding method calculateCorners.

@Override
public void calculateCorners() {
    final AbstractTileEntityColonyBuilding te = getTileEntity();
    if (te != null && !te.getSchematicName().isEmpty()) {
        setCorners(te.getInWorldCorners().getA(), te.getInWorldCorners().getB());
        return;
    }
    final WorkOrderBuildBuilding workOrder = new WorkOrderBuildBuilding(this, Math.max(1, getBuildingLevel()));
    final LoadOnlyStructureHandler wrapper = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), workOrder.getStructureName(), new PlacementSettings(), true);
    if (!wrapper.hasBluePrint()) {
        setCorners(getPosition(), getPosition());
        return;
    }
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(this.getPosition(), colony.getWorld(), wrapper.getBluePrint(), workOrder.getRotation(colony.getWorld()), workOrder.isMirrored());
    this.setCorners(corners.getA(), corners.getB());
}
Also used : WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 2 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

the class ItemResourceScroll method useOn.

/**
 * Used when clicking on block in world.
 *
 * @param ctx the context of use.
 * @return the result
 */
@Override
@NotNull
public ActionResultType useOn(ItemUseContext ctx) {
    final ItemStack scroll = ctx.getPlayer().getItemInHand(ctx.getHand());
    final CompoundNBT compound = checkForCompound(scroll);
    TileEntity entity = ctx.getLevel().getBlockEntity(ctx.getClickedPos());
    if (entity instanceof TileEntityColonyBuilding) {
        compound.putInt(TAG_COLONY_ID, ((AbstractTileEntityColonyBuilding) entity).getColonyId());
        BlockPosUtil.write(compound, TAG_BUILDER, ((AbstractTileEntityColonyBuilding) entity).getPosition());
        if (!ctx.getLevel().isClientSide) {
            LanguageHandler.sendPlayerMessage(ctx.getPlayer(), TranslationConstants.COM_MINECOLONIES_SCROLL_BUILDER_SET, ((AbstractTileEntityColonyBuilding) entity).getColony().getName());
        }
    } else if (ctx.getLevel().isClientSide) {
        openWindow(compound, ctx.getPlayer());
    }
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

the class AbstractEntityAIStructureWithWorkOrder method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    if (job.getBlueprint() == null && job.hasWorkOrder()) {
        // fix for bad structures
        job.complete();
    }
    if (job.getBlueprint() == null) {
        return;
    }
    final String structureName = job.getBlueprint().getName();
    final WorkOrderBuildDecoration wo = job.getWorkOrder();
    if (wo instanceof WorkOrderBuildBuilding) {
        sendCompletionMessage(wo);
        WorkOrderBuild wob = (WorkOrderBuild) wo;
        String buildingName = wo.getStructureName();
        buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.lastIndexOf(String.valueOf(wob.getUpgradeLevel())));
        job.getColony().getEventDescriptionManager().addEventDescription(wob.getUpgradeLevel() > 1 ? new BuildingUpgradedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()) : new BuildingBuiltEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
    } else if (wo instanceof WorkOrderBuildRemoval) {
        worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_DECONSTRUCTION_COMPLETE, structureName);
        WorkOrderBuild wob = (WorkOrderBuild) wo;
        String buildingName = wo.getStructureName();
        buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.indexOf(String.valueOf(wob.getUpgradeLevel())));
        job.getColony().getEventDescriptionManager().addEventDescription(new BuildingDeconstructedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
    } else {
        sendCompletionMessage(wo);
    }
    if (wo == null) {
        Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
    } else {
        job.complete();
        if (wo instanceof WorkOrderBuildBuilding) {
            final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
            } else {
                // Normally levels are done through the schematic data, but incase it is missing we do it manually here.
                final TileEntity te = worker.level.getBlockEntity(building.getID());
                if (te instanceof AbstractTileEntityColonyBuilding && ((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
                    building.onUpgradeComplete(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
                    building.setBuildingLevel(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
                }
            }
        } else if (wo instanceof WorkOrderBuildRemoval) {
            final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
            } else {
                building.setDeconstructed();
            }
        }
    }
    getOwnBuilding().resetNeededResources();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingDeconstructedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingDeconstructedEvent) BuildingBuiltEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingBuiltEvent) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BuildingUpgradedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingUpgradedEvent)

Example 4 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by ldtteam.

the class AbstractBuilding method getTileEntity.

@Override
public AbstractTileEntityColonyBuilding getTileEntity() {
    if (tileEntity != null && tileEntity.isRemoved()) {
        tileEntity = null;
    }
    if ((tileEntity == null) && colony != null && colony.getWorld() != null && getPosition() != null && WorldUtil.isBlockLoaded(colony.getWorld(), getPosition()) && !(colony.getWorld().getBlockState(getPosition()).getBlock() instanceof AirBlock) && colony.getWorld().getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut) {
        final TileEntity te = colony.getWorld().getBlockEntity(getPosition());
        if (te instanceof TileEntityColonyBuilding) {
            tileEntity = (TileEntityColonyBuilding) te;
            if (tileEntity.getBuilding() == null) {
                tileEntity.setColony(colony);
                tileEntity.setBuilding(this);
            }
        } else {
            Log.getLogger().error("Somehow the wrong TileEntity is at the location where the building should be!", new Exception());
            Log.getLogger().error("Trying to restore order!");
            final AbstractTileEntityColonyBuilding tileEntityColonyBuilding = new TileEntityColonyBuilding(MinecoloniesTileEntities.BUILDING);
            colony.getWorld().setBlockEntity(getPosition(), tileEntityColonyBuilding);
            this.tileEntity = tileEntityColonyBuilding;
        }
    }
    return tileEntity;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AirBlock(net.minecraft.block.AirBlock) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut)

Example 5 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by ldtteam.

the class AbstractBuilding method calculateCorners.

@Override
public void calculateCorners() {
    final AbstractTileEntityColonyBuilding te = getTileEntity();
    if (te != null && !te.getSchematicName().isEmpty()) {
        setCorners(te.getInWorldCorners().getA(), te.getInWorldCorners().getB());
        return;
    }
    final WorkOrderBuildBuilding workOrder = new WorkOrderBuildBuilding(this, Math.max(1, getBuildingLevel()));
    final LoadOnlyStructureHandler wrapper = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), workOrder.getStructureName(), new PlacementSettings(), true);
    if (!wrapper.hasBluePrint()) {
        setCorners(getPosition(), getPosition());
        return;
    }
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(this.getPosition(), colony.getWorld(), wrapper.getBluePrint(), workOrder.getRotation(colony.getWorld()), workOrder.isMirrored());
    this.setCorners(corners.getA(), corners.getB());
}
Also used : WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Aggregations

AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)20 TileEntity (net.minecraft.tileentity.TileEntity)16 TileEntityColonyBuilding (com.minecolonies.api.tileentities.TileEntityColonyBuilding)12 ItemStack (net.minecraft.item.ItemStack)8 NotNull (org.jetbrains.annotations.NotNull)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)4 World (net.minecraft.world.World)4 AirBlock (net.minecraft.block.AirBlock)3 BlockPos (net.minecraft.util.math.BlockPos)3 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)2 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 IColony (com.minecolonies.api.colony.IColony)2 IWareHouse (com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery)2