Fixed and cleaned up code

This commit is contained in:
RaphiMC 2025-01-11 23:01:12 +01:00
parent 7c8093d8d6
commit 8cc69447c8
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
5 changed files with 26 additions and 27 deletions

View File

@ -234,7 +234,7 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
final int entityId = wrapper.get(Types.INT, 0);
final byte typeId = wrapper.get(Types.BYTE, 0);
final int data = wrapper.get(Types.INT, 4);
int data = wrapper.get(Types.INT, 4);
final EntityTypes1_8.EntityType type;
if (typeId == 70 || typeId == 71 || typeId == 74) {
type = EntityTypes1_8.ObjectType.FALLING_BLOCK.getType();
@ -248,24 +248,23 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
final double y = wrapper.get(Types.INT, 2) / 32.0D;
final double z = wrapper.get(Types.INT, 3) / 32.0D;
final Location location = new Location(x, y, z);
int throwerEntityId = wrapper.get(Types.INT, 4);
short speedX = 0;
short speedY = 0;
short speedZ = 0;
if (throwerEntityId > 0) {
if (data > 0) {
speedX = wrapper.read(Types.SHORT); // velocity x
speedY = wrapper.read(Types.SHORT); // velocity y
speedZ = wrapper.read(Types.SHORT); // velocity z
}
if (typeId == 70) throwerEntityId = 12; // sand
if (typeId == 71) throwerEntityId = 13; // gravel
if (typeId == 74) throwerEntityId = 122; // dragon egg
if (typeId == 70) data = 12; // sand
if (typeId == 71) data = 13; // gravel
if (typeId == 74) data = 122; // dragon egg
if (typeId == EntityTypes1_8.ObjectType.FISHIHNG_HOOK.getId()) {
final Optional<AbstractTrackedEntity> nearestEntity = entityTracker.getNearestEntity(location, 2.0D, e -> e.getEntityType().isOrHasParent(EntityTypes1_8.EntityType.PLAYER));
throwerEntityId = nearestEntity.map(AbstractTrackedEntity::getEntityId).orElseGet(entityTracker::getPlayerID);
final Optional<AbstractTrackedEntity> nearestEntity = entityTracker.getNearestEntity(location, 2D, e -> e.getEntityType().isOrHasParent(EntityTypes1_8.EntityType.PLAYER));
data = nearestEntity.map(AbstractTrackedEntity::getEntityId).orElseGet(entityTracker::getPlayerID);
}
wrapper.set(Types.INT, 4, throwerEntityId);
if (throwerEntityId > 0) {
wrapper.set(Types.INT, 4, data);
if (data > 0) {
wrapper.write(Types.SHORT, speedX);
wrapper.write(Types.SHORT, speedY);
wrapper.write(Types.SHORT, speedZ);

View File

@ -60,20 +60,20 @@ public class Protocolr1_4_6_7Tor1_5_0_1 extends StatelessProtocol<ClientboundPac
if (typeId == 10 || typeId == 11 || typeId == 12) {
wrapper.set(Types.BYTE, 0, (byte) EntityTypes1_8.ObjectType.MINECART.getId());
}
int throwerEntityId = wrapper.get(Types.INT, 4);
int data = wrapper.get(Types.INT, 4);
short speedX = 0;
short speedY = 0;
short speedZ = 0;
if (throwerEntityId > 0) {
if (data > 0) {
speedX = wrapper.read(Types.SHORT); // velocity x
speedY = wrapper.read(Types.SHORT); // velocity y
speedZ = wrapper.read(Types.SHORT); // velocity z
}
if (typeId == 10) throwerEntityId = 0; // normal minecart
if (typeId == 11) throwerEntityId = 1; // chest minecart
if (typeId == 12) throwerEntityId = 2; // oven minecart
wrapper.set(Types.INT, 4, throwerEntityId);
if (throwerEntityId > 0) {
if (typeId == 10) data = EntityTypes1_8.ObjectType.MINECART.getData();
if (typeId == 11) data = EntityTypes1_8.ObjectType.CHEST_MINECART.getData();
if (typeId == 12) data = EntityTypes1_8.ObjectType.FURNACE_MINECART.getData();
wrapper.set(Types.INT, 4, data);
if (data > 0) {
wrapper.write(Types.SHORT, speedX);
wrapper.write(Types.SHORT, speedY);
wrapper.write(Types.SHORT, speedZ);

View File

@ -133,7 +133,7 @@ public class Protocolr1_5_2Tor1_6_1 extends StatelessProtocol<ClientboundPackets
handler(wrapper -> {
final int entityID = wrapper.get(Types.INT, 0);
final int typeID = wrapper.get(Types.BYTE, 0);
final int data = wrapper.get(Types.INT, 0);
final int data = wrapper.get(Types.INT, 4);
final EntityTypes1_8.EntityType entityType = EntityTypes1_8.ObjectType.getEntityType(typeID, data);
if (entityType != null) {
wrapper.user().get(EntityTracker.class).getTrackedEntities().put(entityID, entityType);

View File

@ -316,7 +316,7 @@ public class Protocolr1_6_4Tor1_7_2_5 extends StatelessTransitionProtocol<Client
handler(wrapper -> {
final int typeID = wrapper.get(Types.BYTE, 0);
int data = wrapper.get(Types.INT, 3);
if (EntityTypes1_8.ObjectType.findById(typeID, data) == EntityTypes1_8.ObjectType.FALLING_BLOCK) {
if (typeID == EntityTypes1_8.ObjectType.FALLING_BLOCK.getId()) {
final int id = data & 0xFFFF;
final int metadata = data >> 16;
final IdAndData block = new IdAndData(id, metadata);

View File

@ -1480,21 +1480,21 @@ public class Protocolr1_7_6_10Tor1_8 extends AbstractProtocol<ClientboundPackets
private int realignEntityY(final EntityTypes1_8.EntityType type, final int y) {
float yPos = y / 32F;
float yOffset = 0F;
if (type == EntityTypes1_8.ObjectType.FALLING_BLOCK.getType())
if (type.isOrHasParent(EntityTypes1_8.ObjectType.FALLING_BLOCK.getType()))
yOffset = 0.98F / 2F;
if (type == EntityTypes1_8.ObjectType.TNT_PRIMED.getType())
if (type.isOrHasParent(EntityTypes1_8.ObjectType.TNT_PRIMED.getType()))
yOffset = 0.98F / 2F;
if (type == EntityTypes1_8.ObjectType.ENDER_CRYSTAL.getType())
if (type.isOrHasParent(EntityTypes1_8.ObjectType.ENDER_CRYSTAL.getType()))
yOffset = 1F;
else if (type == EntityTypes1_8.ObjectType.MINECART.getType())
else if (type.isOrHasParent(EntityTypes1_8.ObjectType.MINECART.getType()))
yOffset = 0.7F / 2F;
else if (type == EntityTypes1_8.ObjectType.BOAT.getType())
else if (type.isOrHasParent(EntityTypes1_8.ObjectType.BOAT.getType()))
yOffset = 0.6F / 2F;
else if (type == EntityTypes1_8.ObjectType.ITEM.getType())
else if (type.isOrHasParent(EntityTypes1_8.ObjectType.ITEM.getType()))
yOffset = 0.24F / 2F; // Should be 0.25F but that causes items to fall through the ground on modern client versions
else if (type == EntityTypes1_8.ObjectType.LEASH.getType())
else if (type.isOrHasParent(EntityTypes1_8.ObjectType.LEASH.getType()))
yOffset = 0.5F;
else if (type == EntityTypes1_8.EntityType.EXPERIENCE_ORB)
else if (type.isOrHasParent(EntityTypes1_8.EntityType.EXPERIENCE_ORB))
yOffset = 0.5F / 2F;
return (int) Math.floor((yPos - yOffset) * 32F);
}