I create my Mod for new Custom Armor slot but, it not work Please, help me for fix code.
Thank.
In your main class:
// your mod id should be all lower case: "jamigapack1" is ok, "JamigaPack1" is not
@Mod(modid="JamigaPack1", name="JamigaPack1", version="1.6.4")
// this should use your mod id, not some random name
@Instance("mod_Armor_main")
In your CommonProxy:
// wtf... you put @SideOnly(Side.CLIENT) for "getSERVERGuiElement"... did you even bother to read the code?
@SideOnly(Side.CLIENT)
@Override
public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z)
// why do you have this when you already registered the GuiHandler in your main class???
public void registerGuiHandler() {
NetworkRegistry.instance().registerGuiHandler(this, new CommonProxy());
}
My advice to you is to take some time to READ the code that you are writing, and if you are not writing it yourself but just pasting it in, STOP IT. Copy / paste is not your friend. Take the time to type everything in yourself so you can better understand what is going on.
Finally updated the Custom Player Inventory code, specifically the KeyHandler portion, as well as cleaning up and fixing some other parts that were not very clear. Hopefully it is easier to follow along now.
Thanks CoolAlias for help , I have remove Public static ClientProxy cproxy;
If you can't even pick up items when you open your custom inventory GUI, I suggest you read through the tutorial again and make sure you followed each step exactly. By that I don't mean you copy and paste it exactly, I mean you READ and understand what each part is doing.
For example, in your Container class, you have this code:
for (i = 0; i < InventaireAccessoires.INV_SIZE; ++i)
{
this.addSlotToContainer(new SlotAmulette(inventory, 0, 80, 8));
this.addSlotToContainer(new SlotAnneaux(inventory, 1, 80, 26));
this.addSlotToContainer(new SlotAnneaux(inventory, 2, 80, 52));
this.addSlotToContainer(new SlotCape(inventory, 3, 80, 70));
}
Does that code make any sense to you? Why on earth would you keep the 'for' loop if you are not using it for your slots? The way you've done it, you are adding each slot FOUR times!
Now i can make customslot.
Thank you very much coolAlias.
but i need render 3D model if i wearing ItemWing in customslot.
who can help me.
if item wearing in ArmorSlot
if item wearing in customslot
customslot class
[/background][/size][/font][/color]
public class SlotCustom extends Slot
{
public SlotCustom(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots
* (and now also not always true for our custom inventory slots)
*/
@Override
public boolean isItemValid(ItemStack itemstack)
{
// We only want our custom item to be storable in this slot
switch (this.getSlotIndex())
{
case 0:
return itemstack.getItem() instanceof ItemArmor;
case 1:
return itemstack.getItem() instanceof ItemSword;
}
return super.isItemValid(itemstack);
}
}
[color=#282828][font=Verdana, Geneva, Tahoma, sans-serif][size=small][background=rgb(232, 239, 244)]
ItemWing Class
[/background][/size][/font][/color]
public class MyCraftWing1 extends ItemArmor
{
private static final ModelBiped var10 = new WingModel(0.01f);
private static EnumArmorMaterial enuma = EnumHelper.addArmorMaterial("Wing", -1, new int[] {1, 4, 4, 4}, 1);
public Icon overlayIcon;
public MyCraftWing1(int par1)
{
super(par1, enuma, 0, 0);
}
@SideOnly(Side.CLIENT)
public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer)
{
return "textures/Wing01.png";
}
@SideOnly(Side.CLIENT)
public ModelBiped getArmorModel(int id){
return var10; //default, if whenever you should have passed on a wrong id
}
@SideOnly(Side.CLIENT)
ModelBiped armorModel = new ModelBiped();
public ModelBiped getArmorModel(EntityLivingBase entityLiving,
ItemStack itemStack, int armorSlot) {
if(itemStack != null){
if(itemStack.getItem() instanceof MyCraftWing1){
int type = ((ItemArmor)itemStack.getItem()).armorType;
if(type == 1 || type == 1){
armorModel = getArmorModel(1);
}else{
armorModel = getArmorModel(1);
}
}
if(armorModel != null){
armorModel.bipedHead.showModel = armorSlot == 3;
armorModel.bipedHeadwear.showModel = armorSlot == 3;
armorModel.bipedBody.showModel = armorSlot == 0;
armorModel.bipedRightArm.showModel = armorSlot == 3;
armorModel.bipedLeftArm.showModel = armorSlot == 3;
armorModel.bipedRightLeg.showModel = armorSlot == 3;
armorModel.bipedLeftLeg.showModel = armorSlot == 3;
armorModel.isSneak = entityLiving.isSneaking();
armorModel.isRiding = entityLiving.isRiding();
armorModel.isChild = entityLiving.isChild();
armorModel.heldItemRight = entityLiving.getCurrentItemOrArmor(0) != null ? 1 :0;
return armorModel;
}
}
return null;
}
}
[color=#282828][font=Verdana, Geneva, Tahoma, sans-serif][size=small][background=rgb(232, 239, 244)]
Now i can make customslot.
Thank you very much coolAlias.
but i need render 3D model if i wearing ItemWing in customslot.
who can help me.
In your custom GuiContainer class, you should have a method for rendering the player model already, right? You have access to the container and the player, so you can check if your custom slot has the appropriate item before rendering the model, and render your wings.
// in this method, if you remove the static modifier, you have access to whatever inventory/player etc.
// that you may have stored as class fields, as well as the inventorySlots that include ALL of the slots
// if you want to keep it static so that you can reuse the same method in many different GUIs, you still
// have access to the EntityLivingBase parameter, which is likely really an EntityPlayer:
public void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) {
// provided you stored your custom inventory in a local field named 'inventory' in the constructor:
if (this.inventory.getStackInSlot(yourCustomSlotIndex) != null && it's your item) {
// render your wings
}
// or if your method is still static:
if (entity instanceof EntityPlayer) {
// get your custom inventory slots from the player's extended properties, and check the slot:
IInventory inventory = ExtendedPlayer.get((EntityPlayer) entity).getInventory(); // or however you access the inventory
if (inventory.getStackInSlot(yourCustomSlotIndex) != null && it's your item) {
// render wings
}
}
// standard player model render code can go here
}
If you mean you just want to add an extra index for your own use, you could try simply using "4" or "5" as the armor type when you construct your custom armors. In the vanilla ItemArmor class, armorType is only used for registering the icons anyway, and if you've overridden everything properly, it may just work. That being said, it could also cause unforeseen crashes, depending on what else, if anything, armorType gets used for in Minecraft.
What do you need to add another armor type value for? It's not going to let you use "player.getCurrentArmor(5)" or add itself automatically to anything like armor value, unless you're willing to do a lot of byte-code manipulation (ASM) and rewrite major portions of the EntityLivingBase / EntityPlayer code.
So depending on what, exactly, you are trying to do will determine how you should approach the issue.
I have a problem with Gui Handler. When I press the button, the packet is successfully delivered to the server, but the action in my GuiHanler class takes place only in original Container. GUI is not called. Can you help me?
I have a problem with Gui Handler. When I press the button, the packet is successfully delivered to the server, but the action in my GuiHanler class takes place only in original Container. GUI is not called. Can you help me?
Not if you don't post your code. I need to at least see the GuiHandler class for starters. You could also compare your code to the 1.7.2 example mod I have on my github repo; I've implemented both types of inventories in it.
The Meaning of Life, the Universe, and Everything.
Join Date:
8/9/2013
Posts:
211
Minecraft:
HappyKiller1O1
Xbox:
HappyKiller101
Member Details
So, I messaged you cool, about the packet troubles I was having but, I fixed them by looking over what I did wrong. But I got another question I have two slots "SlotRing" and "SlotAmulet", I would like to have different potion effects when the ring or amulet is in it's correct slot but, I am having troubles figuring this out. I have searched all over the internet trying to find something but to no avail. I would really love some help on this so I can get my alpha version out. Also, thank you for all of your tutorials, you have helped me avoid a lot of the frustration while coding and you have filled m brain with knowledge to make many things I could only dream of adding to my mods. I hope you know how many people you have helped with their coding and I hope you're more appreciated for the talent you have as a teacher. Anyway, enough of my rambling XD Thanks in advance for helping
So, I messaged you cool, about the packet troubles I was having but, I fixed them by looking over what I did wrong. But I got another question I have two slots "SlotRing" and "SlotAmulet", I would like to have different potion effects when the ring or amulet is in it's correct slot but, I am having troubles figuring this out. I have searched all over the internet trying to find something but to no avail. I would really love some help on this so I can get my alpha version out. Also, thank you for all of your tutorials, you have helped me avoid a lot of the frustration while coding and you have filled m brain with knowledge to make many things I could only dream of adding to my mods. I hope you know how many people you have helped with their coding and I hope you're more appreciated for the talent you have as a teacher. Anyway, enough of my rambling XD Thanks in advance for helping
- Joey
Thanks xD In order to add potion effects, since your custom inventory slots may or may not get their Item onUpdate method called (I think not, unless you do so yourself), you need to use one of the player update ticks to check.
You can use either the LivingUpdateEvent and check if the entity is an instanceof EntityPlayer, or you can use the PlayerTickEvent, which in this case would be the better option. Basically, you must check every single tick if the player's custom inventory slots contain one of your items, and call the onUpdate or onArmorTick method of your Item class, then let the Item determine what effect it will have.
Thanks xD In order to add potion effects, since your custom inventory slots may or may not get their Item onUpdate method called (I think not, unless you do so yourself), you need to use one of the player update ticks to check.
You can use either the LivingUpdateEvent and check if the entity is an instanceof EntityPlayer, or you can use the PlayerTickEvent, which in this case would be the better option. Basically, you must check every single tick if the player's custom inventory slots contain one of your items, and call the onUpdate or onArmorTick method of your Item class, then let the Item determine what effect it will have.
Well, there is no "PlayerTickEvent". Do you mean using a tick handler? And, how would I check if they are my slots? Do I call the onUpdate method in my IInventory or Container class? Sorry if these are simple questions, I'm always wanting to learn. XD
So.. i have new problem. I want make sync my slot on the server like a armor and equipment item. in minecraft 1.5.2 was packet which sync it (id 5). But in new minecraft version packet handling was changed and i can't found it.
p.s. Really big thx for this tutirial!
p.s.s Sorry for my English
Well, there is no "PlayerTickEvent". Do you mean using a tick handler? And, how would I check if they are my slots? Do I call the onUpdate method in my IInventory or Container class? Sorry if these are simple questions, I'm always wanting to learn. XD
Are you coding in 1.6.4? If so, then you need to use ITickHandler for the player tick type; 1.7.2 uses various Tick Events instead.
There is no need to check if they are your slots; get your custom inventory that you made from the extended properties, just as you do for interacting with the custom inventory any other time, and you have your slots.
No, you don't call any update method in the inventory or container - you get whatever Item is in each slot, and call the Item's onUpdate / onArmorTick method.
So.. i have new problem. I want make sync my slot on the server like a armor and equipment item. in minecraft 1.5.2 was packet which sync it (id 5). But in new minecraft version packet handling was changed and i can't found it.
p.s. Really big thx for this tutirial!
p.s.s Sorry for my English
Your inventory slots should only be changed on the server anyway, and should update automatically on the client if you set everything up correctly; there is no need for you to use packets for the inventory.
I just tried it out but onUpdate is also called if the Item is in your hotbar. So I think you have to check and apply it
Item#onUpdate is called when the item is anywhere in the inventory, not just the hotbar; it was merely a suggestion, and if you want your Item to continue updating when it is also in a custom slot, you should probably call it anyway in addition to the armor tick update (which is only called for armor when equipped) or some custom method you create yourself that is specifically for items that go in your custom slots.
Are you coding in 1.6.4? If so, then you need to use ITickHandler for the player tick type; 1.7.2 uses various Tick Events instead.
There is no need to check if they are your slots; get your custom inventory that you made from the extended properties, just as you do for interacting with the custom inventory any other time, and you have your slots.
No, you don't call any update method in the inventory or container - you get whatever Item is in each slot, and call the Item's onUpdate / onArmorTick method.
One more slight question that, I know, is quite stupid. But, do I put it in the Server or Client tick handler? And, how exactly would I get my InventoryExtended from ExtendedPlayer? Again, I'm sorry if I sound like I don't seem to know much. I just, want to get everything right the first time or, at least, semi-right. XDAnd, I am coding in 1.6.4 XD Maybe I should put "I AM CODING IN 1.6.4" as my signature. XD
The Meaning of Life, the Universe, and Everything.
Join Date:
8/9/2013
Posts:
211
Minecraft:
HappyKiller1O1
Xbox:
HappyKiller101
Member Details
Also, one more thing. XD How do I give my slot a custom background icon? This has giving me much frustration. Oh, and sorry about all the questions; but hey, questions are what form the mind to ask more questions.
The Meaning of Life, the Universe, and Everything.
Join Date:
8/9/2013
Posts:
211
Minecraft:
HappyKiller1O1
Xbox:
HappyKiller101
Member Details
And, yes, another question. I am trying to add flying to the player, while in survival mode and, while having this certain item in the custom slot but, it's not seeming to work. Here's the code:
Note: I already checked if the slot is not equal to null and such.
Please, help me for fix code.
--- ClientProxy ---
http://pastebin.com/YE2sFhMN
--- CommonProxy ---
http://pastebin.com/hH4sU57S
--- MainMod ---
http://pastebin.com/nVc9iTD5
--- ContainerCustomPlayer ---
http://pastebin.com/G33tCgsG
--- ExtendedPlayer ---
http://pastebin.com/NL9MiCRS
--- GuiCustomPlayerInventory ---
http://pastebin.com/zatQpUW6
--- InventoryCustomPlayer ---
http://pastebin.com/mEbGstKn
--- PacketHandler ---
http://pastebin.com/3LUegfga
--- PacketOpenServerGui ---
http://pastebin.com/mJmWWhAU
--- RegisterKeyBindings ---
http://pastebin.com/9TN69qJq
--- TutEventHandler ---
http://pastebin.com/jEHSvaYp
Thank.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIn your main class:
// your mod id should be all lower case: "jamigapack1" is ok, "JamigaPack1" is not @Mod(modid="JamigaPack1", name="JamigaPack1", version="1.6.4") // this should use your mod id, not some random name @Instance("mod_Armor_main")In your CommonProxy:
// wtf... you put @SideOnly(Side.CLIENT) for "getSERVERGuiElement"... did you even bother to read the code? @SideOnly(Side.CLIENT) @Override public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z) // why do you have this when you already registered the GuiHandler in your main class??? public void registerGuiHandler() { NetworkRegistry.instance().registerGuiHandler(this, new CommonProxy()); }My advice to you is to take some time to READ the code that you are writing, and if you are not writing it yourself but just pasting it in, STOP IT. Copy / paste is not your friend. Take the time to type everything in yourself so you can better understand what is going on.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf you can't even pick up items when you open your custom inventory GUI, I suggest you read through the tutorial again and make sure you followed each step exactly. By that I don't mean you copy and paste it exactly, I mean you READ and understand what each part is doing.
For example, in your Container class, you have this code:
for (i = 0; i < InventaireAccessoires.INV_SIZE; ++i) { this.addSlotToContainer(new SlotAmulette(inventory, 0, 80, 8)); this.addSlotToContainer(new SlotAnneaux(inventory, 1, 80, 26)); this.addSlotToContainer(new SlotAnneaux(inventory, 2, 80, 52)); this.addSlotToContainer(new SlotCape(inventory, 3, 80, 70)); }Does that code make any sense to you? Why on earth would you keep the 'for' loop if you are not using it for your slots? The way you've done it, you are adding each slot FOUR times!
Thank you very much coolAlias.
but i need render 3D model if i wearing ItemWing in customslot.
who can help me.
if item wearing in ArmorSlot
if item wearing in customslot
customslot class
[/background][/size][/font][/color] public class SlotCustom extends Slot { public SlotCustom(IInventory inventory, int slotIndex, int x, int y) { super(inventory, slotIndex, x, y); } /** * Check if the stack is a valid item for this slot. Always true beside for the armor slots * (and now also not always true for our custom inventory slots) */ @Override public boolean isItemValid(ItemStack itemstack) { // We only want our custom item to be storable in this slot switch (this.getSlotIndex()) { case 0: return itemstack.getItem() instanceof ItemArmor; case 1: return itemstack.getItem() instanceof ItemSword; } return super.isItemValid(itemstack); } } [color=#282828][font=Verdana, Geneva, Tahoma, sans-serif][size=small][background=rgb(232, 239, 244)]ItemWing Class
[/background][/size][/font][/color] public class MyCraftWing1 extends ItemArmor { private static final ModelBiped var10 = new WingModel(0.01f); private static EnumArmorMaterial enuma = EnumHelper.addArmorMaterial("Wing", -1, new int[] {1, 4, 4, 4}, 1); public Icon overlayIcon; public MyCraftWing1(int par1) { super(par1, enuma, 0, 0); } @SideOnly(Side.CLIENT) public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer) { return "textures/Wing01.png"; } @SideOnly(Side.CLIENT) public ModelBiped getArmorModel(int id){ return var10; //default, if whenever you should have passed on a wrong id } @SideOnly(Side.CLIENT) ModelBiped armorModel = new ModelBiped(); public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, int armorSlot) { if(itemStack != null){ if(itemStack.getItem() instanceof MyCraftWing1){ int type = ((ItemArmor)itemStack.getItem()).armorType; if(type == 1 || type == 1){ armorModel = getArmorModel(1); }else{ armorModel = getArmorModel(1); } } if(armorModel != null){ armorModel.bipedHead.showModel = armorSlot == 3; armorModel.bipedHeadwear.showModel = armorSlot == 3; armorModel.bipedBody.showModel = armorSlot == 0; armorModel.bipedRightArm.showModel = armorSlot == 3; armorModel.bipedLeftArm.showModel = armorSlot == 3; armorModel.bipedRightLeg.showModel = armorSlot == 3; armorModel.bipedLeftLeg.showModel = armorSlot == 3; armorModel.isSneak = entityLiving.isSneaking(); armorModel.isRiding = entityLiving.isRiding(); armorModel.isChild = entityLiving.isChild(); armorModel.heldItemRight = entityLiving.getCurrentItemOrArmor(0) != null ? 1 :0; return armorModel; } } return null; } } [color=#282828][font=Verdana, Geneva, Tahoma, sans-serif][size=small][background=rgb(232, 239, 244)]-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIn your custom GuiContainer class, you should have a method for rendering the player model already, right? You have access to the container and the player, so you can check if your custom slot has the appropriate item before rendering the model, and render your wings.
// in this method, if you remove the static modifier, you have access to whatever inventory/player etc. // that you may have stored as class fields, as well as the inventorySlots that include ALL of the slots // if you want to keep it static so that you can reuse the same method in many different GUIs, you still // have access to the EntityLivingBase parameter, which is likely really an EntityPlayer: public void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) { // provided you stored your custom inventory in a local field named 'inventory' in the constructor: if (this.inventory.getStackInSlot(yourCustomSlotIndex) != null && it's your item) { // render your wings } // or if your method is still static: if (entity instanceof EntityPlayer) { // get your custom inventory slots from the player's extended properties, and check the slot: IInventory inventory = ExtendedPlayer.get((EntityPlayer) entity).getInventory(); // or however you access the inventory if (inventory.getStackInSlot(yourCustomSlotIndex) != null && it's your item) { // render wings } } // standard player model render code can go here }I have a question.
this vanilla Armor Type 0 = helm / 1 = chest / 2 = leg / 3 = boot
How i can add more Armor type.
-- example --
0 = helm / 1 = chest / 2 = leg / 3 = boot / 4 = wing / 5 = sheild
(sorry i,m bad eng)
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf you mean you just want to add an extra index for your own use, you could try simply using "4" or "5" as the armor type when you construct your custom armors. In the vanilla ItemArmor class, armorType is only used for registering the icons anyway, and if you've overridden everything properly, it may just work. That being said, it could also cause unforeseen crashes, depending on what else, if anything, armorType gets used for in Minecraft.
What do you need to add another armor type value for? It's not going to let you use "player.getCurrentArmor(5)" or add itself automatically to anything like armor value, unless you're willing to do a lot of byte-code manipulation (ASM) and rewrite major portions of the EntityLivingBase / EntityPlayer code.
So depending on what, exactly, you are trying to do will determine how you should approach the issue.
Minecraft 1.7.2
Forge 1.7.2-10.12.0.1024
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNot if you don't post your code. I need to at least see the GuiHandler class for starters. You could also compare your code to the 1.7.2 example mod I have on my github repo; I've implemented both types of inventories in it.
- Joey
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThanks xD In order to add potion effects, since your custom inventory slots may or may not get their Item onUpdate method called (I think not, unless you do so yourself), you need to use one of the player update ticks to check.
You can use either the LivingUpdateEvent and check if the entity is an instanceof EntityPlayer, or you can use the PlayerTickEvent, which in this case would be the better option. Basically, you must check every single tick if the player's custom inventory slots contain one of your items, and call the onUpdate or onArmorTick method of your Item class, then let the Item determine what effect it will have.
See here for more information on using Events.
Well, there is no "PlayerTickEvent". Do you mean using a tick handler? And, how would I check if they are my slots? Do I call the onUpdate method in my IInventory or Container class? Sorry if these are simple questions, I'm always wanting to learn. XD
p.s. Really big thx for this tutirial!
p.s.s Sorry for my English
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAre you coding in 1.6.4? If so, then you need to use ITickHandler for the player tick type; 1.7.2 uses various Tick Events instead.
There is no need to check if they are your slots; get your custom inventory that you made from the extended properties, just as you do for interacting with the custom inventory any other time, and you have your slots.
No, you don't call any update method in the inventory or container - you get whatever Item is in each slot, and call the Item's onUpdate / onArmorTick method.
Your inventory slots should only be changed on the server anyway, and should update automatically on the client if you set everything up correctly; there is no need for you to use packets for the inventory.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumItem#onUpdate is called when the item is anywhere in the inventory, not just the hotbar; it was merely a suggestion, and if you want your Item to continue updating when it is also in a custom slot, you should probably call it anyway in addition to the armor tick update (which is only called for armor when equipped) or some custom method you create yourself that is specifically for items that go in your custom slots.
One more slight question that, I know, is quite stupid. But, do I put it in the Server or Client tick handler? And, how exactly would I get my InventoryExtended from ExtendedPlayer? Again, I'm sorry if I sound like I don't seem to know much. I just, want to get everything right the first time or, at least, semi-right. XDAnd, I am coding in 1.6.4 XD Maybe I should put "I AM CODING IN 1.6.4" as my signature. XD
This is in my "onPlayerTick" method in my ServerTickHandler. It seems to work but, is there a more efficient way?
if(props.inventory.getStackInSlot(props.inventory.SLOT_RING) != null) { if(props.inventory.getStackInSlot(props.inventory.SLOT_RING).itemID == HappyCraftMod.ShadowstoneRing.itemID) { player.addPotionEffect(new PotionEffect(Potion.resistance.getId(), 40, 3)); player.addPotionEffect(new PotionEffect(Potion.weakness.getId(), 40, 2)); } }Note: I already checked if the slot is not equal to null and such.
if(props.inventory.getStackInSlot(props.inventory.SLOT_AMULET).itemID == HappyCraftMod.DragonSoulAmulet.itemID) { player.capabilities.allowFlying = true; }