Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Uraneptus committed Oct 22, 2024
1 parent 96769d4 commit 34aaafe
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 267 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'pmd'
id 'com.diffplug.spotless' version '5.12.5'
id 'com.diffplug.spotless' version '6.25.0'
id 'net.neoforged.gradle.userdev' version '7.0.145'
}

Expand Down Expand Up @@ -64,9 +64,8 @@ spotless {
}

pmd {
toolVersion '6.22.0'
// no way around this warning unless we upgrade Gradle, apparently
//incrementalAnalysis.set(true)
toolVersion '6.35.0'
incrementalAnalysis.set(true)
ruleSetFiles = files("spotless/pmd-ruleset.xml")
}

Expand Down
29 changes: 7 additions & 22 deletions src/main/java/vazkii/morphtool/AttachementRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.Level;
import vazkii.morphtool.data_components.ToolContentComponent;

import java.util.ArrayList;
import java.util.List;
import vazkii.morphtool.data_components.ToolContentComponent;

public class AttachementRecipe extends CustomRecipe {

Expand Down Expand Up @@ -60,37 +61,21 @@ public ItemStack assemble(CraftingInput input, HolderLookup.Provider provider) {
}
}

if (!tool.has(Registries.TOOL_CONTENT)) return ItemStack.EMPTY;
if (!tool.has(Registries.TOOL_CONTENT))
return ItemStack.EMPTY;
ItemStack copy = tool.copy();
String mod = MorphingHandler.getModFromStack(target);
ToolContentComponent contents = copy.get(Registries.TOOL_CONTENT);
if (contents == null) {
return ItemStack.EMPTY;
}
/*
List<ItemStack> contentStacks = new ArrayList<>(List.copyOf(copy.get(Registries.TOOL_CONTENT).getItems()));
//This assures that only one item of a mod is in the tool
if (!contentStacks.isEmpty()) {
for (ItemStack contentStack : contentStacks) {
if (BuiltInRegistries.ITEM.getKey(contentStack.getItem()).getNamespace().equals(mod)) {
return ItemStack.EMPTY;
}
}
}
contentStacks.add(target);

copy.set(Registries.TOOL_CONTENT, new ToolContentComponent(contentStacks));
*/
ToolContentComponent.Mutable mutable = new ToolContentComponent.Mutable(contents);
if (!target.isEmpty()) {
mutable.tryInsert(target);
}
copy.set(Registries.TOOL_CONTENT, mutable.toImmutable());


return copy;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vazkii/morphtool/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.InputEvent;
import net.neoforged.neoforge.network.PacketDistributor;

import vazkii.morphtool.data_components.ToolContentComponent;
import vazkii.morphtool.network.MessageMorphTool;
import vazkii.morphtool.network.NetworkHandler;
Expand Down Expand Up @@ -130,4 +130,4 @@ public static String previousMod(ToolContentComponent toolContents, String mod)
}
return mods.get(retid);
}
}
}
18 changes: 12 additions & 6 deletions src/main/java/vazkii/morphtool/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.common.base.Predicates;
import com.google.common.collect.Lists;

import net.neoforged.neoforge.common.ModConfigSpec;

import org.apache.commons.lang3.tuple.Pair;

import java.util.List;
Expand All @@ -23,10 +25,10 @@ public class ConfigHandler {
}

