Boomerang type projectile

Started by KBEHAN on Wed, 12/28/2016 - 21:58

Topic category: Help with modding (Java Edition)

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Boomerang type projectile
Sat, 12/31/2016 - 01:09 (edited)

Hey, it's me again here with another complex idea I need help with.

 

I want my entity throwable to have a boomerang type function.  So I kind of know the function of this.  I have code for damaging the entity.  But I need help with actual code for the rest of it.  here is my idea for the mechanic:

so,  entity throwable dissapears when it hits a block or entity is because of set dead.  what I need is to delete that part (I need it later though) and add in a motion, so in place of set dead when it hits a block or entity it has a motion. When it hits an entity or a block the motion will return/be backwards.  Then I need CollideWithPlayer that will 1. Set dead the entity and 2. give the player the item back. 

If anyone wants to help or has code or something please reply.  I am working in 1.7.10  version.

Edited by KBEHAN on Sat, 12/31/2016 - 01:09
Last seen on 02:46, 3. May 2018
Joined Dec 2016
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
i dont know about the
Sat, 12/31/2016 - 01:26

i dont know about the animation but as a temporary solution you could just have it give the item to the player and kill the entity if it still exists (missed and hit a wall)

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:i dont know about the
Sat, 12/31/2016 - 02:25

@#1 I don't need an animation.  I don't think there is an actual easy way around this.  This is quite complex.  It will require some heavy coding.  Plus if I killed the entity that would defeat the purpose of the whole visual of the entity "bouncing".

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
nUpdate(){
Mon, 01/09/2017 - 00:05
nUpdate(){

			double d0 = (target.posX - this.posX);
			double d1 = target.posY + 1 - this.posY;
			double d2 = (target.posZ - this.posZ);

			SetThrowableHeading(d0, d1, d2, 0.4F, 1.0F);

			this.motionX = MovePart(this.motionX, this.PerfectMotionX, 0.02);
			this.motionY = MovePart(this.motionY, this.PerfectMotionY, 0.005);
			this.motionZ = MovePart(this.motionZ, this.PerfectMotionZ, 0.02);



}


	/**
	 * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
	 */
	public void SetThrowableHeading(double par1, double par3, double par5, float par7, float par8)
	{
		float f2 = MathHelper.sqrt_double(par1 * par1 + par3 * par3 + par5 * par5);
		par1 /= (double)f2;
		par3 /= (double)f2;
		par5 /= (double)f2;
		par1 += this.rand.nextGaussian() * 0.007499999832361937D * (double)par8;
		par3 += this.rand.nextGaussian() * 0.007499999832361937D * (double)par8;
		par5 += this.rand.nextGaussian() * 0.007499999832361937D * (double)par8;
		par1 *= (double)par7;
		par3 *= (double)par7;
		par5 *= (double)par7;
		this.PerfectMotionX = par1;
		this.PerfectMotionY = par3;
		this.PerfectMotionZ = par5;

	}



	public double MovePart(double part, double destination, double speed){
		if(part < destination) {
			part += speed;
		} else if (part > destination + speed) {
			part -= speed;
		} else {
			part = destination;
		}
		return part;
	}

 

this code can be used maybe fore the returning mechanic?

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
So, I need some help. I'm
Sat, 01/14/2017 - 21:42

So, I need some help. I'm pretty sure this code makes it so the entity comes back to the player but please correct me if I am wrong.

package mod.mcreator;//based on master condiguration

import cpw.mods.fml.client.*;
import cpw.mods.fml.client.registry.*;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.asm.*;
import cpw.mods.fml.common.asm.transformers.*;
import cpw.mods.fml.common.discovery.*;
import cpw.mods.fml.common.discovery.asm.*;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.functions.*;
import cpw.mods.fml.common.network.*;
import cpw.mods.fml.common.registry.*;
import cpw.mods.fml.common.toposort.*;
import cpw.mods.fml.common.versioning.*;
import cpw.mods.fml.relauncher.*;
import cpw.mods.fml.server.*;
import net.minecraft.block.*;
import net.minecraft.block.material.*;
import net.minecraft.client.*;
import net.minecraft.client.audio.*;
import net.minecraft.client.entity.*;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.achievement.*;
import net.minecraft.client.gui.inventory.*;
import net.minecraft.client.model.*;
import net.minecraft.client.multiplayer.*;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.culling.*;
import net.minecraft.client.renderer.entity.*;
import net.minecraft.client.renderer.tileentity.*;
import net.minecraft.client.settings.*;
import net.minecraft.command.*;
import net.minecraft.crash.*;
import net.minecraft.creativetab.*;
import net.minecraft.dispenser.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.boss.*;
import net.minecraft.entity.effect.*;
import net.minecraft.entity.item.*;
import net.minecraft.entity.monster.*;
import net.minecraft.entity.passive.*;
import net.minecraft.entity.player.*;
import net.minecraft.entity.projectile.*;
import net.minecraft.inventory.*;
import net.minecraft.item.*;
import net.minecraft.item.crafting.*;
import net.minecraft.nbt.*;
import net.minecraft.network.*;
import net.minecraft.network.rcon.*;
import net.minecraft.pathfinding.*;
import net.minecraft.potion.*;
import net.minecraft.profiler.*;
import net.minecraft.server.*;
import net.minecraft.server.dedicated.*;
import net.minecraft.server.gui.*;
import net.minecraft.server.integrated.*;
import net.minecraft.server.management.*;
import net.minecraft.src.*;
import net.minecraft.stats.*;
import net.minecraft.tileentity.*;
import net.minecraft.util.*;
import net.minecraft.village.*;
import net.minecraft.world.*;
import net.minecraft.world.biome.*;
import net.minecraft.world.chunk.*;
import net.minecraft.world.chunk.storage.*;
import net.minecraft.world.demo.*;
import net.minecraft.world.gen.*;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.layer.*;
import net.minecraft.world.gen.structure.*;
import net.minecraft.world.storage.*;
import net.minecraftforge.classloading.*;
import net.minecraftforge.client.*;
import net.minecraftforge.client.event.*;
import net.minecraftforge.client.event.sound.*;
import net.minecraftforge.common.*;
import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.*;
import net.minecraftforge.event.entity.item.*;
import net.minecraftforge.event.entity.living.*;
import net.minecraftforge.event.entity.minecart.*;
import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.event.terraingen.*;
import net.minecraftforge.event.world.*;
import net.minecraftforge.oredict.*;
import net.minecraftforge.transformers.*;
import net.minecraft.init.*;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MathHelper;
import java.util.*;

@SuppressWarnings("unchecked")
public class mcreator_shield {
 
    public static int mobid = 0;
    public Object instance;
 
    public void load(){}
 
    public void generateNether(World world, Random random, int chunkX, int chunkZ){}
    public void generateSurface(World world, Random random, int chunkX, int chunkZ){}
    public int addFuel(ItemStack fuel){
        return 0;
    }
    @SideOnly(Side.CLIENT)
    public void registerRenderers(){
        RenderingRegistry.registerEntityRenderingHandler(mcreator_shield.Entityshield.class, new RenderSnowball(mcreator_stevensShield.block));
    }
 
 
    public void serverLoad(FMLServerStartingEvent event){}
    public void preInit(FMLPreInitializationEvent event){
        int entityID = EntityRegistry.findGlobalUniqueEntityId();
        mobid = entityID;
        EntityRegistry.registerGlobalEntityID(mcreator_shield.Entityshield.class, "shield", entityID);
        EntityRegistry.registerModEntity(mcreator_shield.Entityshield.class, "shield", entityID, instance, 64, 1, true);
       
 
       
    }
 
 
  public static class Entityshield extends EntityThrowable{
 
 
public Entityshield(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}
public Entityshield(World par1World, EntityLivingBase par2EntityLivingBase)
{
super(par1World, par2EntityLivingBase);
}
public Entityshield(World par1World)
{
super(par1World);
}
/**
 * Called when this EntityThrowable hits a block or entity.
 */
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
    {
        if (par1MovingObjectPosition.entityHit != null)
        {
            byte b0 = 54;          
 
            par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
        }
 
        if (!this.worldObj.isRemote)
        {
            this.setDead();
        }
    }
}
private void returnToSender()
    {
        double d0 = this.shootingEntity.posX - this.posX;
        double d1 = this.shootingEntity.boundingBox.minY + (double)(this.shootingEntity.height / 3.0F) - this.posY;
        d1 -= 0.6D;
        double d2 = this.shootingEntity.posZ - this.posZ;
        double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
        
        if (d3 >= 1.0E-7D)
        {
            float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
            float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI));
            this.setLocationAndAngles(this.posX, this.posY, this.posZ, f2, f3);
            float f4 = (float)d3 * 0.2F;
            this.setThrowableHeading(d0, d1 + (double)f4, d2, this.strength, 1.0F);
        }
}
public void interactEvent(EntityInteractEvent event){
if(event.target instanceof EntityCreature){
int entityID = EntityList.getEntityID(event.target);
ItemStack currentItem = event.entityPlayer.inventory.getCurrentItem();
if(currentItem != null){
     if(currentItem == new ItemStack( mcreator_stevensShield.block, 1) && currentItem.getItemDamage() == 0){
     event.target.setDead();
     currentItem.setItemDamage(entityID);
     }
}
}
}}

 

