Skip to content

Commit

Permalink
24w09a
Browse files Browse the repository at this point in the history
still a bunch of todo
  • Loading branch information
BasiqueEvangelist committed Mar 1, 2024
1 parent 13c4f5f commit 044b454
Show file tree
Hide file tree
Showing 21 changed files with 192 additions and 178 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ dependencies {
// modLocalRuntime("dev.emi:emi-fabric:${project.emi_version}")

modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}")
// modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}")

api(include("blue.endless:jankson:${project.jankson_version}"))

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx2G
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_base_version=1.20.5
minecraft_version=24w07a
yarn_mappings=24w07a+build.4
minecraft_version=24w09a
yarn_mappings=24w09a+build.5
loader_version=0.15.7
# Mod Properties
mod_version=0.12.5
maven_group=io.wispforest
archives_base_name=owo-lib
# Dependencies
fabric_version=0.96.3+1.20.5
fabric_version=0.96.5+1.20.5

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=14.0.688
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ private static int executeItem(CommandContext<ServerCommandSource> context, NbtP
feedback(source, TextOps.withFormatting("Not damageable", Formatting.GRAY));
}

if (context.getSource().getPlayer().getMainHandStack().hasNbt()) {
feedback(source, TextOps.withFormatting("NBT" + formatPath(path) + ": ", Formatting.GRAY)
.append(NbtHelper.toPrettyPrintedText(getPath(stack.getNbt(), path))));
} else {
feedback(source, TextOps.withFormatting("No NBT", Formatting.GRAY));
}
// TODO: figure out what to do with this.
// if (context.getSource().getPlayer().getMainHandStack().hasNbt()) {
// feedback(source, TextOps.withFormatting("NBT" + formatPath(path) + ": ", Formatting.GRAY)
// .append(NbtHelper.toPrettyPrintedText(getPath(stack.getNbt(), path))));
// } else {
// feedback(source, TextOps.withFormatting("No NBT", Formatting.GRAY));
// }

feedback(source, TextOps.withFormatting("-----------------------", Formatting.GRAY));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.server.command.LootCommand;
import net.minecraft.server.command.ServerCommandSource;

Expand All @@ -26,7 +28,12 @@ private static int execute(CommandContext<ServerCommandSource> context) throws C
var targetStack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false);
var tableId = IdentifierArgumentType.getIdentifier(context, "loot_table");

targetStack.getOrCreateSubNbt("BlockEntityTag").putString("LootTable", tableId.toString());
var blockEntityTag = targetStack.getOrDefault(DataComponentTypes.BLOCK_ENTITY_DATA, NbtComponent.DEFAULT);
blockEntityTag = blockEntityTag.apply(x -> {
x.putString("LootTable", tableId.toString());
});
targetStack.set(DataComponentTypes.BLOCK_ENTITY_DATA, blockEntityTag);

context.getSource().getPlayer().getInventory().offerOrDrop(targetStack);

return 0;
Expand Down
102 changes: 19 additions & 83 deletions src/main/java/io/wispforest/owo/itemgroup/OwoItemSettings.java
Original file line number Diff line number Diff line change
@@ -1,124 +1,60 @@
package io.wispforest.owo.itemgroup;

