Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brnbrd committed Sep 28, 2024
1 parent 935036d commit 2d5ceef
Show file tree
Hide file tree
Showing 117 changed files with 6,898 additions and 4,726 deletions.
31 changes: 15 additions & 16 deletions src/main/java/net/brnbrd/delightful/Delightful.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
import org.apache.logging.log4j.Logger;

@Mod(Delightful.MODID)
public class Delightful
{
public static final String MODID = "delightful";
public static Delightful instance;
public static CommonProxy proxy;
private static final Logger LOGGER = LogManager.getLogger();
public class Delightful {
public static final String MODID = "delightful";
private static final Logger LOGGER = LogManager.getLogger();
public static Delightful instance;
public static CommonProxy proxy;

public Delightful() {
instance = this;
proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
proxy.start();
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, DelightfulConfig.SPEC);
}
public Delightful() {
instance = this;
proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
proxy.start();
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, DelightfulConfig.SPEC);
}

public static Logger getLogger() {
return LOGGER;
}
}
public static Logger getLogger() {
return LOGGER;
}
}
209 changes: 106 additions & 103 deletions src/main/java/net/brnbrd/delightful/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,111 +22,114 @@
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.function.Supplier;

public class Util {

public static final String LOADER = "forge";

public static ResourceLocation rl(String modid, String path) {
return new ResourceLocation(modid, path);
}

public static ResourceLocation rl(String separated) {
return new ResourceLocation(separated);
}

public static TagKey<Item> it(String modid, String path) {
return ItemTags.create(rl(modid, path));
}

public static TagKey<EntityType<?>> et(String modid, String path) {
return TagKey.create(Registries.ENTITY_TYPE, rl(modid, path));
}

public static ObjectArrayList<ItemStack> with(ObjectArrayList<ItemStack> before, ItemStack addition) {
before.add(addition);
return before;
}

@Nullable public static Item item(String modid, String path) {
return item(rl(modid, path));
}

@Nullable public static Item item(ResourceLocation rl) {
if (ForgeRegistries.ITEMS.containsKey(rl)) {
return ForgeRegistries.ITEMS.getValue(rl);
}
return null;
}

@Nullable public static Block block(String modid, String path) {
return block(rl(modid, path));
}

@Nullable public static Block block(ResourceLocation rl) {
return ForgeRegistries.BLOCKS.getValue(rl);
}

public static ItemStack gs(RegistryObject<Item> r, int count) {
return new ItemStack(r.get(), count);
}

public static ItemStack gs(RegistryObject<Item> r) {
return gs(r, 1);
}

public static String name(Item item) {
return (ForgeRegistries.ITEMS.containsValue(item)) ?
Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(item)).getPath() : "";
}

public static String name(Block block) {
return (ForgeRegistries.BLOCKS.containsValue(block)) ?
Objects.requireNonNull(ForgeRegistries.BLOCKS.getKey(block)).getPath() : "";
}

public static String name(RegistryObject<?> reg) {
return reg.getId().getPath();
}

public static Ingredient ing(Supplier<? extends ItemLike> i) {
return Ingredient.of(i.get());
}

public static ItemStack enchant(ItemStack stack, Enchantment enchantment, int level) {
ItemStack enchanted = stack.copy();
enchanted.enchant(enchantment, level);
return enchanted;
}

public static void dropOrGive(ItemStack stack, Level world, BlockPos drop, Player give) {
if (DelightfulConfig.GIVE_SLICED_DIRECTLY.get()) {
ItemHandlerHelper.giveItemToPlayer(give, stack, 0);
} else {
Containers.dropItemStack(world, drop.getX(), drop.getY() + 0.25F, drop.getZ(), stack);
}
}

public static boolean hasTagString(ItemStack stack, String key, String value) {
if (stack.hasTag()) {
CompoundTag tag = stack.getTag();
return tag != null && tag.contains(key) && tag.getString(key).equals(value);
}
return false;
}

public static boolean enabled(String item) {
return DelightfulConfig.CONFIG.verify(item);
}

public static boolean enabled(RegistryObject<Item> item) {
return enabled(item.getId().getPath());
}

public static boolean enabled(Item item) {
return enabled(Util.name(item));
}
}
public static final String LOADER = "forge";

public static ResourceLocation rl(String modid, String path) {
return new ResourceLocation(modid, path);
}

public static ResourceLocation rl(String separated) {
return new ResourceLocation(separated);
}

