Search in sources :

Example 61 with TextComponentTranslation

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;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) BlockPos(net.minecraft.util.math.BlockPos)

Example 62 with TextComponentTranslation

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();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) PotionEffect(net.minecraft.potion.PotionEffect)

Example 63 with TextComponentTranslation

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;
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) JobGuard(com.minecolonies.coremod.colony.jobs.JobGuard) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with TextComponentTranslation

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;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation)

Example 65 with TextComponentTranslation

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);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) DamageSource(net.minecraft.util.DamageSource)

Aggregations

TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)502 ItemStack (net.minecraft.item.ItemStack)134 ITextComponent (net.minecraft.util.text.ITextComponent)82 EntityPlayer (net.minecraft.entity.player.EntityPlayer)72 BlockPos (net.minecraft.util.math.BlockPos)70 TextComponentString (net.minecraft.util.text.TextComponentString)66 Style (net.minecraft.util.text.Style)60 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)58 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)36 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)33 ArrayList (java.util.ArrayList)32 World (net.minecraft.world.World)30 IBlockState (net.minecraft.block.state.IBlockState)28 EnumFacing (net.minecraft.util.EnumFacing)26 CommandException (net.minecraft.command.CommandException)25 Block (net.minecraft.block.Block)20 Nonnull (javax.annotation.Nonnull)19 WrongUsageException (net.minecraft.command.WrongUsageException)19 EnumActionResult (net.minecraft.util.EnumActionResult)19