/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:164: error: cannot find symbol
>        double d0 = this.shootingEntity.posX - this.posX;
>                        ^
>  symbol: variable shootingEntity
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:164: error: cannot find symbol
>:compileJava FAILED
>        double d0 = this.shootingEnti>                                                   ^
ty.posX - this.posX;
>  symbol: variable posX
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:165: error: cannot find symbol
>        double d1 = this.shootingEntity.boundingBox.minY + (double)(this.shootingEntity.height / 3.0F) - this.posY;
>                        ^
>  symbol: variable shootingEntity
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:165: error: cannot find symbol
>        double d1 = this.shootingEntity.boundingBox.minY + (double)(this.shootingEntity.height / 3.0F) - this.posY;
>                                                                        ^
>  symbol: variable shootingEntity
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:165: error: cannot find symbol
>        double d1 = this.shootingEntity.boundingBox.minY + (double)(this.shootingEntity.height / 3.0F) - this.posY;
>                                                                                                             ^
>  symbol: variable posY
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:167: error: cannot find symbol
>        double d2 = this.shootingEntity.posZ - this.posZ;
>                        ^
>  symbol: variable shootingEntity
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:167: error: cannot find symbol
>        double d2 = this.shootingEntity.posZ - this.posZ;
>                                                   ^
>  symbol: variable posZ
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:174: error: cannot find symbol
>            this.setLocationAndAngles(this.posX, this.posY, this.posZ, f2, f3);
>BUILD FAILED
>                                          ^
>Total time: 11.893 secs
>  symbol: variable posX
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:174: error: cannot find symbol
>            this.setLocationAndAngles(this.posX, this.posY, this.posZ, f2, f3);
>                                                     ^
>  symbol: variable posY
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:174: error: cannot find symbol
>            this.setLocationAndAngles(this.posX, this.posY, this.posZ, f2, f3);
>                                                                ^
>  symbol: variable posZ
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_shield.java:176: error: cannot find symbol
>            this.setThrowableHeading(d0, d1 + (double)f4, d2, this.strength, 1.0F);
>                                                                  ^
>  symbol: variable strength
>Note: /Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_sugilitesFlail.java uses unchecked or unsafe operations.
>11 errors
>FAILURE: Build failed with an exception.
>* What went wrong:
>Execution failed for task ':compileJava'.
>> Compilation failed; see the compiler error output for details.
>* Try:
>Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
>Task completed with return code 1 in 12457 milliseconds
 

 

 

 

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Major breakthrough!
Sun, 01/15/2017 - 17:09

