Try to remove lang postprocessor

Removes the lang postprocessor system and adds additional lang using a
standard ProviderType.LANG generator. This commit will be reverted if it
causes issues.
This commit is contained in:
PepperCode1 2023-09-19 15:12:46 -07:00
parent 6299147e24
commit 07883a588d
8 changed files with 3696 additions and 1558 deletions

View File

@ -582,8 +582,8 @@ bf2b0310500213ff853c748c236eb5d01f61658e assets/create/blockstates/yellow_toolbo
5616dda664dd106d576848124fc0fc1de18d0fd3 assets/create/blockstates/yellow_valve_handle.json 5616dda664dd106d576848124fc0fc1de18d0fd3 assets/create/blockstates/yellow_valve_handle.json
7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json 7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json
b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json
4fd8347dfb20e6e5752b8b905850762a88c88c02 assets/create/lang/en_ud.json e9dd96e4d42068af53f479f1a0a4dab76af78d78 assets/create/lang/en_ud.json
a78f92c3e08c454aba650ef5dda97d8d9a494689 assets/create/lang/en_us.json 64c287f1902a15967fb0c0f7dcc3fc99d647c9e1 assets/create/lang/en_us.json
487a511a01b2a4531fb672f917922312db78f958 assets/create/models/block/acacia_window.json 487a511a01b2a4531fb672f917922312db78f958 assets/create/models/block/acacia_window.json
b48060cba1a382f373a05bf0039054053eccf076 assets/create/models/block/acacia_window_pane_noside.json b48060cba1a382f373a05bf0039054053eccf076 assets/create/models/block/acacia_window_pane_noside.json
3066db1bf03cffa1a9c7fbacf47ae586632f4eb3 assets/create/models/block/acacia_window_pane_noside_alt.json 3066db1bf03cffa1a9c7fbacf47ae586632f4eb3 assets/create/models/block/acacia_window_pane_noside_alt.json

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,12 +2,10 @@ package com.simibubi.create.foundation.data;
import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly; import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly;
import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -23,7 +21,6 @@ import com.tterrag.registrate.builders.BlockBuilder;
import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory; import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory;
import com.tterrag.registrate.builders.Builder; import com.tterrag.registrate.builders.Builder;
import com.tterrag.registrate.builders.FluidBuilder; import com.tterrag.registrate.builders.FluidBuilder;
import com.tterrag.registrate.providers.ProviderType;
import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullBiFunction; import com.tterrag.registrate.util.nullness.NonNullBiFunction;
import com.tterrag.registrate.util.nullness.NonNullConsumer; import com.tterrag.registrate.util.nullness.NonNullConsumer;
@ -45,24 +42,16 @@ import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.data.loading.DatagenModLoader;
import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid; import net.minecraftforge.fluids.ForgeFlowingFluid;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegistryObject; import net.minecraftforge.registries.RegistryObject;
public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> { public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
protected final NonNullSupplier<Boolean> doDatagen = NonNullSupplier.lazy(DatagenModLoader::isRunningDataGen);
@Nullable @Nullable
protected Function<Item, TooltipModifier> currentTooltipModifierFactory; protected Function<Item, TooltipModifier> currentTooltipModifierFactory;
@Nullable
protected UnaryOperator<Map<String, String>> deferredLangPostprocessor;
protected boolean hasDataProvider = false;
protected CreateRegistrate(String modid) { protected CreateRegistrate(String modid) {
super(modid); super(modid);
@ -82,39 +71,11 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
return currentTooltipModifierFactory; return currentTooltipModifierFactory;
} }
/**
* <b>Use {@link #addRawLang(String, String)} instead where possible!</b>
*/
public void addLangPostprocessor(UnaryOperator<Map<String, String>> langPostprocessor) {
if (!doDatagen.get()) {
return;
}
if (hasDataProvider) {
((LanguageProviderExtension) getDataProvider(ProviderType.LANG).orElseThrow()).create$addPostprocessor(langPostprocessor);
} else {
if (this.deferredLangPostprocessor == null) {
this.deferredLangPostprocessor = langPostprocessor;
} else {
UnaryOperator<Map<String, String>> current = this.deferredLangPostprocessor;
this.deferredLangPostprocessor = entries -> langPostprocessor.apply(current.apply(entries));
}
}
}
@Override @Override
public CreateRegistrate registerEventListeners(IEventBus bus) { public CreateRegistrate registerEventListeners(IEventBus bus) {
return super.registerEventListeners(bus); return super.registerEventListeners(bus);
} }
@Override
protected void onData(GatherDataEvent event) {
super.onData(event);
hasDataProvider = true;
((LanguageProviderExtension) getDataProvider(ProviderType.LANG).orElseThrow()).create$addPostprocessor(deferredLangPostprocessor);
deferredLangPostprocessor = null;
}
@Override @Override
protected <R extends IForgeRegistryEntry<R>, T extends R> RegistryEntry<T> accept(String name, ResourceKey<? extends Registry<R>> type, Builder<R, T, ?, ?> builder, NonNullSupplier<? extends T> creator, NonNullFunction<RegistryObject<T>, ? extends RegistryEntry<T>> entryFactory) { protected <R extends IForgeRegistryEntry<R>, T extends R> RegistryEntry<T> accept(String name, ResourceKey<? extends Registry<R>> type, Builder<R, T, ?, ?> builder, NonNullSupplier<? extends T> creator, NonNullFunction<RegistryObject<T>, ? extends RegistryEntry<T>> entryFactory) {
RegistryEntry<T> entry = super.accept(name, type, builder, creator, entryFactory); RegistryEntry<T> entry = super.accept(name, type, builder, creator, entryFactory);

View File

@ -1,8 +0,0 @@
package com.simibubi.create.foundation.data;
import java.util.Map;
import java.util.function.UnaryOperator;
public interface LanguageProviderExtension {
void create$addPostprocessor(UnaryOperator<Map<String, String>> postprocessor);
}

View File

@ -1,48 +0,0 @@
package com.simibubi.create.foundation.mixin;
import java.util.Map;
import java.util.function.UnaryOperator;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.simibubi.create.foundation.data.LanguageProviderExtension;
import net.minecraftforge.common.data.LanguageProvider;
@Mixin(LanguageProvider.class)
public class LanguageProviderMixin implements LanguageProviderExtension {
@Shadow
@Final
@Mutable
private Map<String, String> data;
@Unique
@Nullable
private UnaryOperator<Map<String, String>> postprocessor;
@Override
public void create$addPostprocessor(UnaryOperator<Map<String, String>> postprocessor) {
if (this.postprocessor == null) {
this.postprocessor = postprocessor;
} else {
UnaryOperator<Map<String, String>> current = this.postprocessor;
this.postprocessor = entries -> postprocessor.apply(current.apply(entries));
}
}
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/common/data/LanguageProvider;addTranslations()V", shift = Shift.AFTER, remap = false))
private void create$afterAddTranslations(CallbackInfo ci) {
if (postprocessor != null) {
data = postprocessor.apply(data);
}
}
}

View File

@ -1,7 +1,5 @@
package com.simibubi.create.infrastructure.data; package com.simibubi.create.infrastructure.data;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -20,6 +18,7 @@ import com.simibubi.create.infrastructure.ponder.AllPonderTags;
import com.simibubi.create.infrastructure.ponder.GeneralText; import com.simibubi.create.infrastructure.ponder.GeneralText;
import com.simibubi.create.infrastructure.ponder.PonderIndex; import com.simibubi.create.infrastructure.ponder.PonderIndex;
import com.simibubi.create.infrastructure.ponder.SharedText; import com.simibubi.create.infrastructure.ponder.SharedText;
import com.tterrag.registrate.providers.ProviderType;
import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.common.data.ExistingFileHelper;
@ -53,24 +52,14 @@ public class CreateDatagen {
private static void addExtraRegistrateData() { private static void addExtraRegistrateData() {
CreateRegistrateTags.addGenerators(); CreateRegistrateTags.addGenerators();
// Really all additional lang entries should be added using AbstractRegistrate#addRawLang, Create.REGISTRATE.addDataGenerator(ProviderType.LANG, provider -> {
// but doing so would change the generated lang entry order and potentially mess up Crowndin. BiConsumer<String, String> langConsumer = provider::add;
Create.REGISTRATE.addLangPostprocessor(entries -> {
Map<String, String> newEntries = new LinkedHashMap<>(entries);
BiConsumer<String, String> langConsumer = (key, value) -> {
String oldValue = newEntries.put(key, value);
if (oldValue != null) {
Create.LOGGER.warn("Value of lang key '" + key + "' was overridden!");
}
};
AllAdvancements.provideLang(langConsumer);
provideDefaultLang("interface", langConsumer); provideDefaultLang("interface", langConsumer);
AllSoundEvents.provideLang(langConsumer);
provideDefaultLang("tooltips", langConsumer); provideDefaultLang("tooltips", langConsumer);
AllAdvancements.provideLang(langConsumer);
AllSoundEvents.provideLang(langConsumer);
providePonderLang(langConsumer); providePonderLang(langConsumer);
return newEntries;
}); });
} }

View File

@ -11,7 +11,6 @@
"CustomItemUseEffectsMixin", "CustomItemUseEffectsMixin",
"EnchantmentHelperMixin", "EnchantmentHelperMixin",
"EntityMixin", "EntityMixin",
"LanguageProviderMixin",
"LavaSwimmingMixin", "LavaSwimmingMixin",
"MainMixin", "MainMixin",
"MapItemSavedDataMixin", "MapItemSavedDataMixin",