mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-13 05:21:46 +01:00
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:
parent
6299147e24
commit
07883a588d
8 changed files with 3696 additions and 1558 deletions
|
@ -582,8 +582,8 @@ bf2b0310500213ff853c748c236eb5d01f61658e assets/create/blockstates/yellow_toolbo
|
|||
5616dda664dd106d576848124fc0fc1de18d0fd3 assets/create/blockstates/yellow_valve_handle.json
|
||||
7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json
|
||||
b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json
|
||||
4fd8347dfb20e6e5752b8b905850762a88c88c02 assets/create/lang/en_ud.json
|
||||
a78f92c3e08c454aba650ef5dda97d8d9a494689 assets/create/lang/en_us.json
|
||||
e9dd96e4d42068af53f479f1a0a4dab76af78d78 assets/create/lang/en_ud.json
|
||||
64c287f1902a15967fb0c0f7dcc3fc99d647c9e1 assets/create/lang/en_us.json
|
||||
487a511a01b2a4531fb672f917922312db78f958 assets/create/models/block/acacia_window.json
|
||||
b48060cba1a382f373a05bf0039054053eccf076 assets/create/models/block/acacia_window_pane_noside.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
|
@ -2,12 +2,10 @@ package com.simibubi.create.foundation.data;
|
|||
|
||||
import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
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.Builder;
|
||||
import com.tterrag.registrate.builders.FluidBuilder;
|
||||
import com.tterrag.registrate.providers.ProviderType;
|
||||
import com.tterrag.registrate.util.entry.RegistryEntry;
|
||||
import com.tterrag.registrate.util.nullness.NonNullBiFunction;
|
||||
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.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.data.loading.DatagenModLoader;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.ForgeFlowingFluid;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
|
||||
protected final NonNullSupplier<Boolean> doDatagen = NonNullSupplier.lazy(DatagenModLoader::isRunningDataGen);
|
||||
|
||||
@Nullable
|
||||
protected Function<Item, TooltipModifier> currentTooltipModifierFactory;
|
||||
@Nullable
|
||||
protected UnaryOperator<Map<String, String>> deferredLangPostprocessor;
|
||||
|
||||
protected boolean hasDataProvider = false;
|
||||
|
||||
protected CreateRegistrate(String modid) {
|
||||
super(modid);
|
||||
|
@ -82,39 +71,11 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
|
|||
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
|
||||
public CreateRegistrate registerEventListeners(IEventBus 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
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.infrastructure.data;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
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.PonderIndex;
|
||||
import com.simibubi.create.infrastructure.ponder.SharedText;
|
||||
import com.tterrag.registrate.providers.ProviderType;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
@ -53,24 +52,14 @@ public class CreateDatagen {
|
|||
private static void addExtraRegistrateData() {
|
||||
CreateRegistrateTags.addGenerators();
|
||||
|
||||
// Really all additional lang entries should be added using AbstractRegistrate#addRawLang,
|
||||
// but doing so would change the generated lang entry order and potentially mess up Crowndin.
|
||||
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!");
|
||||
}
|
||||
};
|
||||
Create.REGISTRATE.addDataGenerator(ProviderType.LANG, provider -> {
|
||||
BiConsumer<String, String> langConsumer = provider::add;
|
||||
|
||||
AllAdvancements.provideLang(langConsumer);
|
||||
provideDefaultLang("interface", langConsumer);
|
||||
AllSoundEvents.provideLang(langConsumer);
|
||||
provideDefaultLang("tooltips", langConsumer);
|
||||
AllAdvancements.provideLang(langConsumer);
|
||||
AllSoundEvents.provideLang(langConsumer);
|
||||
providePonderLang(langConsumer);
|
||||
|
||||
return newEntries;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
"CustomItemUseEffectsMixin",
|
||||
"EnchantmentHelperMixin",
|
||||
"EntityMixin",
|
||||
"LanguageProviderMixin",
|
||||
"LavaSwimmingMixin",
|
||||
"MainMixin",
|
||||
"MapItemSavedDataMixin",
|
||||
|
|
Loading…
Reference in a new issue