forked from cookies-mod/mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add visitor rare drop protection (cookies-mod#210)
* first push of visitor drop protection * visitor drop protection might be done just need testing * QOL changes, fix lore detection? only tested with copper * Update VisitorDropProtection.java * Update src/main/java/codes/cookies/mod/features/farming/garden/visitors/VisitorDropProtection.java Co-authored-by: Maik Z. <58326890+zFlxw@users.noreply.github.com> * remove unused int option stuff for now * Update src/main/java/codes/cookies/mod/features/farming/garden/visitors/VisitorDropProtection.java Co-authored-by: Moritz <59416038+Morazzer@users.noreply.github.com> * Update src/main/java/codes/cookies/mod/features/farming/garden/visitors/VisitorDropProtection.java Co-authored-by: Moritz <59416038+Morazzer@users.noreply.github.com> * Update VisitorDropProtection.java * Update src/main/java/codes/cookies/mod/features/farming/garden/visitors/VisitorDropProtection.java Co-authored-by: Moritz <59416038+Morazzer@users.noreply.github.com> * Update VisitorDropProtection.java * update and fixed based on review * Update src/main/java/codes/cookies/mod/features/farming/garden/visitors/VisitorDropProtection.java i forgor its here locally 💀 Co-authored-by: Moritz <59416038+Morazzer@users.noreply.github.com> * Update src/main/java/codes/cookies/mod/features/farming/garden/GardenFeatures.java Co-authored-by: Moritz <59416038+Morazzer@users.noreply.github.com> * fix extraneous translation key * rework regex * make static * use string.matches instead of pattern matcher * cleaned up lore matching --------- Co-authored-by: Maik Z. <58326890+zFlxw@users.noreply.github.com> Co-authored-by: Moritz <59416038+Morazzer@users.noreply.github.com>
- Loading branch information
1 parent
f1d7350
commit 74488e4
Showing
14 changed files
with
203 additions
and
36 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
4 changes: 2 additions & 2 deletions
4
src/main/generated/.cache/cabcb80d088276cffde41e74584028f1c00b99b8
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,2 +1,2 @@ | ||
// 1.21.3 2024-12-07T10:30:22.914149 cookies-mod/Language (en_us) | ||
e7b7bab76739a378cb9b6e48a0534029ba9d04d3 assets/cookies-mod/lang/en_us.json | ||
// 1.21.3 2024-12-11T11:17:47.4766913 cookies-mod/Language (en_us) | ||
b8e506abeadfabc1b260c9088e803802d2607fc9 assets\cookies-mod\lang\en_us.json |
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
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
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
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
118 changes: 118 additions & 0 deletions
118
src/main/java/codes/cookies/mod/features/farming/garden/visitors/VisitorDropProtection.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package codes.cookies.mod.features.farming.garden.visitors; | ||
|
||
import codes.cookies.mod.CookiesMod; | ||
import codes.cookies.mod.config.ConfigManager; | ||
import codes.cookies.mod.events.InventoryEvents; | ||
import codes.cookies.mod.events.api.InventoryContentUpdateEvent; | ||
import codes.cookies.mod.translations.TranslationKeys; | ||
import codes.cookies.mod.utils.exceptions.ExceptionHandler; | ||
import codes.cookies.mod.utils.items.CookiesDataComponentTypes; | ||
import codes.cookies.mod.utils.skyblock.LocationUtils; | ||
import codes.cookies.mod.utils.skyblock.inventories.ItemBuilder; | ||
import com.google.common.util.concurrent.Runnables; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.component.DataComponentTypes; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Style; | ||
import net.minecraft.text.Text; | ||
|
||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.Rarity; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class VisitorDropProtection implements TranslationKeys { | ||
|
||
private static final Pattern rewardsPattern = Pattern.compile("Rewards:([\\S\\s]*)(?:Click|Missing)"); | ||
|
||
private VisitorDropProtection(HandledScreen<?> handledScreen) { | ||
InventoryContentUpdateEvent.registerSlot(handledScreen.getScreenHandler(), | ||
ExceptionHandler.wrap(this::updateSlots)); | ||
} | ||
|
||
private void updateSlots(Slot slot) { | ||
if (slot.id == 33) { | ||
handleRejectButton(slot.getStack(), handleAcceptItem(slot.inventory.getStack(29))); | ||
} | ||
} | ||
|
||
protected static final ItemStack disabledItem = new ItemBuilder(Items.BARRIER).hideAdditionalTooltips().set(CookiesDataComponentTypes.ITEM_CLICK_RUNNABLE, Runnables.doNothing()) | ||
.setName(Text.translatable(DROP_PROTECTION_MESSAGE).setStyle(Style.EMPTY.withColor(Formatting.RED).withItalic(false).withBold(true))).set(DataComponentTypes.RARITY, Rarity.COMMON).build(); | ||
|
||
private void handleRejectButton(ItemStack rejectStack, boolean applyProtection) { | ||
if (!applyProtection || rejectStack == null || rejectStack.isEmpty() || !rejectStack.isOf(Items.RED_TERRACOTTA)) { | ||
return; | ||
} | ||
|
||
rejectStack.set(CookiesDataComponentTypes.ITEM_CLICK_RUNNABLE, Runnables.doNothing()); | ||
rejectStack.set(CookiesDataComponentTypes.OVERRIDE_ITEM, disabledItem); | ||
CookiesMod.getExecutorService().schedule(() -> { | ||
rejectStack.remove(CookiesDataComponentTypes.OVERRIDE_ITEM); | ||
rejectStack.remove(CookiesDataComponentTypes.ITEM_CLICK_RUNNABLE); | ||
}, 5, TimeUnit.SECONDS); | ||
} | ||
|
||
private boolean handleAcceptItem(ItemStack visitorItem) { | ||
if (visitorItem == null || visitorItem.isEmpty() || !visitorItem.isOf(Items.GREEN_TERRACOTTA) || !visitorItem.contains(DataComponentTypes.LORE)) { | ||
return false; | ||
} | ||
var lore = String.join("\n", visitorItem.get(DataComponentTypes.LORE).lines().stream().map(Text::getString).toArray(String[]::new)); | ||
|
||
Matcher matcher = rewardsPattern.matcher(lore); | ||
|
||
if (!matcher.find()) { | ||
return false; | ||
} | ||
|
||
for (String rareDrop : rareDrops) { | ||
if (StringUtils.containsIgnoreCase(lore, rareDrop)) { | ||
return true; | ||
} | ||
} | ||
|
||
if (ConfigManager.getConfig().farmingConfig.visitorNotAsRareDropProtection.getValue()) { | ||
for (String commonDrop : commonDrops) { | ||
if (StringUtils.containsIgnoreCase(lore, commonDrop)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static final String[] rareDrops = new String[] { | ||
"Bandana", | ||
"Music", | ||
"Dedication", | ||
"Jungle Key", | ||
"Soul", | ||
"Space", | ||
"Harbinger", | ||
"Overgrown Grass", | ||
"Dye", | ||
}; | ||
|
||
private static final String[] commonDrops = new String[] { | ||
"Candy", | ||
"Biofuel", | ||
"Pet Cake", | ||
"Fine Flour", | ||
"Pelt", | ||
"Velvet", | ||
"Cashmere", | ||
"Satin", | ||
"Oxford", | ||
"Powder", | ||
}; | ||
|
||
public static void init() { | ||
InventoryEvents.beforeInit("cookies-behaviour:always", inv -> LocationUtils.Island.GARDEN.isActive() && ConfigManager.getConfig().farmingConfig.visitorRareDropProtection.getValue(), VisitorDropProtection::new); | ||
} | ||
} |
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
Oops, something went wrong.