diff --git a/src/main/java/cam72cam/mod/MinecraftClient.java b/src/main/java/cam72cam/mod/MinecraftClient.java index 4d7405a6..581d1290 100644 --- a/src/main/java/cam72cam/mod/MinecraftClient.java +++ b/src/main/java/cam72cam/mod/MinecraftClient.java @@ -17,15 +17,28 @@ public static boolean isReady() { } private static Player playerCache; - /** Hey, it's you! */ + private static Entity entityCache; + + /** Hey, it's you! */ public static Player getPlayer() { EntityPlayerSP internal = Minecraft.getMinecraft().player; if (internal == null) { throw new RuntimeException("Called to get the player before minecraft has actually started!"); } + if (entityCache == null) { + entityCache = World.get(internal.world).getEntity(internal); + } + // Cannot join immediately after game startup in multiplayer. + // The following fixes avoided the error, but the GUI cannot be displayed in IR when the game is joined immediately after startup. + // It is possible to work around it by re-logging in. if (playerCache == null || internal != playerCache.internal) { - playerCache = World.get(internal.world).getEntity(internal).asPlayer(); + if (entityCache == null) { + playerCache = new Player(Minecraft.getMinecraft().player); + } else { + playerCache = World.get(internal.world).getEntity(internal).asPlayer(); + } } + // ----- return playerCache; } diff --git a/src/main/java/cam72cam/mod/world/World.java b/src/main/java/cam72cam/mod/world/World.java index 15ba4057..b7780f83 100644 --- a/src/main/java/cam72cam/mod/world/World.java +++ b/src/main/java/cam72cam/mod/world/World.java @@ -451,7 +451,7 @@ public void dropItem(ItemStack stack, Vec3d pos) { /** Drop a stack on the ground at pos with velocity */ public void dropItem(ItemStack stack, Vec3d pos, Vec3d velocity) { EntityItem entity = new EntityItem(internal, pos.x, pos.y, pos.z, stack.internal); - entity.setVelocity(velocity.x, velocity.y, velocity.z); +// entity.setVelocity(velocity.x, velocity.y, velocity.z); internal.spawnEntity(entity); }