public void readFromNBT(NBTTagCompound compound) { scope.minX = compound.getIntArray(TAG_POSITION)[0]; scope.minY = compound.getIntArray(TAG_POSITION)[1]; scope.maxX = scope.minX + CHUNK_STEP - 1; scope.maxY = scope.minY + CHUNK_STEP - 1; int[] tileArray = compound.getIntArray(TAG_TILES); for (int y = 0; y < CHUNK_STEP; y++) { for (int x = 0; x < CHUNK_STEP; x++) { // order: // 0 1 2 // 3 4 5 // 6 7 8 if (tileArray[x + y * CHUNK_STEP] == -1) { tiles[x][y] = null; } else { tiles[x][y] = new Tile(tileArray[x + y * CHUNK_STEP]); } } } }
@Override protected void process(EntityPlayer player, Side side) { AtlasData data = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, player.world); for (int i = 0; i < tileCount; i++) { data.getDimensionData(dimension).setTile(tileData.readShort(), tileData.readShort(), new Tile(tileData.readShort())); } } }
@Override public void putBiomeTile(World world, int atlasID, int biomeID, int chunkX, int chunkZ) { int dimension = world.provider.getDimension(); PutBiomeTilePacket packet = new PutBiomeTilePacket(atlasID, dimension, chunkX, chunkZ, biomeID); if (world.isRemote) { PacketDispatcher.sendToServer(packet); } else { AtlasData data = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, world); Tile tile = new Tile(biomeID); data.setTile(dimension, chunkX, chunkZ, tile); for (EntityPlayer syncedPlayer : data.getSyncedPlayers()) { PacketDispatcher.sendTo(new PutBiomeTilePacket(atlasID, dimension, chunkX, chunkZ, biomeID), (EntityPlayerMP)syncedPlayer); } } }
} else if (oldTile.biomeID != biomeId) { this.setTile(player.dimension, x, z, new Tile(biomeId)); updatedTiles.add(new TileInfo(x, z, biomeId)); this.setTile(player.dimension, x, z, new Tile(biomeId)); updatedTiles.add(new TileInfo(x, z, biomeId)); this.setTile(player.dimension, x, z, new Tile(biomeId)); updatedTiles.add(new TileInfo(x, z, biomeId)); this.markDirty();
@Override protected void process(EntityPlayer player, Side side) { if (side.isServer()) { // Make sure it's this player's atlas :^) if (SettingsConfig.gameplay.itemNeeded && !player.inventory.hasItemStack(new ItemStack(RegistrarAntiqueAtlas.ATLAS, 1, atlasID))) { Log.warn("Player %s attempted to modify someone else's Atlas #%d", player.getGameProfile().getName(), atlasID); return; } AtlasAPI.tiles.putBiomeTile(player.getEntityWorld(), atlasID, biomeID, x, z); } else { AtlasData data = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, player.getEntityWorld()); data.setTile(dimension, x, z, new Tile(biomeID)); } }
/**Reads from NBT version 2. This is designed to allow easy upgrading to version 3.*/ public void readFromNBT2(NBTTagCompound compound) { this.nbt = compound; int version = compound.getInteger(TAG_VERSION); if (version < 2) { Log.warn("Loading map with version 2 failed"); this.markDirty(); return; } NBTTagList dimensionMapList = compound.getTagList(TAG_DIMENSION_MAP_LIST, Constants.NBT.TAG_COMPOUND); for (int d = 0; d < dimensionMapList.tagCount(); d++) { NBTTagCompound dimTag = dimensionMapList.getCompoundTagAt(d); int dimensionID = dimTag.getInteger(TAG_DIMENSION_ID); int[] intArray = dimTag.getIntArray(TAG_VISITED_CHUNKS); DimensionData dimData = getDimensionData(dimensionID); for (int i = 0; i < intArray.length; i += 3) { if (dimData.getTile(intArray[i], intArray[i+1]) != null){ Log.warn("Duplicate tile at "+ intArray[i] + ", " + intArray[i]); } dimData.setTile(intArray[i], intArray[i+1], new Tile(intArray[i+2])); } Log.info("Updated " + intArray.length/3 + " chunks"); double zoom = (double)dimTag.getInteger(TAG_BROWSING_ZOOM) / BrowsingPositionPacket.ZOOM_SCALE_FACTOR; if (zoom == 0) zoom = 0.5; dimData.setBrowsingPosition(dimTag.getInteger(TAG_BROWSING_X), dimTag.getInteger(TAG_BROWSING_Y), zoom); } }