mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 21:59:05 +00:00
Bank packet
This commit is contained in:
1 parent
30e58dc049
commit
864e1cb8c7
5 files changed
+146
-36
No files matched your search
@@ -1,7 +1,14 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumPlayerPacket {
|
||||
FollowerAction;
|
||||
FollowerAction,
|
||||
Transport, // TODO
|
||||
BankAction,
|
||||
Dialog, // TODO
|
||||
QuestLog, // TODO
|
||||
TrackedQuest, // TODO
|
||||
CheckQuestCompletion, // TODO
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package kamkeel.npcs.network.packets.player;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.data.BankData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BankPacket extends AbstractPacket {
|
||||
public static final String packetName = "Player|Follower";
|
||||
|
||||
private final Action type;
|
||||
private final int slotID;
|
||||
private final int bankID;
|
||||
|
||||
private BankPacket(Action action, int bankID, int slotID) {
|
||||
this.type = action;
|
||||
this.bankID = bankID;
|
||||
this.slotID = slotID;
|
||||
}
|
||||
|
||||
public static BankPacket Open(int bankID, int slotID) {
|
||||
return new BankPacket(Action.OpenSlot, bankID, slotID);
|
||||
}
|
||||
public static BankPacket Upgrade() {
|
||||
return new BankPacket(Action.Upgrade, -1, -1);
|
||||
}
|
||||
public static BankPacket Unlock() {
|
||||
return new BankPacket(Action.Unlock, -1, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.BankAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(type.ordinal());
|
||||
|
||||
if (type == Action.OpenSlot) {
|
||||
out.writeInt(bankID);
|
||||
out.writeInt(slotID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
Action requestedAction = Action.values()[in.readInt()];
|
||||
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
EntityPlayerMP playerMP = (EntityPlayerMP) player;
|
||||
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(playerMP);
|
||||
|
||||
if(npc == null || npc.advanced.role != EnumRoleType.Bank)
|
||||
return;
|
||||
|
||||
switch (requestedAction) {
|
||||
case Unlock:
|
||||
NoppesUtilPlayer.bankUnlock(playerMP, npc);
|
||||
break;
|
||||
case Upgrade:
|
||||
NoppesUtilPlayer.bankUpgrade(playerMP, npc);
|
||||
break;
|
||||
case OpenSlot:
|
||||
int bankID = in.readInt();
|
||||
int slotID = in.readInt();
|
||||
BankData data = PlayerDataController.Instance.getBankData(playerMP,bankID).getBankOrDefault(bankID);
|
||||
data.openBankGui(playerMP, npc, bankID, slotID);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private enum Action {
|
||||
Unlock,
|
||||
Upgrade,
|
||||
OpenSlot
|
||||
}
|
||||
}
|
||||
@@ -158,27 +158,27 @@ public class PacketHandlerPlayer{
|
||||
return;
|
||||
NoppesUtilPlayer.transport(player, npc, ByteBufUtils.readString(buffer));
|
||||
}
|
||||
else if(type == EnumPlayerPacket.BankUpgrade){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null || npc.advanced.role != EnumRoleType.Bank)
|
||||
return;
|
||||
NoppesUtilPlayer.bankUpgrade(player, npc);
|
||||
}
|
||||
else if(type == EnumPlayerPacket.BankUnlock){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null || npc.advanced.role != EnumRoleType.Bank)
|
||||
return;
|
||||
NoppesUtilPlayer.bankUnlock(player, npc);
|
||||
}
|
||||
else if(type == EnumPlayerPacket.BankSlotOpen){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null || npc.advanced.role != EnumRoleType.Bank)
|
||||
return;
|
||||
int slot = buffer.readInt();
|
||||
int bankId = buffer.readInt();
|
||||
BankData data = PlayerDataController.Instance.getBankData(player,bankId).getBankOrDefault(bankId);
|
||||
data.openBankGui(player, npc, bankId, slot);
|
||||
}
|
||||
// else if(type == EnumPlayerPacket.BankUpgrade){
|
||||
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
// if(npc == null || npc.advanced.role != EnumRoleType.Bank)
|
||||
// return;
|
||||
// NoppesUtilPlayer.bankUpgrade(player, npc);
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.BankUnlock){
|
||||
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
// if(npc == null || npc.advanced.role != EnumRoleType.Bank)
|
||||
// return;
|
||||
// NoppesUtilPlayer.bankUnlock(player, npc);
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.BankSlotOpen){
|
||||
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
// if(npc == null || npc.advanced.role != EnumRoleType.Bank)
|
||||
// return;
|
||||
// int slot = buffer.readInt();
|
||||
// int bankId = buffer.readInt();
|
||||
// BankData data = PlayerDataController.Instance.getBankData(player,bankId).getBankOrDefault(bankId);
|
||||
// data.openBankGui(player, npc, bankId, slot);
|
||||
// }
|
||||
else if(type == EnumPlayerPacket.Dialog){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package noppes.npcs.client.gui.player;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.BankPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -26,7 +28,7 @@ public class GuiNPCBankChest extends GuiContainerNPCInterface implements IGuiDat
|
||||
private int maxSlots = 1;
|
||||
private int unlockedSlots = 1;
|
||||
private ItemStack currency;
|
||||
|
||||
|
||||
public GuiNPCBankChest(EntityNPCInterface npc,ContainerNPCBankInterface container)
|
||||
{
|
||||
super(npc,container);
|
||||
@@ -35,7 +37,7 @@ public class GuiNPCBankChest extends GuiContainerNPCInterface implements IGuiDat
|
||||
allowUserInput = false; //allowUserInput
|
||||
ySize = 235;
|
||||
closeOnEsc = true;
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public void initGui(){
|
||||
@@ -70,18 +72,18 @@ public class GuiNPCBankChest extends GuiContainerNPCInterface implements IGuiDat
|
||||
int id = guibutton.id;
|
||||
if(id < 6){
|
||||
close();
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.BankSlotOpen, id, container.bankid);
|
||||
PacketClient.sendClient(BankPacket.Open(container.bankid, id));
|
||||
}
|
||||
if(id == 8){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.BankUnlock);
|
||||
PacketClient.sendClient(BankPacket.Unlock());
|
||||
}
|
||||
if(id == 9){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.BankUpgrade);
|
||||
PacketClient.sendClient(BankPacket.Upgrade());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
|
||||
{
|
||||
@@ -91,8 +93,8 @@ public class GuiNPCBankChest extends GuiContainerNPCInterface implements IGuiDat
|
||||
int i1 = (height - ySize) / 2;
|
||||
drawTexturedModalRect(l, i1, 0, 0, xSize, 6);
|
||||
if(!container.isAvailable()){
|
||||
drawTexturedModalRect(l, i1 + 6, 0, 6, xSize, 64);
|
||||
drawTexturedModalRect(l, i1 + 70, 0, 124, xSize, 222-124);
|
||||
drawTexturedModalRect(l, i1 + 6, 0, 6, xSize, 64);
|
||||
drawTexturedModalRect(l, i1 + 70, 0, 124, xSize, 222-124);
|
||||
int x = guiLeft + 30;
|
||||
int y = guiTop + 8;
|
||||
fontRendererObj.drawString(StatCollector.translateToLocal("bank.unlockCosts")+":", x , y + 4 , CustomNpcResourceListener.DefaultTextColor);
|
||||
@@ -100,7 +102,7 @@ public class GuiNPCBankChest extends GuiContainerNPCInterface implements IGuiDat
|
||||
}
|
||||
else if(container.isUpgraded()){
|
||||
drawTexturedModalRect(l, i1 + 60, 0, 60, xSize, 162);
|
||||
drawTexturedModalRect(l, i1 + 6, 0, 60, xSize, 64);
|
||||
drawTexturedModalRect(l, i1 + 6, 0, 60, xSize, 64);
|
||||
}
|
||||
else if(container.canBeUpgraded()){
|
||||
drawTexturedModalRect(l, i1 + 6, 0, 6, xSize, 216);
|
||||
@@ -136,7 +138,7 @@ public class GuiNPCBankChest extends GuiContainerNPCInterface implements IGuiDat
|
||||
{
|
||||
this.renderToolTip(item, mouseX, mouseY);
|
||||
}
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -5,13 +5,13 @@ public enum EnumPlayerPacket {
|
||||
// FollowerExtend,
|
||||
// FollowerState,
|
||||
Transport,
|
||||
BankUnlock,
|
||||
BankUpgrade,
|
||||
// BankUnlock,
|
||||
// BankUpgrade,
|
||||
Dialog,
|
||||
QuestLog,
|
||||
TrackedQuest,
|
||||
CheckQuestCompletion,
|
||||
BankSlotOpen,
|
||||
// BankSlotOpen,
|
||||
FactionsGet,
|
||||
MailGet,
|
||||
MailDelete,
|
||||
|
||||
Reference in new issue
Block a user