mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 00:47:50 +00:00
CompanionActionPacket
This commit is contained in:
1 parent
54a07ffb48
commit
a5c3c6768b
7 files changed
+147
-50
No files matched your search
@@ -355,6 +355,8 @@ public class PacketHandler {
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket());
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket.MailSendPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new CompanionActionPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new InputDevicePacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new ScreenSizePacket());
|
||||
|
||||
@@ -10,7 +10,7 @@ public enum EnumPlayerPacket {
|
||||
MailSend,
|
||||
SaveSign, // TODO
|
||||
SaveBook, // TODO
|
||||
Companion, // TODO: OpenInv, TalentExp
|
||||
CompanionAction, // TODO: OpenInv, TalentExp
|
||||
GetRole, // TODO
|
||||
InputDevice,
|
||||
ScreenSize
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package kamkeel.npcs.network.packets.player;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumCompanionTalent;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CompanionActionPacket extends AbstractPacket {
|
||||
public static final String packetName = "Player|CompanionAction";
|
||||
|
||||
private Type type;
|
||||
private int talentOrdinal;
|
||||
private int exp;
|
||||
|
||||
public CompanionActionPacket() {
|
||||
|
||||
}
|
||||
|
||||
public static void OpenInventory() {
|
||||
CompanionActionPacket packet = new CompanionActionPacket();
|
||||
packet.type = Type.OpenInventory;
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
public static void TalentExp(EnumCompanionTalent talent, int exp) {
|
||||
CompanionActionPacket packet = new CompanionActionPacket();
|
||||
packet.type = Type.TalentExp;
|
||||
packet.talentOrdinal = talent.ordinal();
|
||||
packet.exp = exp;
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsNPC() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.CompanionAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(type.ordinal());
|
||||
|
||||
if (type == Type.TalentExp) {
|
||||
out.writeInt(talentOrdinal);
|
||||
out.writeInt(exp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
Type type = Type.values()[in.readInt()];
|
||||
|
||||
if(npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
|
||||
return;
|
||||
|
||||
if (type == Type.OpenInventory) {
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.CompanionInv, npc);
|
||||
return;
|
||||
}
|
||||
int id = in.readInt();
|
||||
int exp = in.readInt();
|
||||
RoleCompanion role = (RoleCompanion) npc.roleInterface;
|
||||
if(exp <= 0 || !role.canAddExp(-exp) || id < 0 || id >= EnumCompanionTalent.values().length) //should never happen unless hacking
|
||||
return;
|
||||
EnumCompanionTalent talent = EnumCompanionTalent.values()[id];
|
||||
role.addExp(-exp);
|
||||
role.addTalentExp(talent, exp);
|
||||
}
|
||||
|
||||
private enum Type {
|
||||
OpenInventory,
|
||||
TalentExp
|
||||
}
|
||||
}
|
||||
@@ -43,25 +43,25 @@ public class PacketHandlerPlayer{
|
||||
}
|
||||
|
||||
private void player(ByteBuf buffer, EntityPlayerMP player, EnumPlayerPacket type) throws IOException {
|
||||
if(type == EnumPlayerPacket.CompanionTalentExp){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
|
||||
return;
|
||||
int id = buffer.readInt();
|
||||
int exp = buffer.readInt();
|
||||
RoleCompanion role = (RoleCompanion) npc.roleInterface;
|
||||
if(exp <= 0 || !role.canAddExp(-exp) || id < 0 || id >= EnumCompanionTalent.values().length) //should never happen unless hacking
|
||||
return;
|
||||
EnumCompanionTalent talent = EnumCompanionTalent.values()[id];
|
||||
role.addExp(-exp);
|
||||
role.addTalentExp(talent, exp);
|
||||
}
|
||||
else if(type == EnumPlayerPacket.CompanionOpenInv){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
|
||||
return;
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.CompanionInv, npc);
|
||||
}
|
||||
// if(type == EnumPlayerPacket.CompanionTalentExp){
|
||||
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
// if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
|
||||
// return;
|
||||
// int id = buffer.readInt();
|
||||
// int exp = buffer.readInt();
|
||||
// RoleCompanion role = (RoleCompanion) npc.roleInterface;
|
||||
// if(exp <= 0 || !role.canAddExp(-exp) || id < 0 || id >= EnumCompanionTalent.values().length) //should never happen unless hacking
|
||||
// return;
|
||||
// EnumCompanionTalent talent = EnumCompanionTalent.values()[id];
|
||||
// role.addExp(-exp);
|
||||
// role.addTalentExp(talent, exp);
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.CompanionOpenInv){
|
||||
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
// if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
|
||||
// return;
|
||||
// NoppesUtilServer.sendOpenGui(player, EnumGuiType.CompanionInv, npc);
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.KeyPressed) {
|
||||
// if(ScriptController.Instance.languages.isEmpty()) {
|
||||
// return;
|
||||
@@ -146,7 +146,7 @@ public class PacketHandlerPlayer{
|
||||
// NoppesUtilPlayer.changeFollowerState(player,npc);
|
||||
// GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
|
||||
// }
|
||||
else if(type == EnumPlayerPacket.RoleGet){
|
||||
if(type == EnumPlayerPacket.RoleGet){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null || npc.advanced.role == EnumRoleType.None)
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.client.gui.player.companion;
|
||||
|
||||
import kamkeel.npcs.network.packets.player.CompanionActionPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -41,11 +42,11 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
addLabel(new GuiNpcLabel(3, NoppesStringUtils.translate("companion.strength", ": ", npc.stats.getAttackStrength()), guiLeft + 4, y+=12));
|
||||
addLabel(new GuiNpcLabel(4, NoppesStringUtils.translate("companion.level", ": ", role.getTotalLevel()), guiLeft + 4, y+=12));
|
||||
addLabel(new GuiNpcLabel(5, NoppesStringUtils.translate("job.name", ": ", "gui.none"), guiLeft + 4, y+=12));
|
||||
|
||||
|
||||
addTopMenu(role, this, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void addTopMenu(RoleCompanion role, GuiScreen screen, int active){
|
||||
if(screen instanceof GuiNPCInterface){
|
||||
GuiNPCInterface gui = (GuiNPCInterface) screen;
|
||||
@@ -79,7 +80,7 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
CustomNpcs.proxy.openGui(npc, EnumGuiType.CompanionTalent);
|
||||
}
|
||||
if(id == 3){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.CompanionOpenInv);
|
||||
CompanionActionPacket.OpenInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,12 +90,12 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
if(isEating && !role.isEating()){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.RoleGet);
|
||||
}
|
||||
|
||||
|
||||
isEating = role.isEating();
|
||||
super.drawNpc(34, 150);
|
||||
int y = drawHealth(guiTop + 88);
|
||||
}
|
||||
|
||||
|
||||
private int drawHealth(int y){
|
||||
this.mc.getTextureManager().bindTexture(icons);
|
||||
|
||||
@@ -102,23 +103,23 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
if(role.talents.containsKey(EnumCompanionTalent.ARMOR) || max > 0){
|
||||
for (int i = 0; i < 10; ++i){
|
||||
int x = guiLeft + 66 + i * 10;
|
||||
|
||||
|
||||
if (i * 2 + 1 < max){
|
||||
this.drawTexturedModalRect(x, y, 34, 9, 9, 9);
|
||||
}
|
||||
|
||||
|
||||
if (i * 2 + 1 == max){
|
||||
this.drawTexturedModalRect(x, y, 25, 9, 9, 9);
|
||||
}
|
||||
|
||||
|
||||
if (i * 2 + 1 > max){
|
||||
this.drawTexturedModalRect(x, y, 16, 9, 9, 9);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
y += 10;
|
||||
}
|
||||
|
||||
|
||||
max = MathHelper.ceiling_float_int(npc.getMaxHealth());
|
||||
int k = (int)npc.getHealth();
|
||||
float scale = 1;
|
||||
@@ -134,12 +135,12 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
if(k > i)
|
||||
this.drawTexturedModalRect(x, y + offset, 52 + i % 2 * 5, 0, i % 2 == 1?4:5, 9);
|
||||
}
|
||||
|
||||
|
||||
k = role.foodstats.getFoodLevel();
|
||||
y += 10;
|
||||
if(max > 20)
|
||||
y += 10;
|
||||
|
||||
|
||||
for(int i = 0; i < 20; i++){
|
||||
int x = guiLeft + 66 + i % 20 * 5;
|
||||
this.drawTexturedModalRect(x, y, 16 + i % 2 * 5, 27, i % 2 == 1?4:5, 9);
|
||||
@@ -151,7 +152,7 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.client.gui.player.companion;
|
||||
|
||||
import kamkeel.npcs.network.packets.player.CompanionActionPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -29,7 +30,7 @@ import java.util.Map;
|
||||
|
||||
public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
private RoleCompanion role;
|
||||
private Map<Integer,GuiTalent> talents = new HashMap<Integer,GuiTalent>();
|
||||
private Map<Integer,GuiTalent> talents = new HashMap<Integer,GuiTalent>();
|
||||
private GuiNpcButton selected;
|
||||
|
||||
public GuiNpcCompanionTalents(EntityNPCInterface npc) {
|
||||
@@ -46,7 +47,7 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
super.initGui();
|
||||
talents.clear();
|
||||
int y = guiTop + 12;
|
||||
|
||||
|
||||
addLabel(new GuiNpcLabel(0, NoppesStringUtils.translate("quest.exp", ": "), guiLeft + 4, guiTop + 10));
|
||||
|
||||
GuiNpcCompanionStats.addTopMenu(role, this, 2);
|
||||
@@ -55,7 +56,7 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
addTalent(i++, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addTalent(int i, EnumCompanionTalent talent){
|
||||
int y = guiTop + 28 + i/2 * 26;
|
||||
int x = guiLeft + 4 + i % 2 * 84;
|
||||
@@ -75,7 +76,7 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
CustomNpcs.proxy.openGui(npc, EnumGuiType.Companion);
|
||||
}
|
||||
if(id == 3){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.CompanionOpenInv);
|
||||
CompanionActionPacket.OpenInventory();
|
||||
}
|
||||
if(id >= 10){
|
||||
selected = (GuiNpcButton) guibutton;
|
||||
@@ -83,19 +84,19 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
addExperience(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addExperience(int exp){
|
||||
EnumCompanionTalent talent = talents.get(selected.id - 10).talent;
|
||||
if(!role.canAddExp(-exp) && role.currentExp <= 0)
|
||||
return;
|
||||
if(exp > role.currentExp)
|
||||
exp = role.currentExp;
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.CompanionTalentExp, talent.ordinal(), exp);
|
||||
CompanionActionPacket.TalentExp(talent, exp);
|
||||
role.talents.put(talent, role.talents.get(talent) + exp);
|
||||
role.addExp(-exp);
|
||||
getLabel(selected.id - 10).label = role.talents.get(talent) + "/" + role.getNextLevel(talent);
|
||||
}
|
||||
|
||||
|
||||
private long lastPressedTime = 0;
|
||||
private long startPressedTime = 0;
|
||||
@Override
|
||||
@@ -122,7 +123,7 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
selected = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mc.getTextureManager().bindTexture(Gui.icons);
|
||||
this.drawTexturedModalRect(guiLeft + 4, guiTop + 20, 10, 64, 162, 5);
|
||||
|
||||
@@ -142,9 +143,9 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class GuiTalent extends GuiScreen{
|
||||
private EnumCompanionTalent talent;
|
||||
private int x, y;
|
||||
@@ -156,12 +157,12 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
this.y = y;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int i, int j, float f) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.getTextureManager().bindTexture(resource);
|
||||
|
||||
|
||||
ItemStack item = talent.item;
|
||||
if(item.getItem() == null)
|
||||
item = new ItemStack(Blocks.dirt);
|
||||
@@ -177,7 +178,7 @@ public class GuiNpcCompanionTalents extends GuiNPCInterface{
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
itemRender.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, x + 4, y + 4);
|
||||
itemRender.renderItemOverlayIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, x + 4, y + 4);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glTranslatef(0, 0, 200);
|
||||
this.drawCenteredString(mc.fontRenderer, role.getTalentLevel(talent) + "", x + 20, y + 16, 0xFFFFFF);
|
||||
|
||||
@@ -20,10 +20,10 @@ public enum EnumPlayerPacket {
|
||||
// MailboxOpenMail,
|
||||
SignSave,
|
||||
SaveBook,
|
||||
CompanionOpenInv,
|
||||
// CompanionOpenInv,
|
||||
RoleGet,
|
||||
// KeyPressed,
|
||||
// MouseClicked,
|
||||
CompanionTalentExp,
|
||||
// CompanionTalentExp,
|
||||
// ScreenSize
|
||||
}
|
||||
Reference in new issue
Block a user