Skip to content

Commit

Permalink
Merge pull request #8 from skyinr/merge_taste
Browse files Browse the repository at this point in the history
feat: 将Taste与FoodTate进行合并
  • Loading branch information
luiqn2007 authored Aug 8, 2023
2 parents f9ee7cd + a94bcc3 commit dc7dc3e
Show file tree
Hide file tree
Showing 33 changed files with 244 additions and 263 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 1.20.1 2023-08-08T21:53:40.393013 food_tastes generator for sinofeast
852e90ef37aa9d07b79f85d2ab26904bbcf05cf9 data/sinofeast/food_tastes/acrid.json
03676f66215266b6431df247540fcbe77acbd637 data/sinofeast/food_tastes/bitter.json
9c052da1ce7f8624ca526c6668c74a051caaa53c data/sinofeast/food_tastes/empty.json
383f169a0131f72c7aa6e0531681d9ce93512cf0 data/sinofeast/food_tastes/fresh.json
1d95042b928ab9029a35bc875da588508b6bc48e data/sinofeast/food_tastes/pungent.json
367454eac372bd07428d1850f06457da88b8f03a data/sinofeast/food_tastes/salty.json
7efebb0c2d2f4fb39d04dc6552065323dc0d9e60 data/sinofeast/food_tastes/sour.json
6bd7be539aad86f07a3a7eb9821141a84f8d39f9 data/sinofeast/food_tastes/spicy.json
ea71cc353559fe20ac0008c18a7f3ff0f686b38b data/sinofeast/food_tastes/sweet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": true,
"like_weight": 5,
"name": "sinofeast:acrid",
"taste_key": "sinofeast:tastes/acrid",
"taste_key_primary": "sinofeast:tastes/primary/acrid",
"taste_key_secondary": "sinofeast:tastes/secondary/acrid"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": false,
"like_weight": 5,
"name": "sinofeast:bitter",
"taste_key": "sinofeast:tastes/bitter",
"taste_key_primary": "sinofeast:tastes/primary/bitter",
"taste_key_secondary": "sinofeast:tastes/secondary/bitter"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 0,
"is_advanced": false,
"like_weight": 0,
"name": "sinofeast:empty",
"taste_key": "sinofeast:tastes/empty",
"taste_key_primary": "sinofeast:tastes/primary/empty",
"taste_key_secondary": "sinofeast:tastes/secondary/empty"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": true,
"like_weight": 5,
"name": "sinofeast:fresh",
"taste_key": "sinofeast:tastes/fresh",
"taste_key_primary": "sinofeast:tastes/primary/fresh",
"taste_key_secondary": "sinofeast:tastes/secondary/fresh"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": true,
"like_weight": 5,
"name": "sinofeast:pungent",
"taste_key": "sinofeast:tastes/pungent",
"taste_key_primary": "sinofeast:tastes/primary/pungent",
"taste_key_secondary": "sinofeast:tastes/secondary/pungent"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": false,
"like_weight": 5,
"name": "sinofeast:salty",
"taste_key": "sinofeast:tastes/salty",
"taste_key_primary": "sinofeast:tastes/primary/salty",
"taste_key_secondary": "sinofeast:tastes/secondary/salty"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": false,
"like_weight": 5,
"name": "sinofeast:sour",
"taste_key": "sinofeast:tastes/sour",
"taste_key_primary": "sinofeast:tastes/primary/sour",
"taste_key_secondary": "sinofeast:tastes/secondary/sour"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": false,
"like_weight": 5,
"name": "sinofeast:spicy",
"taste_key": "sinofeast:tastes/spicy",
"taste_key_primary": "sinofeast:tastes/primary/spicy",
"taste_key_secondary": "sinofeast:tastes/secondary/spicy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dislike_weight": 5,
"is_advanced": false,
"like_weight": 5,
"name": "sinofeast:sweet",
"taste_key": "sinofeast:tastes/sweet",
"taste_key_primary": "sinofeast:tastes/primary/sweet",
"taste_key_secondary": "sinofeast:tastes/secondary/sweet"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import games.moegirl.sinocraft.sinofeast.block.SFBlocks;
import games.moegirl.sinocraft.sinofeast.item.SFItems;
import games.moegirl.sinocraft.sinofeast.networking.SFNetworking;
import games.moegirl.sinocraft.sinofeast.taste.TasteCodec;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DataPackRegistryEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,9 +30,6 @@ public SinoFeast() {
SFBlockItems.register(bus);
SFItems.register(bus);

bus.addListener((DataPackRegistryEvent.NewRegistry event) ->
event.dataPackRegistry(TasteCodec.TASTE_KEY, TasteCodec.TASTE_CODEC, TasteCodec.TASTE_CODEC));

}

