Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ object VeinMiningHUD {
VeinMiningNoticeType.TASK_HALT_HINT -> I18n.format("bandit.message.task-halt-hint")
VeinMiningNoticeType.TASK_STOP_KEY_RELEASE -> I18n.format("bandit.message.task-stop.key-release")
VeinMiningNoticeType.TASK_STOP_FOR_COMMAND -> I18n.format("bandit.message.task-stop.for-command")
VeinMiningNoticeType.TASK_STOP_BECAUSE_TOOL_MAX_DAMAGE -> I18n.format("bandit.message.task-stop.tool-max-damage")
VeinMiningNoticeType.TASK_DONE -> {
val statBlocksMined = notice.extraData["statBlocksMined"] ?: 0
val statItemDropped = notice.extraData["statItemDropped"] ?: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cn.elytra.mod.bandit.client
import cn.elytra.mod.bandit.BanditMod
import cn.elytra.mod.bandit.MixinBridger
import cn.elytra.mod.bandit.client.VeinMiningHandlerClient.keyPressed
import cn.elytra.mod.bandit.client.VeinMiningHandlerClient.onMouseInput
import cn.elytra.mod.bandit.client.VeinMiningHandlerClient.veinMiningBlockFilterId
import cn.elytra.mod.bandit.client.VeinMiningHandlerClient.veinMiningExecutorId
import cn.elytra.mod.bandit.network.BanditNetwork
Expand All @@ -30,7 +29,7 @@ import org.lwjgl.input.Mouse
* [keyPressed] stores the status of the trigger key in the last tick. If the value is changed at this tick, it will be
* sync-ed to server.
*
* [onMouseInput] handles the mouse wheel operations, passing the data to [VeinMiningHUD] for the executor/filter selecting.
* [onMouseScrollCancelable] handles the mouse wheel operations, passing the data to [VeinMiningHUD] for the executor/filter selecting.
*
* @see VeinMiningHUD
* @see cn.elytra.mod.bandit.common.mining.VeinMiningHandler
Expand Down Expand Up @@ -58,38 +57,42 @@ object VeinMiningHandlerClient {

init {
// register the callback
MixinBridger.onMouseScrollCancelable += this::onMouseInput
MixinBridger.onMouseScrollCancelable += this::onMouseScrollCancelable
}

private fun syncIfChanged(pressedNow: Boolean) {
if (pressedNow == keyPressed) return
BanditNetwork.syncStatusToServer(pressedNow)
keyPressed = pressedNow
}

@JvmStatic
@SubscribeEvent
fun onKeyInput(e: InputEvent.KeyInputEvent) {
if(Minecraft.getMinecraft().thePlayer == null) return

val keyPressedNow = if(statusKey.keyCode >= 0) {
Keyboard.isKeyDown(statusKey.keyCode)
} else {
val button = Mouse.getEventButton()
if(button == -1) {
keyPressed
} else {
statusKey.keyCode + 100 == button && Mouse.getEventButtonState()
}
}
if(keyPressedNow != keyPressed) {
BanditNetwork.syncStatusToServer(keyPressedNow)
keyPressed = keyPressedNow
if (Minecraft.getMinecraft().thePlayer == null) return
else if (Keyboard.getEventKey() != statusKey.keyCode) return
syncIfChanged(Keyboard.getEventKeyState())
}

@JvmStatic
@SubscribeEvent
fun onMouseInput(e: InputEvent.MouseInputEvent) {
if (Minecraft.getMinecraft().thePlayer == null) return
if (statusKey.keyCode < -1 && Mouse.getEventButton() == (statusKey.keyCode + 100)){
syncIfChanged(Mouse.getEventButtonState())
}
}

fun onMouseInput(d: Int): Boolean {
VeinMiningHUD.withActiveMenu {
if(d < 0) {
this.move(1)
return true
} else if(d > 0) {
this.move(-1)
return true
fun onMouseScrollCancelable(d: Int): Boolean {
if (statusKey.isKeyPressed){
VeinMiningHUD.withActiveMenu {
if(d < 0) {
this.move(1)
return true
} else if(d > 0) {
this.move(-1)
return true
}
}
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ enum class VeinMiningNoticeType(val id: Int) {
*/
TASK_STOP_FOR_COMMAND(4),

/**
* Task stopped because the player failed to destroy the blocks.
* Mining chain was terminated via tool is broken or something.
*/
TASK_STOP_BECAUSE_TOOL_MAX_DAMAGE(5),

/**
* Task completed successfully.
* Mining chain finished naturally and requires statistical processing.
*/
TASK_DONE(5);
TASK_DONE(6);

companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import cn.elytra.mod.bandit.mining.exception.CommandCancellation
import cn.elytra.mod.bandit.mining.exception.FriendlyCancellationException
import cn.elytra.mod.bandit.mining.exception.KeyReleaseCancellation
import cn.elytra.mod.bandit.mining.exception.PlayerLeftCancellation
import cn.elytra.mod.bandit.mining.exception.ToolMaxDamage
import cn.elytra.mod.bandit.mining.executor.BlockPosCacheableExecutorGenerator
import cn.elytra.mod.bandit.mining.executor.VeinMiningExecutorGenerator
import cn.elytra.mod.bandit.mining.filter.VeinMiningBlockFilter
Expand Down Expand Up @@ -244,7 +245,7 @@ data class VeinMiningPlayerData(
BanditMod.logger.info("Cached #${executionId}")
if(it != null) {
when(it) {
is KeyReleaseCancellation, is CommandCancellation, is PlayerLeftCancellation -> {
is FriendlyCancellationException -> {
/* ignored */
}

Expand Down Expand Up @@ -317,15 +318,23 @@ data class VeinMiningPlayerData(
is KeyReleaseCancellation -> {
BanditNetwork.pushSimpleNoticeToClient(player.asMP,
noticeType = VeinMiningNoticeType.TASK_STOP_KEY_RELEASE,
fadeDelay = 10,
fadeDelay = 40,
fadeTicks = 20
)
}

is CommandCancellation -> {
BanditNetwork.pushSimpleNoticeToClient(player.asMP,
noticeType = VeinMiningNoticeType.TASK_STOP_FOR_COMMAND,
fadeDelay = 10,
fadeDelay = 40,
fadeTicks = 20
)
}

is ToolMaxDamage -> {
BanditNetwork.pushSimpleNoticeToClient(player.asMP,
noticeType = VeinMiningNoticeType.TASK_STOP_BECAUSE_TOOL_MAX_DAMAGE,
fadeDelay = 40,
fadeTicks = 20
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ class CommandCancellation : FriendlyCancellationException("Cancelled because of
* The exception represents the vein-mining task was cancelled by the player because the player left
*/
class PlayerLeftCancellation : FriendlyCancellationException("Cancelled because the player left")

/**
* The exception represents the vein-mining task was cancelled because the player failed to destroy the blocks
*/
class ToolMaxDamage : FriendlyCancellationException("Cancelled because the player failed to destroy the blocks.")
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import cn.elytra.mod.bandit.BanditMod
import cn.elytra.mod.bandit.common.BanditCoroutines
import cn.elytra.mod.bandit.common.mining.VeinMiningContext
import cn.elytra.mod.bandit.common.mining.VeinMiningContext.DropPosition
import cn.elytra.mod.bandit.common.player_data.veinMiningData
import cn.elytra.mod.bandit.mining.HarvestCollector
import cn.elytra.mod.bandit.mining.event.VeinMiningEvent
import cn.elytra.mod.bandit.mining.exception.ToolMaxDamage
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
Expand Down Expand Up @@ -38,12 +40,25 @@ abstract class SequencedVeinMiningExecutorGenerator : VeinMiningExecutorGenerato
return event.isBlockMatching
}

protected open fun equippedToolWithMaxDamage(context: VeinMiningContext): Boolean {
val equippedItem: ItemStack? = context.getPlayer().currentEquippedItem
if (equippedItem != null && equippedItem.isItemStackDamageable) {
return (equippedItem.maxDamage - equippedItem.itemDamage < 1)
}
return false
}

/**
* Execute the actual block harvesting, the item dropping, and other things that not related to
* iterating but to the certain "single" block. This function is called in Server Thread, so it is
* safe to do anything!
*/
protected open fun doBlockHarvestOn(context: VeinMiningContext, pos: BlockPos) {
if (equippedToolWithMaxDamage(context)) {
context.getPlayer().veinMiningData.cancelJob(ToolMaxDamage())
return
}

val (drops, xpValue) = HarvestCollector.withHarvestCollectorScope {
context.getPlayer().theItemInWorldManager.tryHarvestBlock(pos.x, pos.y, pos.z)
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/bandit/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bandit.block-filter.match-block-and-meta=Matching Block and Metadata
bandit.message.task-starting=§aStarting Vein Mining task
bandit.message.task-halt-hint=§aYou can type §6/bandit stop §ato halt a ongoing task
bandit.message.task-done=§aVein Mining done! §7Harvested %s §7blocks, and dropped %s §7items.
bandit.message.task-stop.tool-max-damage=§aVein Mining stopped to prevent the tool from breaking.
bandit.message.task-stop.key-release=§aVein Mining stopped because the key was released.
bandit.message.task-stop.for-command=§aVein Mining stopped because the command.

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/bandit/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bandit.block-filter.match-block-and-meta=匹配方块和Meta
bandit.message.task-starting=§a开始连锁挖掘任务
bandit.message.task-halt-hint=§a你可以输入 §6/bandit stop §a来停止正在执行的任务
bandit.message.task-done=§a连锁挖掘完成! §7连锁了 %s §7个方块, 获得 %s §7个掉落物.
bandit.message.task-stop.tool-max-damage=§a阻止工具损失,连锁挖掘已停止.
bandit.message.task-stop.key-release=§a按键已释放,连锁挖掘已停止.
bandit.message.task-stop.for-command=§a指令已生效,连锁挖掘已停止.

Expand Down
Loading