Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.rexozz.pixelengine.client.gui;
- import java.awt.Color;
- import java.io.IOException;
- import java.util.List;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.Gui;
- import net.minecraft.client.gui.GuiButton;
- import net.minecraft.client.gui.GuiTextField;
- import net.minecraft.client.gui.inventory.GuiContainer;
- import net.minecraft.client.gui.inventory.GuiInventory;
- import net.minecraft.client.renderer.GlStateManager;
- import net.minecraft.client.renderer.OpenGlHelper;
- import net.minecraft.client.renderer.RenderHelper;
- import net.minecraft.client.renderer.entity.RenderManager;
- import net.minecraft.client.resources.I18n;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.network.NetHandlerPlayServer;
- import net.rexozz.pixelengine.entity.EntityNPC;
- import net.rexozz.pixelengine.network.PacketHandler;
- import net.rexozz.pixelengine.network.S03PacketUpdateEntity;
- import net.rexozz.pixelengine.server.container.ContainerNPC;
- public class GuiNPC extends GuiContainer{
- int[] pos=new int[3];
- private float oldMouseX;
- private float oldMouseY;
- private EntityNPC npc;
- private boolean fallDmg=true, drown=true, fireImm=false, showTagAlways=false, swim=true;
- boolean slotsShowing=true;
- int sunMode=0, lookMode=1, walkMode=0, attackMode=0;
- //general buttons
- @SuppressWarnings("unused")
- private GuiButton apply, cancel, delete;
- //category_buttons
- private GuiButton catGeneral, catAttributes, catAI, catInventory, catModel;
- //catGeneral_controls
- private GuiTextField name, texture, deathSound, hitSound;
- private GuiButton renderNameTag;
- //catAttributes_controls
- private GuiTextField attMaxHealthVal, attArmorVal, attMoveSpeedVal, attAttackSpeedVal, attArmorTghVal;
- private GuiButton fireImmune, canDrown, sunBurns, fallDamage;
- //catAI_controls
- private GuiButton canSwim, lookPlayer, walking, attack;
- private GuiTextField watchRange;
- public GuiNPC(IInventory playerInv, IInventory npcInv, EntityNPC npc){
- super(new ContainerNPC(playerInv, npcInv,npc,Minecraft.getMinecraft().thePlayer));
- this.npc=npc;
- }
- public void onGuiClosed() {
- super.onGuiClosed();
- }
- public void drawScreen(int mouseX, int mouseY, float partialTicks){
- super.drawScreen(mouseX, mouseY, partialTicks);
- this.oldMouseX = (float)mouseX;
- this.oldMouseY = (float)mouseY;
- }
- public void updateScreen() {
- //general
- this.disEnable(this.catGeneral, this.name);
- this.disEnable(this.catGeneral, this.texture);
- this.disEnable(this.catGeneral, this.renderNameTag);
- this.disEnable(this.catGeneral, this.deathSound);
- this.disEnable(this.catGeneral, this.hitSound);
- //attributes
- this.disEnable(this.catAttributes, this.attMaxHealthVal);
- this.disEnable(this.catAttributes, this.attArmorVal);
- this.disEnable(this.catAttributes, this.attMoveSpeedVal);
- this.disEnable(this.catAttributes, this.attAttackSpeedVal);
- this.disEnable(this.catAttributes, this.attArmorTghVal);
- this.disEnable(this.catAttributes, this.fireImmune);
- this.disEnable(this.catAttributes, this.canDrown);
- this.disEnable(this.catAttributes, this.sunBurns);
- this.disEnable(this.catAttributes, this.fallDamage);
- //ai
- this.disEnable(this.catAI, this.lookPlayer);
- this.disEnable(this.catAI, this.canSwim);
- this.disEnable(this.catAI, this.watchRange);
- this.disEnable(this.catAI, this.walking);
- this.disEnable(this.catAI, this.attack);
- }
- public void disEnable(GuiButton cat, Gui control){
- if(control instanceof GuiButton){
- ((GuiButton) control).enabled=!cat.enabled;
- ((GuiButton) control).visible=!cat.enabled;
- }else if(control instanceof GuiTextField){
- ((GuiTextField) control).setEnabled(!cat.enabled);
- ((GuiTextField) control).setVisible(!cat.enabled);
- }
- }
- public void initGui() {
- this.buttonList.clear();
- int x=this.width;
- int y=this.height;
- this.showTagAlways=npc.getAlwaysRenderNameTag();
- this.fireImm=this.npc.isFireImmune();
- this.sunMode=this.npc.burnsInSun();
- this.fallDmg=this.npc.takesFallDamage();
- this.drown=!this.npc.canBreatheUnderwater();
- this.swim=this.npc.canSwim();
- this.lookMode=this.npc.getLookMode();
- this.walkMode=this.npc.getWalkMode();
- this.attackMode=this.npc.getAttackMode();
- //fixed controls
- this.buttonList.add(this.catGeneral=new GuiButton(0, x/2-208, 20, 80, 20, I18n.format("gui.npc.button.general")));
- this.catGeneral.enabled=false;
- this.buttonList.add(this.catAttributes=new GuiButton(1, x/2-124, 20, 80, 20, I18n.format("gui.npc.button.attributes")));
- this.buttonList.add(this.catAI=new GuiButton(2, x/2-40, 20, 80, 20, I18n.format("gui.npc.button.ai")));
- this.buttonList.add(this.catInventory=new GuiButton(3, x/2+44, 20, 80, 20, I18n.format("gui.npc.button.inventory")));
- this.buttonList.add(this.catModel=new GuiButton(4, x/2+128, 20, 80, 20, I18n.format("gui.npc.button.model")));
- this.catModel.enabled=false;
- this.buttonList.add(this.apply=new GuiButton(5, x/2-208, y-40, 80, 20, I18n.format("gui.npc.button.apply")));
- this.buttonList.add(this.cancel=new GuiButton(6, x/2-124, y-40, 80, 20, I18n.format("gui.npc.button.cancel")));
- this.buttonList.add(this.delete=new GuiButton(7, x/2-40, y-40, 80, 20, I18n.format("gui.npc.button.delete")));
- //category general
- this.buttonList.add(this.renderNameTag=new GuiButton(8, x/2-27, 49, 150, 20, this.showTagAlways ? I18n.format("gui.npc.showTagAlways") : I18n.format("gui.npc.showTagOnLook")));
- this.name=new GuiTextField(9, this.fontRendererObj, x/2-120, 49, 80, 20);
- this.texture=new GuiTextField(10, this.fontRendererObj, x/2-120, 78, 100, 20);
- this.deathSound=new GuiTextField(20, this.fontRendererObj, x/2-120, 107, 100, 20);
- this.hitSound=new GuiTextField(21, this.fontRendererObj, x/2-120, 136, 100, 20);
- //category attributes
- this.attMaxHealthVal=new GuiTextField(11, this.fontRendererObj, x/2-120, 49, 50, 20);
- this.attMaxHealthVal.setVisible(false);
- this.attMaxHealthVal.setEnabled(false);
- this.attMaxHealthVal.setMaxStringLength(5);
- this.attArmorVal=new GuiTextField(12, this.fontRendererObj, x/2-120, 78, 50, 20);
- this.attArmorVal.setVisible(false);
- this.attArmorVal.setEnabled(false);
- this.attArmorVal.setMaxStringLength(5);
- this.attMoveSpeedVal=new GuiTextField(13, this.fontRendererObj, x/2-120, 107, 50, 20);
- this.attMoveSpeedVal.setVisible(false);
- this.attMoveSpeedVal.setEnabled(false);
- this.attMoveSpeedVal.setMaxStringLength(5);
- this.attAttackSpeedVal=new GuiTextField(14, this.fontRendererObj, x/2+48, 49, 50, 20);
- this.attAttackSpeedVal.setVisible(false);
- this.attAttackSpeedVal.setEnabled(false);
- this.attAttackSpeedVal.setMaxStringLength(5);
- this.attArmorTghVal=new GuiTextField(15, this.fontRendererObj, x/2+48, 78, 50, 20);
- this.attArmorTghVal.setVisible(false);
- this.attArmorTghVal.setEnabled(false);
- this.attArmorTghVal.setMaxStringLength(5);
- this.buttonList.add(this.fireImmune=new GuiButton(16, x/2-124, 145, 80, 20, this.fireImm ? I18n.format("gui.npc.yes") : I18n.format("gui.npc.no")));
- this.buttonList.add(this.canDrown=new GuiButton(17, x/2-124, 174, 80, 20, this.drown ? I18n.format("gui.npc.yes") : I18n.format("gui.npc.no")));
- this.buttonList.add(this.sunBurns=new GuiButton(18, x/2+44, 145, 80, 20, this.sunMode==0 ? I18n.format("gui.npc.no") : (this.sunMode==1?I18n.format("gui.npc.yes"):I18n.format("gui.npc.flee"))));
- this.buttonList.add(this.fallDamage=new GuiButton(19, x/2+44, 174, 80, 20, this.fallDmg ? I18n.format("gui.npc.yes") : I18n.format("gui.npc.no")));
- //cat ai
- this.buttonList.add(this.canSwim=new GuiButton(22, x/2-124, 49, 80, 20, this.swim ? I18n.format("gui.npc.yes") : I18n.format("gui.npc.no")));
- this.buttonList.add(this.lookPlayer=new GuiButton(23, x/2-124, 78, 80, 20, this.lookMode==0 ? I18n.format("gui.npc.no") : (this.lookMode==1?I18n.format("gui.npc.lookIdle"):(this.lookMode==2?I18n.format("gui.npc.idleFollow"):I18n.format("gui.npc.follow")))));
- this.watchRange=new GuiTextField(24, this.fontRendererObj, x/2-35, 78, 50, 20);
- this.watchRange.setVisible(false);
- this.watchRange.setEnabled(false);
- this.watchRange.setMaxStringLength(5);
- this.buttonList.add(this.walking=new GuiButton(25, x/2-124, 107, 80, 20, this.walkMode==0 ? I18n.format("gui.npc.stand") : (this.walkMode==1?I18n.format("gui.npc.wander"):I18n.format("gui.npc.path"))));
- this.buttonList.add(this.attack=new GuiButton(26, x/2-124, 136, 80, 20, this.attackMode==0?I18n.format("gui.npc.no"):(this.attackMode==1?I18n.format("gui.npc.revenge"):(this.attackMode==2?I18n.format("gui.npc.nearest"):""))));
- //cat inventory
- //this.showInventory(false);
- this.name.setText(npc.getName());
- this.texture.setText(npc.getTexture());
- this.attMaxHealthVal.setText(String.valueOf(npc.getMaxHealth()));
- this.attArmorVal.setText(String.valueOf(npc.getArmor()));
- this.attMoveSpeedVal.setText(String.valueOf(npc.getMoveSpeed()).substring(0, 3));
- this.attAttackSpeedVal.setText(String.valueOf(npc.getAttackSpeed()));
- this.attArmorTghVal.setText(String.valueOf(npc.getArmorToughness()));
- this.deathSound.setText(npc.getDeathsSound());
- this.hitSound.setText(npc.getHitSound());
- this.watchRange.setText(String.valueOf(npc.getWatchRange()));
- }
- private void showInventory(boolean show){
- if(!show&&this.slotsShowing){
- List<Slot> slots=this.inventorySlots.inventorySlots;
- for(Slot slot:slots){
- int x=slot.xDisplayPosition;
- slot.xDisplayPosition=x-999;
- }
- }else if(show&&!this.slotsShowing){
- List<Slot> slots=this.inventorySlots.inventorySlots;
- for(Slot slot:slots){
- int x=slot.xDisplayPosition;
- slot.xDisplayPosition=x+999;
- }
- }
- this.slotsShowing=show;
- }
- public void switchCategory(int buttonID){
- switch(buttonID){
- case 0:{
- this.catGeneral.enabled=false;
- this.catAttributes.enabled=true;
- this.catAI.enabled=true;
- this.catInventory.enabled=true;
- //this.showInventory(false);
- //this.catModel.enabled=true;
- break;
- }
- case 1:{
- this.catGeneral.enabled=true;
- this.catAttributes.enabled=false;
- this.catAI.enabled=true;
- this.catInventory.enabled=true;
- //this.showInventory(false);
- //this.catModel.enabled=true;
- break;
- }
- case 2:{
- this.catGeneral.enabled=true;
- this.catAttributes.enabled=true;
- this.catAI.enabled=false;
- this.catInventory.enabled=true;
- //this.showInventory(false);
- //this.catModel.enabled=true;
- break;
- }
- case 3:{
- this.catGeneral.enabled=true;
- this.catAttributes.enabled=true;
- this.catAI.enabled=true;
- this.catInventory.enabled=false;
- //this.showInventory(true);
- //this.catModel.enabled=true;
- break;
- }
- /*case 4:{
- this.catGeneral.enabled=true;
- this.catAttributes.enabled=true;
- this.catAI.enabled=true;
- this.catInventory.enabled=true;
- this.catModel.enabled=false;
- break;
- }*/
- }
- }
- protected void actionPerformed(GuiButton button) throws IOException {
- switchCategory(button.id);
- switch(button.id){
- case 5:{
- NBTTagCompound data=new NBTTagCompound();
- data.setString("name", this.name.getText());
- data.setString("texture", this.texture.getText());
- data.setBoolean("showtag", this.showTagAlways);
- data.setDouble("maxHealth", Double.parseDouble(this.attMaxHealthVal.getText()));
- data.setDouble("armor", Double.parseDouble(this.attArmorVal.getText()));
- data.setDouble("movespeed", Double.parseDouble(this.attMoveSpeedVal.getText()));
- data.setDouble("attspeed", Double.parseDouble(this.attAttackSpeedVal.getText()));
- data.setDouble("armortgh", Double.parseDouble(this.attArmorTghVal.getText()));
- data.setBoolean("fireimmune", this.fireImm);
- data.setBoolean("candrown", this.drown);
- data.setInteger("sunburn", this.sunMode);
- data.setBoolean("falldmg", this.fallDmg);
- data.setString("hitSound", this.hitSound.getText());
- data.setString("deathSound", this.deathSound.getText());
- data.setBoolean("canSwim", this.swim);
- data.setInteger("lookMode", this.lookMode);
- data.setFloat("watchRange", Float.parseFloat(this.watchRange.getText()));
- data.setInteger("walkMode", this.walkMode);
- data.setInteger("attack", this.attackMode);
- PacketHandler.sendToServer(new S03PacketUpdateEntity(data,false,this.npc.getEntityId()));
- this.npc.setAttackMode(this.attackMode);
- this.mc.displayGuiScreen((GuiNPC)null);
- break;
- }
- case 6:{
- this.mc.displayGuiScreen((GuiNPC)null);
- break;
- }
- case 7:{
- PacketHandler.sendToServer(new S03PacketUpdateEntity(new NBTTagCompound(),true,this.npc.getEntityId()));
- this.mc.displayGuiScreen((GuiNPC)null);
- break;
- }
- case 8:{
- if(this.showTagAlways)
- this.renderNameTag.displayString=I18n.format("gui.npc.showTagOnLook");
- else
- this.renderNameTag.displayString=I18n.format("gui.npc.showTagAlways");
- this.showTagAlways=!showTagAlways;
- break;
- }
- case 16:{
- if(!this.fireImm)
- this.fireImmune.displayString=I18n.format("gui.npc.yes");
- else
- this.fireImmune.displayString=I18n.format("gui.npc.no");
- this.fireImm=!fireImm;
- break;
- }
- case 17:{
- if(!this.drown)
- this.canDrown.displayString=I18n.format("gui.npc.yes");
- else
- this.canDrown.displayString=I18n.format("gui.npc.no");
- this.drown=!drown;
- break;
- }
- case 18:{
- if(this.sunMode==0){
- this.sunMode=1;
- this.sunBurns.displayString=I18n.format("gui.npc.yes");
- }else if(this.sunMode==1){
- this.sunMode=2;
- this.sunBurns.displayString=I18n.format("gui.npc.flee");
- }else if(this.sunMode==2){
- this.sunMode=0;
- this.sunBurns.displayString=I18n.format("gui.npc.no");
- }else{
- this.sunMode=0;
- this.sunBurns.displayString=I18n.format("gui.npc.no");
- }
- break;
- }
- case 19:{
- if(!this.fallDmg)
- this.fallDamage.displayString=I18n.format("gui.npc.yes");
- else
- this.fallDamage.displayString=I18n.format("gui.npc.no");
- this.fallDmg=!fallDmg;
- break;
- }
- case 22:{
- if(!this.swim)
- this.canSwim.displayString=I18n.format("gui.npc.yes");
- else
- this.canSwim.displayString=I18n.format("gui.npc.no");
- this.swim=!swim;
- break;
- }
- case 23:{
- if(this.lookMode==0){
- this.lookMode=1;
- this.lookPlayer.displayString=I18n.format("gui.npc.lookIdle");
- }else if(this.lookMode==1){
- this.lookMode=2;
- this.lookPlayer.displayString=I18n.format("gui.npc.idleFollow");
- }else if(this.lookMode==2){
- this.lookMode=3;
- this.lookPlayer.displayString=I18n.format("gui.npc.follow");
- }else if(this.lookMode==3){
- this.lookMode=0;
- this.lookPlayer.displayString=I18n.format("gui.npc.no");
- }else{
- this.lookMode=0;
- this.lookPlayer.displayString=I18n.format("gui.npc.no");
- }
- break;
- }
- case 25:{
- if(this.walkMode==0){
- this.walkMode=1;
- this.walking.displayString=I18n.format("gui.npc.wander");
- }else if(this.walkMode==1){
- this.walkMode=2;
- this.walking.displayString=I18n.format("gui.npc.path");
- }else if(this.walkMode==2){
- this.walkMode=0;
- this.walking.displayString=I18n.format("gui.npc.stand");
- }else{
- this.walkMode=0;
- this.walking.displayString=I18n.format("gui.npc.stand");
- }
- break;
- }
- case 26:{
- if(this.attackMode==0){
- this.attackMode=1;
- this.attack.displayString=I18n.format("gui.npc.revenge");
- }else if(this.attackMode==1){
- this.attackMode=2;
- this.attack.displayString=I18n.format("gui.npc.nearest");
- }else if(this.attackMode==2){
- this.attackMode=0;
- this.attack.displayString=I18n.format("gui.npc.no");
- }else{
- this.attackMode=0;
- this.attack.displayString=I18n.format("gui.npc.no");
- }
- break;
- }
- }
- }
- public boolean doesGuiPauseGame() {
- return true;
- }
- protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
- super.mouseClicked(mouseX, mouseY, mouseButton);
- this.name.mouseClicked(mouseX, mouseY, mouseButton);
- this.texture.mouseClicked(mouseX, mouseY, mouseButton);
- this.attMaxHealthVal.mouseClicked(mouseX, mouseY, mouseButton);
- this.attArmorVal.mouseClicked(mouseX, mouseY, mouseButton);
- this.attMoveSpeedVal.mouseClicked(mouseX, mouseY, mouseButton);
- this.attAttackSpeedVal.mouseClicked(mouseX, mouseY, mouseButton);
- this.attArmorTghVal.mouseClicked(mouseX, mouseY, mouseButton);
- this.deathSound.mouseClicked(mouseX, mouseY, mouseButton);
- this.hitSound.mouseClicked(mouseX, mouseY, mouseButton);
- this.watchRange.mouseClicked(mouseX, mouseY, mouseButton);
- }
- protected void keyTyped(char typedChar, int keyCode) throws IOException {
- super.keyTyped(typedChar, keyCode);
- this.name.textboxKeyTyped(typedChar, keyCode);
- this.texture.textboxKeyTyped(typedChar, keyCode);
- this.attMaxHealthVal.textboxKeyTyped(typedChar, keyCode);
- this.attArmorVal.textboxKeyTyped(typedChar, keyCode);
- this.attMoveSpeedVal.textboxKeyTyped(typedChar, keyCode);
- this.attAttackSpeedVal.textboxKeyTyped(typedChar, keyCode);
- this.attArmorTghVal.textboxKeyTyped(typedChar, keyCode);
- this.hitSound.textboxKeyTyped(typedChar, keyCode);
- this.deathSound.textboxKeyTyped(typedChar, keyCode);
- this.watchRange.textboxKeyTyped(typedChar, keyCode);
- }
- protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
- this.drawDefaultBackground();
- GuiInventory.drawEntityOnScreen(this.width-50, this.height-100, 30, (float)(this.width-50) - this.oldMouseX, (float)(this.height-150) - this.oldMouseY, this.npc);
- }
- protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
- int x=this.width;
- this.name.drawTextBox();
- this.texture.drawTextBox();
- this.deathSound.drawTextBox();
- this.hitSound.drawTextBox();
- this.attMaxHealthVal.drawTextBox();
- this.attArmorVal.drawTextBox();
- this.attMoveSpeedVal.drawTextBox();
- this.attAttackSpeedVal.drawTextBox();
- this.attArmorTghVal.drawTextBox();
- this.watchRange.drawTextBox();
- if(!catGeneral.enabled){
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.name"), x/2-198, 54, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.texture"), x/2-198, 83, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.deathSound"), x/2-198, 112, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.hitSound"), x/2-198, 141, Color.WHITE.getRGB());
- }
- if(!catAttributes.enabled){
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.health"), x/2-198, 54, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.armor"), x/2-198, 83, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.speed"), x/2-198, 112, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.agility"), x/2-30, 54, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.toughness"), x/2-30, 83, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.immuneToFire"), x/2-198, 150, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.canDrown"), x/2-198, 179, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.sunDamage"), x/2-30, 150, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.prop.fallDamage"), x/2-30, 179, Color.WHITE.getRGB());
- }
- if(!catAI.enabled){
- drawString(this.fontRendererObj, I18n.format("gui.npc.swim"), x/2-198, 54, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.look"), x/2-198, 83, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.move"), x/2-198, 112, Color.WHITE.getRGB());
- drawString(this.fontRendererObj, I18n.format("gui.npc.revenge"), x/2-198, 141, Color.WHITE.getRGB());
- }
- super.drawGuiContainerForegroundLayer(mouseX, mouseY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment