Skip to content

Commit

Permalink
move mapping remaps into a single class
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Nov 18, 2023
1 parent 3c686ff commit 72a313f
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 163 deletions.
1 change: 1 addition & 0 deletions src/main/java/de/teamlapen/vampirism/VampirismMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public VampirismMod() {

MinecraftForge.EVENT_BUS.register(Permissions.class);
MinecraftForge.EVENT_BUS.register(SitHandler.class);
MinecraftForge.EVENT_BUS.register(MigrationData.class);
MinecraftForge.EVENT_BUS.register(new GeneralEventHandler());
MinecraftForge.EVENT_BUS.addListener(this::onCommandsRegister);
MinecraftForge.EVENT_BUS.addListener(this::onAddReloadListenerEvent);
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/de/teamlapen/vampirism/core/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -229,36 +228,6 @@ private static <T extends Block> RegistryObject<T> registerWithItem(String name,
return registerWithItem(name, supplier, new Item.Properties());
}

public static void fixMappings(@NotNull MissingMappingsEvent event) {
event.getAllMappings(ForgeRegistries.Keys.BLOCKS).forEach(missingMapping -> {
switch (missingMapping.getKey().toString()) {
case "vampirism:blood_potion_table" -> missingMapping.remap(ModBlocks.POTION_TABLE.get());
case "vampirism:garlic_beacon_normal" -> missingMapping.remap(ModBlocks.GARLIC_DIFFUSER_NORMAL.get());
case "vampirism:garlic_beacon_weak" -> missingMapping.remap(ModBlocks.GARLIC_DIFFUSER_WEAK.get());
case "vampirism:garlic_beacon_improved" -> missingMapping.remap(ModBlocks.GARLIC_DIFFUSER_IMPROVED.get());
case "vampirism:church_altar" -> missingMapping.remap(ModBlocks.ALTAR_CLEANSING.get());
case "vampirism:vampire_spruce_leaves", "vampirism:bloody_spruce_leaves" -> missingMapping.remap(ModBlocks.DARK_SPRUCE_LEAVES.get());
case "vampirism:bloody_spruce_log" -> missingMapping.remap(ModBlocks.CURSED_SPRUCE_LOG.get());
case "vampirism:cursed_grass_block" -> missingMapping.remap(ModBlocks.CURSED_GRASS.get());
case "cursed_bark" -> missingMapping.ignore();
case "castle_block_dark_brick" -> missingMapping.remap(ModBlocks.DARK_STONE_BRICKS.get());
case "castle_block_dark_brick_bloody" -> missingMapping.remap(ModBlocks.BLOODY_DARK_STONE_BRICKS.get());
case "castle_block_dark_stone" -> missingMapping.remap(ModBlocks.DARK_STONE.get());
case "castle_block_normal_brick" -> missingMapping.remap(Blocks.STONE_BRICKS);
case "castle_slab_dark_brick" -> missingMapping.remap(ModBlocks.DARK_STONE_BRICK_SLAB.get());
case "castle_slab_dark_stone" -> missingMapping.remap(ModBlocks.DARK_STONE_SLAB.get());
case "castle_stairs_dark_brick" -> missingMapping.remap(ModBlocks.DARK_STONE_BRICK_STAIRS.get());
case "castle_stairs_dark_stone" -> missingMapping.remap(ModBlocks.DARK_STONE_STAIRS.get());
case "castle_block_dark_brick_cracked" -> missingMapping.remap(ModBlocks.CRACKED_DARK_STONE_BRICKS.get());
case "castle_block_dark_brick_wall" -> missingMapping.remap(ModBlocks.DARK_STONE_BRICK_WALL.get());
case "castle_block_purple_brick" -> missingMapping.remap(ModBlocks.PURPLE_STONE_BRICKS.get());
case "castle_slab_purple_brick" -> missingMapping.remap(ModBlocks.PURPLE_STONE_BRICK_SLAB.get());
case "castle_stairs_purple_brick" -> missingMapping.remap(ModBlocks.PURPLE_STONE_BRICK_STAIRS.get());
case "castle_block_purple_brick_wall" -> missingMapping.remap(ModBlocks.PURPLE_STONE_BRICK_WALL.get());
}
});
}

public static @NotNull Set<Block> getAllBlocks() {
return BLOCKS.getEntries().stream().map(RegistryObject::get).collect(Collectors.toUnmodifiableSet());
}
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/de/teamlapen/vampirism/core/ModEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import net.minecraft.world.item.alchemy.Potions;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import net.minecraftforge.registries.*;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -110,13 +113,4 @@ static boolean checkNightVision() {
return true;
}

public static void fixMappings(@NotNull MissingMappingsEvent event) {
event.getAllMappings(ForgeRegistries.Keys.MOB_EFFECTS).forEach(missingMapping -> {
if ("vampirism:thirst".equals(missingMapping.getKey().toString())) {
missingMapping.remap(MobEffects.HUNGER);
}
});
}


}
12 changes: 0 additions & 12 deletions src/main/java/de/teamlapen/vampirism/core/ModEnchantments.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import de.teamlapen.vampirism.items.enchantment.EnchantmentArrowFrugality;
import de.teamlapen.vampirism.items.enchantment.EnchantmentVampireSlayer;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;


