Skip to content

Commit 1d1d77a

Browse files
authored
Add support for armor stands with no gravity as zombie in 1.8->1.7 (#609)
1 parent ae800f1 commit 1d1d77a

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

common/src/main/java/com/viaversion/viarewind/protocol/v1_8to1_7_6_10/data/VirtualHologramEntity.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class VirtualHologramEntity {
4949
private boolean small = false;
5050
private boolean marker = false;
5151
private boolean sneaking = false;
52+
private boolean gravity = false;
5253
private byte alwaysShowNametag;
5354

5455
public VirtualHologramEntity(final UserConnection user, final int entityId) {
@@ -116,12 +117,15 @@ public void syncState(final EntityPacketRewriter1_8 entityRewriter, final List<E
116117
sneaking = (flags & 0x02) != 0;
117118
small = (armorStandFlags & 0x01) != 0;
118119
marker = (armorStandFlags & 0x10) != 0;
120+
gravity = (armorStandFlags & 0x02) == 0;
119121

120122
State prevState = currentState;
121123
if (invisible && name != null) {
122124
currentState = State.HOLOGRAM;
123-
} else {
125+
} else if (gravity) {
124126
currentState = State.ZOMBIE;
127+
} else {
128+
currentState = State.ZOMBIE_NO_GRAVITY;
125129
}
126130

127131
if (currentState != prevState) {
@@ -146,21 +150,25 @@ private void updateLocation() {
146150
entityHeadLook.write(Types.BYTE, (byte) ((headYaw / 360f) * 256));
147151

148152
entityHeadLook.send(Protocol1_8To1_7_6_10.class);
149-
} else if (currentState == State.HOLOGRAM) {
153+
} else if (currentState == State.HOLOGRAM || currentState == State.ZOMBIE_NO_GRAVITY) {
150154
// Don't ask me where this offset is coming from
151-
teleportEntity(entityIds[0], locX, (locY + getOffset()), locZ, 0, 0); // Skull
155+
teleportEntity(entityIds[1], locX, (locY + getOffset()), locZ, 0, 0); // Squid
152156
}
153157
}
154158

155159
private double getOffset() {
156-
double baseOffset = 54.35;
157-
158-
if (marker) {
159-
return baseOffset;
160-
} else if (small) {
161-
return baseOffset + 0.9875;
160+
if (currentState == State.HOLOGRAM) {
161+
double baseOffset = 54.35;
162+
163+
if (marker) {
164+
return baseOffset;
165+
} else if (small) {
166+
return baseOffset + 0.9875;
167+
} else {
168+
return baseOffset + (0.9875 * 2);
169+
}
162170
} else {
163-
return baseOffset + (0.9875 * 2);
171+
return -0.4;
164172
}
165173
}
166174

@@ -202,7 +210,7 @@ public void sendEntityDataUpdate(final EntityPacketRewriter1_8 entityRewriter) {
202210
}
203211
final PacketWrapper setEntityData = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_ENTITY_DATA, user);
204212

205-
if (currentState == State.ZOMBIE) {
213+
if (currentState == State.ZOMBIE || currentState == State.ZOMBIE_NO_GRAVITY) {
206214
writeZombieMeta(entityRewriter, setEntityData);
207215
} else if (currentState == State.HOLOGRAM) {
208216
writeHologramMeta(setEntityData);
@@ -246,7 +254,7 @@ private void writeZombieMeta(final EntityPacketRewriter1_8 entityRewriter, final
246254
}
247255

248256
private void writeHologramMeta(PacketWrapper wrapper) {
249-
wrapper.write(Types.INT, entityIds[1]);
257+
wrapper.write(Types.INT, entityIds[0]);
250258

251259
// Directly write 1.7 entity data here since we are making them up
252260
final List<EntityData> entityDataList = new ArrayList<>();
@@ -266,25 +274,19 @@ public void sendSpawnPacket(final EntityPacketRewriter1_8 entityRewriter) {
266274
spawnEntity(entityId, EntityTypes1_8.EntityType.ZOMBIE.getId(), locX, locY, locZ, new ArrayList<>());
267275

268276
entityIds = new int[]{entityId};
269-
} else if (currentState == State.HOLOGRAM) {
277+
} else if (currentState == State.ZOMBIE_NO_GRAVITY || currentState == State.HOLOGRAM) {
270278
final int[] entityIds = {entityId, additionalEntityId()};
271279

272-
final PacketWrapper spawnSkull = PacketWrapper.create(ClientboundPackets1_7_2_5.ADD_ENTITY, user);
273-
spawnSkull.write(Types.VAR_INT, entityIds[0]);
274-
spawnSkull.write(Types.BYTE, (byte) 66);
275-
spawnSkull.write(Types.INT, (int) (locX * 32.0));
276-
spawnSkull.write(Types.INT, (int) ((locY + getOffset()) * 32.0));
277-
spawnSkull.write(Types.INT, (int) (locZ * 32.0));
278-
spawnSkull.write(Types.BYTE, (byte) 0);
279-
spawnSkull.write(Types.BYTE, (byte) 0);
280-
spawnSkull.write(Types.INT, 0);
281-
spawnSkull.send(Protocol1_8To1_7_6_10.class);
282-
283280
final List<EntityData> squidEntityData = new ArrayList<>();
284281
squidEntityData.add(new EntityData(0, EntityDataTypes1_8.BYTE, (byte) 32));
285282

286-
spawnEntity(entityIds[0], EntityTypes1_8.EntityType.SQUID.getId(), locX, locY + getOffset(), locZ, squidEntityData);
287-
spawnEntity(entityIds[1], EntityTypes1_8.EntityType.HORSE.getId(), locX, locY + (getOffset() + 0.68), locZ, new ArrayList<>());
283+
if (currentState == State.HOLOGRAM) {
284+
spawnEntity(entityIds[0], EntityTypes1_8.EntityType.HORSE.getId(), locX, locY + (getOffset() + 0.68), locZ, new ArrayList<>());
285+
} else {
286+
spawnEntity(entityIds[0], EntityTypes1_8.EntityType.ZOMBIE.getId(), locX, locY, locZ, new ArrayList<>());
287+
}
288+
289+
spawnEntity(entityIds[1], EntityTypes1_8.EntityType.SQUID.getId(), locX, locY + getOffset(), locZ, squidEntityData);
288290

289291
this.entityIds = entityIds;
290292
}
@@ -298,8 +300,8 @@ public void sendSpawnPacket(final EntityPacketRewriter1_8 entityRewriter) {
298300
updateLocation();
299301
} else {
300302
final PacketWrapper attach = PacketWrapper.create(ClientboundPackets1_7_2_5.SET_ENTITY_LINK, user);
301-
attach.write(Types.INT, entityIds[1]);
302303
attach.write(Types.INT, entityIds[0]);
304+
attach.write(Types.INT, entityIds[1]);
303305
attach.write(Types.BOOLEAN, false);
304306

305307
attach.send(Protocol1_8To1_7_6_10.class);
@@ -334,6 +336,6 @@ public void deleteEntity() {
334336
}
335337

336338
private enum State {
337-
HOLOGRAM, ZOMBIE
339+
HOLOGRAM, ZOMBIE, ZOMBIE_NO_GRAVITY
338340
}
339341
}

0 commit comments

Comments
 (0)