...So I'd just look into the attackEntity void and pretty much copy the directional code? Ah, thanks. Unfortunately, I am incapable of working with keybindings (I know there's a Modloader function with it, and since my mod ATM is currently using Modloader, I could use it but I can't figure it out. I'm so incompetent. >_<)
Don't worry, you'll figure it out, whether you do it now, or later with more experience.
When I first ported my code to Forge after running out of sprites I had a hell of a time trying to add my arrows back in with the provided hooks. I eventually had to give up on trying. Later when I had more experience I had a moment where I realized "HERP DERP all I have to do is this tiny simple thing...DERP" and had it working in ~5 minutes.
Unfortunately I haven't done keybinds either or I'd be a bigger help here.
I don't know how Forge works, but I know that when the player dies it simply empties out the players inventory.
EntityPlayer.java, onDeath(). Look for inventory.dropAllItems();. Hopefully that will give you something more to go off of
Edit: Actually, in theory you could create an inventory identical to the players. If the conditions are met, then when the player respawns you'd set his/her inventory to the one you've created. Or something.
Your edit restates what I already said I knew, and already said I was trying to do.
Also, editing EntityPlayer.onDeath() doesn't do what you would expect, and would require editing EntityPlayer anyway. I've already tried it.
It does not simply empty the player's inventory, that method is there to force-drop all of the items before respawning, because when you respawn it deletes the inventory.
I've never used forge so I'm not sure exactly how it works, but what I would do is I would make a new IInventory object and just set it to the players inventory ItemStack by ItemStack using a for loop (because just doing = means when one changes the other does too, at least that's how it's seemed to me when messing with this), but only do this if the conditions are met
then when the player respawns, use another for loop with the saved items and the players inventory, taking the copied items and giving them back to the player
Yeah I've got a feeling I'll have to figure that out...unless what I'm trying now works.
java.lang.NullPointerException
at net.minecraft.src.ItemStack.getIconIndex(ItemStack.java:105)
at net.minecraft.src.RenderItem.renderItemIntoGUI(RenderItem.java:270)
Well from that your either declaring the icon index wrong or havent done so at all
Hello everyone. I'm currently attempting to develop a way for the player to "keep" their inventory after they've died if certain conditions are met. Unfortunately, however, I'm a bit stuck on exactly how to pull this off; here's the full situation:
Mods/APIs:
ModLoader
Forge API
The file I'm editing:
EntityUpdateHandler, which implements IEntityUpdateHandler
What IEntityUpdateHandler is and why I made it:
IEntityUpdateHandler is a custom Forge interface that I wrote earlier today. I'm currently testing it, and if it serves its purpose I'll message one of the Forge team and ask them if they'll patch it into the main API. The purpose of this interface is to provide a direct hook into Entity.onEntityUpdate() at the beginning and end of the method, because that is the root updating method of all Entities, and hooking into it means that modders will have access to a one-stop-shop for modifying the tick updating function of any Entity they desire. Currently this hook functions as intended.
The contents of the current file, what I have working, and what I need help with:
EntityUpdateHandler:
package net.minecraft.src;
import net.minecraft.src.forge.IEntityUpdateHandler;
public class EntityUpdateHandler implements IEntityUpdateHandler
{
/** The first time onEntityUpdateStart(entity) has been run */
private boolean firstTime1 = true;
/** The first time onEntityUpdateEnd(entity) has been run */
private boolean firstTime2 = true;
/** The instance of Entity passed in */
private Entity theEntity;
/** Set on the tick that the player is determined as dead */
private boolean playerHasDied = false;
public void onEntityUpdateStart(Entity entity)
{
this.theEntity = entity;
/* Prints a short message into the console at the start of the first tick that the player updates
* Used for insuring that this method was run */
if (entity instanceof EntityPlayer)
{
if (this.firstTime1)
{
System.out.println("Start!");
this.firstTime1 = false;
}
/* If the "deathTime" field in EntityPlayer is above 0 the player is dead,
* as such I've used it as the means of detecting when the player is dead or alive.
* This performs detection correctly. */
if (((EntityPlayer) entity).deathTime > 0)
{
this.playerHasDied = true;
System.out.println(((EntityPlayer) entity).deathTime + " " + playerHasDied);
}
/* If the player has died and the "deathTime" field in EntityPlayer is now 0
* then the player is alive again, thus this is used to detect when the player has been respawned.
* This performs detection correctly. */
if (playerHasDied == true && ((EntityPlayer) entity).deathTime == 0)
{
playerHasDied = false;
System.out.println(((EntityPlayer) entity).deathTime + " " + playerHasDied);
}
}
}
public void onEntityUpdateEnd(Entity entity)
{
this.theEntity = entity;
/* Prints a short message into the console at the end of the first tick that the player updates
* Used for insuring that this method was run */
if (entity instanceof EntityPlayer)
{
if (this.firstTime2)
{
System.out.println("End!");
this.firstTime2 = false;
}
}
}
}
The fields used are commented with clear javadoc descriptions.
As you can see by the remaining comments in the code, I have all of the methods running correctly, and all of the code for detecting when the player is dead and alive functioning correctly.
Now that that's out of the way, here's my problem.
EntityPlayer and related Inventory classes possess several methods for managing the contents of the player's inventory, including one that should allow you to copy the entire contents of the inventory and store it in an instance of InventoryPlayer. I've determined that I need to store a copy of the player inventory each tick prior to death, and then reapply the inventory to the player after a respawn is detected, however, I can neither figure out how to store a copy of the inventory, nor reapply the inventory from the instance of InventoryPlayer that it's stored in.
In short:
How do I store the player's inventory in an instance of InventoryPlayer?
How do I reapply an instance of InventoryPlayer containing a copy of the inventory to the player?
ok, it doesn't work, how would i work out the texture ID?
I honestly don't know...:mellow:
ModLoader doesn't always assign the same texture to the same texture ID, so having it use a specific number won't work...
If you could find a way to get the ID of the texture ModLoader assigns you could assign it to a variable and use that variable in the block initilializing line...but I don't know how to do that.
EDIT: reread your post, so that means i can pass it the front texture, but i use a custom texture for it, so it doesn't have any coords... Still rather confusing.
When you use ModLoader to override a texture, ModLoader actually places that sprite into a free terrain.png/items.png slot in memory, and thus its ID becomes the ID of that texture slot.
In this typical line of texture assignment code, the iconIndex of the specified item is assigned as the ModLoader override.
In theory (I haven't done this and don't have my normal mod open for an immediate test) you could just place the
"ModLoader.addOverride("/gui/items.png", "/ModTextures/Items/NameHere.png");" line in place of the number for the texture ID.
ahh, i get what you mean, so the boolean should be true. But what about those extra ints and Material. Would i give the public static final line, the par3 int, for the int, and the par4Material for the material.
or do i give the int the render function, 18. I'm rather confused.
The first two ints and the Material are the exact same as any normal block.
The unfamiliar int should probably be the same texture ID as you used for the block. (it's a texture ID, same as normal, but for the side of the block, rather than its face)
You already understand the boolean.
i'm working on making a pane-like block, since i had no idea how, i used the BlockPane class. But minecraft didn't like me doing that unless i added this to my
public static final RiceScreen = new BlockRiceScreen(141, 0).//etc etc
:
new BlockRiceScreen(141,0,0,Material.glass, false).//etc etc
. But whenever i placed the block ingame, the game crashed. The annoying thing is, it doesn't give you the error report, in ModLoader.txt or on screen. So could someone explain what the extra int and boolean mean, I searched the BlockPane code for anything that would give some insight, but to no avail.
The field names and constructor of the BlockPane class tell you exactly what they do...hell, they're the only two things there that are explicitly enumerated in a unique way.
1
If you can't find the IDs of the potions then you haven't progressed far enough in your education to need to know how to apply them to Entities.
0
entity.addPotionEffect(effectID, durationInSeconds*20)
Where entity is the entity being hit.
It's something similar to that, too lazy to go look in my own stuff.
0
0
Don't worry, you'll figure it out, whether you do it now, or later with more experience.
When I first ported my code to Forge after running out of sprites I had a hell of a time trying to add my arrows back in with the provided hooks. I eventually had to give up on trying. Later when I had more experience I had a moment where I realized "HERP DERP all I have to do is this tiny simple thing...DERP" and had it working in ~5 minutes.
Unfortunately I haven't done keybinds either or I'd be a bigger help here.
0
Your edit restates what I already said I knew, and already said I was trying to do.
Also, editing EntityPlayer.onDeath() doesn't do what you would expect, and would require editing EntityPlayer anyway. I've already tried it.
It does not simply empty the player's inventory, that method is there to force-drop all of the items before respawning, because when you respawn it deletes the inventory.
0
Yeah I've got a feeling I'll have to figure that out...unless what I'm trying now works.
0
this
0
Mods/APIs:
ModLoader
Forge API
The file I'm editing:
EntityUpdateHandler, which implements IEntityUpdateHandler
What IEntityUpdateHandler is and why I made it:
IEntityUpdateHandler is a custom Forge interface that I wrote earlier today. I'm currently testing it, and if it serves its purpose I'll message one of the Forge team and ask them if they'll patch it into the main API. The purpose of this interface is to provide a direct hook into Entity.onEntityUpdate() at the beginning and end of the method, because that is the root updating method of all Entities, and hooking into it means that modders will have access to a one-stop-shop for modifying the tick updating function of any Entity they desire. Currently this hook functions as intended.
The contents of the current file, what I have working, and what I need help with:
EntityUpdateHandler:
The fields used are commented with clear javadoc descriptions.
As you can see by the remaining comments in the code, I have all of the methods running correctly, and all of the code for detecting when the player is dead and alive functioning correctly.
Now that that's out of the way, here's my problem.
EntityPlayer and related Inventory classes possess several methods for managing the contents of the player's inventory, including one that should allow you to copy the entire contents of the inventory and store it in an instance of InventoryPlayer. I've determined that I need to store a copy of the player inventory each tick prior to death, and then reapply the inventory to the player after a respawn is detected, however, I can neither figure out how to store a copy of the inventory, nor reapply the inventory from the instance of InventoryPlayer that it's stored in.
In short:
How do I store the player's inventory in an instance of InventoryPlayer?
How do I reapply an instance of InventoryPlayer containing a copy of the inventory to the player?
Help is highly appreciated.
0
I honestly don't know...:mellow:
ModLoader doesn't always assign the same texture to the same texture ID, so having it use a specific number won't work...
If you could find a way to get the ID of the texture ModLoader assigns you could assign it to a variable and use that variable in the block initilializing line...but I don't know how to do that.
0
When you use ModLoader to override a texture, ModLoader actually places that sprite into a free terrain.png/items.png slot in memory, and thus its ID becomes the ID of that texture slot.
If you'll notice:
In this typical line of texture assignment code, the iconIndex of the specified item is assigned as the ModLoader override.
In theory (I haven't done this and don't have my normal mod open for an immediate test) you could just place the
"ModLoader.addOverride("/gui/items.png", "/ModTextures/Items/NameHere.png");" line in place of the number for the texture ID.
Try that and tell me if it actually lets you.
0
That doesn't answer the question.
We don't know whether he actually needs a new instance of the player or not.
0
Accessing EntityPlayer from Entity, for example, is trivial.
0
The first two ints and the Material are the exact same as any normal block.
The unfamiliar int should probably be the same texture ID as you used for the block. (it's a texture ID, same as normal, but for the side of the block, rather than its face)
You already understand the boolean.
0
The field names and constructor of the BlockPane class tell you exactly what they do...hell, they're the only two things there that are explicitly enumerated in a unique way.
0
Yeah that "fix" just makes it use the EnumArmorMaterial for diamond, rather than a new one. It's a pain...