Skip to content

Commit 4ef4a12

Browse files
authored
Merge pull request #2145 from stellanera98/fan-translation
Fan translation
2 parents c7ad718 + 95fe19b commit 4ef4a12

6 files changed

Lines changed: 66 additions & 23 deletions

File tree

src/generated/resources/assets/bloodmagic/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@
581581
"living_upgrade.bloodmagic.storm_trooper": "Storm Trooper",
582582
"living_upgrade.bloodmagic.swim_decrease": "Concrete Shoes",
583583
"living_upgrade.bloodmagic.thaumRunicShielding": "Runic Shielding",
584+
"pack.bloodmagic.fan_translations": "Fanmade translations of Blood Magic",
584585
"ritual.bloodmagic.altarBuilderRitual": "The Assembly of the High Altar",
585586
"ritual.bloodmagic.altarBuilderRitual.info": "Builds an altar out of the components inside of the connected inventory.",
586587
"ritual.bloodmagic.animalGrowthRitual": "Ritual of the Shepherd",

src/main/java/wayoftime/bloodmagic/BloodMagic.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
import net.minecraft.core.dispenser.AbstractProjectileDispenseBehavior;
77
import net.minecraft.data.DataGenerator;
88
import net.minecraft.data.PackOutput;
9+
import net.minecraft.network.chat.Component;
910
import net.minecraft.resources.ResourceLocation;
11+
import net.minecraft.server.packs.PackType;
12+
import net.minecraft.server.packs.repository.Pack;
13+
import net.minecraft.server.packs.repository.PackSource;
1014
import net.minecraft.world.entity.projectile.Projectile;
11-
import net.minecraft.world.entity.projectile.Snowball;
1215
import net.minecraft.world.item.ItemStack;
13-
import net.minecraft.core.dispenser.DispenseItemBehavior;
1416
import net.minecraft.world.level.Level;
1517
import net.minecraft.world.level.block.DispenserBlock;
16-
import net.minecraftforge.client.event.EntityRenderersEvent;
17-
import net.minecraftforge.client.event.ModelEvent.RegisterGeometryLoaders;
1818
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
1919
import net.minecraftforge.common.MinecraftForge;
2020
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
2121
import net.minecraftforge.common.crafting.CraftingHelper;
2222
import net.minecraftforge.data.event.GatherDataEvent;
23+
import net.minecraftforge.event.AddPackFindersEvent;
2324
import net.minecraftforge.eventbus.api.IEventBus;
2425
import net.minecraftforge.eventbus.api.SubscribeEvent;
2526
import net.minecraftforge.fluids.DispenseFluidContainer;
@@ -29,8 +30,12 @@
2930
import net.minecraftforge.fml.config.ModConfig;
3031
import net.minecraftforge.fml.event.lifecycle.*;
3132
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
33+
import net.minecraftforge.fml.javafmlmod.FMLModContainer;
34+
import net.minecraftforge.fml.loading.FMLPaths;
35+
import net.minecraftforge.forgespi.locating.IModFile;
3236
import net.minecraftforge.registries.ForgeRegistries;
3337
import net.minecraftforge.registries.RegisterEvent;
38+
import net.minecraftforge.resource.PathPackResources;
3439
import org.apache.logging.log4j.LogManager;
3540
import org.apache.logging.log4j.Logger;
3641
import wayoftime.bloodmagic.anointment.Anointment;
@@ -39,8 +44,6 @@
3944
import wayoftime.bloodmagic.client.hud.Elements;
4045
import wayoftime.bloodmagic.client.key.BloodMagicKeyHandler;
4146
import wayoftime.bloodmagic.client.key.KeyBindingBloodMagic;
42-
import wayoftime.bloodmagic.client.model.MimicModelLoader;
43-
import wayoftime.bloodmagic.client.model.SigilHoldingModelLoader;
4447
import wayoftime.bloodmagic.client.sounds.SoundRegistry;
4548
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
4649
import wayoftime.bloodmagic.common.data.*;
@@ -77,6 +80,7 @@
7780
import wayoftime.bloodmagic.util.handler.event.GenericHandler;
7881
import wayoftime.bloodmagic.util.handler.event.WillHandler;
7982

