generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TheSilkMiner/fix/use-callbacks-for-registr…
…ation Rework mod to use Neo Callbacks
- Loading branch information
Showing
9 changed files
with
134 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 30 additions & 13 deletions
43
src/main/java/com/portingdeadmods/moreplates/events/MPEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
package com.portingdeadmods.moreplates.events; | ||
|
||
import com.portingdeadmods.moreplates.MorePlatesMod; | ||
import com.portingdeadmods.moreplates.config.MPConfig; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import com.portingdeadmods.moreplates.utils.IngotUtil; | ||
import com.portingdeadmods.moreplates.utils.PlateUtil; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.registries.ModifyRegistriesEvent; | ||
import net.neoforged.neoforge.registries.RegisterEvent; | ||
import net.neoforged.neoforge.registries.callback.AddCallback; | ||
|
||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
|
||
|
||
@EventBusSubscriber(modid = MorePlatesMod.MODID, bus = EventBusSubscriber.Bus.MOD) | ||
public class MPEvents { | ||
private static class ItemRegistrationCallback implements AddCallback<Item> { | ||
@Override | ||
public void onAdd(Registry<Item> registry, int id, ResourceKey<Item> key, Item value) { | ||
registerPlateFor(key.location(), false, (plateId, plate) -> Registry.register(registry, plateId, plate)); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public static void modifyRegistriesEvent(ModifyRegistriesEvent event) { | ||
event.getRegistry(Registries.ITEM).addCallback(new ItemRegistrationCallback()); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onRegisterItems(RegisterEvent event) { | ||
event.register(Registries.ITEM, helper -> { | ||
BuiltInRegistries.ITEM.stream().forEach(item -> { | ||
ResourceLocation itemID = BuiltInRegistries.ITEM.getKey(item); | ||
if (itemID.getPath().contains("ingot") && item.getDescriptionId().contains("minecraft") && !itemID.getPath().contains("block")) { | ||
String plateName = itemID.getPath().replace("ingot", "plate"); | ||
helper.register(ResourceLocation.fromNamespaceAndPath(MorePlatesMod.MODID, plateName), | ||
new Item(new Item.Properties())); | ||
MPConfig.saveIngotPlatePair(itemID.getNamespace() + ":" + itemID.getPath(), MorePlatesMod.MODID + ":" + ResourceLocation.fromNamespaceAndPath(MorePlatesMod.MODID, plateName).getPath()); | ||
} | ||
}); | ||
}); | ||
event.register(Registries.ITEM, helper -> Set.copyOf(event.getRegistry().keySet()).forEach(key -> registerPlateFor(key, true, helper::register))); | ||
} | ||
|
||
private static void registerPlateFor(ResourceLocation id, boolean onlyVanilla, BiConsumer<ResourceLocation, Item> regCallback) { | ||
// Avoid accidental recursion when we register our own thing multiple times | ||
if (!MorePlatesMod.MODID.equals(id.getNamespace()) && IngotUtil.isValidIngot(id, onlyVanilla)) { | ||
String ingotType = IngotUtil.getIngotType(id); | ||
PlateUtil.registerPlateIfNotYetDone(ingotType, id, regCallback); | ||
} | ||
} | ||
} |
58 changes: 0 additions & 58 deletions
58
src/main/java/com/portingdeadmods/moreplates/mixins/DeferredRegisterMixin.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.