Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -14,11 +14,13 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

Set<String> apiModules = [
"fabric-api-base",
"fabric-command-api-v1",
"fabric-command-api-v2",
"fabric-lifecycle-events-v1",
"fabric-networking-api-v1",
"fabric-registry-sync-v0"
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.15.3

# Mod Properties
mod_version = 1.6.3-1.18.2
mod_version = 2.0.0-1.19.2
maven_group = wothers.ift
archives_base_name = items-from-text

# Dependencies
fabric_version=0.47.8+1.18.2
fabric_version=0.77.0+1.19.2
2 changes: 1 addition & 1 deletion src/main/java/wothers/ift/items/ItemProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private boolean initialRecipeCheck() {

private boolean initialShapedRecipeCheck(String[] strings) {
if (NumberUtils.isInteger(strings[1])) return true;
if (strings[1].length() < 1 || strings[1].length() > 3) return true;
if (strings[1].isEmpty() || strings[1].length() > 3) return true;
for (int i = 2; i < 4; i++) {
if (NumberUtils.isInteger(strings[i])) return false;
if (strings[i].length() != strings[1].length()) return true;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/wothers/ift/mixins/ModelLoaderMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import wothers.ift.ItemRegistry;

@Mixin(ModelLoader.class)
public class ModelLoaderMixin {
@Inject(method = "loadModelFromJson", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourceManager;getResource(Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/Resource;"), cancellable = true)
@Inject(method = "loadModelFromJson", at = @At(value = "INVOKE", target="Lnet/minecraft/resource/ResourceManager;openAsReader(Lnet/minecraft/util/Identifier;)Ljava/io/BufferedReader;"), cancellable = true)
private void loadModelFromJson(Identifier id, CallbackInfoReturnable<JsonUnbakedModel> cir) {
if (!ItemRegistry.INSTANCE.getRegisteredItems().containsKey(id.toString())) return;
String modelJson = createItemModelJsonString(id.toString(), ItemRegistry.INSTANCE.getRegisteredItems().get(id.toString()));
String modelJson = ift$createItemModelJsonString(id.toString(), ItemRegistry.INSTANCE.getRegisteredItems().get(id.toString()));
JsonUnbakedModel model = JsonUnbakedModel.deserialize(modelJson);
model.id = id.toString();
cir.setReturnValue(model);
cir.cancel();
}

private String createItemModelJsonString(String id, String modelType) {
@Unique
private String ift$createItemModelJsonString(String id, String modelType) {
return "{\n" + " \"parent\": \"item/" + modelType + "\",\n" + " \"textures\": {\n" + " \"layer0\": \"" + id + "\"\n" + " }\n" + "}";
}
}
19 changes: 12 additions & 7 deletions src/main/java/wothers/ift/mixins/RegistryMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.util.registry.SimpleRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -20,29 +21,33 @@

@Mixin(SimpleRegistry.class)
public abstract class RegistryMixin {
private final Map<RegistryKey<?>, FoodComponent> foodComponentMap = new HashMap<>();

@Unique
private final Map<RegistryKey<?>, FoodComponent> itemsfromtext$foodComponentMap = new HashMap<>();

@Inject(method = "add", at = @At(value = "HEAD"))
private void interceptAddItem(RegistryKey<?> key, Object entry, Lifecycle lifecycle, CallbackInfoReturnable<RegistryEntry<?>> cir) {
if (!this.equals(Registry.ITEM)) return;
addFoodContainingEffects(key, (Item) entry);
itemsfromtext$addFoodContainingEffects(key, (Item) entry);
}

private void addFoodContainingEffects(RegistryKey<?> key, Item item) {
@Unique
private void itemsfromtext$addFoodContainingEffects(RegistryKey<?> key, Item item) {
if (!item.isFood()) return;
FoodComponent foodComponent = item.getFoodComponent();
if (foodComponent.getStatusEffects().isEmpty()) return;
foodComponentMap.put(key, foodComponent);
itemsfromtext$foodComponentMap.put(key, foodComponent);
}

@Inject(method = "freeze", at = @At(value = "HEAD"))
private void validateOnFreeze(CallbackInfoReturnable<Registry<?>> cir) {
if (!this.equals(Registry.ITEM)) return;
validateFoodEffects();
itemsfromtext$validateFoodEffects();
}

private void validateFoodEffects() {
for (Map.Entry<RegistryKey<?>, FoodComponent> entry : foodComponentMap.entrySet()) {
@Unique
private void itemsfromtext$validateFoodEffects() {
for (Map.Entry<RegistryKey<?>, FoodComponent> entry : itemsfromtext$foodComponentMap.entrySet()) {
Iterator<Pair<StatusEffectInstance, Float>> iterator = entry.getValue().getStatusEffects().iterator();
while (iterator.hasNext()) {
Pair<StatusEffectInstance, Float> pair = iterator.next();
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"mixins.json"
],
"depends": {
"fabricloader": ">=0.12.5",
"minecraft": "1.18.x"
"fabricloader": ">=0.15.3",
"minecraft": "~1.19.2",
"java": ">=17",
"fabric-api": "*"
},
"suggests": {
"another-mod": "*"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "wothers.ift.mixins",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_17",
"mixins": [
"FuelLoaderMixin",
"LanguageLoaderMixin",
Expand Down