Skip to content

Commit

Permalink
Added .stack command (#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katinuka authored Dec 21, 2023
1 parent 797d576 commit c3cb2b1
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import net.ccbluex.liquidbounce.event.Listenable
import net.ccbluex.liquidbounce.event.events.ChatSendEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.command.commands.client.*
import net.ccbluex.liquidbounce.features.command.commands.creative.CommandItemEnchant
import net.ccbluex.liquidbounce.features.command.commands.creative.CommandItemGive
import net.ccbluex.liquidbounce.features.command.commands.creative.CommandItemRename
import net.ccbluex.liquidbounce.features.command.commands.creative.CommandItemSkull
import net.ccbluex.liquidbounce.features.command.commands.creative.*
import net.ccbluex.liquidbounce.features.command.commands.utility.CommandPosition
import net.ccbluex.liquidbounce.features.command.commands.utility.CommandUsername
import net.ccbluex.liquidbounce.script.CommandScript
Expand Down Expand Up @@ -153,6 +150,7 @@ object CommandManager : Iterable<Command> {
addCommand(CommandItemRename.createCommand())
addCommand(CommandItemGive.createCommand())
addCommand(CommandItemSkull.createCommand())
addCommand(CommandItemStack.createCommand())
addCommand(CommandItemEnchant.createCommand())

// utility commands
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2023 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/
package net.ccbluex.liquidbounce.features.command.commands.creative

import net.ccbluex.liquidbounce.features.command.Command
import net.ccbluex.liquidbounce.features.command.CommandException
import net.ccbluex.liquidbounce.features.command.builder.CommandBuilder
import net.ccbluex.liquidbounce.features.command.builder.ParameterBuilder
import net.ccbluex.liquidbounce.utils.client.*
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket

object CommandItemStack {

private val amountParameter = ParameterBuilder
.begin<Int>("amount")
.verifiedBy(ParameterBuilder.INTEGER_VALIDATOR)
.autocompletedWith { begin ->
mutableListOf("16", "32", "64").filter { it.startsWith(begin) }
}
.optional()
.build()

fun createCommand(): Command {
return CommandBuilder
.begin("stack")
.parameter(amountParameter)
.handler { command, args ->
if (mc.interactionManager?.hasCreativeInventory() == false) {
throw CommandException(command.result("mustBeCreative"))
}

val mainHandStack = mc.player!!.mainHandStack
if (mainHandStack.isEmpty) {
throw CommandException(command.result("noItem"))
}

val amount = args[0] as? Int ?: 64

if (amount < 1 || amount > 64) {
throw CommandException(command.result("invalidAmount"))
}


if (mainHandStack.count == amount) {
chat(regular(command.result("hasAlreadyAmount", variable(amount.toString()))))
return@handler
}

mainHandStack.count = amount
mc.player!!.inventory!!.setStack(mc.player!!.inventory.selectedSlot, mainHandStack)
mc.networkHandler!!.sendPacket(
CreativeInventoryActionC2SPacket(
36 + mc.player!!.inventory.selectedSlot,
mainHandStack
)
)
chat(regular(command.result("amountChanged", variable(amount.toString()))))
}
.build()
}

}
7 changes: 7 additions & 0 deletions src/main/resources/assets/liquidbounce/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@
"liquidbounce.command.skull.result.mustBeCreative": "Creative mode required!",
"liquidbounce.command.skull.result.noEmptySlot": "There are no empty slots in your inventory.",
"liquidbounce.command.skull.result.skullGiven": "Gave you the skull of %s.",
"liquidbounce.command.stack.description": "Changes the item amount in your main hand.",
"liquidbounce.command.stack.parameter.amount.description": "Optional amount.",
"liquidbounce.command.stack.result.mustBeCreative": "Creative mode required!",
"liquidbounce.command.stack.result.noItem": "There is no item in your main hand.",
"liquidbounce.command.stack.result.invalidAmount": "Invalid item amount. Item amount must be from 1 to 64.",
"liquidbounce.command.stack.result.amountChanged": "The item amount has been changed.",
"liquidbounce.command.stack.result.hasAlreadyAmount": "The item amount is already %s",
"liquidbounce.command.enchant.description": "Enchants the currently selected item.",
"liquidbounce.command.enchant.parameter.enchantment.description": "Enchantment name.",
"liquidbounce.command.enchant.parameter.level.description": "Enchantment level.",
Expand Down

0 comments on commit c3cb2b1

Please sign in to comment.