Skip to content

Commit

Permalink
Merge pull request #65 from ViaVersion/update/vv-api-usage
Browse files Browse the repository at this point in the history
Use VVs IdAndData
  • Loading branch information
RaphiMC authored Apr 16, 2024
2 parents f635bab + ffb88e9 commit 34dbb00
Show file tree
Hide file tree
Showing 31 changed files with 136 additions and 203 deletions.
67 changes: 0 additions & 67 deletions src/main/java/net/raphimc/vialegacy/api/model/IdAndData.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
import net.raphimc.vialegacy.api.model.IdAndData;
import com.viaversion.viaversion.util.IdAndData;

public abstract class AbstractBlockRemapper {

Expand All @@ -35,7 +35,7 @@ protected void registerReplacement(final int from, final int to) {
}

protected void registerReplacement(final IdAndData from, final IdAndData to) {
this.REPLACEMENTS.put(from.toCompressedData(), to.toCompressedData());
this.REPLACEMENTS.put(from.toRawData(), to.toRawData());
}

public void remapChunk(final Chunk chunk) {
Expand All @@ -60,10 +60,10 @@ public void remapBlockChangeRecords(final BlockChangeRecord[] blockChangeRecords
}

public void remapBlock(final IdAndData block) {
if (this.REPLACEMENTS.containsKey(block.toCompressedData())) {
final int replacement = this.REPLACEMENTS.get(block.toCompressedData());
block.id = replacement >> 4;
block.data = replacement & 15;
if (this.REPLACEMENTS.containsKey(block.toRawData())) {
final int replacement = this.REPLACEMENTS.get(block.toRawData());
block.setId(replacement >> 4);
block.setData(replacement & 15);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
import com.viaversion.viaversion.util.IdAndData;
import net.raphimc.vialegacy.api.model.ChunkCoord;
import net.raphimc.vialegacy.api.model.IdAndData;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -107,9 +107,9 @@ public void trackAndRemap(final Chunk chunk) {
for (int z = 0; z < 16; z++) {
final int flatBlock = palette.idAt(x, y, z);
if (this.trackAll || this.toTrack.contains(flatBlock >> 4)) {
final IdAndData block = IdAndData.fromCompressedData(flatBlock);
final IdAndData block = IdAndData.fromRawData(flatBlock);
this.remapBlock(block, x + (chunk.getX() << 4), y + (i * 16), z + (chunk.getZ() << 4));
final int newFlatBlock = block.toCompressedData();
final int newFlatBlock = block.toRawData();
if (newFlatBlock != flatBlock) {
palette.setIdAt(x, y, z, newFlatBlock);
}
Expand All @@ -130,34 +130,34 @@ public void trackAndRemap(final Position position, final IdAndData block) {

if (chunk != null && y >= 0 && y >> 4 < chunk.getSections().length) {
ChunkSection section = chunk.getSections()[y >> 4];
if (this.trackAll || this.toTrack.contains(block.id)) {
if (this.trackAll || this.toTrack.contains(block.getId())) {
if (section == null) {
section = chunk.getSections()[y >> 4] = new ChunkSectionImpl(false);
section.palette(PaletteType.BLOCKS).addId(0);
}
section.palette(PaletteType.BLOCKS).setIdAt(x & 15, y & 15, z & 15, block.toCompressedData());
section.palette(PaletteType.BLOCKS).setIdAt(x & 15, y & 15, z & 15, block.toRawData());
} else if (section != null) {
section.palette(PaletteType.BLOCKS).setIdAt(x & 15, y & 15, z & 15, 0);
}
}

if (this.replacements.containsKey(block.toCompressedData())) {
final int newFlatBlock = this.replacements.get(block.toCompressedData());
block.id = newFlatBlock >> 4;
block.data = newFlatBlock & 15;
if (this.replacements.containsKey(block.toRawData())) {
final int newFlatBlock = this.replacements.get(block.toRawData());
block.setId(newFlatBlock >> 4);
block.setData(newFlatBlock & 15);
}
if (this.trackAll || this.toTrack.contains(block.id)) {
if (this.trackAll || this.toTrack.contains(block.getId())) {
this.remapBlock(block, x, y, z);
}
}

public void remapBlockParticle(final IdAndData block) {
if (this.replacements.containsKey(block.toCompressedData())) {
final int newFlatBlock = this.replacements.get(block.toCompressedData());
block.id = newFlatBlock >> 4;
block.data = newFlatBlock & 15;
if (this.replacements.containsKey(block.toRawData())) {
final int newFlatBlock = this.replacements.get(block.toRawData());
block.setId(newFlatBlock >> 4);
block.setData(newFlatBlock & 15);
}
if (this.trackAll || this.toTrack.contains(block.id)) {
if (this.trackAll || this.toTrack.contains(block.getId())) {
this.remapBlock(block, 0, -16, 0);
}
}
Expand Down Expand Up @@ -190,14 +190,14 @@ public IdAndData getBlock(final int x, final int y, final int z) {
if (y < 0 || y >> 4 > chunk.getSections().length - 1) return null;
final ChunkSection section = chunk.getSections()[y >> 4];
if (section != null) {
return IdAndData.fromCompressedData(section.palette(PaletteType.BLOCKS).idAt(x & 15, y & 15, z & 15));
return IdAndData.fromRawData(section.palette(PaletteType.BLOCKS).idAt(x & 15, y & 15, z & 15));
}
}
return null;
}

protected void registerReplacement(final IdAndData from, final IdAndData to) {
this.replacements.put(from.toCompressedData(), to.toCompressedData());
this.replacements.put(from.toRawData(), to.toRawData());
}

protected void remapBlock(final IdAndData block, final int x, final int y, final int z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
import com.viaversion.viaversion.util.IdAndData;
import net.raphimc.vialegacy.ViaLegacy;
import net.raphimc.vialegacy.api.data.BlockList1_6;
import net.raphimc.vialegacy.api.data.ItemList1_6;
import net.raphimc.vialegacy.api.model.IdAndData;
import net.raphimc.vialegacy.api.protocol.StatelessProtocol;
import net.raphimc.vialegacy.api.splitter.PreNettySplitter;
import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.data.AlphaItems;
Expand Down Expand Up @@ -149,15 +149,15 @@ public void register() {
final IdAndData block = wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos);
final String blockName = tag.get("id") != null ? tag.<StringTag>get("id").getValue() : "";

if (block.id == BlockList1_6.signPost.blockID || block.id == BlockList1_6.signWall.blockID || blockName.equals("Sign")) {
if (block.getId() == BlockList1_6.signPost.blockID || block.getId() == BlockList1_6.signWall.blockID || blockName.equals("Sign")) {
final PacketWrapper updateSign = PacketWrapper.create(ClientboundPacketsb1_1.UPDATE_SIGN, wrapper.user());
updateSign.write(Types1_7_6.POSITION_SHORT, pos); // position
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text1").getValue()); // line 1
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text2").getValue()); // line 2
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text3").getValue()); // line 3
updateSign.write(Typesb1_7_0_3.STRING, tag.<StringTag>get("Text4").getValue()); // line 4
updateSign.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);
} else if (block.id == BlockList1_6.mobSpawner.blockID || blockName.equals("MobSpawner")) {
} else if (block.getId() == BlockList1_6.mobSpawner.blockID || blockName.equals("MobSpawner")) {
if (wrapper.user().getProtocolInfo().getPipeline().contains(Protocol1_2_1_3to1_1.class)) {
final PacketWrapper spawnerData = PacketWrapper.create(ClientboundPackets1_2_1.BLOCK_ENTITY_DATA, wrapper.user());
spawnerData.write(Types1_7_6.POSITION_SHORT, pos); // position
Expand All @@ -167,12 +167,12 @@ public void register() {
spawnerData.write(Type.INT, 0); // unused
spawnerData.send(Protocol1_2_1_3to1_1.class);
}
} else if (block.id == BlockList1_6.chest.blockID || blockName.equals("Chest")) {
} else if (block.getId() == BlockList1_6.chest.blockID || blockName.equals("Chest")) {
final Item[] chestItems = new Item[3 * 9];
readItemsFromTag(tag, chestItems);
tracker.containers.put(pos, chestItems);
if (pos.equals(tracker.openContainerPos)) sendWindowItems(wrapper.user(), InventoryStorage.CHEST_WID, chestItems);
} else if (block.id == BlockList1_6.furnaceIdle.blockID || block.id == BlockList1_6.furnaceBurning.blockID || blockName.equals("Furnace")) {
} else if (block.getId() == BlockList1_6.furnaceIdle.blockID || block.getId() == BlockList1_6.furnaceBurning.blockID || blockName.equals("Furnace")) {
final Item[] furnaceItems = new Item[3];
readItemsFromTag(tag, furnaceItems);
tracker.containers.put(pos, furnaceItems);
Expand Down Expand Up @@ -232,12 +232,12 @@ public void register() {
if (direction == 255) return;

final IdAndData block = wrapper.user().get(ChunkTracker.class).getBlockNotNull(pos);
if (block.id != BlockList1_6.furnaceIdle.blockID && block.id != BlockList1_6.furnaceBurning.blockID && block.id != BlockList1_6.chest.blockID && block.id != BlockList1_6.workbench.blockID) {
if (block.getId() != BlockList1_6.furnaceIdle.blockID && block.getId() != BlockList1_6.furnaceBurning.blockID && block.getId() != BlockList1_6.chest.blockID && block.getId() != BlockList1_6.workbench.blockID) {
return;
}

final Item[] containerItems = tracker.containers.get(tracker.openContainerPos = pos);
if (containerItems == null && block.id != BlockList1_6.workbench.blockID) {
if (containerItems == null && block.getId() != BlockList1_6.workbench.blockID) {
tracker.openContainerPos = null;
final PacketWrapper chatMessage = PacketWrapper.create(ClientboundPacketsb1_1.CHAT_MESSAGE, wrapper.user());
chatMessage.write(Typesb1_7_0_3.STRING, "§cMissing Container"); // message
Expand All @@ -246,13 +246,13 @@ public void register() {
}

final PacketWrapper openWindow = PacketWrapper.create(ClientboundPacketsb1_1.OPEN_WINDOW, wrapper.user());
if (block.id == BlockList1_6.chest.blockID) {
if (block.getId() == BlockList1_6.chest.blockID) {
openWindow.write(Type.UNSIGNED_BYTE, (short) InventoryStorage.CHEST_WID); // window id
openWindow.write(Type.UNSIGNED_BYTE, (short) 0); // window type
openWindow.write(Typesb1_7_0_3.STRING, "Chest"); // title
openWindow.write(Type.UNSIGNED_BYTE, (short) (3 * 9)); // slots
if (inventoryTracker != null) inventoryTracker.onWindowOpen(0, 3 * 9);
} else if (block.id == BlockList1_6.workbench.blockID) {
} else if (block.getId() == BlockList1_6.workbench.blockID) {
openWindow.write(Type.UNSIGNED_BYTE, (short) InventoryStorage.WORKBENCH_WID); // window id
openWindow.write(Type.UNSIGNED_BYTE, (short) 1); // window type
openWindow.write(Typesb1_7_0_3.STRING, "Crafting Table"); // title
Expand All @@ -267,8 +267,8 @@ public void register() {
}
openWindow.send(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class);

if (block.id != BlockList1_6.workbench.blockID) {
sendWindowItems(wrapper.user(), block.id == BlockList1_6.chest.blockID ? InventoryStorage.CHEST_WID : InventoryStorage.FURNACE_WID, containerItems);
if (block.getId() != BlockList1_6.workbench.blockID) {
sendWindowItems(wrapper.user(), block.getId() == BlockList1_6.chest.blockID ? InventoryStorage.CHEST_WID : InventoryStorage.FURNACE_WID, containerItems);
}
});
this.registerServerbound(ServerboundPacketsb1_1.HELD_ITEM_CHANGE, wrapper -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.libs.fastutil.ints.*;
import com.viaversion.viaversion.util.IdAndData;
import net.raphimc.vialegacy.api.data.BlockList1_6;
import net.raphimc.vialegacy.api.model.IdAndData;

import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand Down Expand Up @@ -312,47 +312,47 @@ public class AlphaItems {
}
});
PLACE_ACTION.put(290, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
if (d.value().getId() == BlockList1_6.grass.blockID || d.value().getId() == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 32) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(291, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
if (d.value().getId() == BlockList1_6.grass.blockID || d.value().getId() == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 64) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(292, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
if (d.value().getId() == BlockList1_6.grass.blockID || d.value().getId() == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 128) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(293, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
if (d.value().getId() == BlockList1_6.grass.blockID || d.value().getId() == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 256) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(294, (i, d) -> {
if (d.value().id == BlockList1_6.grass.blockID || d.value().id == BlockList1_6.dirt.blockID) {
if (d.value().getId() == BlockList1_6.grass.blockID || d.value().getId() == BlockList1_6.dirt.blockID) {
i.setData((short) (i.data() + 1));
if (i.data() > 64) {
i.setAmount(i.amount() - 1);
}
}
});
PLACE_ACTION.put(295, (i, d) -> {
if (d.keyInt() == 1 && d.value().id == BlockList1_6.tilledField.blockID) {
if (d.keyInt() == 1 && d.value().getId() == BlockList1_6.tilledField.blockID) {
i.setAmount(i.amount() - 1);
}
});
Expand All @@ -363,30 +363,30 @@ public class AlphaItems {
if (d.keyInt() == 1) i.setAmount(i.amount() - 1);
});
PLACE_ACTION.put(328, (i, d) -> {
if (d.value().id == BlockList1_6.rail.blockID) {
if (d.value().getId() == BlockList1_6.rail.blockID) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(330, (i, d) -> {
if (d.keyInt() == 1) i.setAmount(i.amount() - 1);
});
PLACE_ACTION.put(342, (i, d) -> {
if (d.value().id == BlockList1_6.rail.blockID) {
if (d.value().getId() == BlockList1_6.rail.blockID) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(343, (i, d) -> {
if (d.value().id == BlockList1_6.rail.blockID) {
if (d.value().getId() == BlockList1_6.rail.blockID) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(2256, (i, d) -> {
if (d.value().id == BlockList1_6.jukebox.blockID && d.value().data == 0) {
if (d.value().getId() == BlockList1_6.jukebox.blockID && d.value().getData() == 0) {
i.setAmount(i.amount() - 1);
}
});
PLACE_ACTION.put(2257, (i, d) -> {
if (d.value().id == BlockList1_6.jukebox.blockID && d.value().data == 0) {
if (d.value().getId() == BlockList1_6.jukebox.blockID && d.value().getData() == 0) {
i.setAmount(i.amount() - 1);
}
});
Expand Down
Loading

0 comments on commit 34dbb00

Please sign in to comment.