us.myles.ViaVersion.api.minecraft.Environment Java Examples
The following examples show how to use
us.myles.ViaVersion.api.minecraft.Environment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Chunk1_8Type.java From ViaRewind with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { ByteBuf buf = output.alloc().buffer(); for (int i = 0; i < chunk.getSections().length; i++) { if ((chunk.getBitmask() & 1 << i) == 0) continue; CHUNK_SECTION_TYPE.write(buf, chunk.getSections()[i]); } for (int i = 0; i < chunk.getSections().length; i++) { if ((chunk.getBitmask() & 1 << i) == 0) continue; chunk.getSections()[i].writeBlockLight(buf); } boolean skyLight = world.getEnvironment() == Environment.NORMAL; if (skyLight) { for (int i = 0; i < chunk.getSections().length; i++) { if ((chunk.getBitmask() & 1 << i) == 0) continue; chunk.getSections()[i].writeSkyLight(buf); } } if (chunk.isGroundUp() && chunk.isBiomeData()) { for (int biome : chunk.getBiomeData()) { buf.writeByte((byte) biome); } } output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isGroundUp()); output.writeShort(chunk.getBitmask()); Type.VAR_INT.write(output, buf.readableBytes()); output.writeBytes(buf, buf.readableBytes()); buf.release(); }
Example #2
Source File: Chunk1_9_3_4Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); Type.VAR_INT.readPrimitive(input); // Read sections ChunkSection[] sections = new ChunkSection[16]; for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set ChunkSection section = Types1_9.CHUNK_SECTION.read(input); sections[i] = section; section.readBlockLight(input); if (world.getEnvironment() == Environment.NORMAL) { section.readSkyLight(input); } } int[] biomeData = fullChunk ? new int[256] : null; if (fullChunk) { for (int i = 0; i < 256; i++) { biomeData[i] = input.readByte() & 0xFF; } } List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input))); // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); } } return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); }
Example #3
Source File: Chunk1_13Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); // Read sections ChunkSection[] sections = new ChunkSection[16]; for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set ChunkSection section = Types1_13.CHUNK_SECTION.read(data); sections[i] = section; section.readBlockLight(data); if (world.getEnvironment() == Environment.NORMAL) { section.readSkyLight(data); } } int[] biomeData = fullChunk ? new int[256] : null; if (fullChunk) { if (data.readableBytes() >= 256 * 4) { for (int i = 0; i < 256; i++) { biomeData[i] = data.readInt(); } } else { Via.getPlatform().getLogger().log(Level.WARNING, "Chunk x=" + chunkX + " z=" + chunkZ + " doesn't have biome data!"); } } List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input))); // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); } } return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); }
Example #4
Source File: Chunk1_9_1_2Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { boolean replacePistons = world.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId(); int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean groundUp = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); // Size (unused) Type.VAR_INT.readPrimitive(input); BitSet usedSections = new BitSet(16); ChunkSection[] sections = new ChunkSection[16]; // Calculate section count from bitmask for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) != 0) { usedSections.set(i); } } // Read sections for (int i = 0; i < 16; i++) { if (!usedSections.get(i)) continue; // Section not set ChunkSection section = Types1_9.CHUNK_SECTION.read(input); sections[i] = section; section.readBlockLight(input); if (world.getEnvironment() == Environment.NORMAL) { section.readSkyLight(input); } if (replacePistons) { section.replacePaletteEntry(36, replacementId); } } int[] biomeData = groundUp ? new int[256] : null; if (groundUp) { for (int i = 0; i < 256; i++) { biomeData[i] = input.readByte() & 0xFF; } } return new BaseChunk(chunkX, chunkZ, groundUp, false, primaryBitmask, sections, biomeData, new ArrayList<CompoundTag>()); }
Example #5
Source File: ClientWorld.java From ViaVersion with MIT License | 4 votes |
public Environment getEnvironment() { return environment; }
Example #6
Source File: ClientWorld.java From ViaVersion with MIT License | 4 votes |
public void setEnvironment(int environmentId) { this.environment = Environment.getEnvironmentById(environmentId); }
Example #7
Source File: ClientWorld.java From ViaVersion with MIT License | 4 votes |
public void setEnvironment(String environmentId) { this.environment = Environment.getEnvironmentById(environmentId); }