The Meaning of Life, the Universe, and Everything.
Join Date:
11/17/2016
Posts:
363
Location:
USA (sadly)
Minecraft:
FavouriteDragon
Member Details
So I made a custom entity (SwordBeam, based off of Kirby's sword beam), and I made that when I right click my custom sword, I shoot out my entity. However, it crashes every time. SwordBeam code:
Your entity class is abstract, meaning you can't instantiate an instance of it. That really shouldn't even compile properly - regardless, don't make it abstract and it should work.
The Meaning of Life, the Universe, and Everything.
Join Date:
11/17/2016
Posts:
363
Location:
USA (sadly)
Minecraft:
FavouriteDragon
Member Details
It still crashes... (Btw, I really like Levels. It's awesome :D)
java.lang.NullPointerException: Unexpected error
at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClick(PlayerControllerMP.java:530)
at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1624)
at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2276)
at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2053)
Why are you specifying the onImpact method again? In your sword class, you should create an instance of your entity (SwordBeam entity = new SwordBeam(setup stuff here);) and then spawn it in. The class itself should handle the logic so you don't have to specify it every time you create an instance of your projectile. For example, this is how I handle spawning projectiles (do note I have a lot of extra stuff going on, but the three highlighted lines are all you need - call that whenever you want to spawn a projectile). I believe the way you are doing it could be causing the NPE (you can verify it by looking through that error log some more and finding where it calls your code).
Of course it won't work - directly copying what I have will not work. Instead, modify it to what you need. Like I said, I'm doing a lot of extra stuff you won't need, some of that flows down. Just remove the extra stuff I've added, and do what you normally do. I was just showing that all you need to do is create an instance of your projectile (using your parameters, not mine), and spawn it in.
The Meaning of Life, the Universe, and Everything.
Join Date:
11/17/2016
Posts:
363
Location:
USA (sadly)
Minecraft:
FavouriteDragon
Member Details
Ok! With my amazingly bad ability at setting positions for entities, I have edited the code:
@Override
public ActionResult<ItemStack> onItemRightClick(final World worldIn, final EntityPlayer playerIn, EnumHand handIn) {
SwordBeam entity = new SwordBeam(worldIn);
entity.posX = playerIn.posX;
entity.posY = playerIn.posY;
entity.posZ = playerIn.posZ;
worldIn.spawnEntity(entity);
return null;
}
Minecraft still crashes upon right clicking. However, when I open up minecraft again, my entity is just sitting where I spawned it. Upon trying to summon entity, it says this:
9:11:00] [Server thread/WARN]: Tried to add entity starlight:swordbeam but it was marked as removed already
[19:11:00] [Client thread/INFO]: [CHAT] Unable to summon object
The Meaning of Life, the Universe, and Everything.
Join Date:
11/17/2016
Posts:
363
Location:
USA (sadly)
Minecraft:
FavouriteDragon
Member Details
Yeah for some reason IntelliJ really wants me to return null. Or to make on item right click return void. It's weird. I don't know what else to return, though :/ I'm about 99% sure returning null is the problem at the moment, but i don't know what to replace it with. Help please?
The Meaning of Life, the Universe, and Everything.
Join Date:
11/17/2016
Posts:
363
Location:
USA (sadly)
Minecraft:
FavouriteDragon
Member Details
Omg! I did it! Now I just have to make the entity move upon being summoned... But thanks! Lightning spawn code really comes in handy, for some reason...
Now I'll try and do vectors by myself. It won't end well. I appreciate the help P.S And I can't wait for the next Lost Eclipse update
So I made a custom entity (SwordBeam, based off of Kirby's sword beam), and I made that when I right click my custom sword, I shoot out my entity. However, it crashes every time. SwordBeam code:
Code summoning SwordBeam (in my Sword class):
Side note: even though my sword extends ItemSword, when I try to enchant it, I get armor, bow and tool enchantments. Any help? Sword code:
Image Removed
~ Everybody's FavouriteDragon
Your entity class is abstract, meaning you can't instantiate an instance of it. That really shouldn't even compile properly - regardless, don't make it abstract and it should work.
It still crashes... (Btw, I really like Levels. It's awesome :D)
Image Removed
~ Everybody's FavouriteDragon
Thanks!
Why are you specifying the onImpact method again? In your sword class, you should create an instance of your entity (SwordBeam entity = new SwordBeam(setup stuff here);) and then spawn it in. The class itself should handle the logic so you don't have to specify it every time you create an instance of your projectile. For example, this is how I handle spawning projectiles (do note I have a lot of extra stuff going on, but the three highlighted lines are all you need - call that whenever you want to spawn a projectile). I believe the way you are doing it could be causing the NPE (you can verify it by looking through that error log some more and finding where it calls your code).
Hmm.. When I tried using your location (posY + look.Y, posX + look.X) it was all red and IntelliJ couldn't understand it. What should I use instead?
I had to change a couple things because of IntelliJ and forge.
Image Removed
~ Everybody's FavouriteDragon
Of course it won't work - directly copying what I have will not work. Instead, modify it to what you need. Like I said, I'm doing a lot of extra stuff you won't need, some of that flows down. Just remove the extra stuff I've added, and do what you normally do. I was just showing that all you need to do is create an instance of your projectile (using your parameters, not mine), and spawn it in.
Ok! With my amazingly bad ability at setting positions for entities, I have edited the code:
Minecraft still crashes upon right clicking. However, when I open up minecraft again, my entity is just sitting where I spawned it. Upon trying to summon entity, it says this:
Image Removed
~ Everybody's FavouriteDragon
You're returning null to a method...that is almost never good.
Yeah for some reason IntelliJ really wants me to return null. Or to make on item right click return void. It's weird. I don't know what else to return, though :/ I'm about 99% sure returning null is the problem at the moment, but i don't know what to replace it with. Help please?
Image Removed
~ Everybody's FavouriteDragon
Take some time to learn some Java. The method tells you what you need to return (ActionResult<ItemStack>).
Omg! I did it! Now I just have to make the entity move upon being summoned... But thanks! Lightning spawn code really comes in handy, for some reason...
Now I'll try and do vectors by myself. It won't end well. I appreciate the help P.S And I can't wait for the next Lost Eclipse update
Image Removed
~ Everybody's FavouriteDragon