Skip to content

Commit

Permalink
Added abstraction types for position rewriting in 1.7 -> 1.8, cleanup…
Browse files Browse the repository at this point in the history
… of SpawnPackets, added groups for Via types.
  • Loading branch information
FlorianMichael committed Oct 10, 2023
1 parent dc2babd commit 14a314d
Show file tree
Hide file tree
Showing 21 changed files with 249 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.viaversion.viarewind.protocol.protocol1_7_2_5to1_7_6_10.ClientboundPackets1_7_2_5;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.Protocol1_7_6_10To1_8;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.model.EntityModel1_7_6_10;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.types.MetaType1_7_6_10;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.types.metadata.MetaType1_7_6_10;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10;
import com.viaversion.viarewind.utils.PacketUtil;
import com.viaversion.viarewind.utils.math.AABB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void sendSpawnPacket() {
@Override
public void deleteEntity() {
PacketWrapper despawn = PacketWrapper.create(ClientboundPackets1_7_2_5.DESTROY_ENTITIES, null, user);
despawn.write(Types1_7_6_10.INT_ARRAY, new int[]{entityId});
despawn.write(Types1_7_6_10.BYTE_INT_ARRAY, new int[]{entityId});

PacketUtil.sendPacket(despawn, Protocol1_7_6_10To1_8.class, true, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void sendSpawnPacket() {
@Override
public void deleteEntity() {
PacketWrapper despawn = PacketWrapper.create(ClientboundPackets1_7_2_5.DESTROY_ENTITIES, null, user);
despawn.write(Types1_7_6_10.INT_ARRAY, new int[]{entityId});
despawn.write(Types1_7_6_10.BYTE_INT_ARRAY, new int[]{entityId});

PacketUtil.sendPacket(despawn, Protocol1_7_6_10To1_8.class, true, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void sendSpawnPacket() {
@Override
public void deleteEntity() {
PacketWrapper despawn = PacketWrapper.create(ClientboundPackets1_7_2_5.DESTROY_ENTITIES, null, user);
despawn.write(Types1_7_6_10.INT_ARRAY, new int[]{entityId});
despawn.write(Types1_7_6_10.BYTE_INT_ARRAY, new int[]{entityId});

PacketUtil.sendPacket(despawn, Protocol1_7_6_10To1_8.class, true, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.model;

import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.types.MetaType1_7_6_10;
import com.viaversion.viarewind.protocol.protocol1_7_6_10to1_8.types.metadata.MetaType1_7_6_10;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
import com.viaversion.viaversion.util.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ public void register() {
@Override
public void register() {
map(Type.VAR_INT, Type.INT); // entity id
handler(wrapper -> {
final Position position = wrapper.read(Type.POSITION);

wrapper.write(Type.INT, position.x());
wrapper.write(Type.UNSIGNED_BYTE, (short) position.y());
wrapper.write(Type.INT, position.z());
});
map(Type.POSITION, Types1_7_6_10.U_BYTE_POSITION); // position
}
});

Expand Down Expand Up @@ -109,12 +103,12 @@ public void register() {
protocol.registerClientbound(ClientboundPackets1_8.DESTROY_ENTITIES, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT_ARRAY_PRIMITIVE, Types1_7_6_10.INT_ARRAY); // entity ids
map(Type.VAR_INT_ARRAY_PRIMITIVE, Types1_7_6_10.BYTE_INT_ARRAY); // entity ids

handler(wrapper -> {
final EntityTracker tracker = wrapper.user().get(EntityTracker.class);

for (int entityId : wrapper.get(Types1_7_6_10.INT_ARRAY, 0)) {
for (int entityId : wrapper.get(Types1_7_6_10.BYTE_INT_ARRAY, 0)) {
tracker.removeEntity(entityId);
}
});
Expand Down
Loading

0 comments on commit 14a314d

Please sign in to comment.