mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 03:49:29 +00:00
Fix health display after dimension change #1132
This commit is contained in:
1 parent
dc439705e6
commit
1eb41de35b
4 files changed
+68
No files matched your search
@@ -2,14 +2,22 @@ package tconstruct.armor;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
||||
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.armor.items.TravelGear;
|
||||
import tconstruct.armor.player.TPlayerStats;
|
||||
import tconstruct.library.modifier.IModifyable;
|
||||
import tconstruct.util.network.HealthUpdatePacket;
|
||||
|
||||
public class ArmorAbilities
|
||||
{
|
||||
@@ -112,4 +120,17 @@ public class ArmorAbilities
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void dimensionChanged(PlayerEvent.PlayerChangedDimensionEvent event)
|
||||
{
|
||||
if(event.player == null || !(event.player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
// this callback is only called serverside
|
||||
float oldHealth = event.player.getHealth();
|
||||
// tell the client to update its hp
|
||||
TConstruct.packetPipeline.sendTo(new HealthUpdatePacket(oldHealth), (net.minecraft.entity.player.EntityPlayerMP) event.player);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package tconstruct.armor;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import net.minecraft.entity.boss.*;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.monster.IMob;
|
||||
@@ -10,6 +11,7 @@ import net.minecraftforge.event.entity.living.*;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.armor.items.TravelWings;
|
||||
import tconstruct.armor.player.ArmorExtended;
|
||||
import tconstruct.armor.player.TPlayerStats;
|
||||
import tconstruct.library.modifier.IModifyable;
|
||||
import tconstruct.world.entity.BlueSlime;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package tconstruct.util.network;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import mantle.common.network.AbstractPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import tconstruct.armor.ArmorProxyClient;
|
||||
import tconstruct.armor.player.TPlayerStats;
|
||||
|
||||
public class HealthUpdatePacket extends AbstractPacket {
|
||||
private float health;
|
||||
|
||||
public HealthUpdatePacket() {
|
||||
}
|
||||
|
||||
public HealthUpdatePacket(float health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
buffer.writeFloat(health);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
health = buffer.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
// todo: fix this to use the proper armor extended.. once we sync that stuff...
|
||||
ArmorProxyClient.armorExtended.recalculateHealth(player, TPlayerStats.get(player));
|
||||
player.setHealth(health);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -122,6 +122,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
|
||||
public void registerPackets ()
|
||||
{
|
||||
registerPacket(HealthUpdatePacket.class);
|
||||
registerPacket(DoubleJumpPacket.class);
|
||||
registerPacket(AccessoryInventoryPacket.class);
|
||||
registerPacket(SmelteryPacket.class);
|
||||
|
||||
Reference in new issue
Block a user