Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Use methods for palette rewriting, fix "value already present"
Dieser Commit ist enthalten in:
Ursprung
41ef4f6284
Commit
bb2b8bc538
@ -78,6 +78,24 @@ public class ChunkSection {
|
||||
return blocks[idx];
|
||||
}
|
||||
|
||||
public int getPaletteSize() {
|
||||
return palette.size();
|
||||
}
|
||||
|
||||
public int getPaletteEntry(int index) {
|
||||
if (index < 0 || index >= palette.size()) throw new IndexOutOfBoundsException();
|
||||
return palette.inverse().get(index);
|
||||
}
|
||||
|
||||
public void setPaletteEntry(int index, int id) {
|
||||
if (index < 0 || index >= palette.size()) throw new IndexOutOfBoundsException();
|
||||
palette.forcePut(id, index);
|
||||
}
|
||||
|
||||
public void replacePaletteEntry(int oldId, int newId) {
|
||||
if (palette.containsKey(oldId)) palette.put(newId, palette.remove(oldId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a block state in the chunk
|
||||
* This method will not update non-air blocks count
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
@ -29,9 +28,8 @@ public class WorldPackets {
|
||||
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) continue;
|
||||
BiMap<Integer, Integer> inverse = section.getPalette().inverse();
|
||||
for (int i = 0; i < inverse.size(); i++) {
|
||||
inverse.put(i, Protocol1_13_1To1_13.getNewBlockStateId(inverse.get(i)));
|
||||
for (int i = 0; i < section.getPaletteSize(); i++) {
|
||||
section.setPaletteEntry(i, Protocol1_13_1To1_13.getNewBlockStateId(section.getPaletteEntry(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,14 +242,13 @@ public class WorldPackets {
|
||||
|
||||
boolean willStoreAnyBlock = false;
|
||||
|
||||
BiMap<Integer, Integer> inverse = section.getPalette().inverse();
|
||||
for (int p = 0; p < inverse.size(); p++) {
|
||||
int old = inverse.get(p);
|
||||
for (int p = 0; p < section.getPaletteSize(); p++) {
|
||||
int old = section.getPaletteEntry(p);
|
||||
int newId = toNewId(old);
|
||||
if (storage.isWelcome(newId)) {
|
||||
willStoreAnyBlock = true;
|
||||
}
|
||||
inverse.put(p, newId);
|
||||
section.setPaletteEntry(p, newId);
|
||||
}
|
||||
|
||||
if (willStoreAnyBlock) {
|
||||
|
@ -111,14 +111,13 @@ public class WorldPackets {
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) continue;
|
||||
boolean hasBlock = false;
|
||||
BiMap<Integer, Integer> inverse = section.getPalette().inverse();
|
||||
for (int i = 0; i < inverse.size(); i++) {
|
||||
int old = inverse.get(i);
|
||||
for (int i = 0; i < section.getPaletteSize(); i++) {
|
||||
int old = section.getPaletteEntry(i);
|
||||
int newId = Protocol1_14To1_13_2.getNewBlockStateId(old);
|
||||
if (!hasBlock && newId != AIR && newId != VOID_AIR && newId != CAVE_AIR) { // air, void_air, cave_air
|
||||
hasBlock = true;
|
||||
}
|
||||
inverse.put(i, newId);
|
||||
section.setPaletteEntry(i, newId);
|
||||
}
|
||||
if (!hasBlock) {
|
||||
section.setNonAirBlocksCount(0);
|
||||
|
@ -54,8 +54,8 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
||||
if (world.getEnvironment() == Environment.NORMAL) {
|
||||
section.readSkyLight(input);
|
||||
}
|
||||
if (replacePistons && section.getPalette().containsKey(36)) {
|
||||
section.getPalette().put(replacementId, section.getPalette().remove(36));
|
||||
if (replacePistons) {
|
||||
section.replacePaletteEntry(36, replacementId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,8 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
|
||||
ChunkSection section = Types1_8.CHUNK_SECTION.read(input);
|
||||
sections[i] = section;
|
||||
|
||||
if (replacePistons && section.getPalette().containsKey(36)) {
|
||||
section.getPalette().put(replacementId, section.getPalette().remove(36));
|
||||
if (replacePistons) {
|
||||
section.replacePaletteEntry(36, replacementId);
|
||||
}
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren