mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 01:05:12 +00:00
Mixin Entity Packet Loss Fixer for Server-Side Logic
This commit is contained in:
1 parent
8203fc7d6b
commit
e57fab9160
8 files changed
+93
-133
No files matched your search
@@ -14,7 +14,6 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||
import kamkeel.npcs.network.packets.data.ChatBubblePacket;
|
||||
import kamkeel.npcs.network.packets.data.QuestCompletionPacket;
|
||||
import kamkeel.npcs.network.packets.data.RequestProperSpawnData;
|
||||
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.UpdateNpcPacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.WeaponNpcPacket;
|
||||
@@ -234,10 +233,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
public FlyingMoveHelper flyMoveHelper = new FlyingMoveHelper(this);
|
||||
public PathNavigate flyNavigator = new PathNavigateFlying(this, worldObj);
|
||||
|
||||
// For Client-Side Use Only
|
||||
public int clientFixAttempts = 0;
|
||||
public long clientFixLastRequestMillis = 0L;
|
||||
|
||||
public EntityNPCInterface(World world) {
|
||||
super(world);
|
||||
try {
|
||||
@@ -1846,7 +1841,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
display.writeToNBT(compound);
|
||||
compound.setDouble("MaxHealth", stats.maxHealth);
|
||||
compound.setFloat("CurrentHealth", getHealth());
|
||||
compound.setTag("Armor", NBTTags.nbtItemStackList(inventory.getArmor()));
|
||||
compound.setTag("Weapons", NBTTags.nbtItemStackList(inventory.getWeapons()));
|
||||
compound.setInteger("Speed", ais.getWalkingSpeed());
|
||||
@@ -1889,19 +1883,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
try {
|
||||
readSpawnData(ByteBufUtils.readNBT(buf));
|
||||
} catch (IOException e) {
|
||||
if (this.worldObj != null && this.worldObj.isRemote) {
|
||||
RequestProperSpawnData.reportMissingData(this);
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void readSpawnData(NBTTagCompound compound) {
|
||||
if (this.worldObj != null && this.worldObj.isRemote) {
|
||||
if(requestClientFix(compound))
|
||||
return;
|
||||
}
|
||||
|
||||
float preservedHealth = getHealth();
|
||||
stats.maxHealth = compound.getDouble("MaxHealth");
|
||||
ais.setWalkingSpeed(compound.getInteger("Speed"));
|
||||
stats.hideKilledBody = compound.getBoolean("DeadBody");
|
||||
@@ -1926,12 +1912,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
ais.bodyOffsetY = compound.getFloat("OffsetY");
|
||||
|
||||
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(stats.maxHealth);
|
||||
if (compound.hasKey("CurrentHealth", Constants.NBT.TAG_FLOAT)) {
|
||||
setHealth(MathHelper.clamp_float(compound.getFloat("CurrentHealth"), 0.0F, getMaxHealth()));
|
||||
} else {
|
||||
// Keep previous client health if packet came from an older sender format.
|
||||
setHealth(MathHelper.clamp_float(preservedHealth, 0.0F, getMaxHealth()));
|
||||
}
|
||||
inventory.setArmor(NBTTags.getItemStackList(compound.getTagList("Armor", 10)));
|
||||
inventory.setWeapons(NBTTags.getItemStackList(compound.getTagList("Weapons", 10)));
|
||||
advanced.setRole(compound.getInteger("Role"));
|
||||
@@ -2000,16 +1980,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
}
|
||||
|
||||
public boolean requestClientFix(NBTTagCompound compound){
|
||||
if((compound.hasNoTags() || !compound.hasKey("MaxHealth", Constants.NBT.TAG_DOUBLE))){
|
||||
RequestProperSpawnData.reportMissingData(this);
|
||||
return true;
|
||||
}
|
||||
clientFixAttempts = 0;
|
||||
clientFixLastRequestMillis = 0L;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canBreatheUnderwater() {
|
||||
return stats.drowningType != 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user