use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by Minecolonies.
the class EntityAIWorkComposter method decideWhatToDo.
/**
* Method for the AI to decide what to do. Possible actions: harvest barrels, fill barrels or idle
*
* @return the decision it made
*/
private IAIState decideWhatToDo() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_IDLING));
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
if (walkToBuilding()) {
setDelay(2);
return getState();
}
final BuildingComposter building = this.building;
for (final BlockPos barrel : building.getBarrels()) {
final TileEntity te = world.getBlockEntity(barrel);
if (te instanceof TileEntityBarrel) {
this.currentTarget = barrel;
if (((TileEntityBarrel) te).isDone()) {
setDelay(DECIDE_DELAY);
worker.getCitizenData().setVisibleStatus(COMPOST);
return COMPOSTER_HARVEST;
}
}
}
for (final BlockPos barrel : building.getBarrels()) {
final TileEntity te = world.getBlockEntity(barrel);
if (te instanceof TileEntityBarrel && !((TileEntityBarrel) te).checkIfWorking()) {
this.currentTarget = barrel;
setDelay(DECIDE_DELAY);
worker.getCitizenData().setVisibleStatus(COMPOST);
return COMPOSTER_FILL;
}
}
setDelay(DECIDE_DELAY);
return START_WORKING;
}
use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by Minecolonies.
the class EntityAIWorkComposter method fillBarrels.
/**
* The AI will now fill the barrel that he found empty on his building
*
* @return the nex IAIState after doing this
*/
private IAIState fillBarrels() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_FILLING));
if (worker.getItemInHand(Hand.MAIN_HAND) == ItemStack.EMPTY) {
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(COMPOSTABLE_LIST)).isItemInList(new ItemStorage(stack)));
if (slot >= 0) {
worker.setItemInHand(Hand.MAIN_HAND, worker.getInventoryCitizen().getStackInSlot(slot));
} else {
return GET_MATERIALS;
}
}
if (walkToBlock(currentTarget)) {
setDelay(2);
return getState();
}
if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
final TileEntityBarrel barrel = (TileEntityBarrel) world.getBlockEntity(currentTarget);
worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
barrel.addItem(worker.getItemInHand(Hand.MAIN_HAND));
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
this.incrementActionsDoneAndDecSaturation();
worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
incrementActionsDone();
}
setDelay(AFTER_TASK_DELAY);
return START_WORKING;
}
use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.
the class BlockBarrel method use.
@NotNull
@Override
public ActionResultType use(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult ray) {
final ItemStack itemstack = player.inventory.getSelected();
final TileEntity te = worldIn.getBlockEntity(pos);
if (te instanceof TileEntityBarrel && !worldIn.isClientSide) {
((TileEntityBarrel) te).useBarrel(player, itemstack, ray.getDirection());
((TileEntityBarrel) te).updateBlock(worldIn);
}
return ActionResultType.SUCCESS;
}
use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.
the class EntityAIWorkComposter method accelerateBarrels.
/**
* Actually accelerate the Barrels
*/
private IAIState accelerateBarrels() {
final int accelerationTicks = (worker.getCitizenData().getCitizenSkillHandler().getLevel(getModuleForJob().getPrimarySkill()) / 10) * 2;
final World world = getOwnBuilding().getColony().getWorld();
for (final BlockPos pos : getOwnBuilding().getBarrels()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityBarrel) {
final TileEntityBarrel barrel = (TileEntityBarrel) entity;
for (int i = 0; i < accelerationTicks; i++) {
if (barrel.checkIfWorking() && !barrel.isDone()) {
barrel.tick();
}
}
}
}
}
return null;
}
use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.
the class EntityAIWorkComposter method fillBarrels.
/**
* The AI will now fill the barrel that he found empty on his building
*
* @return the nex IAIState after doing this
*/
private IAIState fillBarrels() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_FILLING));
if (worker.getItemInHand(Hand.MAIN_HAND) == ItemStack.EMPTY) {
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(COMPOSTABLE_LIST)).isItemInList(new ItemStorage(stack)));
if (slot >= 0) {
worker.setItemInHand(Hand.MAIN_HAND, worker.getInventoryCitizen().getStackInSlot(slot));
} else {
return GET_MATERIALS;
}
}
if (walkToBlock(currentTarget)) {
setDelay(2);
return getState();
}
if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
final TileEntityBarrel barrel = (TileEntityBarrel) world.getBlockEntity(currentTarget);
worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
barrel.addItem(worker.getItemInHand(Hand.MAIN_HAND));
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
this.incrementActionsDoneAndDecSaturation();
worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
incrementActionsDone();
}
setDelay(AFTER_TASK_DELAY);
return START_WORKING;
}
Aggregations