Skip to content

Commit

Permalink
fine
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Mar 1, 2024
1 parent 044b454 commit 32ff3b2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 104 deletions.
100 changes: 81 additions & 19 deletions src/main/java/io/wispforest/owo/itemgroup/OwoItemSettings.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,122 @@
package io.wispforest.owo.itemgroup;

import net.fabricmc.fabric.api.item.v1.CustomDamageHandler;
import net.fabricmc.fabric.api.item.v1.EquipmentSlotProvider;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Hand;
import net.minecraft.util.Rarity;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.function.BiConsumer;

public interface OwoItemSettings {
public class OwoItemSettings extends Item.Settings {

default Item.Settings group(ItemGroupReference ref) {
throw new IllegalStateException("Implemented in mixin.");
@Nullable
private OwoItemGroup group = null;
private int tab = 0;
private BiConsumer<Item, ItemGroup.Entries> stackGenerator = OwoItemGroup.DEFAULT_STACK_GENERATOR;
private boolean trackUsageStat = false;

public OwoItemSettings group(ItemGroupReference ref) {
this.group = ref.group();
this.tab = ref.tab();
return this;
}

/**
* @param group The item group this item should appear in
*/
default Item.Settings group(OwoItemGroup group) {
throw new IllegalStateException("Implemented in mixin.");
public OwoItemSettings group(OwoItemGroup group) {
this.group = group;
return this;
}

default OwoItemGroup group() {
throw new IllegalStateException("Implemented in mixin.");
public OwoItemGroup group() {
return this.group;
}

default Item.Settings tab(int tab) {
throw new IllegalStateException("Implemented in mixin.");
public OwoItemSettings tab(int tab) {
this.tab = tab;
return this;
}

default int tab() {
throw new IllegalStateException("Implemented in mixin.");
public int tab() {
return this.tab;
}

/**
* @param generator The function this item uses for creating stacks in the
* {@link OwoItemGroup} it is in, by default this will be {@link OwoItemGroup#DEFAULT_STACK_GENERATOR}
*/
default Item.Settings stackGenerator(BiConsumer<Item, ItemGroup.Entries> generator) {
throw new IllegalStateException("Implemented in mixin.");
public OwoItemSettings stackGenerator(BiConsumer<Item, ItemGroup.Entries> generator) {
this.stackGenerator = generator;
return this;
}

default BiConsumer<Item, ItemGroup.Entries> stackGenerator() {
throw new IllegalStateException("Implemented in mixin.");
public BiConsumer<Item, ItemGroup.Entries> stackGenerator() {
return this.stackGenerator;
}

/**
* Automatically increment {@link net.minecraft.stat.Stats#USED}
* for this item every time {@link Item#use(World, PlayerEntity, Hand)}
* returns an accepted result
*/
default Item.Settings trackUsageStat() {
throw new IllegalStateException("Implemented in mixin.");
public OwoItemSettings trackUsageStat() {
this.trackUsageStat = true;
return this;
}

public boolean shouldTrackUsageStat() {
return this.trackUsageStat;
}

@Override
public OwoItemSettings equipmentSlot(EquipmentSlotProvider equipmentSlotProvider) {
return (OwoItemSettings) super.equipmentSlot(equipmentSlotProvider);
}

@Override
public OwoItemSettings customDamage(CustomDamageHandler handler) {
return (OwoItemSettings) super.customDamage(handler);
}

@Override
public OwoItemSettings food(FoodComponent foodComponent) {
return (OwoItemSettings) super.food(foodComponent);
}

@Override
public OwoItemSettings maxCount(int maxCount) {
return (OwoItemSettings) super.maxCount(maxCount);
}

@Override
public OwoItemSettings maxDamageIfAbsent(int maxDamage) {
return (OwoItemSettings) super.maxDamageIfAbsent(maxDamage);
}

@Override
public OwoItemSettings maxDamage(int maxDamage) {
return (OwoItemSettings) super.maxDamage(maxDamage);
}

@Override
public OwoItemSettings recipeRemainder(Item recipeRemainder) {
return (OwoItemSettings) super.recipeRemainder(recipeRemainder);
}

@Override
public OwoItemSettings rarity(Rarity rarity) {
return (OwoItemSettings) super.rarity(rarity);
}

default boolean shouldTrackUsageStat() {
throw new IllegalStateException("Implemented in mixin.");
@Override
public OwoItemSettings fireproof() {
return (OwoItemSettings) super.fireproof();
}
}
10 changes: 6 additions & 4 deletions src/main/java/io/wispforest/owo/mixin/itemgroup/ItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public class ItemMixin implements OwoItemExtensions {

@Inject(method = "<init>", at = @At("TAIL"))
private void grabTab(Item.Settings settings, CallbackInfo ci) {
this.owo$tab = settings.tab();
this.owo$stackGenerator = settings.stackGenerator();
this.owo$group = settings.group();
this.owo$trackUsageStat = settings.shouldTrackUsageStat();
if (settings instanceof OwoItemSettings owoSettings) {
this.owo$tab = owoSettings.tab();
this.owo$stackGenerator = owoSettings.stackGenerator();
this.owo$group = owoSettings.group();
this.owo$trackUsageStat = owoSettings.shouldTrackUsageStat();
}
}

@Override
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
],
"net/minecraft/class_332": [
"io/wispforest/owo/ui/util/MatrixStackTransformer"
],
"net/minecraft/class_1792\u0024class_1793": [
"io/wispforest/owo/itemgroup/OwoItemSettings"
]
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/owo.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"SimpleRegistryMixin",
"TagGroupLoaderMixin",
"itemgroup.ItemGroupAccessor",
"itemgroup.ItemSettingsMixin",
"itemgroup.ItemMixin",
"offline.AdvancementProgressAccessor",
"offline.PlayerAdvancementTrackerMixin",
Expand Down
2 changes: 1 addition & 1 deletion src/testmod/java/io/wispforest/uwu/items/UwuItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class UwuItems implements ItemRegistryContainer {
public static class OwoCompatItems implements ItemRegistryContainer {

@AssignedName("owo_ingot")
public static final Item OWO_COMPAT_ITEM = new Item(new Item.Settings().group(Uwu.FOUR_TAB_GROUP).tab(2));
public static final Item OWO_COMPAT_ITEM = new Item(new OwoItemSettings().group(Uwu.FOUR_TAB_GROUP).tab(2));

@Override
public boolean shouldProcessField(Item value, String identifier, Field field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class UwuTestStickItem extends Item {
);

public UwuTestStickItem() {
super(new Item.Settings()
super(new OwoItemSettings()
.group(Uwu.SIX_TAB_GROUP).tab(3).maxCount(1)
.trackUsageStat()
.stackGenerator(OwoItemGroup.DEFAULT_STACK_GENERATOR.andThen((item, stacks) -> {
Expand Down

0 comments on commit 32ff3b2

Please sign in to comment.