Skip to content

Commit

Permalink
[1.12.2] Avoid Error.
Browse files Browse the repository at this point in the history
  • Loading branch information
AoiKagase committed Nov 26, 2024
1 parent d384fb2 commit ae5ee07
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/main/java/cam72cam/mod/MinecraftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cam72cam/mod/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ae5ee07

Please sign in to comment.