-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e064853
commit 9ed6fe5
Showing
14 changed files
with
250 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,38 +1,43 @@ | ||
# Example Mod | ||
<div align="center"> | ||
<img src="./icon-rounded.png" alt="The DropConfirm Logo"/> | ||
<h1>DropConfirm</h1> | ||
<h3>Think twice before you drop.</h3> | ||
</div> | ||
|
||
Template for making Babric mods for BTA! | ||
--- | ||
|
||
**Note: *DO NOT fork this repository unless you want to contribute!*** | ||
## What *is* DropConfirm, exactly? | ||
|
||
## Prerequisites | ||
- JDK for Java 17 ([Eclipse Temurin](https://adoptium.net/temurin/releases/) recommended) | ||
- [Intellij IDEA](https://www.jetbrains.com/idea/download/) (Scroll down for the free community edition, if using linux **DO NOT** use the flatpak distribution) | ||
- Minecraft Development plugin (Optional, but highly recommended) | ||
DropConfirm is a **configurable quality-of-life mod** that adds a confirmation dialog when dropping items. I made it | ||
because I was tired of accidentally dropping my items to other players or into lava/voids. | ||
|
||
## Setup instructions | ||
I use this mod personally, and I wanted to share it with others because I've noticed that a lot of my friends have had | ||
this exact problem (and I assume others have too). | ||
|
||
1. Click the `Use this template` button on this repo's page above (Will only appear if logged in). Choose `Create a new repository`, you will be redirected to a new page. Enter your repo's name and description, and hit `Create repository`. | ||
To get your project, open IntelliJ IDEA and click `Get from VCS`. Select `Repository URL` and enter your repo's url | ||
## Compatibility | ||
|
||
2. After the project has finished importing, close it and open it again. | ||
If that does not work, open the right sidebar with `Gradle` on it, open `Tasks` > `fabric` and run `ideaSyncTask`. | ||
DropConfirm currently supports Minecraft 1.20-1.21 (with a less featureful backport for 1.19.4). | ||
|
||
3. Create a new run configuration by going in `Run > Edit Configurations`. | ||
Then click on the plus icon and select Gradle. In the `Tasks and Arguments` field enter `build`. | ||
Running it will build your finished jar files and put them in `build/libs/`. | ||
Newer versions will likely be supported. Older versions may or may not work with some manual modifications to the source and will ***not*** be actively supported. | ||
|
||
4. Lastly, open `File` > `Settings` and head to `Build, Execution, Development` > `Build Tools` > `Gradle`. | ||
Make sure `Build and run using` and `Run tests using` is set to `Gradle`. | ||
## Roadmap | ||
|
||
5. Done! Now, all that's left is to change every mention of `examplemod` and `turniplabs` to your own mod id and mod group, respectively. Happy modding! | ||
- [x] Add configurations | ||
- [x] Add a command/keybind to toggle the mod | ||
- [x] Add sound events for toggling the mod and dropping items | ||
- [x] Add translations | ||
- [ ] Detect if the player is in a dangerous area (e.g. lava, void, etc.) | ||
|
||
## Tips | ||
|
||
1. If you haven't already you should join the BTA modding discord! https://discord.gg/FTUNJhswBT | ||
2. You can set your username when launching the client run configuration by setting `--username <username>` in your program arguments. | ||
3. Set `online-mode` to `false` in order to be able to join your server! | ||
4. When launching the server run configuration you may want to remove the `nogui` program argument in order to see the regular server GUI. | ||
5. In Intellij you can double press shift or press ctrl+N to search class files, change the search from the default `Project Files` to `All Places` you can easily explore the classes for you dependencies and even BTA itself. | ||
6. In Intellij if ctrl+left click on a field or method you can quickly get information on when and where that field or method is assign or used. | ||
## Configuration | ||
|
||
- **Enable:** | ||
- Whether to enable DropConfirm. | ||
- **Play Sounds:** | ||
- Whether or not to play sounds when doing various actions related to DropConfirm, e.g.: | ||
- Enabling/Disabling | ||
- Dropping items | ||
- **Reset Delay:** | ||
- Amount of time (in seconds) before the confirmation status is reset. | ||
- **Blacklist** | ||
- Allows for disabling the confirmation prompt on certain items. | ||
- Can also be used like a whitelist instead. |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions
12
...ava/turniplabs/examplemod/ExampleMod.java → ...main/java/xyz/pupbrained/DropConfirm.java
This file contains 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 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,13 @@ | ||
package xyz.pupbrained; | ||
|
||
import net.minecraft.core.entity.player.EntityPlayer; | ||
|
||
public final class DropConfirmUtil { | ||
public static boolean confirmed = false; | ||
public static boolean showConfirmationPrompt = false; | ||
public static long promptStartTime = 0; | ||
|
||
public static boolean isMainHandStackEmpty(EntityPlayer player) { | ||
return player.getHeldItem() == null; | ||
} | ||
} |
This file contains 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,19 @@ | ||
package xyz.pupbrained.mixin; | ||
|
||
import net.minecraft.core.player.inventory.InventoryPlayer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import xyz.pupbrained.DropConfirmUtil; | ||
|
||
@Mixin(value = InventoryPlayer.class, remap = false) | ||
public class HotbarScrollMixin { | ||
@Inject( | ||
method = "changeCurrentItem(I)V", | ||
at = @At("HEAD") | ||
) | ||
private void onHotbarScroll(int i, CallbackInfo ci) { | ||
DropConfirmUtil.confirmed = false; | ||
} | ||
} |
This file contains 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,52 @@ | ||
package xyz.pupbrained.mixin; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.core.entity.player.EntityPlayer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import xyz.pupbrained.DropConfirm; | ||
import xyz.pupbrained.DropConfirmUtil; | ||
|
||
@Mixin(value = EntityPlayer.class, remap = false) | ||
public class ItemDropMixin { | ||
Minecraft mc = Minecraft.getMinecraft(this); | ||
|
||
@Inject( | ||
method="dropCurrentItem(Z)V", | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private void onItemDrop(boolean dropFullStack, CallbackInfo ci) { | ||
if (DropConfirmUtil.isMainHandStackEmpty(mc.thePlayer)) | ||
return; | ||
|
||
if (!DropConfirmUtil.confirmed) { | ||
DropConfirmUtil.confirmed = true; | ||
DropConfirmUtil.showConfirmationPrompt = true; | ||
DropConfirmUtil.promptStartTime = System.currentTimeMillis(); // Set start time here | ||
|
||
new Thread(() -> { | ||
try { | ||
Thread.sleep(1000); | ||
|
||
synchronized (DropConfirmUtil.class) { | ||
DropConfirmUtil.confirmed = false; | ||
DropConfirmUtil.showConfirmationPrompt = false; | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
DropConfirm.LOGGER.error("Interrupted while waiting to reset confirmation.", e); | ||
} | ||
}).start(); | ||
|
||
ci.cancel(); | ||
} else { | ||
DropConfirmUtil.confirmed = false; | ||
DropConfirmUtil.showConfirmationPrompt = false; | ||
|
||
mc.theWorld.playSoundAtEntity(mc.thePlayer, mc.thePlayer, "random.pop", 1.0F, 1.0F); | ||
} | ||
} | ||
} |
This file contains 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,62 @@ | ||
package xyz.pupbrained.mixin; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import org.lwjgl.opengl.GL11; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import xyz.pupbrained.DropConfirmUtil; | ||
|
||
@Mixin(value = Minecraft.class, remap = false) | ||
public class RenderMixin { | ||
@Inject( | ||
method = "run", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/client/render/WorldRenderer;updateCameraAndRender(F)V", | ||
shift = At.Shift.AFTER | ||
) | ||
) | ||
private void onRender(CallbackInfo ci) { | ||
if (!DropConfirmUtil.showConfirmationPrompt) return; | ||
|
||
Minecraft mc = Minecraft.getMinecraft(this); | ||
|
||
long currentTime = System.currentTimeMillis(); | ||
long elapsedTime = currentTime - DropConfirmUtil.promptStartTime; | ||
|
||
// Calculate alpha value based on elapsed time (fade out over 1000ms) | ||
float alpha = 1.0f - (elapsedTime / 1000.0f); // Alpha decreases over time | ||
if (alpha < 0.0f) { | ||
alpha = 0.0f; // Ensure alpha doesn't go below 0 | ||
} | ||
|
||
// Convert alpha to a hex value (between 0 and 255) and incorporate it into the color | ||
int alphaHex = (int) (alpha * 255) << 24; | ||
int color = 0xFFFFFF | alphaHex; // Combine white color with alpha | ||
|
||
// Weird GL stuff | ||
GL11.glPushMatrix(); | ||
GL11.glDisable(GL11.GL_LIGHTING); | ||
GL11.glEnable(GL11.GL_BLEND); // Enable blending for alpha transparency | ||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // Standard blend function | ||
|
||
mc.fontRenderer.drawCenteredString( | ||
"Press Q again to drop this item.", | ||
mc.resolution.scaledWidth / 2, // Complete center of the screen horizontally | ||
mc.resolution.scaledHeight - 60, // A little above the hotbar | ||
color // Color with alpha | ||
); | ||
|
||
// Undo weird GL stuff | ||
GL11.glDisable(GL11.GL_BLEND); // Disable blending after rendering | ||
GL11.glEnable(GL11.GL_LIGHTING); | ||
GL11.glPopMatrix(); | ||
|
||
// Stop showing the prompt after it has fully faded out | ||
if (alpha == 0.0f) { | ||
DropConfirmUtil.showConfirmationPrompt = false; | ||
} | ||
} | ||
} |
This file contains 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,16 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "xyz.pupbrained.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": [ | ||
], | ||
"client": [ | ||
"HotbarScrollMixin", | ||
"ItemDropMixin", | ||
"RenderMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,44 +1,39 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "examplemod", | ||
"version": "${version}", | ||
|
||
"name": "Example Mod", | ||
"description": "This mod aims to help new BTA modders.", | ||
"authors": [ | ||
"Turnip Labs" | ||
], | ||
"contact": { | ||
"homepage": "", | ||
"sources": "" | ||
}, | ||
|
||
"schemaVersion": 1, | ||
"id": "drop_confirm", | ||
"version": "${version}", | ||
"name": "DropConfirm", | ||
"description": "Think twice before you drop.", | ||
"authors": [ | ||
"pupbrained" | ||
], | ||
"contact": { | ||
"homepage": "https://modrinth.com/mod/drop-confirm", | ||
"issues": "https://github.com/pupbrained/drop-confirm/issues", | ||
"sources": "https://github.com/pupbrained/drop-confirm" | ||
}, | ||
"icon": "icon.png", | ||
"license": "CC0-1.0", | ||
|
||
"environment": "*", | ||
"entrypoints": { | ||
"main": [ | ||
"turniplabs.examplemod.ExampleMod" | ||
], | ||
"license": "Unlicense", | ||
"environment": "*", | ||
"entrypoints": { | ||
"main": [ | ||
"xyz.pupbrained.DropConfirm" | ||
], | ||
"beforeGameStart": [ | ||
"turniplabs.examplemod.ExampleMod" | ||
"xyz.pupbrained.DropConfirm" | ||
], | ||
"afterGameStart": [ | ||
"turniplabs.examplemod.ExampleMod" | ||
"xyz.pupbrained.DropConfirm" | ||
], | ||
"recipesReady": [ | ||
"turniplabs.examplemod.ExampleMod" | ||
"xyz.pupbrained.DropConfirm" | ||
] | ||
}, | ||
"mixins": [ | ||
"examplemod.mixins.json" | ||
], | ||
|
||
"depends": { | ||
"mixins": [ | ||
"drop_confirm.mixins.json" | ||
], | ||
"depends": { | ||
"minecraft": "^7.2-beta", | ||
"fabricloader": ">=0.15.5" | ||
}, | ||
"suggests": { | ||
} | ||
"fabricloader": ">=0.15.5" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,19 @@ | ||
category.drop_confirm.general=General | ||
category.drop_confirm.keybinds=DropConfirm | ||
config.drop_confirm.title=DropConfirm Settings | ||
drop_confirm.confirmation=Press %s again to drop this item. | ||
drop_confirm.toggle.off=OFF | ||
drop_confirm.toggle.on=ON | ||
key.drop_confirm.toggle=Toggle DropConfirm | ||
option.drop_confirm.confirmation_reset_delay=Reset Delay | ||
option.drop_confirm.confirmation_reset_delay.description=The amount of time in seconds before the confirmation status is reset. | ||
option.drop_confirm.enabled=Enable DropConfirm | ||
option.drop_confirm.enabled.description=Whether DropConfirm should be enabled. | ||
option.drop_confirm.play_sounds=Play Sounds | ||
option.drop_confirm.play_sounds.description=Whether DropConfirm should play sounds for various events. | ||
option.drop_confirm.treat_as_whitelist=Treat as white list | ||
option.drop_confirm.treat_as_whitelist.description=Whether the blacklist should be used as a whitelist.\n\nNOTE=This change takes effect instantly but will only show visually upon re-entering the config screen. | ||
option.drop_confirm.blacklisted_items=Blacklisted Items | ||
option.drop_confirm.blacklisted_items.description=Items that should be ignored by DropConfirm. | ||
option.drop_confirm.whitelisted_items=Whitelisted Items | ||
option.drop_confirm.whitelisted_items.description=Items that should not be ignored by DropConfirm. |
Empty file.