Major breakthrough!

but there are some problems/things I want to fix

1:remove the potion effect it gives enties

2:after it bounces off an entity it flys off, thats great! problem is, is that it eventually stops flyig and stays there.  Where do I put setDead?

heres my code:

 

@Override
    public void onImpact(MovingObjectPosition mop) {
        if(mop.entityHit != null) {

            float throwDamage = 5;
            mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), throwDamage);

            if(mop.entityHit instanceof EntityLivingBase) {
                byte b0 = 0;
                
                switch(worldObj.difficultySetting) {
                    case NORMAL:
                        b0 = 10;
                        break;
                    case HARD:
                        b0 = 40;
                        break;
                    default:
                        break;
                }

                if(b0 > 0) {
                    ((EntityLivingBase)mop.entityHit).addPotionEffect(new PotionEffect(Potion.wither.id, 20 * b0, 1));
                }
            }

            for(int l = 0; l < 4; ++l) {
                worldObj.spawnParticle("magicCrit", posX, posY, posZ, 0.0D, 0.0D, 0.0D);
            }
        bounceBack();
        }
    }
    
    protected void bounceBack() {
        setVelocity(-motionX, -motionY, -motionZ);
    }
    
    
    @Override
    protected float getGravityVelocity() {
        return 0.0F;
    }

    /** Returns the shield's velocity makes it bouncy*/
    protected float getVelocity() {
        return func_70182_d();
    }

    /** Returns the shield's velocity makes it bouncy*/
    @Override
    protected float func_70182_d() {
        return 1.25F;
    }
 }
