use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by ldtteam.
the class AbstractItemScroll method useOn.
@Override
@NotNull
public ActionResultType useOn(ItemUseContext ctx) {
// Right click on block
if (ctx.getLevel().isClientSide || !ctx.getPlayer().isShiftKeyDown() || !needsColony()) {
return ActionResultType.PASS;
}
final TileEntity te = ctx.getLevel().getBlockEntity(ctx.getClickedPos());
final ItemStack scroll = ctx.getPlayer().getItemInHand(ctx.getHand());
final CompoundNBT compound = checkForCompound(scroll);
if (te instanceof TileEntityColonyBuilding) {
compound.putInt(TAG_COLONY_ID, ((AbstractTileEntityColonyBuilding) te).getColonyId());
compound.putString(TAG_COLONY_DIM, ((AbstractTileEntityColonyBuilding) te).getColony().getWorld().dimension().location().toString());
BlockPosUtil.write(compound, TAG_BUILDING_POS, ctx.getClickedPos());
LanguageHandler.sendPlayerMessage(ctx.getPlayer(), "minecolonies.scroll.registered", ((AbstractTileEntityColonyBuilding) te).getColony().getName());
}
return ActionResultType.SUCCESS;
}
use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by ldtteam.
the class AbstractBlockHut method onBlockPlacedByBuildTool.
/**
* Event-Handler for placement of this block.
* <p>
* Override for custom logic.
*
* @param worldIn the word we are in.
* @param pos the position where the block was placed.
* @param state the state the placed block is in.
* @param placer the player placing the block.
* @param stack the itemstack from where the block was placed.
* @param mirror the mirror used.
* @param style the style of the building
* @see Block#onPlace(BlockState, World, BlockPos, BlockState, boolean)
*/
public void onBlockPlacedByBuildTool(@NotNull final World worldIn, @NotNull final BlockPos pos, final BlockState state, final LivingEntity placer, final ItemStack stack, final boolean mirror, final String style) {
final TileEntity tileEntity = worldIn.getBlockEntity(pos);
if (tileEntity instanceof AbstractTileEntityColonyBuilding) {
((AbstractTileEntityColonyBuilding) tileEntity).setMirror(mirror);
((AbstractTileEntityColonyBuilding) tileEntity).setStyle(style);
}
setPlacedBy(worldIn, pos, state, placer, stack);
}
use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by ldtteam.
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 EntityAIWorkDeliveryman method deliver.
/**
* Deliver the items to the hut. TODO: Current precondition: The dman's inventory may only consist of the requested itemstack.
*
* @return the next state.
*/
private IAIState deliver() {
final IRequest<? extends IDeliverymanRequestable> currentTask = job.getCurrentTask();
if (!(currentTask instanceof DeliveryRequest)) {
// Since prepareDelivery() was called earlier, go dumping first and then restart.
return DUMPING;
}
worker.getCitizenData().setVisibleStatus(DELIVERING);
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.delivering"));
final ILocation targetBuildingLocation = ((Delivery) currentTask.getRequest()).getTarget();
if (!targetBuildingLocation.isReachableFromLocation(worker.getLocation())) {
Log.getLogger().info(worker.getCitizenColonyHandler().getColony().getName() + ": " + worker.getName() + ": Can't inter dimension yet: ");
return START_WORKING;
}
if (!worker.isWorkerAtSiteWithMove(targetBuildingLocation.getInDimensionLocation(), MIN_DISTANCE_TO_WAREHOUSE)) {
setDelay(WALK_DELAY);
return DELIVERY;
}
final TileEntity tileEntity = world.getBlockEntity(targetBuildingLocation.getInDimensionLocation());
if (!(tileEntity instanceof TileEntityColonyBuilding)) {
// TODO: Non-Colony deliveries are unsupported yet. Fix that at some point in time.
job.finishRequest(true);
return START_WORKING;
}
final IBuilding targetBuilding = ((AbstractTileEntityColonyBuilding) tileEntity).getBuilding();
boolean success = true;
boolean extracted = false;
final IItemHandler workerInventory = worker.getInventoryCitizen();
for (int i = 0; i < workerInventory.getSlots(); i++) {
if (workerInventory.getStackInSlot(i).isEmpty()) {
continue;
}
final ItemStack stack = workerInventory.extractItem(i, Integer.MAX_VALUE, false);
if (ItemStackUtils.isEmpty(stack)) {
continue;
}
extracted = true;
final ItemStack insertionResultStack;
// TODO: Please only push items into the target that were actually requested.
if (targetBuilding instanceof AbstractBuilding) {
insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, ((IBuilding) targetBuilding)::isItemStackInRequest);
} else {
// Buildings that are not inherently part of the request system, but just receive a delivery, cannot have their items replaced.
// Therefore, the keep-predicate always returns true.
insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, itemStack -> true);
}
if (!ItemStackUtils.isEmpty(insertionResultStack)) {
if (ItemStack.matches(insertionResultStack, stack) && worker.getCitizenData() != null) {
// The replaced stack is the same as the one we tried to put into the inventory.
// Meaning, replacing failed.
success = false;
if (targetBuilding.hasModule(WorkerBuildingModule.class)) {
worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, targetBuilding.getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen().getName()), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuilding.getID()));
} else {
worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new StringTextComponent(" :" + targetBuilding.getSchematicName())), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuildingLocation.getInDimensionLocation()));
}
}
// Insert the result back into the inventory so we do not lose it.
workerInventory.insertItem(i, insertionResultStack, false);
}
}
if (!extracted) {
// This can only happen if the dman's inventory was completely empty.
// Let the retry-system handle this case.
worker.decreaseSaturationForContinuousAction();
worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
job.finishRequest(false);
// No need to go dumping in this case.
return START_WORKING;
}
worker.getCitizenExperienceHandler().addExperience(1.5D);
worker.decreaseSaturationForContinuousAction();
worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
job.finishRequest(true);
return success ? START_WORKING : DUMPING;
}
use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.
the class AbstractBlockHut method onBlockPlacedByBuildTool.
/**
* Event-Handler for placement of this block.
* <p>
* Override for custom logic.
*
* @param worldIn the word we are in.
* @param pos the position where the block was placed.
* @param state the state the placed block is in.
* @param placer the player placing the block.
* @param stack the itemstack from where the block was placed.
* @param mirror the mirror used.
* @param style the style of the building
* @see Block#onPlace(BlockState, World, BlockPos, BlockState, boolean)
*/
public void onBlockPlacedByBuildTool(@NotNull final World worldIn, @NotNull final BlockPos pos, final BlockState state, final LivingEntity placer, final ItemStack stack, final boolean mirror, final String style) {
final TileEntity tileEntity = worldIn.getBlockEntity(pos);
if (tileEntity instanceof AbstractTileEntityColonyBuilding) {
((AbstractTileEntityColonyBuilding) tileEntity).setMirror(mirror);
((AbstractTileEntityColonyBuilding) tileEntity).setStyle(style);
}
setPlacedBy(worldIn, pos, state, placer, stack);
}
Aggregations