Try to fix #5573 by peeling the worldclient fetch into a separate handler.

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-02-27 13:45:51 -05:00
parent 0bcc60fbe3
commit dd7e7fc122
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7
3 changed files with 9 additions and 4 deletions

View file

@ -21,14 +21,17 @@ package net.minecraftforge.fml;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public enum LogicalSidedProvider public enum LogicalSidedProvider
{ {
WORKQUEUE((c)->c.get(), (s)->s.get()), WORKQUEUE((c)->c.get(), (s)->s.get()),
INSTANCE((c)->c.get(), (s)->s.get()) INSTANCE((c)->c.get(), (s)->s.get()),
CLIENTWORLD((c)-> Optional.<World>of(c.get().world), (s)->Optional.<World>empty())
; ;
private static Supplier<Minecraft> client; private static Supplier<Minecraft> client;
private static Supplier<MinecraftServer> server; private static Supplier<MinecraftServer> server;

View file

@ -27,11 +27,14 @@ import net.minecraft.entity.EntityType;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.ExtensionPoint; import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.LogicalSidedProvider;
import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModList;
import net.minecraft.util.registry.IRegistry; import net.minecraft.util.registry.IRegistry;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -128,7 +131,8 @@ public class FMLPlayMessages
throw new RuntimeException(String.format("Could not spawn entity (id %d) with unknown type at (%f, %f, %f)", msg.entityId, msg.posX, msg.posY, msg.posZ)); throw new RuntimeException(String.format("Could not spawn entity (id %d) with unknown type at (%f, %f, %f)", msg.entityId, msg.posX, msg.posY, msg.posZ));
} }
Entity e = type.handleSpawnMessage(Minecraft.getInstance().world, msg); Optional<World> world = LogicalSidedProvider.CLIENTWORLD.get(ctx.get().getDirection().getLogicalSide());
Entity e = world.map(w->type.handleSpawnMessage(w, msg)).orElse(null);
if (e == null) if (e == null)
{ {
return; return;

View file

@ -34,9 +34,7 @@ import net.minecraft.util.IThreadListener;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSidedProvider; import net.minecraftforge.fml.LogicalSidedProvider;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;