Search in sources :

Example 66 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.

the class EntityAIWorkLumberjack method checkIfStuckOnLeaves.

/**
 * Check if distance to block changed and
 * if we are not moving for too long, try to get unstuck.
 *
 * @param location the block we want to go to.
 */
private void checkIfStuckOnLeaves(@NotNull final BlockPos location) {
    final int distance = (int) location.distanceSq(worker.getPosition());
    if (previousDistance != distance) {
        // something is moving, reset counters
        stillTicks = 0;
        previousDistance = distance;
        return;
    }
    // Stuck, probably on leaves
    stillTicks++;
    if (stillTicks < STUCK_WAIT_TIME) {
        // Wait for some time before jumping to conclusions
        return;
    }
    // now we seem to be stuck!
    worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.stuckinleaves"));
    tryGettingUnstuckFromLeaves();
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation)

Example 67 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.

the class EntityAIWorkSmelter method smeltStuff.

/**
 * He will smelt down armor, weapons and tools to smaller pieces here.
 * @return the next state to go to.
 */
private AIState smeltStuff() {
    worker.setLatestStatus(new TextComponentTranslation(SMELTING_DOWN));
    if (walkToBuilding()) {
        return getState();
    }
    if (ItemStackUtils.isEmpty(worker.getHeldItem(EnumHand.MAIN_HAND))) {
        progress = 0;
        if (InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon) <= 0) {
            if (InventoryUtils.hasItemInProvider(getOwnBuilding(), EntityAIWorkSmelter::isSmeltableToolOrWeapon)) {
                return START_WORKING;
            }
            InventoryUtils.transferItemStackIntoNextFreeSlotFromProvider(getOwnBuilding(), InventoryUtils.findFirstSlotInProviderWith(getOwnBuilding(), EntityAIWorkSmelter::isSmeltableToolOrWeapon), new InvWrapper(worker.getInventoryCitizen()));
        }
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon);
        if (slot == -1) {
            return START_WORKING;
        }
        worker.setHeldItem(slot);
    }
    worker.hitBlockWithToolInHand(getOwnBuilding().getLocation());
    if (progress >= getRequiredProgressForMakingRawMaterial()) {
        progress = 0;
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon);
        if (slot == -1) {
            worker.setHeldItem(EnumHand.MAIN_HAND, ItemStackUtils.EMPTY);
            return START_WORKING;
        }
        final ItemStack stack = new InvWrapper(worker.getInventoryCitizen()).extractItem(slot, 1, false);
        final Tuple<ItemStack, Integer> materialTuple = getMaterialAndAmount(stack);
        final ItemStack material = materialTuple.getFirst();
        if (!ItemStackUtils.isEmpty(material)) {
            material.setCount(materialTuple.getSecond());
            material.setItemDamage(0);
            new InvWrapper(worker.getInventoryCitizen()).setStackInSlot(slot, material);
            incrementActionsDoneAndDecSaturation();
        } else {
            new InvWrapper(worker.getInventoryCitizen()).setStackInSlot(slot, stack);
        }
        worker.addExperience(BASE_XP_GAIN);
        worker.setHeldItem(EnumHand.MAIN_HAND, ItemStackUtils.EMPTY);
        return START_WORKING;
    }
    progress++;
    setDelay(HIT_DELAY);
    return getState();
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper)

Example 68 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project minecolonies by Minecolonies.

the class EntityAIWorkSmelter method checkForAdditionalJobs.

/**
 * If no clear tasks are given, check if something else is to do.
 * @return the next AIState to traverse to.
 */
@Override
protected AIState checkForAdditionalJobs() {
    final int amountOfTools = InventoryUtils.getItemCountInProvider(getOwnBuilding(), EntityAIWorkSmelter::isSmeltableToolOrWeapon) + InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), EntityAIWorkSmelter::isSmeltableToolOrWeapon);
    if (amountOfTools > 0) {
        return SMELTER_SMELTING_ITEMS;
    }
    worker.setLatestStatus(new TextComponentTranslation(COM_MINECOLONIES_COREMOD_STATUS_IDLING));
    setDelay(WAIT_AFTER_REQUEST);
    walkToBuilding();
    return START_WORKING;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper)

Example 69 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Minestuck by mraof.

the class ServerEditHandler method onRightClickBlockControl.

