Fix first load crashing; fix NPE

This commit is contained in:
DoctorMacc 2020-04-10 16:36:41 -04:00
parent 1dc6d4fbdc
commit d547b31b38
3 changed files with 19 additions and 4 deletions

View file

@ -13,7 +13,6 @@ import java.util.List;
public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator {
@Override
public List<Tag<?>> translateTag(CompoundTag tag) {
System.out.println(tag);
List<Tag<?>> tags = new ArrayList<>();
tags.add(new IntTag("Age", (int) (long) tag.get("Age").getValue()));
// Java sometimes does not provide this tag, but Bedrock crashes if it doesn't exist
@ -37,14 +36,18 @@ public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator {
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
System.out.println("Default Bedrock tag being created");
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
tagBuilder.listTag("ExitPortal", IntTag.class, new ArrayList<>());
List<IntTag> tagsList = new ArrayList<>();
tagsList.add(new IntTag("", 0));
tagsList.add(new IntTag("", 0));
tagsList.add(new IntTag("", 0));
tagBuilder.listTag("ExitPortal", IntTag.class, tagsList);
return tagBuilder.buildRootTag();
}
private int getExitPortalCoordinate(CompoundTag tag, String axis) {
if (tag.get("ExitPortal").getValue() != null) {
// Return 0 if it doesn't exist, otherwise give proper value
if (tag.get("ExitPortal") != null) {
LinkedHashMap compoundTag = (LinkedHashMap) tag.get("ExitPortal").getValue();
com.github.steveice10.opennbt.tag.builtin.IntTag intTag = (com.github.steveice10.opennbt.tag.builtin.IntTag) compoundTag.get(axis);
return intTag.getValue();

View file

@ -110,10 +110,18 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
ChunkUtils.updateBlock(session, new BlockState(blockEntityEntry.getIntValue()), new Position(x, y, z));
}
for (Object2IntMap.Entry<CompoundTag> blockEntityEntry : chunkData.gateways.object2IntEntrySet()) {
int x = blockEntityEntry.getKey().getInt("x");
int y = blockEntityEntry.getKey().getInt("y");
int z = blockEntityEntry.getKey().getInt("z");
ChunkUtils.updateBlock(session, new BlockState(blockEntityEntry.getIntValue()), new Position(x, y, z));
}
for (Map.Entry<Position, BlockState> blockEntityEntry: chunkData.beds.entrySet()) {
ChunkUtils.updateBlock(session, blockEntityEntry.getValue(), blockEntityEntry.getKey());
}
chunkData.signs.clear();
chunkData.gateways.clear();
chunkData.beds.clear();
} catch (Exception ex) {
ex.printStackTrace();

View file

@ -78,6 +78,9 @@ public class ChunkUtils {
if (BlockTranslator.getBlockEntityString(blockState) != null && BlockTranslator.getBlockEntityString(blockState).contains("sign[")) {
Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z);
chunkData.signs.put(Translators.getBlockEntityTranslators().get("Sign").getDefaultBedrockTag("Sign", pos.getX(), pos.getY(), pos.getZ()), blockState.getId());
} else if (BlockTranslator.getBlockEntityString(blockState) != null && BlockTranslator.getBlockEntityString(blockState).contains("end_gateway")) {
Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z);
chunkData.gateways.put(Translators.getBlockEntityTranslators().get("EndGateway").getDefaultBedrockTag("EndGateway", pos.getX(), pos.getY(), pos.getZ()), blockState.getId());
} else if (BlockTranslator.getBedColor(blockState) > -1) {
Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z);
// Beds need to be updated separately to add the bed color tag
@ -189,6 +192,7 @@ public class ChunkUtils {
public com.nukkitx.nbt.tag.CompoundTag[] blockEntities = new com.nukkitx.nbt.tag.CompoundTag[0];
public Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> signs = new Object2IntOpenHashMap<>();
public Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> gateways = new Object2IntOpenHashMap<>();
public Map<Position, BlockState> beds = new HashMap<>();
}
}