seperate shaking into a seperate function in the metadata factory to avoid creating unnessecary lists

This commit is contained in:
Pyrbu 2023-06-22 23:29:08 +02:00
parent 8093e709dd
commit 81204688e5
7 changed files with 23 additions and 19 deletions

@ -21,9 +21,10 @@ import java.util.Collection;
*/
public interface MetadataFactory {
EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat);
Collection<EntityData> effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean shaking);
EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra);
EntityData silent(boolean enabled);
Collection<EntityData> name(Component name);
EntityData noGravity();
EntityData pose(EntityPose pose);
EntityData shaking();
}

@ -3,8 +3,6 @@ package lol.pyr.znpcsplus.metadata;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import java.util.Collection;
public class V1_17MetadataFactory extends V1_16MetadataFactory {
@Override
public EntityData skinLayers(boolean cape, boolean jacket, boolean leftSleeve, boolean rightSleeve, boolean leftLeg, boolean rightLeg, boolean hat) {
@ -12,10 +10,12 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory {
}
@Override
public Collection<EntityData> effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean shaking) {
return list(
newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0) | (usingElytra ? 0x80 : 0))),
newEntityData(7, EntityDataTypes.INT, shaking ? 140 : 0)
);
public EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra) {
return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0) | (usingElytra ? 0x80 : 0)));
}
@Override
public EntityData shaking() {
return newEntityData(7, EntityDataTypes.INT, 140);
}
}

@ -18,8 +18,8 @@ public class V1_8MetadataFactory implements MetadataFactory {
}
@Override
public Collection<EntityData> effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean shaking) {
return list(newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0))));
public EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra) {
return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0)));
}
@Override
@ -40,6 +40,11 @@ public class V1_8MetadataFactory implements MetadataFactory {
throw new UnsupportedOperationException("The pose entity data isn't supported on this version");
}
@Override
public EntityData shaking() {
throw new UnsupportedOperationException("The shaking entity data isn't supported on this version");
}
@Override
public EntityData silent(boolean enabled) {
return newEntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0));

@ -14,8 +14,8 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory {
}
@Override
public Collection<EntityData> effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra, boolean shaking) {
return list(newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0) | (usingElytra ? 0x80 : 0))));
public EntityData effects(boolean onFire, boolean glowing, boolean invisible, boolean usingElytra) {
return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0) | (usingElytra ? 0x80 : 0)));
}
@Override

@ -20,11 +20,11 @@ public class V1_17PacketFactory extends V1_16PacketFactory {
@Override
public Map<Integer, EntityData> generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) {
Map<Integer, EntityData> data = super.generateMetadata(player, entity, properties);
addAll(data, metadataFactory.effects(properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)),
add(data, metadataFactory.effects(properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)),
properties.hasProperty(propertyRegistry.getByName("glow", Boolean.class)),
properties.getProperty(propertyRegistry.getByName("invisible", Boolean.class)),
false,
properties.getProperty(propertyRegistry.getByName("shaking", Boolean.class))));
false));
if (properties.getProperty(propertyRegistry.getByName("shaking", Boolean.class))) add(data, metadataFactory.shaking());
return data;
}
}

@ -135,11 +135,10 @@ public class V1_8PacketFactory implements PacketFactory {
properties.getProperty(propertyRegistry.getByName("skin_right_leg", Boolean.class)),
properties.getProperty(propertyRegistry.getByName("skin_hat", Boolean.class))
));
addAll(data, metadataFactory.effects(
add(data, metadataFactory.effects(
properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)),
false,
properties.getProperty(propertyRegistry.getByName("invisible", Boolean.class)),
false,
false)
);
add(data, metadataFactory.silent(properties.getProperty(propertyRegistry.getByName("silent", Boolean.class))));

@ -20,10 +20,9 @@ public class V1_9PacketFactory extends V1_8PacketFactory {
@Override
public Map<Integer, EntityData> generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) {
Map<Integer, EntityData> data = super.generateMetadata(player, entity, properties);
addAll(data, metadataFactory.effects(properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)),
add(data, metadataFactory.effects(properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)),
properties.hasProperty(propertyRegistry.getByName("glow", Boolean.class)),
properties.getProperty(propertyRegistry.getByName("invisible", Boolean.class)),
false,
false));
return data;
}