Skip to content

Commit

Permalink
fix a lot of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
IAFEnvoy committed Jul 18, 2024
1 parent a5584aa commit b22a846
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/net/haoooozhang/thinkbeforedrop/DropManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.shedaniel.autoconfig.AutoConfig;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.*;
Expand All @@ -17,15 +17,14 @@ public class DropManager {
private static int lastSlot = -1;
private static boolean dropped = false;

private static boolean shouldHandleDrop(ItemStack stack){
private static boolean shouldHandleDrop(ItemStack stack) {
ModConfig config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
if (!config.configenable) return false;
Item item = stack.getItem();
Block block = null;
if (item instanceof BlockItem)
block = ((BlockItem) item).getBlock();
ResourceLocation location = Registries.ITEM.location();//有问题
assert location != null;
if (item instanceof BlockItem blockItem)
block = blockItem.getBlock();
ResourceLocation location = BuiltInRegistries.ITEM.getKey(item);//有问题
String name = location.toString();
if (config.internal.weapon)
if (item instanceof SwordItem || item instanceof BowItem || item instanceof CrossbowItem || item instanceof TridentItem || item instanceof ArrowItem)
Expand All @@ -45,13 +44,13 @@ private static boolean shouldHandleDrop(ItemStack stack){
if (item instanceof DiscFragmentItem || item.components().has(DataComponents.JUKEBOX_PLAYABLE))
return true;
if (config.internal.uncommon)
if (item.components().has(DataComponents.RARITY) == Rarity.UNCOMMON)
if (item.components().get(DataComponents.RARITY) == Rarity.UNCOMMON)
return true;
if (config.internal.rare)
if (item.components().has(DataComponents.RARITY) == Rarity.RARE)
if (item.components().get(DataComponents.RARITY) == Rarity.RARE)
return true;
if (config.internal.epic)
if (item.components().has(DataComponents.RARITY) == Rarity.EPIC)
if (item.components().get(DataComponents.RARITY) == Rarity.EPIC)
return true;
if (config.internal.enchanted) {
if (stack.isEnchanted())
Expand All @@ -67,6 +66,7 @@ private static boolean shouldHandleDrop(ItemStack stack){
return true;
return config.custom.customItems.contains(name);
}

public static boolean shouldThrow(ItemStack stack, int slot) {
ModConfig config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
if (slot != lastSlot) {
Expand All @@ -85,6 +85,7 @@ public static boolean shouldThrow(ItemStack stack, int slot) {
lastSlot = slot;
return false;
}

public static Component getWarningText() {
return Component.translatable("tbt.warning");
}
Expand Down

0 comments on commit b22a846

Please sign in to comment.