public static SinoFeast getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;

public record FoodTaste(ResourceLocation key, String name, boolean isAdvanced, int likeWeight, int dislikeWeight,
public record FoodTaste(ResourceLocation key, boolean isAdvanced, int likeWeight, int dislikeWeight,
TagKey<Item> tasteKey, TagKey<Item> tasteKeyPrimary, TagKey<Item> tasteKeySecondary) {
public Component getName() {
return Component.translatable(name());
return Component.translatable("sinofeast.taste."+key.getPath());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package games.moegirl.sinocraft.sinofeast.data.food.taste;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;

public class FoodTasteCodec {
public static final Codec<FoodTaste> TASTE_CODEC = RecordCodecBuilder.create(builder ->
builder.group(
ResourceLocation.CODEC.fieldOf("name").forGetter(FoodTaste::key),
Codec.BOOL.fieldOf("is_advanced").forGetter(FoodTaste::isAdvanced),
Codec.INT.fieldOf("like_weight").forGetter(FoodTaste::likeWeight),
Codec.INT.fieldOf("dislike_weight").forGetter(FoodTaste::dislikeWeight),
TagKey.codec(Registries.ITEM).fieldOf("taste_key").forGetter(FoodTaste::tasteKey),
TagKey.codec(Registries.ITEM).fieldOf("taste_key_primary").forGetter(FoodTaste::tasteKeyPrimary),
TagKey.codec(Registries.ITEM).fieldOf("taste_key_secondary").forGetter(FoodTaste::tasteKeySecondary)
).apply(builder, FoodTaste::new)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.mojang.serialization.JsonOps;
import games.moegirl.sinocraft.sinofeast.SinoFeast;
import games.moegirl.sinocraft.sinofeast.networking.packet.S2CSyncFoodTastePacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.event.OnDatapackSyncEvent;
Expand All @@ -21,33 +21,24 @@ public class FoodTasteReloadListener extends SimpleJsonResourceReloadListener {
private static final Gson GSON = new Gson();

public FoodTasteReloadListener() {
super(GSON, "sinoseries/sinofeast/food_tastes");
super(GSON, "food_tastes");
}

@Override
protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager resourceManager, ProfilerFiller profiler) {
FoodTastes.getInstance().initTastes();

for (var entry : map.entrySet()) {
var key = entry.getKey();
var json = entry.getValue().getAsJsonObject();
var name = json.get("name").getAsString();
var isAdvanced = json.get("is_advanced").getAsBoolean();
var likeWeight = json.get("like_weight").getAsInt();
var dislikeWeight = json.get("dislike_weight").getAsInt();
var tasteKey = json.get("taste_key").getAsString();
var tasteKeyPrimary = json.get("taste_key_primary").getAsString();
var tasteKeySecondary = json.get("taste_key_secondary").getAsString();
FoodTastes.getInstance().addTaste(key, new FoodTaste(key, name, isAdvanced, likeWeight, dislikeWeight,
ItemTags.create(new ResourceLocation(tasteKey)),
ItemTags.create(new ResourceLocation(tasteKeyPrimary)),
ItemTags.create(new ResourceLocation(tasteKeySecondary))));

FoodTaste first = FoodTasteCodec.TASTE_CODEC.parse(JsonOps.INSTANCE, entry.getValue()).get().orThrow();

FoodTastes.getInstance().addTaste(first.key(),first);
}
}

@Override
public String getName() {
return "SinoFeast: Food TasteCodec Reload Listener";
return "SinoFeast: Food Tastes Reload Listener";
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import net.minecraft.resources.ResourceLocation;

import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class FoodTastes {
private static final Random RAND = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void onGatherData(GatherDataEvent event) {
gen.addProvider(true, blockTagsProvider);
gen.addProvider(true, new SFItemTagsProvider(output, lookupProvider, blockTagsProvider.contentsGetter(), SinoFeast.MODID, exHelper));

gen.addProvider(true, new SFTasteProvider(output, lookupProvider));
gen.addProvider(true, new SFTasteProvider(output, exHelper));
}
}
}
Loading

0 comments on commit dc7dc3e

Please sign in to comment.