mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 11:19:19 +00:00
Switch the initial recipe sync to a login packet
Should fix JEI not loading Botania recipes on server join. This removes the need to run a resource reload to force JEI to pick them up
This commit is contained in:
1 parent
f65afb2aff
commit
fe4d3157c3
5 files changed
+118
-10
No files matched your search
@@ -78,12 +78,4 @@ public class SyncHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID)
|
||||
public static class CommonEvents {
|
||||
@SubscribeEvent
|
||||
public static void serverLogin(PlayerEvent.PlayerLoggedInEvent evt) {
|
||||
PacketHandler.sendNonLocal((ServerPlayerEntity) evt.getPlayer(), syncPacket());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* This class was created by <Hubry>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [2020-01-13, 17:34 (UTC+2)]
|
||||
*/
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public interface ILoginPacket extends IntSupplier {
|
||||
|
||||
void setLoginIndex(int index);
|
||||
|
||||
int getLoginIndex();
|
||||
|
||||
@Override
|
||||
default int getAsInt() {
|
||||
return getLoginIndex();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This class was created by <Hubry>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [2020-01-13, 17:43 (UTC+2)]
|
||||
*/
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PacketAck implements ILoginPacket {
|
||||
private int loginIndex;
|
||||
|
||||
public static PacketAck decode(PacketBuffer buf) {
|
||||
return new PacketAck();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginIndex(int index) {
|
||||
this.loginIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoginIndex() {
|
||||
return loginIndex;
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.fml.network.FMLHandshakeHandler;
|
||||
import net.minecraftforge.fml.network.NetworkDirection;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
@@ -14,7 +15,7 @@ import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
public final class PacketHandler {
|
||||
private static final String PROTOCOL = "2";
|
||||
private static final String PROTOCOL = "3";
|
||||
public static final SimpleChannel HANDLER = NetworkRegistry.newSimpleChannel(
|
||||
new ResourceLocation(LibMisc.MOD_ID, "chan"),
|
||||
() -> PROTOCOL,
|
||||
@@ -31,6 +32,18 @@ public final class PacketHandler {
|
||||
HANDLER.registerMessage(id++, PacketItemAge.class, PacketItemAge::encode, PacketItemAge::decode, PacketItemAge::handle);
|
||||
HANDLER.registerMessage(id++, PacketSyncRecipes.class, PacketSyncRecipes::encode, PacketSyncRecipes::decode, PacketSyncRecipes::handle);
|
||||
HANDLER.registerMessage(id++, PacketIndexKeybindRequest.class, PacketIndexKeybindRequest::encode, PacketIndexKeybindRequest::decode, PacketIndexKeybindRequest::handle);
|
||||
|
||||
HANDLER.messageBuilder(PacketSyncRecipes.Login.class, id++)
|
||||
.loginIndex(ILoginPacket::getLoginIndex, ILoginPacket::setLoginIndex)
|
||||
.encoder(PacketSyncRecipes.Login::encode).decoder(PacketSyncRecipes.Login::decode)
|
||||
.consumer(FMLHandshakeHandler.biConsumerFor((hh, msg, ctx) -> msg.handle(ctx)))
|
||||
.markAsLoginPacket().add();
|
||||
|
||||
HANDLER.messageBuilder(PacketAck.class, id++)
|
||||
.loginIndex(ILoginPacket::getLoginIndex, ILoginPacket::setLoginIndex)
|
||||
.encoder((packet, buf) -> {}).decoder(PacketAck::decode)
|
||||
.consumer(FMLHandshakeHandler.indexFirst((hh, msg, ctx) -> msg.handle(ctx)))
|
||||
.add();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package vazkii.botania.common.network;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
@@ -12,6 +12,7 @@ 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.common.Botania;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
@@ -104,4 +105,43 @@ public class PacketSyncRecipes {
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
// The login packet wraps the proper one because directly extending it will cause a freeze on the handshake.
|
||||
public static class Login implements ILoginPacket {
|
||||
private final PacketSyncRecipes wrapped;
|
||||
private int loginIndex;
|
||||
|
||||
public Login() {
|
||||
this(new PacketSyncRecipes(BotaniaAPI.brewRecipes, BotaniaAPI.elvenTradeRecipes,
|
||||
BotaniaAPI.manaInfusionRecipes, BotaniaAPI.petalRecipes,
|
||||
BotaniaAPI.pureDaisyRecipes, BotaniaAPI.runeAltarRecipes));
|
||||
}
|
||||
|
||||
public Login(PacketSyncRecipes packet) {
|
||||
this.wrapped = packet;
|
||||
}
|
||||
|
||||
public static Login decode(PacketBuffer buf) {
|
||||
return new Login(PacketSyncRecipes.decode(buf));
|
||||
}
|
||||
|
||||
public void encode(PacketBuffer buf) {
|
||||
wrapped.encode(buf);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||
wrapped.handle(ctx);
|
||||
PacketHandler.HANDLER.reply(new PacketAck(), ctx.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginIndex(int index) {
|
||||
this.loginIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoginIndex() {
|
||||
return loginIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user