fix: no longer spam packets

This commit is contained in:
LordMZTE 2023-03-13 19:53:04 +01:00
parent 481846b73e
commit 1a3c60f456
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -9,16 +9,25 @@ import com.gildedgames.the_aether.api.player.IPlayerAether;
import com.gildedgames.the_aether.api.player.util.IAccessoryInventory;
import com.gildedgames.the_aether.api.player.util.IAetherAbility;
import com.gildedgames.the_aether.api.player.util.IAetherBoss;
import com.gildedgames.the_aether.blocks.BlocksAether;
import com.gildedgames.the_aether.entities.passive.mountable.EntityParachute;
import com.gildedgames.the_aether.inventory.InventoryAccessories;
import com.gildedgames.the_aether.network.packets.*;
import com.gildedgames.the_aether.registry.achievements.AchievementsAether;
import com.gildedgames.the_aether.items.ItemsAether;
import com.gildedgames.the_aether.items.tools.ItemValkyrieTool;
import com.gildedgames.the_aether.network.AetherNetwork;
import com.gildedgames.the_aether.network.packets.*;
import com.gildedgames.the_aether.player.abilities.AbilityAccessories;
import com.gildedgames.the_aether.player.abilities.AbilityArmor;
import com.gildedgames.the_aether.player.abilities.AbilityFlight;
import com.gildedgames.the_aether.player.abilities.AbilityRepulsion;
import com.gildedgames.the_aether.player.perks.AetherRankings;
import com.gildedgames.the_aether.player.perks.util.DonatorMoaSkin;
import com.gildedgames.the_aether.player.perks.util.EnumAetherPerkType;
import com.gildedgames.the_aether.registry.achievements.AchievementsAether;
import com.gildedgames.the_aether.world.TeleporterAether;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
@ -33,20 +42,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.*;
import net.minecraft.world.World;
import com.gildedgames.the_aether.blocks.BlocksAether;
import com.gildedgames.the_aether.items.tools.ItemValkyrieTool;
import com.gildedgames.the_aether.player.abilities.AbilityAccessories;
import com.gildedgames.the_aether.player.abilities.AbilityArmor;
import com.gildedgames.the_aether.player.abilities.AbilityFlight;
import com.gildedgames.the_aether.player.abilities.AbilityRepulsion;
import com.gildedgames.the_aether.player.perks.util.DonatorMoaSkin;
import com.gildedgames.the_aether.world.TeleporterAether;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.ReflectionHelper;
public class PlayerAether implements IPlayerAether {
private EntityPlayer player;
private IAetherBoss focusedBoss;
@ -62,8 +58,10 @@ public class PlayerAether implements IPlayerAether {
public DonatorMoaSkin donatorMoaSkin = new DonatorMoaSkin();
public boolean shouldRenderHalo, shouldRenderGlow, shouldRenderCape;
public boolean shouldRenderHaloPrev, shouldRenderGlowPrev, shouldRenderCapePrev;
public boolean seenSpiritDialog = false;
public boolean seenSpiritDialogPrev = true;
private boolean isJumping;
@ -94,8 +92,10 @@ public class PlayerAether implements IPlayerAether {
public boolean isPoisoned = false, isCured = false;
public boolean shouldGetPortal;
public boolean shouldGetPortalPrev;
public int poisonTime = 0, cureTime = 0;
public int poisonTimePrev = -1;
private UUID uuid = UUID.fromString("df6eabe7-6947-4a56-9099-002f90370706");
@ -103,10 +103,23 @@ public class PlayerAether implements IPlayerAether {
public PlayerAether() {
this.shouldRenderHalo = true;
this.shouldRenderHaloPrev = !this.shouldRenderHalo;
this.shouldRenderGlow = false;
this.shouldRenderGlowPrev = !this.shouldRenderGlow;
this.shouldRenderCape = true;
this.shouldRenderCapePrev = !this.shouldRenderCape;
this.shouldGetPortal = true;
this.abilities.addAll(Arrays.<IAetherAbility>asList(new AbilityAccessories(this), new AbilityArmor(this), new AbilityFlight(this), new AbilityRepulsion(this)));
this.shouldGetPortalPrev = !this.shouldGetPortal;
this.abilities.addAll(Arrays.<IAetherAbility>asList(
new AbilityAccessories(this),
new AbilityArmor(this),
new AbilityFlight(this),
new AbilityRepulsion(this)
));
}
public static PlayerAether get(EntityPlayer player) {
@ -120,37 +133,23 @@ public class PlayerAether implements IPlayerAether {
@Override
public void onUpdate() {
if (!this.player.worldObj.isRemote)
{
AetherNetwork.sendToAll(new PacketPerkChanged(this.getEntity().getEntityId(), EnumAetherPerkType.Halo, this.shouldRenderHalo));
AetherNetwork.sendToAll(new PacketPerkChanged(this.getEntity().getEntityId(), EnumAetherPerkType.Glow, this.shouldRenderGlow));
AetherNetwork.sendToAll(new PacketCapeChanged(this.getEntity().getEntityId(), this.shouldRenderCape));
AetherNetwork.sendToAll(new PacketSendPoisonTime(this.getEntity(), this.poisonTime));
AetherNetwork.sendToAll(new PacketSendSeenDialogue(this.getEntity(), this.seenSpiritDialog));
AetherNetwork.sendToAll(new PacketPortalItem(this.getEntity(), this.shouldGetPortal));
if (!this.player.worldObj.isRemote) {
sendPackets();
}
if (this.isPoisoned)
{
if (poisonTime > 0)
{
if (this.isPoisoned) {
if (poisonTime > 0) {
this.poisonTime--;
}
else
{
} else {
this.poisonTime = 0;
this.isPoisoned = false;
}
}
if (this.isCured)
{
if (cureTime > 0)
{
if (this.isCured) {
if (cureTime > 0) {
this.cureTime--;
}
else
{
} else {
this.cureTime = 0;
this.isCured = false;
}
@ -180,8 +179,7 @@ public class PlayerAether implements IPlayerAether {
this.getEntity().fallDistance = 0.0F;
}
if (this.getEntity().motionY < -2F)
{
if (this.getEntity().motionY < -2F) {
this.activateParachute();
}
@ -197,7 +195,9 @@ public class PlayerAether implements IPlayerAether {
this.wingSinage += 0.1F;
}
boolean hasJumped = ReflectionHelper.getPrivateValue(EntityLivingBase.class, this.getEntity(), "isJumping", "field_70703_bu");
boolean hasJumped = ReflectionHelper.getPrivateValue(
EntityLivingBase.class, this.getEntity(), "isJumping", "field_70703_bu"
);
this.setJumping(hasJumped);
@ -207,8 +207,7 @@ public class PlayerAether implements IPlayerAether {
if (this.getEntity().posY < -2) {
this.teleportPlayer(false);
if (this.riddenEntity != null)
{
if (this.riddenEntity != null) {
this.getEntity().mountEntity(this.riddenEntity);
this.riddenEntity = null;
}
@ -220,34 +219,43 @@ public class PlayerAether implements IPlayerAether {
int limit = this.getEntity().getMaxInPortalTime();
if (this.getEntity().ridingEntity == null) {
if (this.portalCounter >= limit)
{
if (this.portalCounter >= limit) {
this.portalCounter = 0;
this.getEntity().timeUntilPortal = this.getEntity().getPortalCooldown();
this.getEntity().timeUntilPortal
= this.getEntity().getPortalCooldown();
if (!this.getEntity().worldObj.isRemote) {
this.teleportPlayer(true);
this.getEntity().triggerAchievement(AchievementsAether.enter_aether);
this.getEntity().triggerAchievement(
AchievementsAether.enter_aether
);
}
}
else
{
} else {
this.portalCounter++;
}
}
}
else
{
} else {
this.getEntity().timeUntilPortal = this.getEntity().getPortalCooldown();
}
if (this.getEntity().worldObj.getBlock((int) this.getEntity().posX, (int) this.getEntity().posY - 1, (int) this.getEntity().posZ) != Blocks.air)
{
if (this.getEntity().worldObj.getBlock(
(int) this.getEntity().posX,
(int) this.getEntity().posY - 1,
(int) this.getEntity().posZ
)
!= Blocks.air) {
AxisAlignedBB playerBounding = this.getEntity().boundingBox;
if (this.getEntity().worldObj.getBlock((int) playerBounding.minX, (int) playerBounding.minY, (int) playerBounding.minZ) != BlocksAether.aether_portal
&& this.getEntity().worldObj.getBlock((int) playerBounding.minX, (int) playerBounding.minY, (int) playerBounding.minZ) != BlocksAether.aether_portal)
{
if (this.getEntity().worldObj.getBlock(
(int) playerBounding.minX,
(int) playerBounding.minY,
(int) playerBounding.minZ
) != BlocksAether.aether_portal
&& this.getEntity().worldObj.getBlock(
(int) playerBounding.minX,
(int) playerBounding.minY,
(int) playerBounding.minZ
) != BlocksAether.aether_portal) {
this.inPortal = false;
}
}
@ -272,17 +280,15 @@ public class PlayerAether implements IPlayerAether {
distance = 8.0D;
}
((EntityPlayerMP) this.getEntity()).theItemInWorldManager.setBlockReachDistance(distance);
}
else {
((EntityPlayerMP) this.getEntity())
.theItemInWorldManager.setBlockReachDistance(distance);
} else {
this.prevTimeInPortal = this.timeInPortal;
if (this.isInsideBlock(BlocksAether.aether_portal))
{
if (this.isInsideBlock(BlocksAether.aether_portal)) {
this.timeInPortal += 0.0125F;
if (this.timeInPortal >= 1.0F)
{
if (this.timeInPortal >= 1.0F) {
this.timeInPortal = 1.0F;
}
}
@ -290,33 +296,29 @@ public class PlayerAether implements IPlayerAether {
{
this.timeInPortal += 0.006666667F;
if (this.timeInPortal > 1.0F)
{
if (this.timeInPortal > 1.0F) {
this.timeInPortal = 1.0F;
}
}
else
{
if (this.timeInPortal > 0.0F)
{
} else {
if (this.timeInPortal > 0.0F) {
this.timeInPortal -= 0.05F;
}
if (this.timeInPortal < 0.0F)
{
if (this.timeInPortal < 0.0F) {
this.timeInPortal = 0.0F;
}
}
}
if (!player.worldObj.isRemote)
{
if (this.bedLocation != null)
{
if (player.dimension == AetherConfig.getAetherDimensionID())
{
if (player.worldObj.getBlock(this.bedLocation.posX, this.bedLocation.posY, this.bedLocation.posZ) != BlocksAether.skyroot_bed)
{
if (!player.worldObj.isRemote) {
if (this.bedLocation != null) {
if (player.dimension == AetherConfig.getAetherDimensionID()) {
if (player.worldObj.getBlock(
this.bedLocation.posX,
this.bedLocation.posY,
this.bedLocation.posZ
)
!= BlocksAether.skyroot_bed) {
this.setBedLocation(null);
}
}
@ -336,49 +338,51 @@ public class PlayerAether implements IPlayerAether {
this.inPortal = true;
}
private void activateParachute()
{
if (!this.player.capabilities.isCreativeMode)
{
private void activateParachute() {
if (!this.player.capabilities.isCreativeMode) {
EntityParachute parachute = null;
ItemStack itemstack = null;
for (int i = 0; i < this.getEntity().inventory.getSizeInventory(); i++)
{
for (int i = 0; i < this.getEntity().inventory.getSizeInventory(); i++) {
ItemStack stackInSlot = this.getEntity().inventory.getStackInSlot(i);
if(stackInSlot != null && stackInSlot.getItem() == ItemsAether.cloud_parachute)
{
if (stackInSlot != null
&& stackInSlot.getItem() == ItemsAether.cloud_parachute) {
itemstack = stackInSlot;
break;
}
else
{
if (stackInSlot != null && stackInSlot.getItem() == ItemsAether.golden_parachute)
{
} else {
if (stackInSlot != null
&& stackInSlot.getItem() == ItemsAether.golden_parachute) {
itemstack = stackInSlot;
break;
}
}
}
if (itemstack != null)
{
if (itemstack.getItem() == ItemsAether.cloud_parachute)
{
parachute = new EntityParachute(this.getEntity().worldObj, this.getEntity(), false);
parachute.setPosition(this.getEntity().posX, this.getEntity().posY, this.getEntity().posZ);
if (itemstack != null) {
if (itemstack.getItem() == ItemsAether.cloud_parachute) {
parachute = new EntityParachute(
this.getEntity().worldObj, this.getEntity(), false
);
parachute.setPosition(
this.getEntity().posX,
this.getEntity().posY,
this.getEntity().posZ
);
this.getEntity().worldObj.spawnEntityInWorld(parachute);
this.getEntity().inventory.consumeInventoryItem(itemstack.getItem());
}
else
{
if (itemstack.getItem() == ItemsAether.golden_parachute)
{
} else {
if (itemstack.getItem() == ItemsAether.golden_parachute) {
itemstack.damageItem(1, this.getEntity());
parachute = new EntityParachute(this.getEntity().worldObj, this.getEntity(), true);
parachute.setPosition(this.getEntity().posX, this.getEntity().posY, this.getEntity().posZ);
parachute = new EntityParachute(
this.getEntity().worldObj, this.getEntity(), true
);
parachute.setPosition(
this.getEntity().posX,
this.getEntity().posY,
this.getEntity().posZ
);
this.getEntity().worldObj.spawnEntityInWorld(parachute);
}
}
@ -414,9 +418,15 @@ public class PlayerAether implements IPlayerAether {
private void teleportPlayer(boolean shouldSpawnPortal) {
if (this.getEntity() instanceof EntityPlayerMP) {
int previousDimension = this.getEntity().dimension;
int transferDimension = previousDimension == AetherConfig.getAetherDimensionID() ? AetherConfig.getTravelDimensionID() : AetherConfig.getAetherDimensionID();
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
TeleporterAether teleporter = new TeleporterAether(shouldSpawnPortal, server.worldServerForDimension(transferDimension));
int transferDimension
= previousDimension == AetherConfig.getAetherDimensionID()
? AetherConfig.getTravelDimensionID()
: AetherConfig.getAetherDimensionID();
MinecraftServer server
= FMLCommonHandler.instance().getMinecraftServerInstance();
TeleporterAether teleporter = new TeleporterAether(
shouldSpawnPortal, server.worldServerForDimension(transferDimension)
);
if (this.getEntity().ridingEntity != null) {
this.getEntity().ridingEntity.mountEntity(null);
@ -426,9 +436,10 @@ public class PlayerAether implements IPlayerAether {
this.getEntity().riddenByEntity.mountEntity(null);
}
if (server != null && server.getConfigurationManager() != null)
{
server.getConfigurationManager().transferPlayerToDimension((EntityPlayerMP) this.getEntity(), transferDimension, teleporter);
if (server != null && server.getConfigurationManager() != null) {
server.getConfigurationManager().transferPlayerToDimension(
(EntityPlayerMP) this.getEntity(), transferDimension, teleporter
);
}
}
}
@ -437,13 +448,11 @@ public class PlayerAether implements IPlayerAether {
public void saveNBTData(NBTTagCompound compound) {
NBTTagCompound aetherTag = new NBTTagCompound();
if (AetherRankings.isRankedPlayer(this.player.getUniqueID()))
{
if (AetherRankings.isRankedPlayer(this.player.getUniqueID())) {
aetherTag.setBoolean("halo", this.shouldRenderHalo);
}
if (AetherRankings.isDeveloper(this.player.getUniqueID()))
{
if (AetherRankings.isDeveloper(this.player.getUniqueID())) {
aetherTag.setBoolean("glow", this.shouldRenderGlow);
}
@ -451,12 +460,13 @@ public class PlayerAether implements IPlayerAether {
aetherTag.setInteger("poison_time", this.poisonTime);
aetherTag.setBoolean("cape", this.shouldRenderCape);
aetherTag.setInteger("shardCount", this.shardCount);
aetherTag.setTag("accessories", this.getAccessoryInventory().writeToNBT(aetherTag));
aetherTag.setTag(
"accessories", this.getAccessoryInventory().writeToNBT(aetherTag)
);
aetherTag.setBoolean("seen_spirit_dialog", this.seenSpiritDialog);
aetherTag.setBoolean("get_portal", this.shouldGetPortal);
if (this.bedLocation != null)
{
if (this.bedLocation != null) {
aetherTag.setInteger("bedX", this.bedLocation.posX);
aetherTag.setInteger("bedY", this.bedLocation.posY);
aetherTag.setInteger("bedZ", this.bedLocation.posZ);
@ -469,48 +479,44 @@ public class PlayerAether implements IPlayerAether {
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound aetherTag = compound.getCompoundTag("aetherI");
if (aetherTag.hasKey("halo"))
{
if (aetherTag.hasKey("halo")) {
this.shouldRenderHalo = aetherTag.getBoolean("halo");
}
if (aetherTag.hasKey("glow"))
{
if (aetherTag.hasKey("glow")) {
this.shouldRenderGlow = aetherTag.getBoolean("glow");
}
if (aetherTag.hasKey("cape"))
{
if (aetherTag.hasKey("cape")) {
this.shouldRenderCape = aetherTag.getBoolean("cape");
}
if (aetherTag.hasKey("poisoned"))
{
if (aetherTag.hasKey("poisoned")) {
this.isPoisoned = aetherTag.getBoolean("poisoned");
}
if (aetherTag.hasKey("poison_time"))
{
if (aetherTag.hasKey("poison_time")) {
this.poisonTime = aetherTag.getInteger("poison_time");
}
if (aetherTag.hasKey("seen_spirit_dialog"))
{
if (aetherTag.hasKey("seen_spirit_dialog")) {
this.seenSpiritDialog = aetherTag.getBoolean("seen_spirit_dialog");
}
if (aetherTag.hasKey("get_portal"))
{
if (aetherTag.hasKey("get_portal")) {
this.shouldGetPortal = aetherTag.getBoolean("get_portal");
}
if (aetherTag.hasKey("shardCount"))
{
this. shardCount = aetherTag.getInteger("shardCount");
if (aetherTag.hasKey("shardCount")) {
this.shardCount = aetherTag.getInteger("shardCount");
}
this.getAccessoryInventory().readFromNBT(aetherTag.getTagList("accessories", 10));
this.setBedLocation(new ChunkCoordinates(aetherTag.getInteger("bedX"), aetherTag.getInteger("bedY"), aetherTag.getInteger("bedZ")));
this.setBedLocation(new ChunkCoordinates(
aetherTag.getInteger("bedX"),
aetherTag.getInteger("bedY"),
aetherTag.getInteger("bedZ")
));
}
@Override
@ -545,26 +551,30 @@ public class PlayerAether implements IPlayerAether {
@Override
public void updateShardCount(int amount) {
if (!this.getEntity().worldObj.isRemote)
{
if (this.getShardsUsed() < this.getMaxShardCount())
{
if (!this.getEntity().worldObj.isRemote) {
if (this.getShardsUsed() < this.getMaxShardCount()) {
this.shardCount += amount;
AetherNetwork.sendToAll(new PacketUpdateLifeShardCount(this.player, this.shardCount));
AetherNetwork.sendToAll(
new PacketUpdateLifeShardCount(this.player, this.shardCount)
);
this.healthModifier = new AttributeModifier(uuid, "Aether Health Modifier", (this.shardCount * 2.0D), 0);
this.healthModifier = new AttributeModifier(
uuid, "Aether Health Modifier", (this.shardCount * 2.0D), 0
);
if (this.player.getEntityAttribute(SharedMonsterAttributes.maxHealth).getModifier(this.uuid) != null)
{
this.player.getEntityAttribute(SharedMonsterAttributes.maxHealth).removeModifier(this.healthModifier);
if (this.player.getEntityAttribute(SharedMonsterAttributes.maxHealth)
.getModifier(this.uuid)
!= null) {
this.player.getEntityAttribute(SharedMonsterAttributes.maxHealth)
.removeModifier(this.healthModifier);
}
this.player.getEntityAttribute(SharedMonsterAttributes.maxHealth).applyModifier(this.healthModifier);
}
else
{
AetherNetwork.sendToAll(new PacketUpdateLifeShardCount(this.player, this.shardCount));
this.player.getEntityAttribute(SharedMonsterAttributes.maxHealth)
.applyModifier(this.healthModifier);
} else {
AetherNetwork.sendToAll(
new PacketUpdateLifeShardCount(this.player, this.shardCount)
);
}
}
}
@ -631,34 +641,28 @@ public class PlayerAether implements IPlayerAether {
return this.cooldownMax;
}
public void setBedLocation(ChunkCoordinates bedLocation)
{
public void setBedLocation(ChunkCoordinates bedLocation) {
this.bedLocation = bedLocation;
}
public ChunkCoordinates getBedLocation()
{
public ChunkCoordinates getBedLocation() {
return bedLocation;
}
public boolean isPoisoned()
{
public boolean isPoisoned() {
return this.isPoisoned;
}
public void setPoisoned()
{
public void setPoisoned() {
this.isPoisoned = true;
this.poisonTime = 500;
}
public boolean isCured()
{
public boolean isCured() {
return this.isCured;
}
public void setCured(int time)
{
public void setCured(int time) {
this.isCured = true;
this.cureTime = time;
@ -666,12 +670,66 @@ public class PlayerAether implements IPlayerAether {
this.poisonTime = 0;
}
public void givePortalFrame()
{
if (this.shouldGetPortal)
{
this.player.inventory.addItemStackToInventory(new ItemStack(ItemsAether.aether_portal_frame));
public void givePortalFrame() {
if (this.shouldGetPortal) {
this.player.inventory.addItemStackToInventory(
new ItemStack(ItemsAether.aether_portal_frame)
);
this.shouldGetPortal = false;
}
}
public void sendPackets() {
if (this.shouldRenderHalo != this.shouldRenderHaloPrev) {
AetherNetwork.sendToAll(new PacketPerkChanged(
this.getEntity().getEntityId(),
EnumAetherPerkType.Halo,
this.shouldRenderHalo
));
this.shouldRenderHaloPrev = this.shouldRenderHalo;
}
if (this.shouldRenderGlow != this.shouldRenderGlowPrev) {
AetherNetwork.sendToAll(new PacketPerkChanged(
this.getEntity().getEntityId(),
EnumAetherPerkType.Glow,
this.shouldRenderGlow
));
this.shouldRenderGlowPrev = this.shouldRenderGlow;
}
if (this.shouldRenderCape != this.shouldRenderCapePrev) {
AetherNetwork.sendToAll(new PacketCapeChanged(
this.getEntity().getEntityId(), this.shouldRenderCape
));
this.shouldRenderCapePrev = this.shouldRenderCape;
}
if (this.poisonTime != this.poisonTimePrev) {
AetherNetwork.sendToAll(
new PacketSendPoisonTime(this.getEntity(), this.poisonTime)
);
this.poisonTimePrev = this.poisonTime;
}
if (this.seenSpiritDialog != this.seenSpiritDialogPrev) {
AetherNetwork.sendToAll(
new PacketSendSeenDialogue(this.getEntity(), this.seenSpiritDialog)
);
this.seenSpiritDialogPrev = this.seenSpiritDialog;
}
if (this.shouldGetPortal != this.shouldGetPortalPrev) {
AetherNetwork.sendToAll(
new PacketPortalItem(this.getEntity(), this.shouldGetPortal)
);
this.shouldGetPortalPrev = this.shouldGetPortal;
}
}
}