mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 10:55:17 +00:00
Tweak recipe syncing
This commit is contained in:
1 parent
435e5e4ff0
commit
d69389a32e
4 files changed
+98
-60
No files matched your search
@@ -11,10 +11,7 @@
|
||||
package vazkii.botania.common;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.conditions.LootConditionManager;
|
||||
import net.minecraft.world.storage.loot.functions.LootFunctionManager;
|
||||
@@ -64,7 +61,7 @@ import vazkii.botania.common.core.loot.TrueGuardianKiller;
|
||||
import vazkii.botania.common.core.proxy.IProxy;
|
||||
import vazkii.botania.common.core.proxy.ServerProxy;
|
||||
import vazkii.botania.common.crafting.FluxfieldCondition;
|
||||
import vazkii.botania.common.crafting.ReloadListener;
|
||||
import vazkii.botania.common.crafting.SyncHandler;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
import vazkii.botania.common.lib.ModTags;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
@@ -74,7 +71,6 @@ import vazkii.botania.common.world.WorldTypeSkyblock;
|
||||
import vazkii.patchouli.api.IMultiblock;
|
||||
import vazkii.patchouli.api.IStateMatcher;
|
||||
import vazkii.patchouli.api.PatchouliAPI;
|
||||
import vazkii.patchouli.common.multiblock.Multiblock;
|
||||
import vazkii.patchouli.common.multiblock.StateMatcher;
|
||||
|
||||
@Mod(LibMisc.MOD_ID)
|
||||
@@ -332,7 +328,7 @@ public class Botania {
|
||||
+ " \"Do not Override\". Whoever had the brilliant idea of overriding it needs to go"
|
||||
+ " back to elementary school and learn to read. (Expected classname: " + expect + ", Actual classname: " + clname + ")");
|
||||
}
|
||||
event.getServer().getResourceManager().addReloadListener(new ReloadListener());
|
||||
event.getServer().getResourceManager().addReloadListener(new SyncHandler.ReloadListener());
|
||||
}
|
||||
|
||||
private void serverStarting(FMLServerStartingEvent event) {
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.api.recipe.RegisterRecipesEvent;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
import vazkii.botania.common.network.PacketSyncRecipes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReloadListener implements IResourceManagerReloadListener {
|
||||
@Override
|
||||
public void onResourceManagerReload(@Nullable IResourceManager manager) {
|
||||
Map<ResourceLocation, RecipePureDaisy> pureDaisy = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeManaInfusion> manaInfusion = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeBrew> brew = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeElvenTrade> elvenTrade = new HashMap<>();
|
||||
Map<ResourceLocation, RecipePetals> apothecary = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeRuneAltar> runeAltar = new HashMap<>();
|
||||
|
||||
RegisterRecipesEvent evt = new RegisterRecipesEvent(
|
||||
r -> pureDaisy.put(r.getId(), r),
|
||||
r -> manaInfusion.put(r.getId(), r),
|
||||
r -> brew.put(r.getId(), r),
|
||||
r -> elvenTrade.put(r.getId(), r),
|
||||
r -> apothecary.put(r.getId(), r),
|
||||
r -> runeAltar.put(r.getId(), r)
|
||||
);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
|
||||
BotaniaAPI.pureDaisyRecipes = ImmutableMap.copyOf(pureDaisy);
|
||||
BotaniaAPI.manaInfusionRecipes = ImmutableMap.copyOf(manaInfusion);
|
||||
BotaniaAPI.brewRecipes = ImmutableMap.copyOf(brew);
|
||||
BotaniaAPI.elvenTradeRecipes = ImmutableMap.copyOf(elvenTrade);
|
||||
BotaniaAPI.petalRecipes = ImmutableMap.copyOf(apothecary);
|
||||
BotaniaAPI.runeAltarRecipes = ImmutableMap.copyOf(runeAltar);
|
||||
PacketHandler.HANDLER.send(PacketDistributor.ALL.noArg(), new PacketSyncRecipes(brew, elvenTrade, manaInfusion,
|
||||
apothecary, pureDaisy, runeAltar));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.api.recipe.RegisterRecipesEvent;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
import vazkii.botania.common.network.PacketHandler;
|
||||
import vazkii.botania.common.network.PacketSyncRecipes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SyncHandler {
|
||||
public static class ReloadListener implements IResourceManagerReloadListener {
|
||||
@Override
|
||||
public void onResourceManagerReload(@Nullable IResourceManager manager) {
|
||||
Map<ResourceLocation, RecipePureDaisy> pureDaisy = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeManaInfusion> manaInfusion = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeBrew> brew = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeElvenTrade> elvenTrade = new HashMap<>();
|
||||
Map<ResourceLocation, RecipePetals> apothecary = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeRuneAltar> runeAltar = new HashMap<>();
|
||||
|
||||
RegisterRecipesEvent evt = new RegisterRecipesEvent(
|
||||
r -> pureDaisy.put(r.getId(), r),
|
||||
r -> manaInfusion.put(r.getId(), r),
|
||||
r -> brew.put(r.getId(), r),
|
||||
r -> elvenTrade.put(r.getId(), r),
|
||||
r -> apothecary.put(r.getId(), r),
|
||||
r -> runeAltar.put(r.getId(), r)
|
||||
);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
|
||||
BotaniaAPI.pureDaisyRecipes = ImmutableMap.copyOf(pureDaisy);
|
||||
BotaniaAPI.manaInfusionRecipes = ImmutableMap.copyOf(manaInfusion);
|
||||
BotaniaAPI.brewRecipes = ImmutableMap.copyOf(brew);
|
||||
BotaniaAPI.elvenTradeRecipes = ImmutableMap.copyOf(elvenTrade);
|
||||
BotaniaAPI.petalRecipes = ImmutableMap.copyOf(apothecary);
|
||||
BotaniaAPI.runeAltarRecipes = ImmutableMap.copyOf(runeAltar);
|
||||
PacketHandler.HANDLER.send(PacketDistributor.ALL.noArg(), syncPacket());
|
||||
}
|
||||
}
|
||||
|
||||
private static PacketSyncRecipes syncPacket() {
|
||||
return new PacketSyncRecipes(BotaniaAPI.brewRecipes, BotaniaAPI.elvenTradeRecipes, BotaniaAPI.manaInfusionRecipes,
|
||||
BotaniaAPI.petalRecipes, BotaniaAPI.pureDaisyRecipes, BotaniaAPI.runeAltarRecipes);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, value = Dist.CLIENT)
|
||||
public static class ClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void clientLogout(ClientPlayerNetworkEvent.LoggedOutEvent evt) {
|
||||
BotaniaAPI.brewRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.elvenTradeRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.manaInfusionRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.petalRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.pureDaisyRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.runeAltarRecipes = Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID)
|
||||
public static class CommonEvents {
|
||||
@SubscribeEvent
|
||||
public static void serverLogin(PlayerEvent.PlayerLoggedInEvent evt) {
|
||||
PacketHandler.sendNonLocal((ServerPlayerEntity) evt.getPlayer(), syncPacket());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,6 +58,12 @@ public final class PacketHandler {
|
||||
HANDLER.sendTo(toSend, playerMP.connection.getNetworkManager(), NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
|
||||
public static void sendNonLocal(ServerPlayerEntity playerMP, Object toSend) {
|
||||
if(playerMP.server.isDedicatedServer() || !playerMP.getGameProfile().getName().equals(playerMP.server.getServerOwner())) {
|
||||
sendTo(playerMP, toSend);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToServer(Object msg) {
|
||||
HANDLER.sendToServer(msg);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user