@Override public boolean equals(Object obj) { if (!(obj instanceof DimensionData)) return false; DimensionData other = (DimensionData)obj; if (other.tileGroups.size() != tileGroups.size()) return false; for (ShortVec2 entry : tileGroups.keySet()) { if (!this.tileGroups.get(entry).equals(other.tileGroups.get(entry))) return false; } return true; } }
public void addData(DimensionData other){ for (Entry<ShortVec2, TileGroup> e:other.tileGroups.entrySet()){ TileGroup group = e.getValue(); Rect s = group.getScope(); for (int x = s.minX; x <= s.maxX; x++){ for (int y = s.minY; y <= s.maxY; y++){ Tile tile = group.getTile(x, y); if (tile != null) setTile(x, y, tile); } } } }
@Test public void testNBT(){ NBTTagCompound tagTG = new NBTTagCompound(); tg.writeToNBT(tagTG); TileGroup tg2 = new TileGroup(0,0); tg2.readFromNBT(tagTG); assertEquals(tg, tg2); NBTTagList tagDD = dd.writeToNBT(); DimensionData dd2 = new DimensionData(null, 0); dd2.readFromNBT(tagDD); } }
public void readFromNBT(NBTTagList me){ if (me == null){ return; } for (int d = 0; d < me.tagCount(); d++) { NBTTagCompound tgTag = me.getCompoundTagAt(d); TileGroup tg = new TileGroup(0, 0); tg.readFromNBT(tgTag); putTileGroup(tg); } }
@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(); }
public NBTTagList writeToNBT() { NBTTagList tileGroupList = new NBTTagList(); for (Entry<ShortVec2, TileGroup> entry : tileGroups.entrySet()) { NBTTagCompound newbie = new NBTTagCompound(); entry.getValue().writeToNBT(newbie); tileGroupList.appendTag(newbie); } return tileGroupList; }
@Override public boolean hasTileAt(int x, int y) { return getTile(x, y) != null; }
private void extendToTileGroup(TileGroup tg){ for (int x = tg.scope.minX; x <= tg.scope.maxX; x++){ for (int y = tg.scope.minY; y <= tg.scope.maxY; y++){ if (tg.hasTileAt(x, y)){ scope.extendTo(x, y); } } } }
@Override protected void read(PacketBuffer buffer) throws IOException { atlasID = buffer.readVarInt(); dimension = buffer.readVarInt(); int length = buffer.readVarInt(); tileGroups = new ArrayList<TileGroup>(length); for (int i = 0; i < length; i++) { TileGroup newbie = new TileGroup(0, 0); newbie.readFromNBT(ByteBufUtils.readTag(buffer)); tileGroups.add(newbie); } }
@Override protected void write(PacketBuffer buffer) throws IOException { buffer.writeVarInt(atlasID); buffer.writeVarInt(dimension); buffer.writeVarInt(tileGroups.size()); for (TileGroup t : tileGroups) { NBTTagCompound me = new NBTTagCompound(); t.writeToNBT(me); ByteBufUtils.writeTag(buffer, me); } }
@Override public Tile getTile(int x, int y) { 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) { return null; } return tg.getTile(x, y); }
/** * This function has to create a new map on each call since the packet rework */ public Map<ShortVec2, Tile> getSeenChunks() { Map<ShortVec2, Tile> chunks = new ConcurrentHashMap<ShortVec2, Tile>(2, 0.75f, 2); Tile t = null; for (Map.Entry<ShortVec2, TileGroup> entry: tileGroups.entrySet()){ int basex = entry.getValue().getScope().minX; int basey = entry.getValue().getScope().minY; for (int x = basex; x < basex+TileGroup.CHUNK_STEP; x++){ for (int y = basey; y < basey+TileGroup.CHUNK_STEP; y++){ t = entry.getValue().getTile(x, y); if (t!=null){ chunks.put(new ShortVec2(x, y), t); } } } } return chunks; }