import net.fabricmc.fabric.api.item.v1.CustomDamageHandler;
import net.fabricmc.fabric.api.item.v1.EquipmentSlotProvider;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
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 class OwoItemSettings extends FabricItemSettings {
public interface OwoItemSettings {

@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;
default Item.Settings group(ItemGroupReference ref) {
throw new IllegalStateException("Implemented in mixin.");
}

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

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

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

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

/**
* @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}
*/
public OwoItemSettings stackGenerator(BiConsumer<Item, ItemGroup.Entries> generator) {
this.stackGenerator = generator;
return this;
default Item.Settings stackGenerator(BiConsumer<Item, ItemGroup.Entries> generator) {
throw new IllegalStateException("Implemented in mixin.");
}

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

/**
* Automatically increment {@link net.minecraft.stat.Stats#USED}
* for this item every time {@link Item#use(World, PlayerEntity, Hand)}
* returns an accepted result
*/
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);
default Item.Settings trackUsageStat() {
throw new IllegalStateException("Implemented in mixin.");
}

@Override
public OwoItemSettings recipeRemainder(Item recipeRemainder) {
return (OwoItemSettings) super.recipeRemainder(recipeRemainder);
default boolean shouldTrackUsageStat() {
throw new IllegalStateException("Implemented in mixin.");
}

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

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

}
48 changes: 0 additions & 48 deletions src/main/java/io/wispforest/owo/mixin/ItemStackMixin.java

This file was deleted.

17 changes: 17 additions & 0 deletions src/main/java/io/wispforest/owo/mixin/class_9320Accessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.wispforest.owo.mixin;

import net.minecraft.class_9320;
import net.minecraft.component.ComponentChanges;
import net.minecraft.loot.condition.LootCondition;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.util.List;

@Mixin(class_9320.class)
public interface class_9320Accessor {
@Invoker("<init>")
static class_9320 createClass_9320(List<LootCondition> list, ComponentChanges componentChanges) {
throw new UnsupportedOperationException();
}
}
10 changes: 4 additions & 6 deletions src/main/java/io/wispforest/owo/mixin/itemgroup/ItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ public class ItemMixin implements OwoItemExtensions {

@Inject(method = "<init>", at = @At("TAIL"))
private void grabTab(Item.Settings settings, CallbackInfo ci) {
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();
}
this.owo$tab = settings.tab();
this.owo$stackGenerator = settings.stackGenerator();
this.owo$group = settings.group();
this.owo$trackUsageStat = settings.shouldTrackUsageStat();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.wispforest.owo.mixin.itemgroup;

import io.wispforest.owo.itemgroup.ItemGroupReference;
import io.wispforest.owo.itemgroup.OwoItemGroup;
import io.wispforest.owo.itemgroup.OwoItemSettings;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import org.spongepowered.asm.mixin.Mixin;

import java.util.function.BiConsumer;

@Mixin(Item.Settings.class)
public class ItemSettingsMixin implements OwoItemSettings {
private OwoItemGroup owo$group = null;
private int owo$tab = 0;
// TODO: OwoItemGroup.DEFAULT_STACK_GENERATOR was inlined to not cause clinit issues. fix.
private BiConsumer<Item, ItemGroup.Entries> owo$stackGenerator = (item, stacks) -> stacks.add(item.getDefaultStack());
private boolean owo$trackUsageStat = false;

@Override
public Item.Settings group(ItemGroupReference ref) {
this.owo$group = ref.group();
this.owo$tab = ref.tab();

return (Item.Settings)(Object) this;
}

@Override
public Item.Settings group(OwoItemGroup group) {
this.owo$group = group;

return (Item.Settings)(Object) this;
}

@Override
public OwoItemGroup group() {
return owo$group;
}

@Override
public Item.Settings tab(int tab) {
this.owo$tab = tab;

return (Item.Settings)(Object) this;
}

@Override
public int tab() {
return owo$tab;
}

@Override
public Item.Settings stackGenerator(BiConsumer<Item, ItemGroup.Entries> generator) {
this.owo$stackGenerator = generator;

return (Item.Settings)(Object) this;
}

@Override
public BiConsumer<Item, ItemGroup.Entries> stackGenerator() {
return owo$stackGenerator;
}

@Override
public Item.Settings trackUsageStat() {
this.owo$trackUsageStat = true;

return (Item.Settings)(Object) this;
}

@Override
public boolean shouldTrackUsageStat() {
return owo$trackUsageStat;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.wispforest.owo.mixin.text;

import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.mojang.serialization.JsonOps;
import io.wispforest.owo.text.LanguageAccess;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.Language;
import net.minecraft.util.Util;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -24,7 +28,7 @@ private static String skipIfObjectOrArray(JsonElement el, String str, InputStrea
if (!el.isJsonPrimitive() && LanguageAccess.textConsumer != null) {
skipNext = true;

MutableText text = Text.Serialization.fromJsonTree(el);
MutableText text = (MutableText) Util.getResult(TextCodecs.CODEC.parse(JsonOps.INSTANCE, el), JsonParseException::new);
LanguageAccess.textConsumer.accept(str, text);

return "";
Expand Down
Loading

0 comments on commit 044b454

Please sign in to comment.