mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
Refactor of XP stuff to use it in all the places.
This commit is contained in:
1 parent
a1152d5316
commit
e8319e20a2
12 files changed
+346
-242
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package crazypants.enderio.xp;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
|
||||
public class PacketExperianceContainer extends MessageTileEntity<TileEntity> implements IMessageHandler<PacketExperianceContainer, IMessage> {
|
||||
|
||||
private static boolean registered = false;
|
||||
|
||||
public static void register() {
|
||||
if(!registered) {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketExperianceContainer.class, PacketExperianceContainer.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
private ExperienceContainer xpCon;
|
||||
|
||||
public PacketExperianceContainer() {
|
||||
xpCon = new ExperienceContainer();
|
||||
}
|
||||
|
||||
public PacketExperianceContainer(TileEntity tile) {
|
||||
super(tile);
|
||||
IHaveExperience xpTile = (IHaveExperience)tile;
|
||||
xpCon = xpTile.getContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
xpCon.toBytes(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
xpCon.fromBytes(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketExperianceContainer message, MessageContext ctx) {
|
||||
EntityPlayer player = EnderIO.proxy.getClientPlayer();
|
||||
TileEntity tile = message.getTileEntity(player.worldObj);
|
||||
if (tile instanceof IHaveExperience) {
|
||||
IHaveExperience xpTile = (IHaveExperience)tile;
|
||||
xpTile.getContainer().set(message.xpCon);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user