Skip to content

Commit

Permalink
little code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
unldenis committed Jan 14, 2024
1 parent d391dd2 commit bcf0a38
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.unldenis.corpse</groupId>
<artifactId>Corpse</artifactId>
<version>1.0.9-SNAPSHOT</version>
<version>1.0.10</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/github/unldenis/corpse/logic/Corpse.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ public Corpse(
public void show(@NotNull Player player) {
this.seeingPlayers.add(player);

// hide name tag if option disabled
if (!this.pool.isShowTags()) {
hideNameTag(player);
}

// spawn and set sleep
sendPackets(player,
this.packetLoader.getWrapperPlayerInfoAdd().get(),
this.packetLoader.getWrapperNamedEntitySpawn().get(),
this.packetLoader.getWrapperEntityMetadata().get()); // Set sleep

// if version below 1.12
if (VersionUtil.isBelow(VersionUtil.VersionEnum.V1_12)) {
player.sendBlockChange(BedUtil.getBedLocation(location), Material.valueOf("BED_BLOCK"),
(byte) BedUtil.yawToFacing(location.getYaw()));
Expand All @@ -123,6 +127,7 @@ public void show(@NotNull Player player) {
.get()); // Set the correct height of the player lying down
}

// show armor
if (armor) {
sendPackets(player, this.packetLoader.getWrapperEntityEquipment().getMore());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

public class WrapperEntityMetadata implements IPacket {

private static final byte FLAGS =
(byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80);

private final int id;
private PacketContainer packet;

Expand All @@ -40,16 +43,13 @@ public WrapperEntityMetadata(int entityID) {
public void load() {
packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, this.id);

WrappedDataWatcher watcher = new WrappedDataWatcher();
if (VersionUtil.isAbove(VersionUtil.VersionEnum.V1_13)) {
WrappedDataWatcher.WrappedDataWatcherObject visible = new WrappedDataWatcher.WrappedDataWatcherObject(
6, WrappedDataWatcher.Registry.get(EnumWrappers.getEntityPoseClass()));
watcher.setObject(visible, EnumWrappers.EntityPose.SLEEPING.toNms());
/*
//Works and set location a little higher
WrappedDataWatcher.WrappedDataWatcherObject bed = new WrappedDataWatcher.WrappedDataWatcherObject(14, WrappedDataWatcher.Registry.getBlockPositionSerializer(true));
watcher.setObject(bed, Optional.of(BlockPosition.getConverter().getGeneric(new BlockPosition(corpse.location.toVector()))));
*/
WrappedDataWatcher.WrappedDataWatcherObject visible = new WrappedDataWatcher.WrappedDataWatcherObject(
6, WrappedDataWatcher.Registry.get(EnumWrappers.getEntityPoseClass()));
watcher.setObject(visible, EnumWrappers.EntityPose.SLEEPING.toNms());

int indexSkinLayer = VersionUtil.isAbove(VersionUtil.VersionEnum.V1_17) ? 17 : 16;
WrappedDataWatcher.WrappedDataWatcherObject skinLayers = new WrappedDataWatcher.WrappedDataWatcherObject(
indexSkinLayer, WrappedDataWatcher.Registry.get(Byte.class));
Expand All @@ -59,20 +59,16 @@ public void load() {
final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject();
wrappedDataValueList.add(new WrappedDataValue(dataWatcherObject.getIndex(), dataWatcherObject.getSerializer(), entry.getRawValue()));
});
wrappedDataValueList.add(new WrappedDataValue(skinLayers.getIndex(), skinLayers.getSerializer(),
(byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80)));
wrappedDataValueList.add(new WrappedDataValue(skinLayers.getIndex(), skinLayers.getSerializer(), FLAGS));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
} else {
watcher.setObject(skinLayers, (byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80));
watcher.setObject(skinLayers, FLAGS);
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
}



} else {
watcher.setObject(10, (byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80));
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
}
} else {
watcher.setObject(10, FLAGS);
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
}

}

Expand Down

0 comments on commit bcf0a38

Please sign in to comment.