@SubscribeEvent(priority = EventPriority.NORMAL)
public void onRightClickBlockControl(PlayerInteractEvent.RightClickBlock event) {
    if (!event.getWorld().isRemote && getData(event.getEntityPlayer()) != null) {
        EditData data = getData(event.getEntityPlayer());
        Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
        ItemStack stack = event.getEntityPlayer().getHeldItemMainhand();
        event.setUseBlock(stack.isEmpty() && (block instanceof BlockDoor || block instanceof BlockTrapDoor || block instanceof BlockFenceGate) ? Result.ALLOW : Result.DENY);
        if (event.getUseBlock() == Result.ALLOW)
            return;
        if (stack.isEmpty() || !isBlockItem(stack.getItem()) || event.getHand().equals(EnumHand.OFF_HAND)) {
            event.setCanceled(true);
            return;
        }
        cleanStackNBT(stack);
        if (DeployList.containsItemStack(stack)) {
            GristSet cost = data.connection.givenItems()[DeployList.getOrdinal(stack)] ? DeployList.getSecondaryCost(stack) : DeployList.getPrimaryCost(stack);
            if (!GristHelper.canAfford(MinestuckPlayerData.getGristSet(data.connection.getClientIdentifier()), cost)) {
                StringBuilder str = new StringBuilder();
                if (cost != null) {
                    for (GristAmount grist : cost.getArray()) {
                        if (cost.getArray().indexOf(grist) != 0)
                            str.append(", ");
                        str.append(grist.getAmount() + " " + grist.getType().getDisplayName());
                    }
                    event.getEntityPlayer().sendMessage(new TextComponentTranslation("grist.missing", str.toString()));
                }
                event.setCanceled(true);
            }
        } else if (!isBlockItem(stack.getItem()) || !GristHelper.canAfford(data.connection.getClientIdentifier(), stack, false)) {
            event.setCanceled(true);
        }
        if (event.getUseItem() == Result.DEFAULT)
            event.setUseItem(Result.ALLOW);
    }
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) BlockFenceGate(net.minecraft.block.BlockFenceGate) BlockTrapDoor(net.minecraft.block.BlockTrapDoor) Block(net.minecraft.block.Block) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 70 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Minestuck by mraof.

the class CommandGrist method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 1 || (!args[0].equalsIgnoreCase("get") && args.length < 2))
        throw new WrongUsageException(this.getUsage(sender));
    String command = args[0];
    PlayerIdentifier identifier;
    int offset = 1;
    if (!(command.equalsIgnoreCase("set") || command.equalsIgnoreCase("add") || command.equalsIgnoreCase("get"))) {
        command = args[1];
        identifier = IdentifierHandler.getForCommand(server, sender, args[0]);
        offset = 2;
    } else {
        EntityPlayerMP player = getCommandSenderAsPlayer(sender);
        identifier = IdentifierHandler.encode(player);
    }
    if ((args.length - offset) % 2 != 0)
        throw new WrongUsageException(this.getUsage(sender));
    String displayName = identifier.getUsername();
    if (command.equalsIgnoreCase("set")) {
        // Using a GristAmount array instead of a GristSet gives support for setting grist to 0
        GristAmount[] grist = parseGrist(args, offset);
        for (GristAmount amount : grist) GristHelper.setGrist(identifier, amount.getType(), amount.getAmount());
        MinestuckPlayerTracker.updateGristCache(identifier);
        notifyCommandListener(sender, this, "commands.grist.setSuccess", displayName);
    } else if (command.equalsIgnoreCase("add")) {
        GristSet grist = new GristSet(parseGrist(args, offset));
        GristHelper.increase(identifier, grist);
        MinestuckPlayerTracker.updateGristCache(identifier);
        notifyCommandListener(sender, this, "commands.grist.addSuccess", displayName);
    } else if (command.equalsIgnoreCase("get")) {
        StringBuilder grist = new StringBuilder();
        for (GristAmount amount : MinestuckPlayerData.getGristSet(identifier).getArray()) if (amount.getAmount() != 0)
            // TODO properly translate display name for client side
            grist.append("\n").append(amount.getAmount()).append(" ").append(amount.getType().getDisplayName());
        sender.sendMessage(new TextComponentTranslation("commands.grist.get", displayName, grist.toString()));
    } else
        throw new WrongUsageException("commands.invalidSubCommand", command);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

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