-
Notifications
You must be signed in to change notification settings - Fork 19
feature easy-trash module #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IceTank
wants to merge
7
commits into
lambda-client:1.21.11
Choose a base branch
from
IceTank:feature/module/easy-trash
base: 1.21.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
900e4ab
Add easy trash prototype
IceTank 5dec1d4
Improved EasyTrash
IceTank c128fd1
Improved EasyTrash
IceTank 2bc9bb8
Lint
IceTank 70c9add
Add InventoryEvent$SlotAction$Click Event
IceTank 9c6358e
Add named module initialization parameters
IceTank 47111d8
Delegate item drop speed to InventoryManager
IceTank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/kotlin/com/lambda/module/modules/player/EasyTrash.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Copyright 2025 Lambda | ||
| * | ||
| * This program 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. | ||
| * | ||
| * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.lambda.module.modules.player | ||
|
|
||
| import com.lambda.context.SafeContext | ||
| import com.lambda.event.events.InventoryEvent | ||
| import com.lambda.event.events.TickEvent | ||
| import com.lambda.event.listener.SafeListener.Companion.listen | ||
| import com.lambda.interaction.managers.inventory.InventoryRequest.Companion.inventoryRequest | ||
| import com.lambda.interaction.material.StackSelection | ||
| import com.lambda.interaction.material.container.containers.InventoryContainer | ||
| import com.lambda.module.Module | ||
| import com.lambda.module.tag.ModuleTag | ||
| import net.minecraft.entity.EntityType | ||
| import net.minecraft.entity.ItemEntity | ||
| import net.minecraft.item.Item | ||
| import net.minecraft.item.Items | ||
| import net.minecraft.registry.Registries.ITEM | ||
| import net.minecraft.screen.GenericContainerScreenHandler | ||
| import net.minecraft.screen.ScreenHandler | ||
| import net.minecraft.screen.slot.SlotActionType | ||
|
|
||
| object EasyTrash : Module( | ||
| name = "EasyTrash", | ||
| description = "Automatically trashes unwanted items", | ||
| tag = ModuleTag.PLAYER | ||
| ) { | ||
| private val itemsCanTrash by setting("Items Can Trash", setOf<Item>(Items.NETHERRACK, Items.COBBLESTONE), ITEM.toSet()) | ||
|
|
||
| private val dropToPickup by setting("Drop To Pickup", true) | ||
| private val itemsToPickup by setting("Items To Pickup", setOf(), ITEM.toSet()) | ||
|
|
||
| init { | ||
| listen<TickEvent.Pre> { | ||
| checkShouldTrashSomething() | ||
| } | ||
|
|
||
| listen<InventoryEvent.SlotAction.Click> { event -> | ||
| if (event.actionType != SlotActionType.QUICK_MOVE || event.button != 0) { | ||
| return@listen | ||
| } | ||
|
|
||
| if (event.screenHandler is GenericContainerScreenHandler) { | ||
| val sh = event.screenHandler | ||
| val rows = sh.rows | ||
|
|
||
| if (event.slotId >= rows * 9) { | ||
| // Clicked in inventory, not in container | ||
| return@listen | ||
| } | ||
|
|
||
| if (sh.slots.subList(rows * 9, sh.slots.size).any { !it.hasStack() }) { | ||
| // There is empty space in the inventory, no need to trash | ||
| return@listen | ||
| } | ||
|
|
||
| StackSelection.selectStack { | ||
| isOneOfItems(itemsCanTrash) | ||
| }.filterSlots(InventoryContainer.slots).firstOrNull()?.let { trashSlot -> | ||
| inventoryRequest { | ||
| pickup(event.slotId, 0) | ||
| pickup(trashSlot.id, 0) | ||
| pickup(ScreenHandler.EMPTY_SPACE_SLOT_INDEX, 0) | ||
| }.submit(true) | ||
| event.cancel() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun SafeContext.checkShouldTrashSomething() { | ||
| if (player.health > 0.0f && !player.isSpectator && dropToPickup && !player.isCreative) { | ||
| val vehicle = player.vehicle | ||
| val box = if (vehicle != null && !vehicle.isRemoved) { | ||
| player.boundingBox.union(vehicle.boundingBox).expand(1.0, 0.0, 1.0) | ||
| } else { | ||
| player.boundingBox.expand(1.0, 0.5, 1.0) | ||
| } | ||
| val items = world.getEntitiesByType<ItemEntity>(EntityType.ITEM, box) { | ||
| entity -> itemsToPickup.contains(entity.stack.item) && entity.isOnGround | ||
| }.map { i -> i.stack.item } | ||
| if (items.isNotEmpty() && InventoryContainer.spaceAvailable(StackSelection.selectStack { isOneOfItems(items) }) <= 0) { | ||
| dropOneTrashStack() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun SafeContext.dropOneTrashStack(): Boolean { | ||
| StackSelection.selectStack { | ||
| isOneOfItems(itemsCanTrash) | ||
| }.filterSlots(InventoryContainer.slots).firstOrNull()?.let { | ||
| inventoryRequest { | ||
| throwStack(it.id) | ||
| }.submit(true) | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.