generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
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.
- Loading branch information
1 parent
9a90e59
commit a5584aa
Showing
14 changed files
with
287 additions
and
206 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
src/main/java/net/haoooozhang/thinkbeforedrop/DropManager.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,91 @@ | ||
package net.haoooozhang.thinkbeforedrop; | ||
|
||
import me.shedaniel.autoconfig.AutoConfig; | ||
import net.minecraft.core.component.DataComponents; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.*; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.ShulkerBoxBlock; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class DropManager { | ||
private static long lastDropTime = 0; | ||
private static int lastSlot = -1; | ||
private static boolean dropped = false; | ||
|
||
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; | ||
String name = location.toString(); | ||
if (config.internal.weapon) | ||
if (item instanceof SwordItem || item instanceof BowItem || item instanceof CrossbowItem || item instanceof TridentItem || item instanceof ArrowItem) | ||
return true; | ||
if (config.internal.tool) | ||
if (item instanceof AxeItem || item instanceof PickaxeItem || item instanceof ShovelItem || item instanceof HoeItem) | ||
return true; | ||
if (config.internal.shulkerBox) | ||
if (block != null) | ||
if (block instanceof ShulkerBoxBlock) | ||
return true; | ||
if (config.internal.armor) | ||
if (item instanceof ArmorItem || item instanceof ElytraItem) | ||
return true; | ||
//ore todo | ||
if (config.internal.disc) | ||
if (item instanceof DiscFragmentItem || item.components().has(DataComponents.JUKEBOX_PLAYABLE)) | ||
return true; | ||
if (config.internal.uncommon) | ||
if (item.components().has(DataComponents.RARITY) == Rarity.UNCOMMON) | ||
return true; | ||
if (config.internal.rare) | ||
if (item.components().has(DataComponents.RARITY) == Rarity.RARE) | ||
return true; | ||
if (config.internal.epic) | ||
if (item.components().has(DataComponents.RARITY) == Rarity.EPIC) | ||
return true; | ||
if (config.internal.enchanted) { | ||
if (stack.isEnchanted()) | ||
return true; | ||
} | ||
//hasNBT Todo | ||
//hasComponent Todo | ||
if (config.internal.enchantedBook) | ||
if (item instanceof EnchantedBookItem) | ||
return true; | ||
if (config.internal.book) | ||
if (item instanceof WritableBookItem || item instanceof WrittenBookItem) | ||
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) { | ||
lastDropTime = 0; | ||
dropped = false; | ||
} | ||
if (!shouldHandleDrop(stack) || dropped) return true; | ||
long now = System.currentTimeMillis(); | ||
if (now - lastDropTime >= config.time.minSecond * 1000 && now - lastDropTime <= config.time.maxSecond * 1000) { | ||
if (stack.getCount() != 1) | ||
dropped = true; | ||
lastDropTime = 0; | ||
return true; | ||
} | ||
lastDropTime = now; | ||
lastSlot = slot; | ||
return false; | ||
} | ||
public static Component getWarningText() { | ||
return Component.translatable("tbt.warning"); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/net/haoooozhang/thinkbeforedrop/ModConfig.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,54 @@ | ||
package net.haoooozhang.thinkbeforedrop; | ||
|
||
import me.shedaniel.autoconfig.ConfigData; | ||
import me.shedaniel.autoconfig.annotation.Config; | ||
import me.shedaniel.autoconfig.annotation.ConfigEntry; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.api.distmarker.OnlyIn; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@Config(name = ThinkBeforeDrop.MODID) | ||
public class ModConfig implements ConfigData { | ||
public boolean configenable = true; | ||
@ConfigEntry.Gui.CollapsibleObject | ||
public Time time = new Time(); | ||
@ConfigEntry.Gui.CollapsibleObject | ||
public Internal internal = new Internal(); | ||
@ConfigEntry.Gui.CollapsibleObject | ||
public Custom custom = new Custom(); | ||
|
||
//设置两次按下Q的允许间隔 | ||
@Config(name = "time") | ||
public static class Time implements ConfigData { | ||
public double minSecond = 0.5; | ||
public double maxSecond = 5; | ||
} | ||
|
||
//配置表 | ||
@Config(name = "internal") | ||
public static class Internal implements ConfigData { | ||
public boolean weapon = false;//所有武器 | ||
public boolean tool = false;//所有工具 | ||
public boolean shulkerBox = false;//所有潜影盒 | ||
public boolean armor = false;//所有装备 | ||
public boolean ore = false;//所有矿石 | ||
public boolean disc = false;//所有唱片 | ||
public boolean uncommon = false;//所有黄名物品 | ||
public boolean rare = false;//所有蓝名物品 | ||
public boolean epic = false;//所有紫名物品 | ||
public boolean enchanted = false;//所有有附魔的物品,包括物品有的附魔(只能指令拿到的那种) | ||
public boolean hasNbt = false;//所有有特殊nbt的(不包括耐久、附魔惩罚等) | ||
public boolean hasComponent = false;//有hasComponent | ||
public boolean enchantedBook = false;//所有附魔书 | ||
public boolean book = false;//所有成书 | ||
} | ||
|
||
@Config(name = "custom") | ||
public static class Custom implements ConfigData { | ||
public List<String> customItems = new ArrayList<>();//自定义,使用英文逗号分隔 | ||
public List<String> excludeItems = new ArrayList<>();//排除物品,使用英文逗号分隔 | ||
} | ||
} |
Oops, something went wrong.