Skip to content

Commit

Permalink
Small fixes + changes
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Feb 29, 2024
1 parent 1454e00 commit 322417c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected FabricAdvancementProvider(FabricDataOutput output, CompletableFuture<R
*
* <p>Use {@link Advancement.Builder#build(Consumer, String)} to help build advancements.
*/
public abstract void generateAdvancement(Consumer<AdvancementEntry> consumer);
public abstract void generateAdvancement(RegistryWrapper.WrapperLookup registryLookup, Consumer<AdvancementEntry> consumer);

/**
* Return a new exporter that applies the specified conditions to any advancement it receives.
Expand All @@ -80,12 +80,12 @@ protected Consumer<AdvancementEntry> withConditions(Consumer<AdvancementEntry> e

@Override
public CompletableFuture<?> run(DataWriter writer) {
final Set<Identifier> identifiers = Sets.newHashSet();
final Set<AdvancementEntry> advancements = Sets.newHashSet();
return this.registryLookup.thenCompose(lookup -> {
final Set<Identifier> identifiers = Sets.newHashSet();
final Set<AdvancementEntry> advancements = Sets.newHashSet();

generateAdvancement(advancements::add);
generateAdvancement(lookup, advancements::add);

return this.registryLookup.thenCompose(lookup -> {
RegistryOps<JsonElement> ops = lookup.getOps(JsonOps.INSTANCE);
final List<CompletableFuture<?>> futures = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.minecraft.item.ItemGroup;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.stat.StatType;
import net.minecraft.text.TextContent;
Expand All @@ -52,52 +53,56 @@

/**
* Extend this class and implement {@link FabricLanguageProvider#generateTranslations(TranslationBuilder)}.
* Make sure to use {@link FabricLanguageProvider#FabricLanguageProvider(FabricDataOutput, String)} FabricLanguageProvider} to declare what language code is being generated if it isn't {@code en_us}.
* Make sure to use {@link FabricLanguageProvider#FabricLanguageProvider(FabricDataOutput, String, CompletableFuture)} FabricLanguageProvider} to declare what language code is being generated if it isn't {@code en_us}.
*
* <p>Register an instance of the class with {@link FabricDataGenerator.Pack#addProvider} in a {@link net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint}.
*/
public abstract class FabricLanguageProvider implements DataProvider {
protected final FabricDataOutput dataOutput;
private final String languageCode;
private final CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup;

protected FabricLanguageProvider(FabricDataOutput dataOutput) {
this(dataOutput, "en_us");
protected FabricLanguageProvider(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
this(dataOutput, "en_us", registryLookup);
}

protected FabricLanguageProvider(FabricDataOutput dataOutput, String languageCode) {
protected FabricLanguageProvider(FabricDataOutput dataOutput, String languageCode, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
this.dataOutput = dataOutput;
this.languageCode = languageCode;
this.registryLookup = registryLookup;
}

/**
* Implement this method to register languages.
*
* <p>Call {@link TranslationBuilder#add(String, String)} to add a translation.
*/
public abstract void generateTranslations(TranslationBuilder translationBuilder);
public abstract void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder);

@Override
public CompletableFuture<?> run(DataWriter writer) {
TreeMap<String, String> translationEntries = new TreeMap<>();

generateTranslations((String key, String value) -> {
Objects.requireNonNull(key);
Objects.requireNonNull(value);
return this.registryLookup.thenCompose(lookup -> {
generateTranslations(lookup, (String key, String value) -> {
Objects.requireNonNull(key);
Objects.requireNonNull(value);

if (translationEntries.containsKey(key)) {
throw new RuntimeException("Existing translation key found - " + key + " - Duplicate will be ignored.");
}
if (translationEntries.containsKey(key)) {
throw new RuntimeException("Existing translation key found - " + key + " - Duplicate will be ignored.");
}

translationEntries.put(key, value);
});
translationEntries.put(key, value);
});

JsonObject langEntryJson = new JsonObject();
JsonObject langEntryJson = new JsonObject();

for (Map.Entry<String, String> entry : translationEntries.entrySet()) {
langEntryJson.addProperty(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : translationEntries.entrySet()) {
langEntryJson.addProperty(entry.getKey(), entry.getValue());
}

return DataProvider.writeToPath(writer, langEntryJson, getLangFilePath(this.languageCode));
return DataProvider.writeToPath(writer, langEntryJson, getLangFilePath(this.languageCode));
});
}

private Path getLangFilePath(String code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public FabricTagProvider(FabricDataOutput output, RegistryKey<? extends Registry
/**
* Implement this method and then use {@link FabricTagProvider#getOrCreateTagBuilder} to get and register new tag builders.
*/
protected abstract void configure(RegistryWrapper.WrapperLookup arg);
protected abstract void configure(RegistryWrapper.WrapperLookup wrapperLookup);

/**
* Override to enable adding objects to the tag builder directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ public void generate(RecipeExporter exporter) {
}

private static class ExistingEnglishLangProvider extends FabricLanguageProvider {
private ExistingEnglishLangProvider(FabricDataOutput output) {
super(output);
private ExistingEnglishLangProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output, registriesFuture);
}

@Override
public void generateTranslations(TranslationBuilder translationBuilder) {
public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder) {
translationBuilder.add(SIMPLE_BLOCK, "Simple Block");
translationBuilder.add(new Identifier(MOD_ID, "identifier_test"), "Identifier Test");
translationBuilder.add(EntityType.ALLAY, "Allay");
Expand All @@ -282,12 +282,12 @@ public void generateTranslations(TranslationBuilder translationBuilder) {
}

private static class JapaneseLangProvider extends FabricLanguageProvider {
private JapaneseLangProvider(FabricDataOutput output) {
super(output, "ja_jp");
private JapaneseLangProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output, "ja_jp", registriesFuture);
}

@Override
public void generateTranslations(TranslationBuilder translationBuilder) {
public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder) {
translationBuilder.add(SIMPLE_BLOCK, "シンプルブロック");
translationBuilder.add(SIMPLE_ITEM_GROUP, "データ生成項目");
translationBuilder.add("this.is.a.test", "こんにちは");
Expand Down Expand Up @@ -369,7 +369,7 @@ private TestAdvancementProvider(FabricDataOutput output, CompletableFuture<Regis
}

@Override
public void generateAdvancement(Consumer<AdvancementEntry> consumer) {
public void generateAdvancement(RegistryWrapper.WrapperLookup registryLookup, Consumer<AdvancementEntry> consumer) {
AdvancementEntry root = Advancement.Builder.create()
.display(
SIMPLE_BLOCK,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ private void hookDamage(ItemStack instance, int amount, Random random, ServerPla
original.call(instance, amount, random, serverPlayerEntity, runnable);
}

// TODO 1.20.5
// @Redirect(
// method = "getAttributeModifiers",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/item/Item;getAttributeModifiers(Lnet/minecraft/entity/EquipmentSlot;)Lcom/google/common/collect/Multimap;"
// )
// )
// public Multimap<RegistryEntry<EntityAttribute>, EntityAttributeModifier> hookGetAttributeModifiers(Item item, EquipmentSlot slot) {
// ItemStack stack = (ItemStack) (Object) this;
// //we need to ensure it is modifiable for the callback, use linked map to preserve ordering
// Multimap<RegistryEntry<EntityAttribute>, EntityAttributeModifier> attributeModifiers = LinkedHashMultimap.create(item.getAttributeModifiers(stack, slot));
// ModifyItemAttributeModifiersCallback.EVENT.invoker().modifyAttributeModifiers(stack, slot, attributeModifiers);
// return attributeModifiers;
// }

@Redirect(
method = "isSuitableFor",
at = @At(
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion fabric-item-api-v1/src/testmod/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"main": [
"net.fabricmc.fabric.test.item.CustomDamageTest",
"net.fabricmc.fabric.test.item.ItemUpdateAnimationTest",
"net.fabricmc.fabric.test.item.ModifyItemAttributeModifiersCallbackTest",
"net.fabricmc.fabric.test.item.ArmorKnockbackResistanceTest",
"net.fabricmc.fabric.test.item.FoodGameInitializer"
],
Expand Down

0 comments on commit 322417c

Please sign in to comment.