use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method getTotalAmount.
/**
* Check how much of a certain stuck is actually required.
*
* @param stack the stack to check.
* @return the new stack with the correct amount.
*/
@Override
@Nullable
public ItemStack getTotalAmount(@Nullable final ItemStack stack) {
final AbstractBuildingWorker buildingWorker = getOwnBuilding();
if (stack == null || stack.getItem() == null) {
return null;
}
final BuildingBuilderResource resource = ((BuildingBuilder) buildingWorker).getNeededResources().get(stack.getUnlocalizedName());
return resource == null ? stack : new ItemStack(resource.getItem(), resource.getAmount(), resource.getDamageValue());
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class HireFireMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final HireFireMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony != null) {
//Verify player has permission to change this huts settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
if (message.hire) {
final CitizenData citizen = colony.getCitizen(message.citizenID);
((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(citizen);
} else {
((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(null);
}
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method requestMaterials.
/**
* Iterates through all the required resources and stores them in the building.
* Suppressing Sonar Rule Squid:S135
* The rule thinks we should have less continue and breaks.
* But in this case the rule does not apply because code would become unreadable and uneffective without.
*/
@SuppressWarnings(LOOPS_SHOULD_NOT_CONTAIN_MORE_THAN_A_SINGLE_BREAK_OR_CONTINUE_STATEMENT)
private void requestMaterials() {
if (job.getWorkOrder().isRequested()) {
return;
}
final AbstractBuildingWorker buildingWorker = getOwnBuilding();
if (buildingWorker instanceof BuildingBuilder) {
((BuildingBuilder) buildingWorker).resetNeededResources();
}
while (job.getStructure().findNextBlock()) {
@Nullable final Template.BlockInfo blockInfo = job.getStructure().getBlockInfo();
@Nullable final Template.EntityInfo entityInfo = job.getStructure().getEntityinfo();
if (entityInfo != null) {
requestEntityToBuildingIfRequired(entityInfo);
}
if (blockInfo == null) {
continue;
}
@Nullable IBlockState blockState = blockInfo.blockState;
@Nullable Block block = blockState.getBlock();
if (job.getStructure().isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
continue;
}
if (block instanceof BlockSolidSubstitution) {
blockState = getSolidSubstitution(job.getStructure().getBlockPosition());
block = blockState.getBlock();
}
final Block worldBlock = BlockPosUtil.getBlock(world, job.getStructure().getBlockPosition());
if (block != null && block != Blocks.AIR && worldBlock != Blocks.BEDROCK && !(worldBlock instanceof AbstractBlockHut) && !isBlockFree(block, 0)) {
requestBlockToBuildingIfRequired((BuildingBuilder) getOwnBuilding(), blockState);
}
}
job.getWorkOrder().setRequested(true);
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method dumpOneMoreSlot.
/**
* Dumps one inventory slot into the building chest.
*
* @param keepIt used to test it that stack should be kept
* @return true if is has to dump more.
*/
private boolean dumpOneMoreSlot(@NotNull final Predicate<ItemStack> keepIt) {
//Items already kept in the inventory
final Map<ItemStorage, Integer> alreadyKept = new HashMap<>();
final Map<ItemStorage, Integer> shouldKeep = getOwnBuilding().getRequiredItemsAndAmount();
@Nullable final AbstractBuildingWorker buildingWorker = getOwnBuilding();
return buildingWorker != null && (walkToBuilding() || InventoryFunctions.matchFirstInProvider(worker, (slot, stack) -> !(InventoryUtils.isItemStackEmpty(stack) || keepIt.test(stack)) && shouldDumpItem(alreadyKept, shouldKeep, buildingWorker, stack, slot)));
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method isToolInHut.
/**
* Check all chests in the worker hut for a required tool.
*
* @param tool the type of tool requested (amount is ignored)
* @return true if a stack of that type was found
*/
public boolean isToolInHut(final String tool) {
@Nullable final AbstractBuildingWorker building = getOwnBuilding();
boolean hasItem;
if (building != null) {
hasItem = isToolInTileEntity(building.getTileEntity(), tool);
if (hasItem) {
return true;
}
for (final BlockPos pos : building.getAdditionalCountainers()) {
final TileEntity entity = world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
hasItem = isToolInTileEntity((TileEntityChest) entity, tool);
if (hasItem) {
return true;
}
}
}
}
return false;
}
Aggregations