public static TagKey<Item> it(String modid, String path) {
return ItemTags.create(rl(modid, path));
}

public static TagKey<EntityType<?>> et(String modid, String path) {
return TagKey.create(Registries.ENTITY_TYPE, rl(modid, path));
}

public static ObjectArrayList<ItemStack> with(ObjectArrayList<ItemStack> before, ItemStack addition) {
before.add(addition);
return before;
}

@Nullable
public static Item item(String modid, String path) {
return item(rl(modid, path));
}

@Nullable
public static Item item(ResourceLocation rl) {
if (ForgeRegistries.ITEMS.containsKey(rl)) {
return ForgeRegistries.ITEMS.getValue(rl);
}
return null;
}

@Nullable
public static Block block(String modid, String path) {
return block(rl(modid, path));
}

@Nullable
public static Block block(ResourceLocation rl) {
return ForgeRegistries.BLOCKS.getValue(rl);
}

public static ItemStack gs(RegistryObject<Item> r, int count) {
return new ItemStack(r.get(), count);
}

public static ItemStack gs(RegistryObject<Item> r) {
return gs(r, 1);
}

public static String name(Item item) {
return (ForgeRegistries.ITEMS.containsValue(item)) ?
Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(item)).getPath() : "";
}

public static String name(Block block) {
return (ForgeRegistries.BLOCKS.containsValue(block)) ?
Objects.requireNonNull(ForgeRegistries.BLOCKS.getKey(block)).getPath() : "";
}

public static String name(RegistryObject<?> reg) {
return reg.getId().getPath();
}

public static Ingredient ing(Supplier<? extends ItemLike> i) {
return Ingredient.of(i.get());
}

public static ItemStack enchant(ItemStack stack, Enchantment enchantment, int level) {
ItemStack enchanted = stack.copy();
enchanted.enchant(enchantment, level);
return enchanted;
}

public static void dropOrGive(ItemStack stack, Level world, BlockPos drop, Player give) {
if (DelightfulConfig.GIVE_SLICED_DIRECTLY.get()) {
ItemHandlerHelper.giveItemToPlayer(give, stack, 0);
} else {
Containers.dropItemStack(world, drop.getX(), drop.getY() + 0.25F, drop.getZ(), stack);
}
}

public static boolean hasTagString(ItemStack stack, String key, String value) {
if (stack.hasTag()) {
CompoundTag tag = stack.getTag();
return tag != null && tag.contains(key) && tag.getString(key).equals(value);
}
return false;
}

public static boolean enabled(String item) {
return DelightfulConfig.CONFIG.verify(item);
}

public static boolean enabled(RegistryObject<Item> item) {
return enabled(item.getId().getPath());
}

public static boolean enabled(Item item) {
return enabled(Util.name(item));
}
}
125 changes: 63 additions & 62 deletions src/main/java/net/brnbrd/delightful/common/DelightfulConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,71 @@

