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);
}
}
}
}
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);
}
}
}
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;
}
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());
}
}
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());
}
}
Aggregations