Skip to content

Commit 0618037

Browse files
committed
Rename Position
1 parent d7f550f commit 0618037

File tree

18 files changed

+61
-62
lines changed

18 files changed

+61
-62
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/WorldPacketRewriter1_13_1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
2121
import com.viaversion.viaversion.api.minecraft.BlockFace;
2222
import com.viaversion.viaversion.api.minecraft.ClientWorld;
23-
import com.viaversion.viaversion.api.minecraft.Position;
23+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
2424
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
2525
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
2626
import com.viaversion.viaversion.api.type.Types;
@@ -59,7 +59,7 @@ public void register() {
5959
} else if (id == 2000) { // Smoke
6060
switch (data) { // Down
6161
case 0, 1 -> { // Up
62-
Position pos = wrapper.get(Types.BLOCK_POSITION1_8, 0);
62+
BlockPosition pos = wrapper.get(Types.BLOCK_POSITION1_8, 0);
6363
BlockFace relative = data == 0 ? BlockFace.BOTTOM : BlockFace.TOP;
6464
wrapper.set(Types.BLOCK_POSITION1_8, 0, pos.getRelative(relative)); // Y Offset
6565
wrapper.set(Types.INT, 1, 4); // Self

common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/provider/BackwardsBlockEntityProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.SpawnerHandler;
2727
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage;
2828
import com.viaversion.viaversion.api.connection.UserConnection;
29-
import com.viaversion.viaversion.api.minecraft.Position;
29+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
3030
import com.viaversion.viaversion.api.platform.providers.Provider;
3131
import com.viaversion.nbt.tag.CompoundTag;
3232
import com.viaversion.nbt.tag.StringTag;
@@ -62,7 +62,7 @@ public boolean isHandled(String key) {
6262
* @param position The position of the block entity
6363
* @param tag The block entity tag
6464
*/
65-
public CompoundTag transform(UserConnection user, Position position, CompoundTag tag) {
65+
public CompoundTag transform(UserConnection user, BlockPosition position, CompoundTag tag) {
6666
final StringTag idTag = tag.getStringTag("id");
6767
if (idTag == null) {
6868
return tag;
@@ -90,7 +90,7 @@ public CompoundTag transform(UserConnection user, Position position, CompoundTag
9090
* @param position The position of the block entity
9191
* @param id The block entity id
9292
*/
93-
public CompoundTag transform(UserConnection user, Position position, String id) {
93+
public CompoundTag transform(UserConnection user, BlockPosition position, String id) {
9494
CompoundTag tag = new CompoundTag();
9595
tag.putString("id", id);
9696
tag.putInt("x", Math.toIntExact(position.x()));

common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/BlockItemPacketRewriter1_13.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.viaversion.viaversion.api.connection.UserConnection;
3232
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
3333
import com.viaversion.viaversion.api.minecraft.ClientWorld;
34-
import com.viaversion.viaversion.api.minecraft.Position;
34+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
3535
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
3636
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
3737
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
@@ -142,7 +142,7 @@ else if (blockId >= 483 && blockId <= 498)
142142
if (blockId == 25) { // Note block
143143
final NoteBlockStorage noteBlockStorage = wrapper.user().get(NoteBlockStorage.class);
144144

145-
final Position position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
145+
final BlockPosition position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
146146
final Pair<Integer, Integer> update = noteBlockStorage.getNoteBlockUpdate(position);
147147
if (update != null) { // Use values from block state update
148148
wrapper.set(Types.UNSIGNED_BYTE, 0, update.key().shortValue());
@@ -187,7 +187,7 @@ public void register() {
187187
int chunkMaxZ = chunkMinZ + 15;
188188
BackwardsBlockStorage blockStorage = wrapper.user().get(BackwardsBlockStorage.class);
189189
blockStorage.getBlocks().entrySet().removeIf(entry -> {
190-
Position position = entry.getKey();
190+
BlockPosition position = entry.getKey();
191191
return position.x() >= chunkMinX && position.z() >= chunkMinZ
192192
&& position.x() <= chunkMaxX && position.z() <= chunkMaxZ;
193193
});
@@ -201,7 +201,7 @@ public void register() {
201201

202202
handler(wrapper -> {
203203
int blockState = wrapper.read(Types.VAR_INT);
204-
Position position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
204+
BlockPosition position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
205205

206206
// Note block special treatment
207207
if (blockState >= 249 && blockState <= 748) { // Note block states id range
@@ -234,7 +234,7 @@ public void register() {
234234
int chunkX = wrapper.get(Types.INT, 0);
235235
int chunkZ = wrapper.get(Types.INT, 1);
236236
int block = record.getBlockId();
237-
Position position = new Position(
237+
BlockPosition position = new BlockPosition(
238238
record.getSectionX() + (chunkX * 16),
239239
record.getY(),
240240
record.getSectionZ() + (chunkZ * 16));
@@ -306,9 +306,9 @@ public void register() {
306306
ChunkSection section = chunk.getSections()[sectionIndex];
307307

308308
int x = tag.getNumberTag("x").asInt();
309-
int y = tag.getNumberTag("y").asInt();
309+
short y = tag.getNumberTag("y").asShort();
310310
int z = tag.getNumberTag("z").asInt();
311-
Position position = new Position(x, (short) y, z);
311+
BlockPosition position = new BlockPosition(x, y, z);
312312

313313
int block = section.palette(PaletteType.BLOCKS).idAt(x & 0xF, y & 0xF, z & 0xF);
314314
storage.checkAndStore(position, block);
@@ -332,7 +332,7 @@ public void register() {
332332

333333
// Check if the block is a flower
334334
if (FlowerPotHandler.isFlowah(block)) {
335-
Position pos = new Position(
335+
BlockPosition pos = new BlockPosition(
336336
(x + (chunk.getX() << 4)),
337337
(short) (y + (i << 4)),
338338
(z + (chunk.getZ() << 4))
@@ -964,7 +964,7 @@ private void invertShieldAndBannerId(Item item, CompoundTag tag) {
964964
}
965965

966966
// TODO find a less hacky way to do this (https://bugs.mojang.com/browse/MC-74231)
967-
private static void flowerPotSpecialTreatment(UserConnection user, int blockState, Position position) {
967+
private static void flowerPotSpecialTreatment(UserConnection user, int blockState, BlockPosition position) {
968968
if (FlowerPotHandler.isFlowah(blockState)) {
969969
BackwardsBlockEntityProvider beProvider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
970970

common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/PlayerPacketRewriter1_13.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.TabCompleteStorage;
2525
import com.viaversion.viabackwards.utils.ChatUtil;
2626
import com.viaversion.viaversion.api.Via;
27-
import com.viaversion.viaversion.api.minecraft.Position;
27+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
2828
import com.viaversion.viaversion.api.minecraft.item.Item;
2929
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
3030
import com.viaversion.viaversion.api.protocol.packet.State;
@@ -411,7 +411,7 @@ public void register() {
411411
int y = wrapper.read(Types.INT);
412412
int z = wrapper.read(Types.INT);
413413

414-
wrapper.write(Types.BLOCK_POSITION1_8, new Position(x, (short) y, z));
414+
wrapper.write(Types.BLOCK_POSITION1_8, new BlockPosition(x, (short) y, z));
415415

416416
wrapper.passthrough(Types.STRING); //Command
417417

@@ -433,7 +433,7 @@ public void register() {
433433
int x = wrapper.read(Types.INT);
434434
int y = wrapper.read(Types.INT);
435435
int z = wrapper.read(Types.INT);
436-
wrapper.write(Types.BLOCK_POSITION1_8, new Position(x, (short) y, z));
436+
wrapper.write(Types.BLOCK_POSITION1_8, new BlockPosition(x, (short) y, z));
437437
wrapper.write(Types.VAR_INT, wrapper.read(Types.BYTE) - 1);
438438
String mode = wrapper.read(Types.STRING);
439439
int modeId = mode.equals("SAVE") ? 0 : mode.equals("LOAD") ? 1 : mode.equals("CORNER") ? 2 : 3;

common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/storage/BackwardsBlockStorage.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage;
2020

2121
import com.viaversion.viaversion.api.connection.StorableObject;
22-
import com.viaversion.viaversion.api.minecraft.Position;
22+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
2323
import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
2424
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
2525
import java.util.Map;
@@ -66,9 +66,9 @@ public class BackwardsBlockStorage implements StorableObject {
6666
}
6767
}
6868

69-
private final Map<Position, Integer> blocks = new ConcurrentHashMap<>();
69+
private final Map<BlockPosition, Integer> blocks = new ConcurrentHashMap<>();
7070

71-
public void checkAndStore(Position position, int block) {
71+
public void checkAndStore(BlockPosition position, int block) {
7272
if (!WHITELIST.contains(block)) {
7373
// Remove if not whitelisted
7474
blocks.remove(position);
@@ -78,19 +78,19 @@ public void checkAndStore(Position position, int block) {
7878
blocks.put(position, block);
7979
}
8080

81-
public @Nullable Integer get(Position position) {
81+
public @Nullable Integer get(BlockPosition position) {
8282
return blocks.get(position);
8383
}
8484

85-
public int remove(Position position) {
85+
public int remove(BlockPosition position) {
8686
return blocks.remove(position);
8787
}
8888

8989
public void clear() {
9090
blocks.clear();
9191
}
9292

93-
public Map<Position, Integer> getBlocks() {
93+
public Map<BlockPosition, Integer> getBlocks() {
9494
return blocks;
9595
}
9696
}

common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/storage/NoteBlockStorage.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage;
1919

2020
import com.viaversion.viaversion.api.connection.StorableObject;
21-
import com.viaversion.viaversion.api.minecraft.Position;
21+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
2222
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
2323
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
2424
import com.viaversion.viaversion.util.Pair;
@@ -27,13 +27,13 @@ public class NoteBlockStorage implements StorableObject {
2727

2828
private static final int MAX_NOTE_ID = 24;
2929

30-
private final Object2IntMap<Position> noteBlockUpdates = new Object2IntOpenHashMap<>();
30+
private final Object2IntMap<BlockPosition> noteBlockUpdates = new Object2IntOpenHashMap<>();
3131

32-
public void storeNoteBlockUpdate(final Position position, final int blockStateId) {
32+
public void storeNoteBlockUpdate(final BlockPosition position, final int blockStateId) {
3333
noteBlockUpdates.put(position, blockStateId);
3434
}
3535

36-
public Pair<Integer, Integer> getNoteBlockUpdate(final Position position) {
36+
public Pair<Integer, Integer> getNoteBlockUpdate(final BlockPosition position) {
3737
if (!noteBlockUpdates.containsKey(position)) {
3838
return null;
3939
}

common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.viaversion.viaversion.api.data.entity.EntityTracker;
2828
import com.viaversion.viaversion.api.minecraft.ClientWorld;
2929
import com.viaversion.viaversion.api.minecraft.Particle;
30-
import com.viaversion.viaversion.api.minecraft.Position;
30+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
3131
import com.viaversion.viaversion.api.minecraft.VillagerData;
3232
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
3333
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
@@ -57,7 +57,7 @@ protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType
5757

5858
// Cache the position for every newly tracked entity
5959
if (type == EntityTypes1_14.PAINTING) {
60-
final Position position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
60+
final BlockPosition position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
6161
positionHandler.cacheEntityPosition(wrapper, position.x(), position.y(), position.z(), true, false);
6262
} else if (wrapper.getId() != ClientboundPackets1_14.LOGIN.getId()) { // ignore join game
6363
positionHandler.cacheEntityPosition(wrapper, true, false);
@@ -411,7 +411,7 @@ protected void registerRewrites() {
411411
filter().type(EntityTypes1_14.LIVING_ENTITY).handler((event, meta) -> {
412412
int index = event.index();
413413
if (index == 12) {
414-
Position position = (Position) meta.getValue();
414+
BlockPosition position = (BlockPosition) meta.getValue();
415415
if (position != null) {
416416
// Use bed
417417
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.PLAYER_SLEEP, null, event.user());

common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/PlayerPacketRewriter1_14.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import com.viaversion.viabackwards.protocol.v1_14to1_13_2.Protocol1_14To1_13_2;
2121
import com.viaversion.viabackwards.protocol.v1_14to1_13_2.storage.DifficultyStorage;
22-
import com.viaversion.viaversion.api.minecraft.Position;
22+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
2323
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
2424
import com.viaversion.viaversion.api.rewriter.RewriterBase;
2525
import com.viaversion.viaversion.api.type.Types;
@@ -111,7 +111,7 @@ public void register() {
111111
});
112112

113113
protocol.registerServerbound(ServerboundPackets1_13.USE_ITEM_ON, wrapper -> {
114-
Position position = wrapper.read(Types.BLOCK_POSITION1_8);
114+
BlockPosition position = wrapper.read(Types.BLOCK_POSITION1_8);
115115
int face = wrapper.read(Types.VAR_INT);
116116
int hand = wrapper.read(Types.VAR_INT);
117117
float x = wrapper.read(Types.FLOAT);

common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/BlockItemPacketRewriter1_18.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.viaversion.viabackwards.protocol.v1_18to1_17_1.data.BlockEntityMappings1_17_1;
2323
import com.viaversion.viaversion.api.data.ParticleMappings;
2424
import com.viaversion.viaversion.api.data.entity.EntityTracker;
25-
import com.viaversion.viaversion.api.minecraft.Position;
25+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
2626
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
2727
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
2828
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
@@ -147,7 +147,7 @@ public void register() {
147147
// If those were the only fields on the block entity (e.g.: skull, bed), we'll receive a null NBT
148148
// We initialize one and add the missing fields, so it can be handled correctly down the line
149149
final CompoundTag newTag = tag == null ? new CompoundTag() : tag;
150-
final Position pos = wrapper.get(Types.BLOCK_POSITION1_14, 0);
150+
final BlockPosition pos = wrapper.get(Types.BLOCK_POSITION1_14, 0);
151151

152152
// The protocol converters downstream rely on this field, let's add it back
153153
newTag.putString("id", Key.namespaced(identifier));

common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/EntityPacketRewriter1_19.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.viaversion.viaversion.api.data.ParticleMappings;
2525
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
2626
import com.viaversion.viaversion.api.minecraft.Particle;
27-
import com.viaversion.viaversion.api.minecraft.Position;
27+
import com.viaversion.viaversion.api.minecraft.BlockPosition;
2828
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
2929
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
3030
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
@@ -87,7 +87,7 @@ public void register() {
8787
// The entity has been tracked, now we wait for the metadata packet
8888
final int entityId = wrapper.get(Types.VAR_INT, 0);
8989
final StoredEntityData entityData = tracker(wrapper.user()).entityData(entityId);
90-
final Position position = new Position(wrapper.get(Types.DOUBLE, 0).intValue(), wrapper.get(Types.DOUBLE, 1).intValue(), wrapper.get(Types.DOUBLE, 2).intValue());
90+
final BlockPosition position = new BlockPosition(wrapper.get(Types.DOUBLE, 0).intValue(), wrapper.get(Types.DOUBLE, 1).intValue(), wrapper.get(Types.DOUBLE, 2).intValue());
9191
entityData.put(new StoredPainting(entityId, wrapper.get(Types.UUID, 0), position, data));
9292
return;
9393
}

0 commit comments

Comments
 (0)