Search in sources :

Example 1 with IRSComponent

use of com.minecolonies.api.colony.buildings.IRSComponent in project minecolonies by ldtteam.

the class BuildingManager method addNewBuilding.

@Override
public IBuilding addNewBuilding(@NotNull final AbstractTileEntityColonyBuilding tileEntity, final World world) {
    tileEntity.setColony(colony);
    if (!buildings.containsKey(tileEntity.getPosition())) {
        @Nullable final IBuilding building = IBuildingDataManager.getInstance().createFrom(colony, tileEntity);
        if (building != null) {
            addBuilding(building);
            tileEntity.setBuilding(building);
            building.upgradeBuildingLevelToSchematicData();
            Log.getLogger().info(String.format("Colony %d - new AbstractBuilding for %s at %s", colony.getID(), tileEntity.getBlockState().getClass(), tileEntity.getPosition()));
            building.setIsMirrored(tileEntity.isMirrored());
            if (!tileEntity.getStyle().isEmpty()) {
                building.setStyle(tileEntity.getStyle());
            } else {
                building.setStyle(colony.getStyle());
            }
            if (world != null && !(building instanceof IRSComponent)) {
                building.onPlacement();
                ConstructionTapeHelper.placeConstructionTape(building.getCorners(), world);
            }
            colony.getRequestManager().onProviderAddedToColony(building);
            setMaxChunk(building);
        } else {
            Log.getLogger().error(String.format("Colony %d unable to create AbstractBuilding for %s at %s", colony.getID(), tileEntity.getBlockState().getClass(), tileEntity.getPosition()), new Exception());
        }
        colony.getCitizenManager().calculateMaxCitizens();
        colony.getPackageManager().updateSubscribers();
        return building;
    }
    return null;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IRSComponent(com.minecolonies.api.colony.buildings.IRSComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IRSComponent

use of com.minecolonies.api.colony.buildings.IRSComponent in project minecolonies by ldtteam.

the class BuildToolPasteMessage method setupBuilding.

/**
 * setup the building once it has been placed.
 *
 * @param world    World the hut is being placed into.
 * @param player   Who placed the hut.
 * @param sn       The name of the structure.
 * @param rotation The number of times the structure should be rotated.
 * @param buildPos The location the hut is being placed.
 * @param mirror   Whether or not the strcture is mirrored.
 */
private static void setupBuilding(@NotNull final World world, @NotNull final PlayerEntity player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    @Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(world, buildPos);
    if (building == null) {
        Log.getLogger().error("BuildTool: building is null!", new Exception());
    } else {
        if (building.getTileEntity() != null) {
            final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, buildPos);
            if (colony == null) {
                Log.getLogger().info("No colony for " + player.getName().getString());
            } else {
                building.getTileEntity().setColony(colony);
            }
        }
        // Don't set the building level here; that will be set later in
        // readSchematicDataFromNBT (provided that the schematic has
        // TAG_BLUEPRINTDATA, but buildings always should).  This allows
        // level 0 -> N upgrade events to properly be triggered on paste.
        building.setStyle(sn.getStyle());
        if (!(building instanceof IRSComponent)) {
            ConstructionTapeHelper.removeConstructionTape(building.getCorners(), world);
        }
        building.setIsMirrored(mirror);
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony) IRSComponent(com.minecolonies.api.colony.buildings.IRSComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with IRSComponent

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

the class BuildingManager method addNewBuilding.

@Override
public IBuilding addNewBuilding(@NotNull final AbstractTileEntityColonyBuilding tileEntity, final World world) {
    tileEntity.setColony(colony);
    if (!buildings.containsKey(tileEntity.getPosition())) {
        @Nullable final IBuilding building = IBuildingDataManager.getInstance().createFrom(colony, tileEntity);
        if (building != null) {
            addBuilding(building);
            tileEntity.setBuilding(building);
            building.upgradeBuildingLevelToSchematicData();
            Log.getLogger().info(String.format("Colony %d - new AbstractBuilding for %s at %s", colony.getID(), tileEntity.getBlockState().getClass(), tileEntity.getPosition()));
            building.setIsMirrored(tileEntity.isMirrored());
            if (!tileEntity.getStyle().isEmpty()) {
                building.setStyle(tileEntity.getStyle());
            } else {
                building.setStyle(colony.getStyle());
            }
            if (world != null && !(building instanceof IRSComponent)) {
                building.onPlacement();
                ConstructionTapeHelper.placeConstructionTape(building.getCorners(), world);
            }
            colony.getRequestManager().onProviderAddedToColony(building);
            setMaxChunk(building);
        } else {
            Log.getLogger().error(String.format("Colony %d unable to create AbstractBuilding for %s at %s", colony.getID(), tileEntity.getBlockState().getClass(), tileEntity.getPosition()), new Exception());
        }
        colony.getCitizenManager().calculateMaxCitizens();
        colony.getPackageManager().updateSubscribers();
        return building;
    }
    return null;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IRSComponent(com.minecolonies.api.colony.buildings.IRSComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with IRSComponent

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

the class RegisteredStructureManager method addNewBuilding.

@Override
public IBuilding addNewBuilding(@NotNull final AbstractTileEntityColonyBuilding tileEntity, final World world) {
    tileEntity.setColony(colony);
    if (!buildings.containsKey(tileEntity.getPosition())) {
        @Nullable final IBuilding building = IBuildingDataManager.getInstance().createFrom(colony, tileEntity);
        if (building != null) {
            addBuilding(building);
            tileEntity.setBuilding(building);
            building.upgradeBuildingLevelToSchematicData();
            Log.getLogger().info(String.format("Colony %d - new AbstractBuilding for %s at %s", colony.getID(), tileEntity.getBlockState().getClass(), tileEntity.getPosition()));
            building.setIsMirrored(tileEntity.isMirrored());
            if (!tileEntity.getStyle().isEmpty()) {
                building.setStyle(tileEntity.getStyle());
            } else {
                building.setStyle(colony.getStyle());
            }
            if (world != null && !(building instanceof IRSComponent)) {
                building.onPlacement();
                ConstructionTapeHelper.placeConstructionTape(building.getCorners(), world);
            }
            colony.getRequestManager().onProviderAddedToColony(building);
            setMaxChunk(building);
        } else {
            Log.getLogger().error(String.format("Colony %d unable to create AbstractBuilding for %s at %s", colony.getID(), tileEntity.getBlockState().getClass(), tileEntity.getPosition()), new Exception());
        }
        colony.getCitizenManager().calculateMaxCitizens();
        colony.getPackageManager().updateSubscribers();
        return building;
    }
    return null;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IRSComponent(com.minecolonies.api.colony.buildings.IRSComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with IRSComponent

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

the class BuildToolPasteMessage method setupBuilding.

/**
 * setup the building once it has been placed.
 *
 * @param world    World the hut is being placed into.
 * @param player   Who placed the hut.
 * @param sn       The name of the structure.
 * @param rotation The number of times the structure should be rotated.
 * @param buildPos The location the hut is being placed.
 * @param mirror   Whether or not the strcture is mirrored.
 */
private static void setupBuilding(@NotNull final World world, @NotNull final PlayerEntity player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    @Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(world, buildPos);
    if (building == null) {
        Log.getLogger().error("BuildTool: building is null!", new Exception());
    } else {
        if (building.getTileEntity() != null) {
            final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, buildPos);
            if (colony == null) {
                Log.getLogger().info("No colony for " + player.getName().getString());
            } else {
                building.getTileEntity().setColony(colony);
            }
        }
        // Don't set the building level here; that will be set later in
        // readSchematicDataFromNBT (provided that the schematic has
        // TAG_BLUEPRINTDATA, but buildings always should).  This allows
        // level 0 -> N upgrade events to properly be triggered on paste.
        building.setStyle(sn.getStyle());
        if (!(building instanceof IRSComponent)) {
            ConstructionTapeHelper.removeConstructionTape(building.getCorners(), world);
        }
        building.setIsMirrored(mirror);
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony) IRSComponent(com.minecolonies.api.colony.buildings.IRSComponent) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)7 IRSComponent (com.minecolonies.api.colony.buildings.IRSComponent)7 Nullable (org.jetbrains.annotations.Nullable)7 IColony (com.minecolonies.api.colony.IColony)4