83+
import java.nio.file.Path;
8084
import java.util.concurrent.CompletableFuture;
8185

8286
@Mod("bloodmagic")
@@ -137,6 +141,7 @@ public BloodMagic() {
137141
// Register the doClientStuff method for modloading
138142
modBus.addListener(this::doClientStuff);
139143
modBus.addListener(this::gatherData);
144+
modBus.addListener(this::addPackfinders);
140145
modBus.addListener(this::onRegisterCapabilities);
141146

142147
modBus.addListener(this::registerRecipes);
@@ -236,6 +241,27 @@ public void gatherData(GatherDataEvent event) {
236241
gen.addProvider(event.includeServer(), new GeneratorEntityTags(output, provider, event.getExistingFileHelper()));
237242
}
238243

244+
public void addPackfinders(AddPackFindersEvent event) {
245+
if (event.getPackType().equals(PackType.CLIENT_RESOURCES)) {
246+
PathPackResources res = new PathPackResources(
247+
rl("translations").toString(),
248+
true,
249+
ModList.get().getModFileById(MODID).getFile().getSecureJar().getPath("packs", "translations")
250+
);
251+
Pack pack = Pack.readMetaAndCreate(
252+
res.packId(),
253+
Component.translatable("pack.bloodmagic.fan_translations"),
254+
false,
255+
id -> res,
256+
PackType.CLIENT_RESOURCES,
257+
Pack.Position.TOP,
258+
PackSource.BUILT_IN
259+
);
260+
if (pack != null) {
261+
event.addRepositorySource(consumer -> consumer.accept(pack));
262+
}
263+
}
264+
}
239265

240266
private void setup(final FMLCommonSetupEvent event) {
241267
packetHandler.initialize();

src/main/java/wayoftime/bloodmagic/common/data/GeneratorLanguage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ protected void addTranslations()
1919
// HUD
2020
add("hud.bloodmagic.inactive", "Inactive");
2121

22+
add("pack.bloodmagic.fan_translations", "Fanmade translations of Blood Magic");
23+
2224
// Creative Tab
2325
add("itemGroup.bloodmagic.creativeTab", "Blood Magic");
2426
add("itemGroup.bloodmagic.upgradeTab", "Blood Magic Living Upgrades");

src/main/java/wayoftime/bloodmagic/loot/GlobalLootModifier.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import wayoftime.bloodmagic.anointment.AnointmentHolder;
3434
import wayoftime.bloodmagic.common.tags.BloodMagicTags;
3535
import wayoftime.bloodmagic.core.AnointmentRegistrar;
36+
import wayoftime.bloodmagic.util.BMLog;
3637

3738
import javax.annotation.Nonnull;
39+
import java.util.List;
3840
import java.util.Map;
3941
import java.util.function.Supplier;
4042

@@ -48,6 +50,19 @@ public class GlobalLootModifier
4850
public static final RegistryObject<Codec<SmeltingModifier>> SMELT = GLM.register("smelt", SmeltingModifier.CODEC);
4951
public static final RegistryObject<Codec<VoidingModifier>> VOID = GLM.register("voiding", VoidingModifier.CODEC);
5052

53+
private static LootParams.Builder copyBlockNoTool(LootContext context) {
54+
LootParams.Builder builder = new LootParams.Builder(context.getLevel());
55+
builder.withLuck(context.getLuck());
56+
builder.withParameter(LootContextParams.BLOCK_STATE, context.getParam(LootContextParams.BLOCK_STATE));
57+
builder.withParameter(LootContextParams.ORIGIN, context.getParam(LootContextParams.ORIGIN));
58+
59+
builder.withOptionalParameter(LootContextParams.THIS_ENTITY, context.getParamOrNull(LootContextParams.THIS_ENTITY));
60+
builder.withOptionalParameter(LootContextParams.BLOCK_ENTITY, context.getParamOrNull(LootContextParams.BLOCK_ENTITY));
61+
builder.withOptionalParameter(LootContextParams.EXPLOSION_RADIUS, context.getParamOrNull(LootContextParams.EXPLOSION_RADIUS));
62+
63+
return builder;
64+
}
65+
5166
private static class SilkTouchTestModifier extends LootModifier
5267
{
5368
public static final Supplier<Codec<SilkTouchTestModifier>> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst).apply(inst, SilkTouchTestModifier::new)));
@@ -60,14 +75,17 @@ public SilkTouchTestModifier(LootItemCondition[] conditionsIn)
6075
@Nonnull
6176
@Override
6277
protected @NotNull ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
78+
BMLog.DEFAULT.info("doApply!");
6379
ItemStack ctxTool = context.getParamOrNull(LootContextParams.TOOL);
6480
if (ctxTool.is(BloodMagicTags.CHARGES)) {
6581
return generatedLoot;
6682
}
6783
// return early if silk-touch is already applied (otherwise we'll get stuck in
6884
// an infinite loop).
69-
if (EnchantmentHelper.getEnchantments(ctxTool).containsKey(Enchantments.SILK_TOUCH))
70-
return generatedLoot;
85+
if (EnchantmentHelper.getEnchantments(ctxTool).containsKey(Enchantments.SILK_TOUCH)) {
86+
BMLog.DEFAULT.info("silk touch present, returning data '{}'", generatedLoot.get(0).getOrCreateTag());
87+
return generatedLoot;
88+
}
7189
AnointmentHolder holder = AnointmentHolder.fromItemStack(ctxTool);
7290
if (holder == null || holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_SILK_TOUCH.get()) <= 0)
7391
{
@@ -76,21 +94,11 @@ public SilkTouchTestModifier(LootItemCondition[] conditionsIn)
7694

7795
ItemStack fakeTool = ctxTool.copy();
7896
fakeTool.enchant(Enchantments.SILK_TOUCH, 1);
79-
LootParams.Builder builder = new LootParams.Builder(context.getLevel());
80-
builder.withParameter(LootContextParams.TOOL, fakeTool);
81-
82-
Vec3 vec = context.getParam(LootContextParams.ORIGIN);
83-
if (vec != null) {
84-
BlockPos pos = BlockPos.containing(vec);
85-
BlockEntity be = context.getLevel().getBlockEntity(pos);
86-
if (be != null) {
87-
builder.withParameter(LootContextParams.BLOCK_ENTITY, be);
88-
}
89-
}
90-
91-
LootParams ctx = builder.create(LootContextParamSets.EMPTY);
92-
LootTable loottable = context.getLevel().getServer().getLootData().getLootTable(context.getParamOrNull(LootContextParams.BLOCK_STATE).getBlock().getLootTable());
93-
return loottable.getRandomItems(ctx);
97+
LootParams.Builder builder = copyBlockNoTool(context);
98+
builder.withParameter(LootContextParams.TOOL, fakeTool);
99+
LootTable lootTable = context.getLevel().getServer().getLootData().getLootTable(context.getParam(LootContextParams.BLOCK_STATE).getBlock().getLootTable());
100+
BMLog.DEFAULT.info("loot table I guess '{}'", lootTable.getLootTableId());
101+
return lootTable.getRandomItems(builder.create(LootContextParamSets.EMPTY));
94102
}
95103

96104
@Override

src/generated/resources/assets/bloodmagic/lang/zh_cn.json renamed to src/main/resources/packs/translations/assets/bloodmagic/lang/zh_cn.json

File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"pack": {
3+
"description": "Fanmade translation files for Blood Magic",
4+
"pack_format": 15
5+
}
6+
}

0 commit comments

Comments
 (0)