Skip to content

Commit

Permalink
apply editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Aug 25, 2024
1 parent c8e1907 commit 583b367
Show file tree
Hide file tree
Showing 91 changed files with 518 additions and 498 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ Requires <a href="https://modrinth.com/mod/connector">Connector</a> and <a href=
Recipes are driven by defining **Tool Materials**, **Armor Materials**, **Equipment Types**, and **Unit Cost Overrides**.

- **Materials** inherit from vanilla tool/armor materials. They define upgrade paths like Iron->Diamond.
- By default, all vanilla materials are defined.
- By default, all vanilla materials are defined.
- **Types** define "alike" items. Items with matching types can upgrade .
- By default, the 5 tools (e.g. `c:swords`) and 4 armor slots are defined.
- By default, the 5 tools (e.g. `c:swords`) and 4 armor slots are defined.
- **Unit Cost** is what an item costs to upgrade to or repair. It's usually guessed from the material and a recipe.
- By default, vanilla non-tool/armor items are made repairable by overriding this.
- Netherite is also overridden to have appropriate diamond unit costs.
- By default, vanilla non-tool/armor items are made repairable by overriding this.
- Netherite is also overridden to have appropriate diamond unit costs.

For data structure examples, check out the [built-in datapack](https://github.com/sisby-folk/tinkerers-smithing/tree/1.19/src/main/resources/data/minecraft) or the mod compatibility packs in [Tinkerer's Quilt](https://github.com/sisby-folk/tinkerers-quilt/tree/1.19_modded/resources/datapacks).

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ processResources {
mc : compatibleVersions.split(", ")[0],
fl : libs.versions.fl.get(),
fapi : libs.versions.fapi.get(),
emi : libs.versions.emi.get()
emi : libs.versions.emi.get()
]
inputs.properties(meta)
filesMatching("*.mod.json") { expand(meta) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.resource.ResourceReloader;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.resource.ResourceReloader;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -44,6 +43,30 @@ public class TinkerersSmithingLoader {

public final List<Recipe<?>> RECIPES = new ArrayList<>();

public static Identifier recipeId(String recipeType, String... names) {
return new Identifier(ID, recipeType + "/" + String.join("/", names));
}

public static Identifier recipeId(String recipeType, Identifier... ids) {
return recipeId(recipeType, Arrays.stream(ids).map(id -> id.getNamespace().equals("minecraft") ? id.getPath() : id.getNamespace() + "/" + id.getPath()).toArray(String[]::new));
}

public static Identifier recipeId(String recipeType, Item... items) {
return recipeId(recipeType, Arrays.stream(items).map(Registries.ITEM::getId).toArray(Identifier[]::new));
}

public static Identifier appendId(Identifier id, String name) {
return new Identifier(id.toString() + "/" + name);
}

public static Identifier repairRecipeId(Item baseItem, Ingredient ingredient) {
if (ingredient.entries.length == 0) {
throw new IllegalArgumentException("Ingredients for Tinkerer's Smithing recipes can't be empty! When repairing item %s".formatted(Registries.ITEM.getId(baseItem)));
}
Identifier ingredientId = ingredient.entries[0] instanceof Ingredient.StackEntry se ? Registries.ITEM.getId(se.stack.getItem()) : ingredient.entries[0] instanceof Ingredient.TagEntry te ? te.tag.id() : new Identifier("ERROR");
return recipeId("repair", Registries.ITEM.getId(baseItem), ingredientId);
}

public void generateItemSmithingData(Map<Identifier, Recipe<?>> recipes) {
new LoaderRun().generateItemSmithingData(recipes);
SMITHING_TYPES.clear();
Expand Down Expand Up @@ -316,28 +339,4 @@ public void generateItemSmithingData(Map<Identifier, Recipe<?>> recipes) {
LOGGER.info("[Tinkerer's Smithing] Data Initialized!");
}
}

public static Identifier recipeId(String recipeType, String... names) {
return new Identifier(ID, recipeType + "/" + String.join("/", names));
}

public static Identifier recipeId(String recipeType, Identifier... ids) {
return recipeId(recipeType, Arrays.stream(ids).map(id -> id.getNamespace().equals("minecraft") ? id.getPath() : id.getNamespace() + "/" + id.getPath()).toArray(String[]::new));
}

public static Identifier recipeId(String recipeType, Item... items) {
return recipeId(recipeType, Arrays.stream(items).map(Registries.ITEM::getId).toArray(Identifier[]::new));
}

public static Identifier appendId(Identifier id, String name) {
return new Identifier(id.toString() + "/" + name);
}

public static Identifier repairRecipeId(Item baseItem, Ingredient ingredient) {
if (ingredient.entries.length == 0) {
throw new IllegalArgumentException("Ingredients for Tinkerer's Smithing recipes can't be empty! When repairing item %s".formatted(Registries.ITEM.getId(baseItem)));
}
Identifier ingredientId = ingredient.entries[0] instanceof Ingredient.StackEntry se ? Registries.ITEM.getId(se.stack.getItem()) : ingredient.entries[0] instanceof Ingredient.TagEntry te ? te.tag.id() : new Identifier("ERROR");
return recipeId("repair", Registries.ITEM.getId(baseItem), ingredientId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class TinkerersSmithingClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ClientPlayNetworking.registerGlobalReceiver(TinkerersSmithing.S2C_PING, (client, handler, buf, sender) -> {});
ClientPlayNetworking.registerGlobalReceiver(TinkerersSmithing.S2C_PING, (client, handler, buf, sender) -> {
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public void register(EmiRegistry registry) {
replacedIdPrefixes.clear();
addedRecipes.clear();

registry.getRecipeManager().listAllOfType(RecipeType.CRAFTING).stream().filter(ShapelessUpgradeRecipe.class::isInstance).map(r -> new EmiShapelessUpgradeRecipe((ShapelessUpgradeRecipe) r)).forEach(this::replaceRecipe);
registry.getRecipeManager().listAllOfType(RecipeType.CRAFTING).stream().filter(ShapelessRepairRecipe.class::isInstance).map(r -> new EmiShapelessRepairRecipe((ShapelessRepairRecipe) r)).forEach(this::replaceRecipe);
registry.getRecipeManager().listAllOfType(RecipeType.SMITHING).stream().filter(SmithingUpgradeRecipe.class::isInstance).map(r -> new EmiSmithingUpgradeRecipe((SmithingUpgradeRecipe) r)).forEach(this::replaceRecipe);
registry.getRecipeManager().listAllOfType(RecipeType.CRAFTING).stream().filter(recipe -> recipe instanceof ShapelessRepairRecipe).forEach(r -> replaceAnvilRecipe((ShapelessRepairRecipe) r));
registry.getRecipeManager().listAllOfType(RecipeType.CRAFTING).stream().filter(ShapelessUpgradeRecipe.class::isInstance).map(r -> new EmiShapelessUpgradeRecipe((ShapelessUpgradeRecipe) r)).forEach(this::replaceRecipe);
registry.getRecipeManager().listAllOfType(RecipeType.CRAFTING).stream().filter(ShapelessRepairRecipe.class::isInstance).map(r -> new EmiShapelessRepairRecipe((ShapelessRepairRecipe) r)).forEach(this::replaceRecipe);
registry.getRecipeManager().listAllOfType(RecipeType.SMITHING).stream().filter(SmithingUpgradeRecipe.class::isInstance).map(r -> new EmiSmithingUpgradeRecipe((SmithingUpgradeRecipe) r)).forEach(this::replaceRecipe);
registry.getRecipeManager().listAllOfType(RecipeType.CRAFTING).stream().filter(recipe -> recipe instanceof ShapelessRepairRecipe).forEach(r -> replaceAnvilRecipe((ShapelessRepairRecipe) r));
Multimap<ItemPair, SacrificeUpgradeRecipe> cappedRecipes = HashMultimap.create();
for (SmithingRecipe recipe : registry.getRecipeManager().listAllOfType(RecipeType.SMITHING)) {
if (recipe instanceof SacrificeUpgradeRecipe sur) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public boolean hideCraftable() {
public void addWidgets(WidgetHolder widgets) {
widgets.addTexture(EmiTexture.PLUS, 27, 3);
widgets.addTexture(EmiTexture.EMPTY_ARROW, 75, 1);
widgets.add(new IterativeSlotWidget(i -> getTool(i, false),0, 0).appendTooltip(ingredient -> new OrderedTextTooltipComponent(Text.literal("Repair Cost: " + ingredient.getEmiStacks().get(0).getItemStack().getRepairCost()).setStyle(Style.EMPTY.withColor(Formatting.GRAY)).asOrderedText())));
widgets.add(new IterativeSlotWidget(i -> getTool(i, false), 0, 0).appendTooltip(ingredient -> new OrderedTextTooltipComponent(Text.literal("Repair Cost: " + ingredient.getEmiStacks().get(0).getItemStack().getRepairCost()).setStyle(Style.EMPTY.withColor(Formatting.GRAY)).asOrderedText())));
widgets.add(new IterativeSlotWidget(this::getRepairStack, 49, 0));
widgets.add(new IterativeSlotWidget(i -> getTool(i, true), 107, 0).appendTooltip(ingredient -> new OrderedTextTooltipComponent(Text.literal("Repair Cost: " + ingredient.getEmiStacks().get(0).getItemStack().getRepairCost()).setStyle(Style.EMPTY.withColor(Formatting.GRAY)).asOrderedText())).recipeContext(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.util.JsonHelper;
import net.minecraft.util.Pair;
import net.minecraft.util.profiler.Profiler;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

import java.io.IOException;
Expand All @@ -40,7 +39,7 @@ public MultiJsonDataLoader(Gson gson, String dataType) {
protected Map<Identifier, Collection<Pair<JsonElement, String>>> prepare(ResourceManager manager, Profiler profiler) {
Map<Identifier, Collection<Pair<JsonElement, String>>> outMap = Maps.newHashMap();

for(Map.Entry<Identifier, List<Resource>> entry : manager.findAllResources(this.dataType, id -> id.getPath().endsWith(".json")).entrySet()) {
for (Map.Entry<Identifier, List<Resource>> entry : manager.findAllResources(this.dataType, id -> id.getPath().endsWith(".json")).entrySet()) {
Identifier fileId = entry.getKey();
Identifier id = new Identifier(fileId.getNamespace(), fileId.getPath().substring(dataType.length() + 1, fileId.getPath().length() - FILE_SUFFIX.length()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@
import net.minecraft.util.Pair;
import net.minecraft.util.profiler.Profiler;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public abstract class SmithingMaterialLoader extends MultiJsonDataLoader {
public final TinkerersSmithingMaterial.EQUIPMENT_TYPE type;

public static final String KEY_INHERIT_FROM_ITEM = "inheritFromItem";
public static final String KEY_REPAIR_MATERIALS = "repairMaterials";
public static final String KEY_ADD_ITEM = "addItem";
public static final String KEY_REMOVE_ITEM = "removeItem";
public static final String KEY_UPGRADES_FROM = "upgradesFrom";
public static final String KEY_UPGRADES_TO = "upgradesTo";
public static final String KEY_SACRIFICE_VIA = "sacrificesVia";
public final TinkerersSmithingMaterial.EQUIPMENT_TYPE type;

public SmithingMaterialLoader(Gson gson, String dataType, TinkerersSmithingMaterial.EQUIPMENT_TYPE type) {
super(gson, dataType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public SmithingTypeLoader(Gson gson) {
super(gson, "smithing_types");
}

@Override
public String getName() {
return ID.toString();
}

public static void addToTag(Map<Identifier, Collection<Item>> tags, String path, Item item) {
Identifier id = new Identifier(path); // minecraft for slot stuff
HashSet<Item> mutable = new HashSet<>(tags.computeIfAbsent(id, k -> new HashSet<>()));
mutable.add(item);
tags.put(id, ImmutableList.copyOf(mutable));
}

@Override
public String getName() {
return ID.toString();
}

@Override
protected void apply(Map<Identifier, Collection<Pair<JsonElement, String>>> prepared, ResourceManager manager, Profiler profiler) {
TinkerersSmithing.LOGGER.info("[Tinkerer's Smithing] Loading Types!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@

@Mixin(AnvilScreenHandler.class)
public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler {
@Shadow private int repairItemUsage;
@Final @Shadow private Property levelCost;
@Shadow
private int repairItemUsage;
@Final
@Shadow
private Property levelCost;

public AnvilScreenHandlerMixin(@Nullable ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) {
super(type, syncId, playerInventory, context);
Expand Down Expand Up @@ -84,8 +87,8 @@ private void applyDeworkMaterial(CallbackInfo ci) {
if (ingredient.isIn(TinkerersSmithing.DEWORK_INGREDIENTS) && base.getRepairCost() > 0) {
ItemStack result = base.copy();
this.repairItemUsage = 0;
do {
result.setRepairCost(((result.getRepairCost() + 1)/2)-1);
do {
result.setRepairCost(((result.getRepairCost() + 1) / 2) - 1);
this.repairItemUsage++;
} while (result.getRepairCost() > 0 && this.repairItemUsage < ingredient.getCount());
this.getSlot(AnvilScreenHandler.OUTPUT_ID).setStack(result);
Expand All @@ -95,7 +98,8 @@ private void applyDeworkMaterial(CallbackInfo ci) {
}
}

@Unique private int getSRCost(Map<Enchantment, Integer> base, Map<Enchantment, Integer> ingredient) {
@Unique
private int getSRCost(Map<Enchantment, Integer> base, Map<Enchantment, Integer> ingredient) {
return ingredient.entrySet().stream().map(entry -> {
Enchantment enchantment = entry.getKey();
int level = entry.getValue();
Expand All @@ -111,7 +115,8 @@ private void applyDeworkMaterial(CallbackInfo ci) {
}).reduce(0, Integer::sum);
}

@Unique private boolean doSwapEnchantments(Map<Enchantment, Integer> base, Map<Enchantment, Integer> ingredient) {
@Unique
private boolean doSwapEnchantments(Map<Enchantment, Integer> base, Map<Enchantment, Integer> ingredient) {
return !(this.getSlot(AnvilScreenHandler.INPUT_2_ID).getStack().isOf(Items.ENCHANTED_BOOK)) && getSRCost(base, ingredient) > getSRCost(ingredient, base);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

@Mixin(Ingredient.class)
public class IngredientMixin {
@Unique private boolean isFootgun() {
@Unique
private boolean isFootgun() {
Ingredient self = (Ingredient) (Object) this;
if (Arrays.stream(self.entries).anyMatch(e -> e instanceof Ingredient.TagEntry) && (Registries.ITEM.getEntryList(ItemTags.PLANKS).isEmpty() || Registries.ITEM.getEntryList(ItemTags.PLANKS).get().size() == 0)) {
TinkerersSmithing.LOGGER.error("[Tinkerer's Smithing] Cowardly refusing to access an unloaded tag ingredient: {}", self.toJson().toString(), new IllegalStateException("A tag ingredient was accessed before tags are loaded - This can break recipes! Report this to the mod in the trace below."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand All @@ -30,11 +33,13 @@

@Mixin(ItemStack.class)
public abstract class ItemStackMixin {
@Unique private boolean isBroken() {
@Unique
private boolean isBroken() {
return TinkerersSmithing.isBroken((ItemStack) (Object) this);
}

@Unique private boolean isKeeper() {
@Unique
private boolean isKeeper() {
return TinkerersSmithing.isKeeper((ItemStack) (Object) this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

@Mixin(RecipeManager.class)
public class RecipeManagerMixin {
@Unique private ImmutableMap.Builder<Identifier, Recipe<?>> builder = null;
@Unique
private ImmutableMap.Builder<Identifier, Recipe<?>> builder = null;

@ModifyVariable(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;", ordinal = 0), index = 5)
private ImmutableMap.Builder<Identifier, Recipe<?>> AddRuntimeRecipes(ImmutableMap.Builder<Identifier, Recipe<?>> builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

@Mixin(SmithingScreenHandler.class)
public abstract class SmithingScreenHandlerMixin extends ForgingScreenHandler {
@Shadow @Nullable private SmithingRecipe currentRecipe;
@Unique private int ingredientsUsed = 0;
@Shadow
@Nullable
private SmithingRecipe currentRecipe;
@Unique
private int ingredientsUsed = 0;

public SmithingScreenHandlerMixin(@Nullable ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) {
super(type, syncId, playerInventory, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

@Mixin(SynchronizeRecipesS2CPacket.class)
public class SynchronizeRecipesS2CPacketMixin implements ServerRecipePacket<SynchronizeRecipesS2CPacket> {
@Unique private boolean tinkerersSmithing$fallback = false;
@Unique
private boolean tinkerersSmithing$fallback = false;

@ModifyArg(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;writeCollection(Ljava/util/Collection;Lnet/minecraft/network/PacketByteBuf$PacketWriter;)V"), index = 0)
private Collection<Recipe<?>> writeSafeRecipes(Collection<Recipe<?>> original) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

@Mixin(InGameHud.class)
public class InGameHudMixin {
@Shadow private ItemStack currentStack;
@Shadow
private ItemStack currentStack;

@ModifyExpressionValue(method = "renderHeldItemTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;empty()Lnet/minecraft/text/MutableText;", ordinal = 0))
private MutableText showBrokenHeldItemTooltip(MutableText text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static ItemStack getPreviewResult(Item resultItem, int additionUnits, in
}

public static int resultDamage(Item resultItem, int additionUnits, int resultUnits, int additionDamage, int additionMaxDamage) {
return (int) Math.ceil(resultItem.getMaxDamage() - ((additionMaxDamage - additionDamage) * ((double) additionUnits * resultItem.getMaxDamage()) / ((double)additionMaxDamage * resultUnits)));
return (int) Math.ceil(resultItem.getMaxDamage() - ((additionMaxDamage - additionDamage) * ((double) additionUnits * resultItem.getMaxDamage()) / ((double) additionMaxDamage * resultUnits)));
}

@Override
Expand All @@ -54,6 +54,16 @@ public boolean isIgnoredInRecipeBook() {
return true;
}

@Override
public RecipeSerializer<?> getSerializer() {
return TinkerersSmithing.SACRIFICE_UPGRADE_SERIALIZER;
}

@Override
public @Nullable RecipeSerializer<SmithingTransformRecipe> getFallbackSerializer() {
return RecipeSerializer.SMITHING_TRANSFORM;
}

public static class Serializer implements RecipeSerializer<SacrificeUpgradeRecipe> {
public SacrificeUpgradeRecipe read(Identifier id, JsonObject json) {
Item baseItem = JsonHelper.getItem(json, "base");
Expand Down Expand Up @@ -81,14 +91,4 @@ public void write(PacketByteBuf buf, SacrificeUpgradeRecipe recipe) {
buf.writeVarInt(recipe.resultUnits);
}
}

@Override
public RecipeSerializer<?> getSerializer() {
return TinkerersSmithing.SACRIFICE_UPGRADE_SERIALIZER;
}

@Override
public @Nullable RecipeSerializer<SmithingTransformRecipe> getFallbackSerializer() {
return RecipeSerializer.SMITHING_TRANSFORM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import net.minecraft.registry.Registries;

public interface ServerRecipePacket<T extends Packet<?>> {
T tinkerersSmithing$withFallback();

static <T extends F, F extends Recipe<?>> void writeRecipeWithFallback(PacketByteBuf buf, T recipe) {
if (recipe instanceof ServerRecipe<?> sr) {
RecipeSerializer<F> serializer = (RecipeSerializer<F>) sr.getFallbackSerializer();
Expand All @@ -20,4 +18,6 @@ static <T extends F, F extends Recipe<?>> void writeRecipeWithFallback(PacketByt
SynchronizeRecipesS2CPacket.writeRecipe(buf, recipe);
}
}

T tinkerersSmithing$withFallback();
}
Loading

0 comments on commit 583b367

Please sign in to comment.