public class DelightfulConfig {

public static final DelightfulConfig CONFIG;
public static final ForgeConfigSpec SPEC;
private final Map<String, ForgeConfigSpec.BooleanValue> stuff = new HashMap<>();
public static ForgeConfigSpec.BooleanValue CRAFT_NUT_MILK;
public static ForgeConfigSpec.BooleanValue COOK_CLOVER_HONEY;
public static ForgeConfigSpec.BooleanValue GIVE_SLICED_DIRECTLY;
public static ForgeConfigSpec.BooleanValue MELON_JUICING;
private static final ImmutableList<String> DEFAULT_DISABLED = ImmutableList.of(
Util.name(Knives.COPPER),
Util.name(Knives.AMETHYST),
Util.name(Knives.EMERALD),
Util.name(Knives.LAPIS_LAZULI)
);
public static final DelightfulConfig CONFIG;
public static final ForgeConfigSpec SPEC;
private static final ImmutableList<String> DEFAULT_DISABLED = ImmutableList.of(
Util.name(Knives.COPPER),
Util.name(Knives.AMETHYST),
Util.name(Knives.EMERALD),
Util.name(Knives.LAPIS_LAZULI)
);
public static ForgeConfigSpec.BooleanValue CRAFT_NUT_MILK;
public static ForgeConfigSpec.BooleanValue COOK_CLOVER_HONEY;
public static ForgeConfigSpec.BooleanValue GIVE_SLICED_DIRECTLY;
public static ForgeConfigSpec.BooleanValue MELON_JUICING;

DelightfulConfig(ForgeConfigSpec.Builder builder) {
List<String> items = DelightfulItems.ITEMS.getEntries().stream()
.map(obj -> obj.getId().getPath())
.sorted()
.toList();
builder.comment(" Let's Configure Delightful");
stuff.clear();
builder.push("Knives");
items.stream()
.filter(path -> path.contains("_knife"))
.forEach(knife -> put(builder, stuff, knife, !DEFAULT_DISABLED.contains(knife)));
builder.pop();
builder.push("Pie Overhauls");
items.stream()
.filter(path -> path.contains("_pie_slice"))
.forEach(knife -> put(builder, stuff, knife, !DEFAULT_DISABLED.contains(knife)));
builder.pop();
builder.push("Registry & Recipes");
items.stream()
.filter(path -> !path.contains("_knife") && !path.contains("_pie_slice"))
.forEach(not -> put(builder, stuff, not, !DEFAULT_DISABLED.contains(not)));
CRAFT_NUT_MILK = builder
.comment("Allow cooking milk from nuts")
.define("nut_milk", true);
stuff.put("nut_milk", CRAFT_NUT_MILK);
COOK_CLOVER_HONEY = builder
.comment("Allow cooking honey from honey and clovers")
.define("clover_honey", false);
stuff.put("clover_honey", COOK_CLOVER_HONEY);
GIVE_SLICED_DIRECTLY = builder
.comment("Give items that are sliced off of blocks directly to player's inventory instead of dropping")
.define("give_sliced_directly", false);
MELON_JUICING = builder
.comment("Allow sliced melons to be juiced in-world (right click)")
.define("melon_juicing", true);
builder.pop();
}
static {
var pair = new ForgeConfigSpec.Builder().configure(DelightfulConfig::new);
SPEC = pair.getRight();
CONFIG = pair.getLeft();
}

private static void put(ForgeConfigSpec.Builder builder, Map<String, ForgeConfigSpec.BooleanValue> map, String name, boolean def) {
map.put(name, builder.define(name, def));
}
private final Map<String, ForgeConfigSpec.BooleanValue> stuff = new HashMap<>();

public boolean verify(String item) {
return CONFIG.stuff.containsKey(item) ?
CONFIG.stuff.get(item).get() : false;
}
DelightfulConfig(ForgeConfigSpec.Builder builder) {
List<String> items = DelightfulItems.ITEMS.getEntries().stream()
.map(obj -> obj.getId().getPath())
.sorted()
.toList();
builder.comment(" Let's Configure Delightful");
stuff.clear();
builder.push("Knives");
items.stream()
.filter(path -> path.contains("_knife"))
.forEach(knife -> put(builder, stuff, knife, !DEFAULT_DISABLED.contains(knife)));
builder.pop();
builder.push("Pie Overhauls");
items.stream()
.filter(path -> path.contains("_pie_slice"))
.forEach(knife -> put(builder, stuff, knife, !DEFAULT_DISABLED.contains(knife)));
builder.pop();
builder.push("Registry & Recipes");
items.stream()
.filter(path -> !path.contains("_knife") && !path.contains("_pie_slice"))
.forEach(not -> put(builder, stuff, not, !DEFAULT_DISABLED.contains(not)));
CRAFT_NUT_MILK = builder
.comment("Allow cooking milk from nuts")
.define("nut_milk", true);
stuff.put("nut_milk", CRAFT_NUT_MILK);
COOK_CLOVER_HONEY = builder
.comment("Allow cooking honey from honey and clovers")
.define("clover_honey", false);
stuff.put("clover_honey", COOK_CLOVER_HONEY);
GIVE_SLICED_DIRECTLY = builder
.comment("Give items that are sliced off of blocks directly to player's inventory instead of dropping")
.define("give_sliced_directly", false);
MELON_JUICING = builder
.comment("Allow sliced melons to be juiced in-world (right click)")
.define("melon_juicing", true);
builder.pop();
}

static {
var pair = new ForgeConfigSpec.Builder().configure(DelightfulConfig::new);
SPEC = pair.getRight();
CONFIG = pair.getLeft();
}
private static void put(ForgeConfigSpec.Builder builder, Map<String, ForgeConfigSpec.BooleanValue> map, String name, boolean def) {
map.put(name, builder.define(name, def));
}

public boolean verify(String item) {
return CONFIG.stuff.containsKey(item) ?
CONFIG.stuff.get(item).get() : false;
}
}
Loading

0 comments on commit 2d5ceef

Please sign in to comment.