use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.
the class EntityAIWorkComposter method harvestBarrels.
/**
* The AI will harvest the finished barrels they found in their hut.
*
* @return the next IAIState after doing this
*/
private IAIState harvestBarrels() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_HARVESTING));
if (walkToBlock(currentTarget)) {
setDelay(2);
return getState();
}
if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
final TileEntityBarrel te = (TileEntityBarrel) world.getBlockEntity(currentTarget);
final ItemStack compost = te.retrieveCompost(getLootMultiplier(worker.getRandom()));
if (getOwnBuilding().getSetting(BuildingComposter.PRODUCE_DIRT).getValue()) {
/**
* Podzol or dirt?
* 5% chance (by default) for podzol, else dirt.
* Two researches to increase it to 10% and 15%, respectively.
*/
if (((worker.getRandom().nextInt(100)) + 1) <= (5 * (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(PODZOL_CHANCE)))) {
InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.PODZOL, MineColonies.getConfig().getServer().dirtFromCompost.get()));
} else {
InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.DIRT, MineColonies.getConfig().getServer().dirtFromCompost.get()));
}
} else {
InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), compost);
}
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
this.incrementActionsDoneAndDecSaturation();
}
setDelay(AFTER_TASK_DELAY);
return START_WORKING;
}
use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.
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.getOwnBuilding();
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 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 Minecolonies.
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 = building.getColony().getWorld();
for (final BlockPos pos : building.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 Minecolonies.
the class EntityAIWorkComposter method harvestBarrels.
/**
* The AI will harvest the finished barrels they found in their hut.
*
* @return the next IAIState after doing this
*/
private IAIState harvestBarrels() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_HARVESTING));
if (walkToBlock(currentTarget)) {
setDelay(2);
return getState();
}
if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
final TileEntityBarrel te = (TileEntityBarrel) world.getBlockEntity(currentTarget);
final ItemStack compost = te.retrieveCompost(getLootMultiplier(worker.getRandom()));
if (building.getSetting(BuildingComposter.PRODUCE_DIRT).getValue()) {
/**
* Podzol or dirt?
* 5% chance (by default) for podzol, else dirt.
* Two researches to increase it to 10% and 15%, respectively.
*/
if (((worker.getRandom().nextInt(100)) + 1) <= (5 * (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(PODZOL_CHANCE)))) {
InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.PODZOL, MineColonies.getConfig().getServer().dirtFromCompost.get()));
} else {
InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.DIRT, MineColonies.getConfig().getServer().dirtFromCompost.get()));
}
} else {
InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), compost);
}
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
this.incrementActionsDoneAndDecSaturation();
}
setDelay(AFTER_TASK_DELAY);
return START_WORKING;
}
Aggregations