public class ModEnchantments {
Expand All @@ -23,13 +20,4 @@ public class ModEnchantments {
static void register(IEventBus bus) {
ENCHANTMENTS.register(bus);
}

static void fixMapping(@NotNull MissingMappingsEvent event) {
event.getAllMappings(ForgeRegistries.Keys.ENCHANTMENTS).forEach(missingMapping -> {
//noinspection SwitchStatementWithTooFewBranches
switch (missingMapping.getKey().toString()) {
case "vampirism:crossbowinfinite" -> missingMapping.remap(Enchantments.INFINITY_ARROWS);
}
});
}
}
11 changes: 0 additions & 11 deletions src/main/java/de/teamlapen/vampirism/core/ModEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -168,16 +167,6 @@ private static <T extends Entity> RegistryObject<EntityType<T>> prepareEntityTyp
});
}

static void fixMapping(@NotNull MissingMappingsEvent missingMappings) {
missingMappings.getAllMappings(ForgeRegistries.Keys.ENTITY_TYPES).forEach((mapping) -> {
switch (mapping.getKey().toString()) {
case "vampirism:vampire_hunter" -> mapping.remap(ModEntities.HUNTER.get());
case "vampirism:vampire_hunter_imob" -> mapping.remap(ModEntities.HUNTER_IMOB.get());
}
});
}


public static @NotNull Set<EntityType<?>> getAllEntities() {
return ENTITY_TYPES.getEntries().stream().map(RegistryObject::get).collect(Collectors.toUnmodifiableSet());
}
Expand Down
35 changes: 0 additions & 35 deletions src/main/java/de/teamlapen/vampirism/core/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.apache.logging.log4j.LogManager;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -309,37 +307,4 @@ public static void registerOtherCreativeTabItems(BuildCreativeModeTabContentsEve
}
});
}

public static void fixMappings(@NotNull MissingMappingsEvent event) {
event.getAllMappings(ForgeRegistries.Keys.ITEMS).forEach(missingMapping -> {
switch (missingMapping.getKey().toString()) {
case "vampirism:blood_potion", "vampirism:blood_potion_table" -> missingMapping.ignore();
case "vampirism:vampire_clothing_head" -> missingMapping.remap(VAMPIRE_CLOTHING_CROWN.get());
case "vampirism:vampire_clothing_feet" -> missingMapping.remap(VAMPIRE_CLOTHING_BOOTS.get());
case "vampirism:garlic_beacon_core" -> missingMapping.remap(GARLIC_DIFFUSER_CORE.get());
case "vampirism:garlic_beacon_core_improved" -> missingMapping.remap(GARLIC_DIFFUSER_CORE_IMPROVED.get());
case "vampirism:garlic_beacon_normal" -> missingMapping.remap(ModBlocks.GARLIC_DIFFUSER_NORMAL.get().asItem());
case "vampirism:garlic_beacon_weak" -> missingMapping.remap(ModBlocks.GARLIC_DIFFUSER_WEAK.get().asItem());
case "vampirism:garlic_beacon_improved" -> missingMapping.remap(ModBlocks.GARLIC_DIFFUSER_IMPROVED.get().asItem());
case "vampirism:church_altar" -> missingMapping.remap(ModBlocks.ALTAR_CLEANSING.get().asItem());
case "vampirism:item_med_chair" -> missingMapping.remap(ModBlocks.MED_CHAIR.get().asItem());
case "vampirism:bloody_spruce_log" -> missingMapping.remap(ModBlocks.CURSED_SPRUCE_LOG.get().asItem());
case "vampirism:bloody_spruce_leaves" -> missingMapping.remap(ModBlocks.DARK_SPRUCE_LEAVES.get().asItem());
case "vampirism:coffin" -> missingMapping.remap(ModBlocks.COFFIN_RED.get().asItem());
case "vampirism:holy_salt_water" -> missingMapping.remap(PURE_SALT_WATER.get());
case "vampirism:holy_salt" -> missingMapping.remap(PURE_SALT.get());
case "vampirism:injection_zombie_blood" -> missingMapping.remap(Items.APPLE);
case "vampirism:cure_apple" -> missingMapping.remap(Items.GOLDEN_APPLE);
}
if (missingMapping.getKey().toString().startsWith("vampirism:obsidian_armor")) {
Item hunterArmorReplacement = (Item) event.getRegistry().getValue(new ResourceLocation(missingMapping.getKey().toString().replace("obsidian_armor", "hunter_coat")));
if (hunterArmorReplacement != null) {
missingMapping.remap(hunterArmorReplacement);
} else {
LogManager.getLogger().warn("Could not find hunter armor replacement for {}", missingMapping.getKey().toString());
missingMapping.ignore();
}
}
});
}
}
14 changes: 0 additions & 14 deletions src/main/java/de/teamlapen/vampirism/core/ModPotions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