public void interactEvent(EntityInteractEvent event){
if(event.target instanceof EntityCreature){
int entityID = EntityList.getEntityID(event.target);
ItemStack currentItem = event.entityPlayer.inventory.getCurrentItem();
if(currentItem != null){
     if(currentItem == new ItemStack( mcreator_stevensShield.block, 1) && currentItem.getItemDamage() == 0){
     event.target.setDead();
     currentItem.setItemDamage(entityID);
     }
}
}
}}

PLZ HELP!  I want to be able to make this perfect so I can make a tutorial/custom code eventually!

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
That's the problem of things
Sun, 01/15/2017 - 17:43

That's the problem of things like Minecraft Forge forum,GitHub,..... . They do not tell why is the thing there.
Anyway it is not hard to see that this gives the effect:   ((EntityLivingBase)mop.entityHit).addPotionEffect(new PotionEffect(Potion.wither.id, 20 * b0, 1));
To the second point , it depends on what do you want it be like, you can for example make it that it will fly back , until it collides with block/player ,  you can have a timer for it, or else you can check if the position is same as the starting position. For colliding oen you can use onImpact() , for the else onUpdate(). 

 

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:That's the problem of things
Sun, 01/15/2017 - 18:14

@#5

if I use onUpdate wouldn't that effect when it hits the entity too? I was thinking of using ticksInAir, but that would also affect when it hits the entity.  I just need it so when it flies away it dies.  So ticksInAir but after it hits the entity.

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:That's the problem of things
Sun, 01/15/2017 - 18:22

@#5 for onUpdate you mean something like this?

@Override
    public void onUpdate() {
        if (--distance < -LIFESPAN && !worldObj.isRemote) {
            worldObj.spawnEntityInWorld(new EntityItem(worldObj, posX, posY, posZ, getshield()));
            setDead();
            }
        }

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
onUpdate() -  call on every
Sun, 01/15/2017 - 18:29

onUpdate() -  call on every tick upate.
Now to the counter. Do you have some imagination what would happen in this case ,if you miss the entity? Yes it would fly forever (or until its is in loaded chunks). And that means that if you would be using it for example on server where people would like using your item , after some time would begin lags because of undespawned entities.
Well, let's say that this is just small detail. Then you need make a boolean that will switch after the collision . and in onUpdate() you will check for the boolean and case that it has the value that you want , then increase/descrease the timer (depends if you are counting from 0 up , or from some number to 0)

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:onUpdate() -  call on every
Sun, 01/15/2017 - 18:45

@#6

So this code is not useable?  I would need something like ticksInAir?

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Why are you negaing the
Sun, 01/15/2017 - 19:06

Why are you negaing the LIFESPAN?

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:Why are you negaing the
Sun, 01/15/2017 - 19:10

@#7

Well, I wanted to make it so as it was flying away after bouncing off of entity it eventually setDead

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:Why are you negaing the
Sun, 01/15/2017 - 19:10

@#7 *negating

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
It whole does not do almost
Sun, 01/15/2017 - 19:16

It whole does not do almost any of the things that I wrote.
       --distance < -LIFESPAN
This does only that it checks if the distance-1 is smaller that negated value of 
LIFESPAN

There is no even sign about the boolean , like
if(hasCollided){
inAirTicks++;
if(inAirTicks > 60){
//DO SOME STUFF
}
}