Skip to content

Commit

Permalink
first push!
Browse files Browse the repository at this point in the history
  • Loading branch information
HaooooZhang committed Jul 18, 2024
1 parent 9a90e59 commit a5584aa
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 206 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ group = mod_group_id

repositories {
mavenLocal()
maven {
url "https://cursemaven.com"
}
}

base {
Expand Down Expand Up @@ -97,6 +100,7 @@ dependencies {
// And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version.
// For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
implementation "net.neoforged:neoforge:${neo_version}"
implementation "curse.maven:cloth-config-348521:5424576"

// Example optional mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ loader_version_range=[4,)

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=examplemod
mod_id=thinkbeforedrop
# The human-readable display name for the mod.
mod_name=Example Mod
mod_name=Think Before Drop
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.0.0
mod_version=2.1
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=com.example.examplemod
mod_group_id=com.haoooozhang
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=YourNameHere, OtherNameHere
mod_authors=HaooooZhang, IAFEnvoy
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Example mod description.\nNewline characters can be used and will be replaced properly.
mod_description=Press Q twice before drop specific items
63 changes: 0 additions & 63 deletions src/main/java/com/example/examplemod/Config.java

This file was deleted.

136 changes: 0 additions & 136 deletions src/main/java/com/example/examplemod/ExampleMod.java

This file was deleted.

91 changes: 91 additions & 0 deletions src/main/java/net/haoooozhang/thinkbeforedrop/DropManager.java
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 src/main/java/net/haoooozhang/thinkbeforedrop/ModConfig.java
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<>();//排除物品,使用英文逗号分隔
}
}
Loading

0 comments on commit a5584aa

Please sign in to comment.