Search in sources :

Example 1 with JoCode

use of com.ferreusveritas.dynamictrees.worldgen.JoCode in project DynamicTrees by DynamicTreesTeam.

the class CommandRotateJoCode method execute.

@Override
public void execute(World world, ICommandSender sender, String[] args) throws CommandException {
    String code = "";
    int turns = 0;
    if (args.length < 2) {
        throw new WrongUsageException("commands.dynamictrees.rotatejocode.usage");
    }
    for (int arg = 0; arg < args.length; arg++) {
        switch(arg) {
            case 1:
                code = args[1];
                break;
            case 2:
                try {
                    turns = Integer.parseInt(args[2]);
                } catch (NumberFormatException e) {
                    throw new WrongUsageException("commands.dynamictrees.rotatejocode.turnserror", args[2]);
                }
                break;
        }
    }
    if (code.isEmpty()) {
        code = CommandSetTree.DEFAULTJOCODE;
    }
    turns = (3 - (turns % 4)) + 3;
    code = new JoCode(code).rotate(EnumFacing.getHorizontal(turns)).toString();
    sender.sendMessage((new TextComponentString(code)));
}
Also used : JoCode(com.ferreusveritas.dynamictrees.worldgen.JoCode) WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with JoCode

use of com.ferreusveritas.dynamictrees.worldgen.JoCode in project DynamicTrees by DynamicTreesTeam.

the class Staff method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldStack = player.getHeldItem(hand);
    IBlockState clickedBlockState = world.getBlockState(pos);
    if (!isReadOnly(heldStack)) {
        Species species = TreeHelper.getBestGuessSpecies(world, pos);
        if (species.isValid()) {
            setSpecies(heldStack, species);
            if (!player.isSneaking()) {
                EnumFacing playerFacing = player.getHorizontalFacing();
                Optional<JoCode> joCode = TreeHelper.getJoCode(world, pos, playerFacing, species);
                if (joCode.isPresent()) {
                    String code = joCode.get().toString();
                    setCode(heldStack, code);
                    if (world.isRemote) {
                        // Make sure this doesn't run on the server
                        // Put the code in the system clipboard to annoy everyone.
                        GuiScreen.setClipboardString(code);
                    }
                }
            }
            return EnumActionResult.SUCCESS;
        }
    }
    // Create a tree from right clicking on soil
    Species species = getSpecies(heldStack);
    if (species.isValid() && species.isAcceptableSoil(world, pos, clickedBlockState)) {
        species.getJoCode(getCode(heldStack)).setCareful(true).generate(world, species, pos, world.getBiome(pos), player.getHorizontalFacing(), 8, SafeChunkBounds.ANY);
        if (!player.isCreative()) {
            if (hasMaxUses(heldStack)) {
                if (decUses(heldStack)) {
                    // If the player is in creative this will have no effect.
                    heldStack.shrink(1);
                }
            } else {
                // If the player is in creative this will have no effect.
                heldStack.shrink(1);
            }
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.FAIL;
}
Also used : JoCode(com.ferreusveritas.dynamictrees.worldgen.JoCode) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack) Species(com.ferreusveritas.dynamictrees.trees.Species)

Aggregations

JoCode (com.ferreusveritas.dynamictrees.worldgen.JoCode)2 Species (com.ferreusveritas.dynamictrees.trees.Species)1 IBlockState (net.minecraft.block.state.IBlockState)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1 TextComponentString (net.minecraft.util.text.TextComponentString)1