Expand Down Expand Up @@ -150,16 +148,4 @@ private static void veryStrong(Supplier<? extends Potion> in, Supplier<? extends
private static void master(Supplier<? extends Potion> out, NonNullSupplier<Ingredient> in, int count, int countReduced) {
VampirismAPI.extendedBrewingRecipeRegistry().addMix(new ExtendedPotionMix.Builder(() -> Potions.AWKWARD, out).master().ingredient(in, count, countReduced).blood().build());
}


public static void fixMappings(@NotNull MissingMappingsEvent event) {
event.getAllMappings(ForgeRegistries.Keys.POTIONS).forEach(missingMapping -> {
switch (missingMapping.getKey().toString()) {
case "vampirism:long_strong_resistance", "vampirism:very_long_resistance" -> missingMapping.remap(ModPotions.LONG_RESISTANCE.get());
case "vampirism:very_strong_resistance" -> missingMapping.remap(ModPotions.STRONG_RESISTANCE.get());
case "vampirism:thirst", "vampirism:long_thirst", "vampirism:strong_thirst", "vampirism:very_long_thirst", "vampirism:very_strong_thirst", "vampirism:long_strong_thirst" -> missingMapping.ignore();
case "vampirism:very_strong_harming" -> missingMapping.remap(Potions.STRONG_HARMING);
}
});
}
}
9 changes: 0 additions & 9 deletions src/main/java/de/teamlapen/vampirism/core/ModTiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -68,12 +67,4 @@ public static void registerTileExtensionsUnsafe() {

}

public static void fixMappings(@NotNull MissingMappingsEvent event) {
event.getAllMappings(ForgeRegistries.Keys.BLOCK_ENTITY_TYPES).forEach(missingMapping -> {
//noinspection SwitchStatementWithTooFewBranches
switch (missingMapping.getKey().toString()) {
case "vampirism:garlic_beacon" -> missingMapping.remap(GARLIC_DIFFUSER.get());
}
});
}
}
14 changes: 0 additions & 14 deletions src/main/java/de/teamlapen/vampirism/core/RegistryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import de.teamlapen.vampirism.world.gen.VampirismFeatures;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.ParallelDispatchEvent;
Expand All @@ -32,7 +31,6 @@ public class RegistryManager implements IInitListener {

public RegistryManager() {
FMLJavaModLoadingContext.get().getModEventBus().register(this);
MinecraftForge.EVENT_BUS.addListener(this::onMissingMappings);
}

public static void setupRegistries(@NotNull IEventBus modbus) {
Expand Down Expand Up @@ -105,18 +103,6 @@ public void onInitStep(@NotNull Step step, @NotNull ParallelDispatchEvent event)
}
}

public void onMissingMappings(@NotNull MissingMappingsEvent event) {
VampireSkills.fixMappings(event);
HunterSkills.fixMappings(event);
ModPotions.fixMappings(event);
ModTiles.fixMappings(event);
ModItems.fixMappings(event);
ModBlocks.fixMappings(event);
ModEnchantments.fixMapping(event);
ModEntities.fixMapping(event);
ModEffects.fixMappings(event);
}

@SubscribeEvent
public void onNewDatapackRegistries(@NotNull DataPackRegistryEvent.NewRegistry event) {
ModRegistries.registerDatapackRegistries(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* Registers the default hunter skills
Expand Down Expand Up @@ -92,19 +90,4 @@ public class HunterSkills {
public static void register(IEventBus bus) {
SKILLS.register(bus);
}

public static void fixMappings(@NotNull MissingMappingsEvent event) {
event.getAllMappings(VampirismRegistries.SKILLS_ID).forEach(missingMapping -> {
switch (missingMapping.getKey().toString()) {
case "vampirism:garlic_beacon_improved" -> missingMapping.remap(GARLIC_DIFFUSER_IMPROVED.get());
case "vampirism:garlic_beacon" -> missingMapping.remap(GARLIC_DIFFUSER.get());
case "vampirism:holy_water_enhanced" -> missingMapping.remap(ENHANCED_BLESSING.get());
default -> {
if (missingMapping.getKey().toString().startsWith("vampirism:blood_potion_")) {
missingMapping.ignore();
}
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.MissingMappingsEvent;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -89,13 +88,4 @@ public static void register(IEventBus bus) {
SKILLS.register(SkillType.LEVEL.createIdForFaction(VReference.VAMPIRE_FACTION.getID()).getPath(), () -> new VampirismSkill.SimpleVampireSkill(2, false));
SKILLS.register(SkillType.LORD.createIdForFaction(VReference.VAMPIRE_FACTION.getID()).getPath(), () -> new VampirismSkill.SimpleVampireSkill(2, false));
}

public static void fixMappings(@NotNull MissingMappingsEvent event) {
event.getAllMappings(VampirismRegistries.SKILLS_ID).forEach(missingMapping -> {
switch (missingMapping.getKey().toString()) {
case "vampirism:creeper_avoided", "vampirism:enhanced_crossbow", "vampirism:vampire_forest_fog" -> missingMapping.ignore();
case "vampirism:bat" -> missingMapping.remap(FLEDGLING.get());
}
});
}
}
Loading

0 comments on commit 72a313f

Please sign in to comment.