Skip to content

Commit

Permalink
Workaround for null player
Browse files Browse the repository at this point in the history
  • Loading branch information
tyra314 committed Sep 11, 2022
1 parent da59206 commit 0ded504
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import hunternif.mc.impl.atlas.network.packet.s2c.S2CPacket;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;

import javax.swing.text.html.parser.Entity;

/**
* Deletes a marker. A client sends a {@link DeleteMarkerC2SPacket}
* to the server as a request, and the server sends this back to all players as a response, including the
Expand Down Expand Up @@ -39,9 +43,11 @@ public static void apply(PacketByteBuf buf, NetworkManager.PacketContext context
int markerID = buf.readVarInt();

context.queue(() -> {
PlayerEntity player = MinecraftClient.getInstance().player;
assert player != null;
MarkersData data = atlasID == GLOBAL ?
AntiqueAtlasMod.globalMarkersData.getData() :
AntiqueAtlasMod.markersData.getMarkersData(atlasID, context.getPlayer().getEntityWorld());
AntiqueAtlasMod.markersData.getMarkersData(atlasID, player.getEntityWorld());
data.removeMarker(markerID);

AntiqueAtlasModClient.getAtlasGUI().updateBookmarkerList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import hunternif.mc.impl.atlas.core.AtlasData;
import hunternif.mc.impl.atlas.core.TileInfo;
import hunternif.mc.impl.atlas.network.packet.s2c.S2CPacket;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -55,8 +57,9 @@ public static void apply(PacketByteBuf buf, NetworkManager.PacketContext context
}

context.queue(() -> {
assert context.getPlayer() != null;
AtlasData data = AntiqueAtlasMod.tileData.getData(atlasID, context.getPlayer().getEntityWorld());
PlayerEntity player = MinecraftClient.getInstance().player;
assert player != null;
AtlasData data = AntiqueAtlasMod.tileData.getData(atlasID, player.getEntityWorld());

for (TileInfo info : tiles) {
data.getWorldData(world).setTile(info.x, info.z, info.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -38,7 +39,9 @@ public static void apply(PacketByteBuf buf, NetworkManager.PacketContext context
if (data == null) return;

context.queue(() -> {
AtlasData atlasData = AntiqueAtlasMod.tileData.getData(atlasID, context.getPlayer().getEntityWorld());
PlayerEntity player = MinecraftClient.getInstance().player;
assert player != null;
AtlasData atlasData = AntiqueAtlasMod.tileData.getData(atlasID, player.getEntityWorld());
atlasData.updateFromNbt(data);

if (AntiqueAtlasMod.CONFIG.doSaveBrowsingPos && MinecraftClient.getInstance().currentScreen instanceof GuiAtlas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import hunternif.mc.impl.atlas.registry.MarkerType;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -73,9 +75,12 @@ public static void apply(PacketByteBuf buf, NetworkManager.PacketContext context
}

context.queue(() -> {
PlayerEntity player = MinecraftClient.getInstance().player;
assert player != null;

MarkersData markersData = atlasID == GLOBAL
? AntiqueAtlasMod.globalMarkersData.getData()
: AntiqueAtlasMod.markersData.getMarkersData(atlasID, context.getPlayer().getEntityWorld());
: AntiqueAtlasMod.markersData.getMarkersData(atlasID, player.getEntityWorld());

for (Identifier type : markersByType.keys()) {
MarkerType markerType = MarkerType.REGISTRY.get(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.core.AtlasData;
import hunternif.mc.impl.atlas.network.packet.s2c.S2CPacket;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -39,7 +41,10 @@ public static void apply(PacketByteBuf buf, NetworkManager.PacketContext context
Identifier tile = buf.readIdentifier();

context.queue(() -> {
AtlasData data = AntiqueAtlasMod.tileData.getData(atlasID, context.getPlayer().getEntityWorld());
PlayerEntity player = MinecraftClient.getInstance().player;
assert player != null;

AtlasData data = AntiqueAtlasMod.tileData.getData(atlasID, player.getEntityWorld());
data.setTile(world, x, z, tile);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import hunternif.mc.impl.atlas.core.WorldData;
import hunternif.mc.impl.atlas.core.TileGroup;
import hunternif.mc.impl.atlas.network.packet.s2c.S2CPacket;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -56,7 +58,10 @@ public static void apply(PacketByteBuf buf, NetworkManager.PacketContext context
}

context.queue(() -> {
AtlasData atlasData = AntiqueAtlasMod.tileData.getData(atlasID, context.getPlayer().getEntityWorld());
PlayerEntity player = MinecraftClient.getInstance().player;
assert player != null;

AtlasData atlasData = AntiqueAtlasMod.tileData.getData(atlasID, player.getEntityWorld());
WorldData dimData = atlasData.getWorldData(world);
for (TileGroup t : tileGroups) {
dimData.putTileGroup(t);
Expand Down

0 comments on commit 0ded504

Please sign in to comment.