public ConfigHandler(ModConfigSpec.Builder builder) {
allItems = builder.define("Allow all items to be added", false);
invertHandShift = builder.define("Morph in the offhand instead of mainhand", false);
allItems = builder.define("allow_all_items", false); //Allow all items to be added
invertHandShift = builder.define("offhand_morph", false); //Morph in the offhand instead of mainhand

whitelistedItems = builder.defineList("Whitelisted Items",
whitelistedItems = builder.defineList("whitelist_items", //"Whitelisted Items"
Lists.newArrayList("botania:twig_wand",
"appliedenergistics2:network_tool",
"immersiveengineering:tool",
Expand All @@ -35,23 +37,26 @@ public ConfigHandler(ModConfigSpec.Builder builder) {
"bloodmagic:ritual_reader",
"draconicevolution:crystal_binder",
"crossroads:omnimeter"),
String::new,
Predicates.alwaysTrue());

whitelistedNames = builder.defineList("Whitelisted Names",
whitelistedNames = builder.defineList("whitelist_names", //"Whitelisted Names"
Lists.newArrayList("wrench",
"screwdriver",
"hammer",
"rotator",
"configurator",
"crowbar"),
String::new,
Predicates.alwaysTrue());

blacklistedMods = builder.defineList("Blacklisted Mods",
blacklistedMods = builder.defineList("blacklist_mods", //Blacklisted Mods
Lists.newArrayList("tconstruct",
"intangible"),
String::new,
Predicates.alwaysTrue());

aliasesList = builder.defineList("Mod Aliases",
aliasesList = builder.defineList("mod_aliasses", //Mod Aliases
Lists.newArrayList("nautralpledge=botania",
"thermalexpansion=thermalfoundation",
"thermaldynamics=thermalfoundation",
Expand All @@ -72,6 +77,7 @@ public ConfigHandler(ModConfigSpec.Builder builder) {
"buildcraftsilicon=buildcraft",
"cabletiers=refinedstorage",
"extrastorage=refinedstorage"),
String::new,
Predicates.alwaysTrue());

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vazkii/morphtool/MorphTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;

import vazkii.morphtool.network.NetworkHandler;
import vazkii.morphtool.proxy.CommonProxy;

Expand Down
25 changes: 13 additions & 12 deletions src/main/java/vazkii/morphtool/MorphToolClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;

import vazkii.morphtool.proxy.ClientProxy;
import vazkii.morphtool.proxy.CommonProxy;

@Mod(value = MorphTool.MOD_ID, dist = Dist.CLIENT)
public class MorphToolClient {
public static CommonProxy proxy;
public static CommonProxy proxy;

public MorphToolClient(IEventBus bus, ModContainer modContainer) {
bus.addListener(this::addToCreativeTab);
public MorphToolClient(IEventBus bus, ModContainer modContainer) {
bus.addListener(this::addToCreativeTab);

proxy = new ClientProxy();
proxy.preInit();
modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
}
proxy = new ClientProxy();
proxy.preInit();
modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
}

private void addToCreativeTab(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
event.accept(Registries.MORPH_TOOL);
}
}
private void addToCreativeTab(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
event.accept(Registries.MORPH_TOOL);
}
}
}
40 changes: 4 additions & 36 deletions src/main/java/vazkii/morphtool/MorphToolItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;

import vazkii.morphtool.data_components.ToolContentComponent;

import java.util.List;
Expand All @@ -35,23 +36,12 @@ public InteractionResult useOn(UseOnContext context) {

@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext tooltipContext, List<Component> tooltip, TooltipFlag advanced) {
if (!stack.has(Registries.TOOL_CONTENT)) return;

ToolContentComponent contents = stack.get(Registries.TOOL_CONTENT);
if (contents == null || contents.isEmpty()) return;

/*
if (!stack.hasTag() || !stack.getTag().contains(MorphingHandler.TAG_MORPH_TOOL_DATA)) {
if (!stack.has(Registries.TOOL_CONTENT))
return;
}

CompoundTag data = stack.getTag().getCompound(MorphingHandler.TAG_MORPH_TOOL_DATA);
if (data.getAllKeys().isEmpty()) {
ToolContentComponent contents = stack.get(Registries.TOOL_CONTENT);
if (contents == null || contents.isEmpty())
return;
}
*/

if (Screen.hasShiftDown()) {
for (ItemStack contentStack : contents.getItems()) {
if (!contentStack.isEmpty()) {
Expand All @@ -62,32 +52,10 @@ public void appendHoverText(ItemStack stack, Item.TooltipContext tooltipContext,
name = contentStack.getHoverName();
}


String mod = MorphingHandler.getModFromStack(contentStack);
tooltip.add(Component.literal(" " + mod + " : " + name.getString()));
}
}
/*
for (String s : data.getAllKeys()) {
CompoundTag cmp = data.getCompound(s);
if (cmp != null) {
ItemStack modStack = ItemStack.of(cmp);
if (!stack.isEmpty()) {
String name = modStack.getHoverName().getString();
if (modStack.hasTag() && modStack.getTag().contains(MorphingHandler.TAG_MORPH_TOOL_DISPLAY_NAME)) {
CompoundTag rawName = ((CompoundTag) modStack.getTag().get(MorphingHandler.TAG_MORPH_TOOL_DISPLAY_NAME));
Component nameComp = Component.Serializer.fromJson(rawName.getString("text"));
if(nameComp != null)
name = nameComp.getString();
}
String mod = MorphingHandler.getModFromStack(modStack);
tooltip.add(Component.literal(" " + mod + " : " + name));
}
}
}
*/
} else {
tooltip.add(Component.translatable(MorphTool.MOD_ID + ".misc.shift_for_info"));
}
Expand Down
Loading

0 comments on commit 34aaafe

Please sign in to comment.