Files
BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/MessageKeyPressed.java
T
2022-11-08 19:34:25 +01:00

55 lines
1.7 KiB
Java

package WayofTime.alchemicalWizardry.common;
import WayofTime.alchemicalWizardry.common.items.armour.OmegaArmour;
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 io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class MessageKeyPressed implements IMessage, IMessageHandler<MessageKeyPressed, IMessage> {
private byte keyPressed;
public MessageKeyPressed() {}
public MessageKeyPressed(Key key) {
if (key == Key.OMEGA_ACTIVE) {
this.keyPressed = (byte) Key.OMEGA_ACTIVE.ordinal();
}
}
@Override
public void fromBytes(ByteBuf buf) {
this.keyPressed = buf.readByte();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeByte(keyPressed);
}
@Override
public IMessage onMessage(MessageKeyPressed message, MessageContext ctx) {
EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity;
if (message.keyPressed == Key.OMEGA_ACTIVE.ordinal()) {
if (entityPlayer != null) {
ItemStack[] armourInventory = entityPlayer.inventory.armorInventory;
if (armourInventory[2] != null) {
ItemStack chestStack = armourInventory[2];
if (chestStack.getItem() instanceof OmegaArmour) {
((OmegaArmour) chestStack.getItem()).onOmegaKeyPressed(entityPlayer, chestStack);
}
}
}
}
return null;
}
public enum Key {
OMEGA_ACTIVE
}
}