use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class AbstractEntityAIUsesFurnace method getNeededItem.
/**
* Retrieve burnable material from the building to get to start smelting.
* For this go to the building if no position has been set.
* Then check for the chest with the required material and set the position and return.
*
* If the position has been set navigate to it.
* On arrival transfer to inventory and return to StartWorking.
*
* @return the next state to transfer to.
*/
private AIState getNeededItem() {
worker.setLatestStatus(new TextComponentTranslation(COM_MINECOLONIES_COREMOD_STATUS_GATHERING));
if (walkTo == null && walkToBuilding()) {
return getState();
}
if (needsCurrently == null || !InventoryUtils.hasItemInProvider(getOwnBuilding(), needsCurrently)) {
setDelay(STANDARD_DELAY);
return START_WORKING;
} else {
if (walkTo == null) {
final BlockPos pos = getOwnBuilding().getTileEntity().getPositionOfChestWithItemStack(needsCurrently);
if (pos == null) {
setDelay(STANDARD_DELAY);
return START_WORKING;
}
walkTo = pos;
}
if (walkToBlock(walkTo)) {
setDelay(2);
return getState();
}
final boolean transfered = tryTransferFromPosToWorker(walkTo, needsCurrently);
if (!transfered) {
walkTo = null;
return START_WORKING;
}
walkTo = null;
}
setDelay(STANDARD_DELAY);
return START_WORKING;
}
use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class EntityCitizen method onLivingUpdate.
/**
* Called frequently so the entity can update its state every tick as
* required. For example, zombies and skeletons. use this to react to
* sunlight and start to burn.
*/
@Override
public void onLivingUpdate() {
if (recentlyHit > 0) {
citizenData.markDirty();
}
if (CompatibilityUtils.getWorld(this).isRemote) {
updateColonyClient();
} else {
if (getOffsetTicks() % TICKS_20 == 0) {
this.setAlwaysRenderNameTag(Configurations.gameplay.alwaysRenderNameTag);
pickupItems();
cleanupChatMessages();
updateColonyServer();
}
if (getColonyJob() != null || !CompatibilityUtils.getWorld(this).isDaytime()) {
if (ticksExisted % TICKS_20 == 0) {
checkIfStuck();
if (ticksExisted % (MAX_STUCK_TIME * 2 + TICKS_20) == 0) {
triedMovingAway = false;
}
}
} else {
setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.waitingForWork"));
}
if (CompatibilityUtils.getWorld(this).isDaytime() && !CompatibilityUtils.getWorld(this).isRaining() && citizenData != null) {
SoundUtils.playRandomSound(CompatibilityUtils.getWorld(this), this, citizenData.getSaturation());
} else if (CompatibilityUtils.getWorld(this).isRaining() && 1 >= rand.nextInt(RANT_ABOUT_WEATHER_CHANCE) && this.getColonyJob() != null) {
SoundUtils.playSoundAtCitizenWithChance(CompatibilityUtils.getWorld(this), this.getPosition(), this.getColonyJob().getBadWeatherSound(), 1);
}
}
if (isEntityInsideOpaqueBlock() || isInsideOfMaterial(Material.LEAVES)) {
getNavigator().moveAwayFromXYZ(this.getPosition(), MOVE_AWAY_RANGE, MOVE_AWAY_SPEED);
}
gatherXp();
if (citizenData != null) {
if (citizenData.getSaturation() <= 0) {
this.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("slowness")));
} else {
this.removeActivePotionEffect(Potion.getPotionFromResourceLocation("slowness"));
}
if (citizenData.getSaturation() < HIGH_SATURATION) {
tryToEat();
}
if ((distanceWalkedModified + 1.0) % ACTIONS_EACH_BLOCKS_WALKED == 0) {
decreaseSaturationForAction();
}
}
if (dataBackup != null) {
final NBTTagList nbttaglist = dataBackup.getTagList("Inventory", 10);
this.getCitizenData().getInventory().readFromNBT(nbttaglist);
this.getCitizenData().getInventory().setHeldItem(dataBackup.getInteger(TAG_HELD_ITEM_SLOT));
dataBackup = null;
}
checkHeal();
super.onLivingUpdate();
}
use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class EntityCitizen method getDesiredActivity.
@NotNull
public DesiredActivity getDesiredActivity() {
if (this.getColonyJob() instanceof JobGuard) {
return DesiredActivity.WORK;
}
if (BarbarianUtils.getClosestBarbarianToEntity(this, AVOID_BARBARIAN_RANGE) != null && !(this.getColonyJob() instanceof JobGuard)) {
return DesiredActivity.SLEEP;
}
if (!CompatibilityUtils.getWorld(this).isDaytime()) {
if (isDay && citizenData != null) {
isDay = false;
final double decreaseBy = getPerBuildingFoodCost();
citizenData.decreaseSaturation(decreaseBy);
citizenData.markDirty();
}
setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.sleeping"));
return DesiredActivity.SLEEP;
}
isDay = true;
if (CompatibilityUtils.getWorld(this).isRaining() && !shouldWorkWhileRaining()) {
setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.waiting"), new TextComponentTranslation("com.minecolonies.coremod.status.rainStop"));
return DesiredActivity.IDLE;
} else {
if (this.getNavigator() != null && (this.getNavigator().getPath() != null && this.getNavigator().getPath().getCurrentPathLength() == 0)) {
this.getNavigator().clearPath();
}
return DesiredActivity.WORK;
}
}
use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class AbstractEntityAIGuard method gathering.
/**
* Checks if the guard found items on the ground,
* if yes collect them, if not search for them.
*
* @return GUARD_GATHERING as long as gathering takes.
*/
private AIState gathering() {
worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.gathering"));
if (getItemsForPickUp() == null) {
fillItemsList();
}
if (getItemsForPickUp() != null && !getItemsForPickUp().isEmpty()) {
gatherItems();
return getState();
}
resetGatheringItems();
return GUARD_PATROL;
}
use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.
the class AbstractEntityAIHerder method butcherAnimal.
/**
* Butcher an animal.
*
* @param animal the {@link EntityAnimal} we are butchering
*/
private void butcherAnimal(@Nullable final EntityAnimal animal) {
worker.setLatestStatus(new TextComponentTranslation(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_HERDER_BUTCHERING));
if (animal != null && !walkingToAnimal(animal) && !ItemStackUtils.isEmpty(worker.getHeldItemMainhand())) {
worker.swingArm(EnumHand.MAIN_HAND);
animal.attackEntityFrom(new DamageSource(worker.getName()), (float) BUTCHERING_ATTACK_DAMAGE);
worker.getHeldItemMainhand().damageItem(1, animal);
}
}
Aggregations