Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Use methods for palette rewriting, fix "value already present"
Dieser Commit ist enthalten in:
Ursprung
9a87adf51b
Commit
3b14dd3b04
@ -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) {
|
||||
|
@ -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