Renamed RecipeUpdateEventHandler to UpdateRecipesEventHandler. Added method for mod config reload event on server-side to send packet to client.
This commit is contained in:
@ -3,6 +3,8 @@ package dev.micle.totemofreviving.event;
|
|||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
import dev.micle.totemofreviving.TotemOfReviving;
|
||||||
import dev.micle.totemofreviving.config.Config;
|
import dev.micle.totemofreviving.config.Config;
|
||||||
import dev.micle.totemofreviving.item.StrawTotemItem;
|
import dev.micle.totemofreviving.item.StrawTotemItem;
|
||||||
|
import dev.micle.totemofreviving.network.Network;
|
||||||
|
import dev.micle.totemofreviving.network.UpdateRecipesPacket;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
@ -12,26 +14,29 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
|||||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
import net.minecraftforge.fml.config.ModConfig;
|
||||||
|
import net.minecraftforge.fml.network.PacketDistributor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class RecipeUpdateEventHandler {
|
public class UpdateRecipesEventHandler {
|
||||||
public static class ModBus {
|
public static class ModBus {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void onModConfigReloadEvent(ModConfig.Reloading event) {
|
public void onClientModConfigReloadEvent(ModConfig.Reloading event) {
|
||||||
|
if (!event.getConfig().getModId().equals(TotemOfReviving.MOD_ID) ||
|
||||||
|
Minecraft.getInstance().getSingleplayerServer() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateRecipeManager(Minecraft.getInstance().getSingleplayerServer().getRecipeManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
@OnlyIn(Dist.DEDICATED_SERVER)
|
||||||
|
public void onServerModConfigReloadEvent(ModConfig.Reloading event) {
|
||||||
if (!event.getConfig().getModId().equals(TotemOfReviving.MOD_ID)) {
|
if (!event.getConfig().getModId().equals(TotemOfReviving.MOD_ID)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Minecraft.getInstance().getSingleplayerServer() != null) {
|
Network.channel.send(PacketDistributor.ALL.noArg(), new UpdateRecipesPacket());
|
||||||
updateRecipeManager(Minecraft.getInstance().getSingleplayerServer().getRecipeManager());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Minecraft.getInstance().getConnection() != null) {
|
|
||||||
updateRecipeManager(Minecraft.getInstance().getConnection().getRecipeManager());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.println("FAILED TO GET RECIPE MANAGER!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +49,7 @@ public class RecipeUpdateEventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateRecipeManager(RecipeManager recipeManager) {
|
public static void updateRecipeManager(RecipeManager recipeManager) {
|
||||||
ArrayList<IRecipe<?>> newRecipes = new ArrayList<>();
|
ArrayList<IRecipe<?>> newRecipes = new ArrayList<>();
|
||||||
for (IRecipe<?> recipe : recipeManager.getRecipes()) {
|
for (IRecipe<?> recipe : recipeManager.getRecipes()) {
|
||||||
if (recipe.getResultItem().getItem() instanceof StrawTotemItem) {
|
if (recipe.getResultItem().getItem() instanceof StrawTotemItem) {
|
@ -1,7 +1,7 @@
|
|||||||
package dev.micle.totemofreviving.setup;
|
package dev.micle.totemofreviving.setup;
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
import dev.micle.totemofreviving.TotemOfReviving;
|
||||||
import dev.micle.totemofreviving.event.RecipeUpdateEventHandler;
|
import dev.micle.totemofreviving.event.UpdateRecipesEventHandler;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
@ -20,9 +20,9 @@ public class Registration {
|
|||||||
ITEMS.register(modEventBus);
|
ITEMS.register(modEventBus);
|
||||||
ModItems.register();
|
ModItems.register();
|
||||||
|
|
||||||
modEventBus.register(new RecipeUpdateEventHandler.ModBus());
|
modEventBus.register(new UpdateRecipesEventHandler.ModBus());
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(new RecipeUpdateEventHandler.EventBus());
|
MinecraftForge.EVENT_BUS.register(new UpdateRecipesEventHandler.EventBus());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends IForgeRegistryEntry<T>> DeferredRegister<T> create(IForgeRegistry<T> registry) {
|
private static <T extends IForgeRegistryEntry<T>> DeferredRegister<T> create(IForgeRegistry<T> registry) {
|
||||||
|
Reference in New Issue
Block a user