Follower packet

This commit is contained in:
somehussar committed 2025-02-02 22:21:29 +01:00
1 parent 0124154380
commit 7c2ad0749b
6 files changed
+120 -41

No files matched your search

@@ -1,4 +1,8 @@
package kamkeel.npcs.network.enums;
public enum EnumPlayerPacket {
FollowerAction;
}
@@ -0,0 +1,74 @@
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.PacketHandler;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.constants.EnumJobType;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public class FollowerPacket extends AbstractPacket {
public static final String packetName = "Player|Follower";
private final Action type;
public FollowerPacket(Action action) {
this.type = action;
}
@Override
public Enum getType() {
return EnumPlayerPacket.FollowerAction;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Action requestedAction = Action.values()[in.readInt()];
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if (npc == null || npc.advanced.job != EnumJobType.Follower)
return;
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player;
switch (requestedAction) {
case Hire:
NoppesUtilPlayer.hireFollower(entityPlayerMP, npc);
break;
case Extend:
NoppesUtilPlayer.extendFollower(entityPlayerMP, npc);
GuiDataPacket.sendGuiData(entityPlayerMP, npc.roleInterface.writeToNBT(new NBTTagCompound()));
break;
case State:
NoppesUtilPlayer.changeFollowerState(entityPlayerMP, npc);
GuiDataPacket.sendGuiData(entityPlayerMP, npc.roleInterface.writeToNBT(new NBTTagCompound()));
break;
}
}
public enum Action {
Hire,
Extend,
State
}
}
@@ -126,26 +126,26 @@ public class PacketHandlerPlayer{
EventHooks.onPlayerMouseClicked(player, button, mouseWheel, buttonDown, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, keysDown);
}
else if(type == EnumPlayerPacket.FollowerHire){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Follower)
return;
NoppesUtilPlayer.hireFollower(player, npc);
}
else if(type == EnumPlayerPacket.FollowerExtend){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Follower)
return;
NoppesUtilPlayer.extendFollower(player, npc);
GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
}
else if(type == EnumPlayerPacket.FollowerState){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Follower)
return;
NoppesUtilPlayer.changeFollowerState(player,npc);
GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
}
// else if(type == EnumPlayerPacket.FollowerHire){
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
// if(npc == null || npc.advanced.role != EnumRoleType.Follower)
// return;
// NoppesUtilPlayer.hireFollower(player, npc);
// }
// else if(type == EnumPlayerPacket.FollowerExtend){
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
// if(npc == null || npc.advanced.role != EnumRoleType.Follower)
// return;
// NoppesUtilPlayer.extendFollower(player, npc);
// GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
// }
// else if(type == EnumPlayerPacket.FollowerState){
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
// if(npc == null || npc.advanced.role != EnumRoleType.Follower)
// return;
// NoppesUtilPlayer.changeFollowerState(player,npc);
// GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
// }
else if(type == EnumPlayerPacket.RoleGet){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role == EnumRoleType.None)
@@ -1,5 +1,7 @@
package noppes.npcs.client.gui.player;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.player.FollowerPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
@@ -22,13 +24,13 @@ public class GuiNpcFollower extends GuiContainerNPCInterface implements IGuiDat
private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/follower.png");
private EntityNPCInterface npc;
private RoleFollower role;
public GuiNpcFollower(EntityNPCInterface npc,ContainerNPCFollower container){
super(npc, container);
this.npc = npc;
role = (RoleFollower) npc.roleInterface;
closeOnEsc = true;
NoppesUtilPlayer.sendData(EnumPlayerPacket.RoleGet);
}
@Override
@@ -44,10 +46,10 @@ public class GuiNpcFollower extends GuiContainerNPCInterface implements IGuiDat
super.actionPerformed(guibutton);
int id = guibutton.id;
if(id == 4){
NoppesUtilPlayer.sendData(EnumPlayerPacket.FollowerState);
PacketClient.sendClient(new FollowerPacket(FollowerPacket.Action.State));
}
if(id == 5){
NoppesUtilPlayer.sendData(EnumPlayerPacket.FollowerExtend);
PacketClient.sendClient(new FollowerPacket(FollowerPacket.Action.Extend));
}
}
@@ -58,7 +60,7 @@ public class GuiNpcFollower extends GuiContainerNPCInterface implements IGuiDat
if(role.getDaysLeft() <= 1)
fontRendererObj.drawString(StatCollector.translateToLocal("follower.daysleft")+": " + StatCollector.translateToLocal("follower.lastday"), 62, 94, CustomNpcResourceListener.DefaultTextColor);
else
fontRendererObj.drawString(StatCollector.translateToLocal("follower.daysleft") + ": " + (role.getDaysLeft()-1), 62, 94, CustomNpcResourceListener.DefaultTextColor);
fontRendererObj.drawString(StatCollector.translateToLocal("follower.daysleft") + ": " + (role.getDaysLeft()-1), 62, 94, CustomNpcResourceListener.DefaultTextColor);
}
}
@@ -78,9 +80,9 @@ public class GuiNpcFollower extends GuiContainerNPCInterface implements IGuiDat
int days = 1;
if(role.rates.containsKey(id))
days = role.rates.get(id);
int yOffset = index * 20;
int x = guiLeft + 68;
int y = guiTop + yOffset + 4;
RenderHelper.enableGUIStandardItemLighting();
@@ -89,22 +91,22 @@ public class GuiNpcFollower extends GuiContainerNPCInterface implements IGuiDat
GL11.glEnable(GL11.GL_LIGHTING);
itemRender.renderItemIntoGUI(fontRendererObj, mc.renderEngine, itemstack, x + 11,y);
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, itemstack, x+11,y);
RenderHelper.disableStandardItemLighting();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(32826 /*GL_RESCALE_NORMAL_EXT*/);
String daysS = days + " " + ((days == 1)?StatCollector.translateToLocal("follower.day"):StatCollector.translateToLocal("follower.days"));
fontRendererObj.drawString(" = "+daysS, x + 27, y + 4, CustomNpcResourceListener.DefaultTextColor);
//fontRenderer.drawString(quantity, x + 0 + (12-fontRenderer.getStringWidth(quantity))/2, y + 4, 0x404040);
index++;
}
}
this.drawNpc(33, 131);
}
@Override
public void save() {
}
@Override
public void setGuiData(NBTTagCompound compound) {
@@ -1,5 +1,7 @@
package noppes.npcs.client.gui.player;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.player.FollowerPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
@@ -41,7 +43,7 @@ public class GuiNpcFollowerHire extends GuiContainerNPCInterface
super.actionPerformed(guibutton);
if(guibutton.id == 5)
{
NoppesUtilPlayer.sendData(EnumPlayerPacket.FollowerHire);
PacketClient.sendClient(new FollowerPacket(FollowerPacket.Action.Hire));
close();
}
}
@@ -68,10 +70,10 @@ public class GuiNpcFollowerHire extends GuiContainerNPCInterface
int days = 1;
if(role.rates.containsKey(id))
days = role.rates.get(id);
int yOffset = index * 26;
int x = guiLeft + 78;
int y = guiTop + yOffset + 10;
GL11.glEnable(32826 /*GL_RESCALE_NORMAL_EXT*/);
@@ -79,7 +81,7 @@ public class GuiNpcFollowerHire extends GuiContainerNPCInterface
itemRender.renderItemIntoGUI(fontRendererObj, mc.renderEngine, itemstack, x + 11,y);
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, itemstack, x+11,y);
RenderHelper.disableStandardItemLighting();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(32826 /*GL_RESCALE_NORMAL_EXT*/);
String daysS = days + " " + ((days == 1)?StatCollector.translateToLocal("follower.day"):StatCollector.translateToLocal("follower.days"));
@@ -92,7 +94,7 @@ public class GuiNpcFollowerHire extends GuiContainerNPCInterface
}
index++;
}
}
@Override
public void save() {
@@ -1,9 +1,6 @@
package noppes.npcs.constants;
public enum EnumPlayerPacket {
FollowerHire,
FollowerExtend,
FollowerState,
Transport,
BankUnlock,
BankUpgrade,