/** Returns the Tile previously set at given coordinates. */ private Tile removeTile(int dimension, int x, int y) { DimensionData dimData = getDimensionData(dimension); return dimData.removeTile(x, y); }
/** Loads data for the given atlas or creates a new one. */ public AtlasData getAtlasData(int atlasID, World world) { String key = getAtlasDataKey(atlasID); AtlasData data = null; if (world.isRemote) { // Since atlas data doesn't really belong to a single world-dimension, // it can be cached. This should fix #67 data = atlasDataClientCache.get(key); } if (data == null) { data = (AtlasData) world.loadData(AtlasData.class, key); if (data == null) { data = new AtlasData(key); world.setData(key, data); } if (world.isRemote) atlasDataClientCache.put(key, data); } return data; }
@SubscribeEvent public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { EntityPlayer player = event.player; World world = player.world; int atlasID = player.getUniqueID().hashCode(); AtlasData data = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, world); // On the player join send the map from the server to the client: if (!data.isEmpty()) { data.syncOnPlayer(atlasID, player); } // Same thing with the local markers: MarkersData markers = AntiqueAtlasMod.markersData.getMarkersData(atlasID, world); if (!markers.isEmpty()) { markers.syncOnPlayer(atlasID, player); } }
ITileStorage seenChunks = this.getDimensionData(player.dimension); IBiomeDetector biomeDetector = getBiomeDetectorForDimension(player.dimension); int scanRadius = SettingsConfig.performance.scanRadius; this.removeTile(player.dimension, x, z); } 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();
destBiomes.markDirty(); MarkersData destMarkers = AntiqueAtlasMod.markersData.getMarkersData(atlasID, world); destMarkers.markDirty(); AtlasData srcBiomes = AntiqueAtlasMod.atlasData.getAtlasData(stack, world); if (destBiomes != null && srcBiomes != null && destBiomes != srcBiomes) { for (int dim : srcBiomes.getVisitedDimensions()) { destBiomes.getDimensionData(dim).addData(srcBiomes.getDimensionData(dim));
@Override public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isEquipped) { AtlasData data = AntiqueAtlasMod.atlasData.getAtlasData(stack, world); if (data == null || !(entity instanceof EntityPlayer)) return; // On the first run send the map from the server to the client: EntityPlayer player = (EntityPlayer) entity; if (!world.isRemote && !data.isSyncedOnPlayer(player) && !data.isEmpty()) { data.syncOnPlayer(stack.getItemDamage(), player); } // Same thing with the local markers: MarkersData markers = AntiqueAtlasMod.markersData.getMarkersData(stack, world); if (!world.isRemote && !markers.isSyncedOnPlayer(player) && !markers.isEmpty()) { markers.syncOnPlayer(stack.getItemDamage(), player); } // Updating map around player ArrayList<TileInfo> newTiles = data.updateMapAroundPlayer(player); if (!world.isRemote) { if (newTiles.size() > 0) { DimensionUpdatePacket packet = new DimensionUpdatePacket(stack.getItemDamage(), player.dimension); for (TileInfo t : newTiles) { packet.addTile(t.x, t.z, t.biome); } PacketDispatcher.sendToAll(packet); } } }
/**Creates a pre-packet-rework AtlasData NBT tag*/ public void writeToNBTv2(AtlasData atlasdata, NBTTagCompound compound) { compound.setInteger(AtlasData.TAG_VERSION, 2); NBTTagList dimensionMapList = new NBTTagList(); int dimension = 0; int key; Iterator<Integer> dimensionEntryKey = atlasdata.getVisitedDimensions().iterator(); for (dimension = 0; dimension<atlasdata.getVisitedDimensions().size(); dimension++) { NBTTagCompound dimTag = new NBTTagCompound(); key = dimensionEntryKey.next().intValue(); dimTag.setInteger(AtlasData.TAG_DIMENSION_ID, key); DimensionData dimData = atlasdata.getDimensionData(key); Map<ShortVec2, Tile> seenChunks = dimData.getSeenChunks(); int[] intArray = new int[seenChunks.size()*3]; int i = 0; for (Entry<ShortVec2, Tile> entry : seenChunks.entrySet()) { intArray[i++] = entry.getKey().x; intArray[i++] = entry.getKey().y; intArray[i++] = entry.getValue().biomeID; } dimTag.setIntArray(AtlasData.TAG_VISITED_CHUNKS, intArray); dimTag.setInteger(AtlasData.TAG_BROWSING_X, dimData.getBrowsingX()); dimTag.setInteger(AtlasData.TAG_BROWSING_Y, dimData.getBrowsingY()); dimTag.setInteger(AtlasData.TAG_BROWSING_ZOOM, (int)Math.round(dimData.getBrowsingZoom() * BrowsingPositionPacket.ZOOM_SCALE_FACTOR)); dimensionMapList.appendTag(dimTag); } compound.setTag(AtlasData.TAG_DIMENSION_MAP_LIST, dimensionMapList); }
atlasData.getDimensionData(player.dimension).setBrowsingPosition( (int)Math.round(-player.posX * SettingsConfig.userInterface.defaultScale), (int)Math.round(-player.posZ * SettingsConfig.userInterface.defaultScale), SettingsConfig.userInterface.defaultScale); atlasData.markDirty();
@Override public void readFromNBT(NBTTagCompound compound) { this.nbt = compound; int version = compound.getInteger(TAG_VERSION); if (version < VERSION) { Log.warn("Outdated atlas data format! Was %d but current is %d. Updating.", version, VERSION); readFromNBT2(compound); 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); NBTTagList dimensionTag = (NBTTagList) dimTag.getTag(TAG_VISITED_CHUNKS); DimensionData dimData = getDimensionData(dimensionID); dimData.readFromNBT(dimensionTag); 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); } }
@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); } } }
/** Set world coordinates that are in the center of the GUI. */ public void setBrowsingPosition(int x, int y, double zoom) { this.browsingX = x; this.browsingY = y; this.browsingZoom = zoom; if (browsingZoom <= 0) { Log.warn("Setting map zoom to invalid value of %f", zoom); browsingZoom = SettingsConfig.userInterface.minScale; } parent.markDirty(); }
@Override @SideOnly(Side.CLIENT) protected void process(EntityPlayer player, Side side) { if (data == null) return; // Atlas is empty AtlasData atlasData = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, player.getEntityWorld()); atlasData.readFromNBT(data); // GuiAtlas may already be opened at (0, 0) browsing position, force load saved position: if (SettingsConfig.gameplay.doSaveBrowsingPos && Minecraft.getMinecraft().currentScreen instanceof GuiAtlas) { ((GuiAtlas)Minecraft.getMinecraft().currentScreen).loadSavedBrowsingPosition(); } } }
/**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); } }
@Override public void setTile(int x, int y, Tile tile) { ShortVec2 groupPos = getKey().set((int)Math.floor(x / (float) TileGroup.CHUNK_STEP), (int)Math.floor(y / (float) TileGroup.CHUNK_STEP)); TileGroup tg = tileGroups.get(groupPos); if (tg == null) { tg = new TileGroup(groupPos.x * TileGroup.CHUNK_STEP, groupPos.y * TileGroup.CHUNK_STEP); tileGroups.put(groupPos, tg); } tg.setTile(x, y, tile); scope.extendTo(x, y); parent.markDirty(); }
/** Puts a given tile into given map at specified coordinates and, * if tileStitcher is present, sets appropriate sectors on adjacent tiles. */ public void setTile(int dimension, int x, int y, Tile tile) { DimensionData dimData = getDimensionData(dimension); dimData.setTile(x, y, tile); }
public Map<ShortVec2, Tile> getSeenChunksInDimension(int dimension) { return getDimensionData(dimension).getSeenChunks(); }
@Override protected void process(EntityPlayer player, Side side) { AtlasData atlasData = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, player.world); DimensionData dimData = atlasData.getDimensionData(dimension); for (TileGroup t : tileGroups) { dimData.putTileGroup(t); } } }
@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 protected void process(EntityPlayer player, Side side) { // 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 put position marker into someone else's Atlas #%d", player.getGameProfile().getName(), atlasID); return; } AntiqueAtlasMod.atlasData.getAtlasData(atlasID, player.getEntityWorld()) .getDimensionData(dimension).setBrowsingPosition(x, y, zoom); }
/** Update {@link #biomeData}, {@link #localMarkersData}, * {@link #globalMarkersData} */ private void updateAtlasData() { int atlasID = getAtlasID(); biomeData = AntiqueAtlasMod.atlasData .getAtlasData(atlasID, player.getEntityWorld()) .getDimensionData(player.dimension); globalMarkersData = AntiqueAtlasMod.globalMarkersData.getData() .getMarkersDataInDimension(player.dimension); MarkersData markersData = AntiqueAtlasMod.markersData .getMarkersData(atlasID, player.getEntityWorld()); if (markersData != null) { localMarkersData = markersData .getMarkersDataInDimension(player.dimension); } else { localMarkersData = null; } }