Search in sources :

Example 61 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class BuildingBarracks method registerBlockPosition.

@Override
public void registerBlockPosition(@NotNull final BlockState block, @NotNull final BlockPos pos, @NotNull final World world) {
    super.registerBlockPosition(block, pos, world);
    if (block.getBlock() == ModBlocks.blockHutBarracksTower) {
        final IBuilding building = getColony().getBuildingManager().getBuilding(pos);
        if (building instanceof BuildingBarracksTower) {
            building.setStyle(this.getStyle());
            ((BuildingBarracksTower) building).addBarracks(getPosition());
            if (!towers.contains(pos)) {
                towers.add(pos);
            }
        }
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding)

Example 62 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class BuildingBarracksTower method onUpgradeComplete.

@Override
public void onUpgradeComplete(final int newLevel) {
    super.onUpgradeComplete(newLevel);
    final IBuilding barrack = colony.getBuildingManager().getBuilding(barracks);
    if (barrack == null) {
        return;
    }
    ChunkDataHelper.claimBuildingChunks(colony, true, barracks, barrack.getClaimRadius(newLevel));
    if (newLevel == barrack.getMaxBuildingLevel()) {
        boolean allUpgraded = true;
        for (BlockPos tower : ((BuildingBarracks) barrack).getTowers()) {
            Log.getLogger().info("Upgraded: " + allUpgraded);
            if (colony.getBuildingManager().getBuilding(tower).getBuildingLevel() != barrack.getMaxBuildingLevel()) {
                allUpgraded = false;
            }
        }
        if (allUpgraded) {
            AdvancementUtils.TriggerAdvancementPlayersForColony(colony, AdvancementTriggers.ALL_TOWERS::trigger);
        }
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockPos(net.minecraft.util.math.BlockPos)

Example 63 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class BuildingDataManager method createFrom.

@Override
public IBuilding createFrom(final IColony colony, final CompoundNBT compound) {
    final ResourceLocation type = new ResourceLocation(compound.getString(TAG_BUILDING_TYPE));
    final BlockPos pos = BlockPosUtil.read(compound, TAG_LOCATION);
    IBuilding building = this.createFrom(colony, pos, type);
    try {
        building.deserializeNBT(compound);
    } catch (final RuntimeException ex) {
        Log.getLogger().error(String.format("A Building %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author", type, building.getClass().getName()), ex);
        building = null;
    }
    return building;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos)

Example 64 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class AbstractWorkOrder method migrateOldNbt.

// TODO: In 1.19 remove this method as this is purely for backwards compatibility with old class mappings
private static void migrateOldNbt(final CompoundNBT compound, IWorkManager manager) {
    // When the old TAG_BUILDING tag no longer exists in the compound NBT, it means the work order has already migrated
    if (!compound.contains(TAG_BUILDING_OLD) && !compound.getString(TAG_TYPE).equals("removal")) {
        return;
    }
    // Migrate tags
    // Re-write the location
    BlockPosUtil.write(compound, TAG_LOCATION, BlockPosUtil.read(compound, TAG_BUILDING_OLD));
    // Re-write the rotation
    compound.putInt(TAG_ROTATION, compound.getInt(TAG_BUILDING_ROTATION_OLD));
    // Re-write the mirrored state
    compound.putBoolean(TAG_ROTATION, compound.getBoolean(TAG_BUILDING_ROTATION_OLD));
    // Re-write the mirrored state
    compound.putInt(TAG_AMOUNT_OF_RESOURCES, compound.getInt(TAG_AMOUNT_OF_RESOURCES_OLD));
    // Re-write the current and upgrade level
    int targetLevel = compound.getInt(TAG_UPGRADE_LEVEL_OLD);
    // If the tag is removal it's indicating an old removal request
    if (compound.getString(TAG_TYPE).equals("removal")) {
        compound.putString(TAG_TYPE, "building");
        compound.putInt(TAG_WO_TYPE, WorkOrderType.REMOVE.ordinal());
        compound.putInt(TAG_CURRENT_LEVEL, targetLevel);
        compound.putInt(TAG_TARGET_LEVEL, 0);
    } else if (targetLevel == 1) {
        compound.putInt(TAG_WO_TYPE, WorkOrderType.BUILD.ordinal());
        compound.putInt(TAG_CURRENT_LEVEL, 0);
        compound.putInt(TAG_TARGET_LEVEL, targetLevel);
    } else if (targetLevel > 1) {
        IBuilding building = manager.getColony().getBuildingManager().getBuilding(BlockPosUtil.read(compound, TAG_LOCATION));
        TileEntity entity = manager.getColony().getWorld().getBlockEntity(BlockPosUtil.read(compound, TAG_LOCATION));
        if (building != null) {
            if (building.getBuildingLevel() == targetLevel) {
                compound.putInt(TAG_WO_TYPE, WorkOrderType.REPAIR.ordinal());
            } else {
                compound.putInt(TAG_WO_TYPE, WorkOrderType.UPGRADE.ordinal());
            }
        } else if (entity instanceof TileEntityDecorationController) {
            TileEntityDecorationController dEntity = (TileEntityDecorationController) entity;
            if (dEntity.getTier() == targetLevel) {
                compound.putInt(TAG_WO_TYPE, WorkOrderType.REPAIR.ordinal());
            } else {
                compound.putInt(TAG_WO_TYPE, WorkOrderType.UPGRADE.ordinal());
            }
        }
        compound.putInt(TAG_TARGET_LEVEL, targetLevel);
        compound.putInt(TAG_CURRENT_LEVEL, building.getBuildingLevel());
    }
    // Remove old NBT
    compound.remove(TAG_BUILDING_OLD);
    compound.remove(TAG_BUILDING_ROTATION_OLD);
    compound.remove(TAG_IS_MIRRORED_OLD);
    compound.remove(TAG_AMOUNT_OF_RESOURCES_OLD);
    compound.remove(TAG_UPGRADE_LEVEL_OLD);
    // Building specific info
    IBuilding building = manager.getColony().getBuildingManager().getBuilding(BlockPosUtil.read(compound, TAG_LOCATION));
    if (building != null) {
        final WorkOrderBuilding test = new WorkOrderBuilding();
        test.setCustomName(building);
        compound.putString("customName", test.getCustomName());
        compound.putString("customParentName", test.getCustomParentName());
        compound.putString("parentTranslationKey", test.getParentTranslationKey());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController)

Example 65 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class WorkOrderBuilding method onRemoved.

@Override
public void onRemoved(final IColony colony) {
    final IBuilding building = colony.getBuildingManager().getBuilding(getLocation());
    if (building != null) {
        building.markDirty();
        ConstructionTapeHelper.removeConstructionTape(building.getCorners(), colony.getWorld());
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)187 BlockPos (net.minecraft.util.math.BlockPos)71 NotNull (org.jetbrains.annotations.NotNull)45 IColony (com.minecolonies.api.colony.IColony)37 Nullable (org.jetbrains.annotations.Nullable)26 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)24 ICitizenData (com.minecolonies.api.colony.ICitizenData)22 World (net.minecraft.world.World)20 ItemStack (net.minecraft.item.ItemStack)19 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)19 TileEntity (net.minecraft.tileentity.TileEntity)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)15 ArrayList (java.util.ArrayList)14 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)10 ItemStorage (com.minecolonies.api.crafting.ItemStorage)9 ResourceLocation (net.minecraft.util.ResourceLocation)9 IItemHandler (net.minecraftforge.items.IItemHandler)9 InventoryUtils (com.minecolonies.api.util.InventoryUtils)8 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)8 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)8