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