Jump to content

[Unsolved][1.12.2] Problem on spawning one-per-player-entity spawned by item


Recommended Posts

Posted (edited)

I know that I also try that but for big Problems like that I often start with Vanilla code that works quite similar like in this case the FishingRod and FishHook similar to my Clawshot and its head to get the theory.

BTW: How would I add a signature to my posts?

Edited by _Cruelar_

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

Posted

I feel pretty dumb to ask but how get I an Entity by its UUID as world only has the method getPlayerEntitiesByUUID()

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted
40 minutes ago, _Cruelar_ said:

BTW: How would I add a signature to my posts?

You go into your account settings.

13 minutes ago, _Cruelar_ said:

I feel pretty dumb to ask but how get I an Entity by its UUID as world only has the method getPlayerEntitiesByUUID()

You'll have to loop through the loadedEntityList and look for it yourself. Since there is no method available already.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I've wrote a method to find the Entity

Code

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class Clawshot_TP extends Item {

    public Clawshot_TP(){
        this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD);
        this.setRegistryName("clawshot_tp");
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".clawshot_tp");
        this.addPropertyOverride(new ResourceLocation("cast"), new IItemPropertyGetter() {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack p_apply_1_, @Nullable World p_apply_2_, @Nullable EntityLivingBase p_apply_3_) {
                if (p_apply_3_ == null) {
                    return 0.0F;
                } else {
                    boolean lvt_4_1_ = p_apply_3_.getHeldItemMainhand() == p_apply_1_;
                    boolean lvt_5_1_ = p_apply_3_.getHeldItemOffhand() == p_apply_1_;
                    if (p_apply_3_.getHeldItemMainhand().getItem() instanceof Clawshot_TP) {
                        lvt_5_1_ = false;
                    }

                    return (lvt_4_1_ || lvt_5_1_) && p_apply_3_ instanceof EntityPlayer && ((EntityPlayer)p_apply_3_).fishEntity != null ? 1.0F : 0.0F;
                }
            }
        });
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer,EnumHand enumHand) {
        ItemStack itemStack = entityPlayer.getHeldItem(enumHand);
        Clawshot_Head clawshot_head = new Clawshot_Head(world, entityPlayer);
        if (!world.isRemote) {
            if (!this.getTagCompoundSafe(itemStack).hasKey("shot") || !this.getTagCompoundSafe(itemStack).getBoolean("shot") || this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack).isDead) {
                world.spawnEntity(clawshot_head);
                this.getTagCompoundSafe(itemStack).setBoolean("shot",true);
                this.getTagCompoundSafe(itemStack).setUniqueId("head",clawshot_head.getUniqueID());
            } else {
                clawshot_head.setDead();
                this.getTagCompoundSafe(itemStack).setBoolean("shot",false);
            }
        }
        return new ActionResult(EnumActionResult.SUCCESS,itemStack);
    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    public Entity getEntityByUUID(UUID entityUUID, World worldIn, ItemStack itemStack){
        int lenght =worldIn.getLoadedEntityList().size();
        List<Entity> loadedEntityList= worldIn.getLoadedEntityList();
        Entity foundEntity = null;
        for (int i = 0;i<lenght;i++){
            if (loadedEntityList.get(i).getUniqueID()==entityUUID){
                foundEntity = loadedEntityList.get(i);
            }
        }
        return foundEntity;
    }
}

Error:

Spoiler

[22:18:22] [Server thread/FATAL] [net.minecraft.server.MinecraftServer]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_152]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_152]
    at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
Caused by: java.lang.NullPointerException
    at com.cruelar.cruelars_triforcemod.items.Clawshot_TP.onItemRightClick(Clawshot_TP.java:57) ~[Clawshot_TP.class:?]
    at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:234) ~[ItemStack.class:?]
    at net.minecraft.server.management.PlayerInteractionManager.processRightClick(PlayerInteractionManager.java:384) ~[PlayerInteractionManager.class:?]
    at net.minecraft.network.NetHandlerPlayServer.processTryUseItem(NetHandlerPlayServer.java:794) ~[NetHandlerPlayServer.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:43) ~[CPacketPlayerTryUseItem.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:9) ~[CPacketPlayerTryUseItem.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_152]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_152]
    at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
    ... 5 more

Still the Entity respawns after being setDead. What am I missing?

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted
4 minutes ago, _Cruelar_ said:

Error:

What happens in the if statement if the compound doesn't have a UUID saved to it. Hint: The entity will be null.

5 minutes ago, _Cruelar_ said:

Still the Entity respawns after being setDead. What am I missing?

clawshot_head.setDead();

What does this do? It references a new Entity just created in this method, not yet spawned in the world, and sets it to be dead.

What it should do is gets the entity from the nbt and set that entity to be dead.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
12 hours ago, Animefan8888 said:
13 hours ago, _Cruelar_ said:

Still the Entity respawns after being setDead. What am I missing?


clawshot_head.setDead();

What does this do? It references a new Entity just created in this method, not yet spawned in the world, and sets it to be dead.

What it should do is gets the entity from the nbt and set that entity to be dead.

Ok, I should give more details about that:

The Entity is spawned correctly. Check.

It lives a certain time. Check. (Not exactly what I want it to do but I should already know how to fix that)

Then it dies (NOT by Right clicking again). Check

And Respawns at its original spawnPos and moves again.

But you're right about the error in the code,will fix that.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted

Updated code of Item(doesn't results in NPE anymore):

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class Clawshot_TP extends Item {

    public Clawshot_TP(){
        this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD);
        this.setRegistryName("clawshot_tp");
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".clawshot_tp");
        this.addPropertyOverride(new ResourceLocation("cast"), new IItemPropertyGetter() {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack p_apply_1_, @Nullable World p_apply_2_, @Nullable EntityLivingBase p_apply_3_) {
                if (p_apply_3_ == null) {
                    return 0.0F;
                } else {
                    boolean lvt_4_1_ = p_apply_3_.getHeldItemMainhand() == p_apply_1_;
                    boolean lvt_5_1_ = p_apply_3_.getHeldItemOffhand() == p_apply_1_;
                    if (p_apply_3_.getHeldItemMainhand().getItem() instanceof Clawshot_TP) {
                        lvt_5_1_ = false;
                    }

                    return (lvt_4_1_ || lvt_5_1_) && p_apply_3_ instanceof EntityPlayer && ((EntityPlayer)p_apply_3_).fishEntity != null ? 1.0F : 0.0F;
                }
            }
        });
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer,EnumHand enumHand) {
        ItemStack itemStack = entityPlayer.getHeldItem(enumHand);
        Clawshot_Head clawshot_head = new Clawshot_Head(world, entityPlayer);
        if (!world.isRemote) {
            if (!this.getTagCompoundSafe(itemStack).hasKey("shot") || !this.getTagCompoundSafe(itemStack).getBoolean("shot") || this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack)!=null && this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack).isDead) {
                world.spawnEntity(clawshot_head);
                this.getTagCompoundSafe(itemStack).setBoolean("shot",true);
                this.getTagCompoundSafe(itemStack).setUniqueId("head",clawshot_head.getUniqueID());
            } else if (this.getEntityByUUID(this.getTagCompoundSafe(itemStack).getUniqueId("head"),world,itemStack)!=null){
                this.getEntityByUUID(this.getTagCompoundSafe(itemStack).getUniqueId("head"),world,itemStack).setDead();
                this.getTagCompoundSafe(itemStack).setBoolean("shot",false);
            }
        }
        return new ActionResult(EnumActionResult.SUCCESS,itemStack);
    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    private Entity getEntityByUUID(UUID entityUUID, World worldIn, ItemStack itemStack){
        int lenght =worldIn.getLoadedEntityList().size();
        List<Entity> loadedEntityList= worldIn.getLoadedEntityList();
        Entity foundEntity = null;
        for (int i = 0;i<lenght;i++){
            if (loadedEntityList.get(i).getUniqueID()==entityUUID){
                foundEntity = loadedEntityList.get(i);
            }
        }
        return foundEntity;
    }
}

The Entity:

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Iterator;
import java.util.List;

public class Clawshot_Head extends Entity implements IEntityAdditionalSpawnData{
    private EntityPlayer entityPlayer;
    public Entity caughtEntity;
    public Clawshot_Head.State currentState;
    private static final DataParameter<Integer> DATA_HOOKED_ENTITY;
    private boolean inGround;
    private int ticksInAir;
    private int ticksInGround;
    public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png");

    public Clawshot_Head(World world){
        super(world);
    }

    public Clawshot_Head(World world, EntityPlayer entityPlayer){
        super(world);
        this.init(entityPlayer);
        this.currentState = Clawshot_Head.State.FLYING;
        this.setPosition((double)entityPlayer.posX,(double)entityPlayer.posY+entityPlayer.getEyeHeight(),(double)entityPlayer.posZ);
        this.shoot(entityPlayer);
    }

    @SideOnly(Side.CLIENT)
    public Clawshot_Head(World world, EntityPlayer entityPlayer, double posX, double posY, double posZ) {
        super(world);
        this.init(entityPlayer);
        this.setPosition(posX,posY,posZ);
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
    }

    public void notifyDataManagerChange(DataParameter<?> p_notifyDataManagerChange_1_) {
        if (DATA_HOOKED_ENTITY.equals(p_notifyDataManagerChange_1_)) {
            int i = (Integer)this.getDataManager().get(DATA_HOOKED_ENTITY);
            this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null;
        }

        super.notifyDataManagerChange(p_notifyDataManagerChange_1_);
    }

    public void onUpdate()
    {
        super.onUpdate();
        if (this.entityPlayer == null)
        {
            this.setDead();
        }
        else if (this.world.isRemote)
        {
            if (this.inGround)
            {
                ++this.ticksInGround;
                motionX=0;
                motionY=0;
                motionZ=0;

                if (this.ticksInGround >= 1200)
                {
                    this.setDead();
                    return;
                }
            }
            if(this.getDistance(entityPlayer)>=64){
                this.setDead();
                return;
            }
            BlockPos blockpos = new BlockPos(this);
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            if (this.currentState == Clawshot_Head.State.FLYING)
            {
                if (this.caughtEntity != null)
                {
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                    this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY;
                    return;
                }

                if (!this.world.isRemote)
                {
                    this.checkCollision();
                }

                if (!this.inGround && !this.onGround && !this.collidedHorizontally)
                {
                    ++this.ticksInAir;
                }
                else
                {
                    this.ticksInAir = 0;
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                }
                if (ticksInAir>=100){
                    this.setDead();
                    return;
                }
            }
            else
            {
                if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY)
                {
                    if (this.caughtEntity != null)
                    {
                        if (this.caughtEntity.isDead)
                        {
                            this.caughtEntity = null;
                            this.currentState = Clawshot_Head.State.FLYING;
                        }
                        else
                        {
                            this.posX = this.caughtEntity.posX;
                            double d2 = (double)this.caughtEntity.height;
                            this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D;
                            this.posZ = this.caughtEntity.posZ;
                            this.setPosition(this.posX, this.posY, this.posZ);
                        }
                    }

                    return;
                }
            }

            this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
            this.updateRotation();
            this.setPosition(this.posX, this.posY, this.posZ);
        }
    }

    private void updateRotation()
    {
        float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));

        for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
        {

        }

        while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
        {
            this.prevRotationPitch += 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw < -180.0F)
        {
            this.prevRotationYaw -= 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
        {
            this.prevRotationYaw += 360.0F;
        }

        this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
        this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    }

    public void shoot(Entity entity) {
        System.out.println(entity);
        this.motionX=0.6D*entity.getLookVec().x;
        this.motionY=0.6D*entity.getLookVec().y;
        this.motionZ=0.6D*entity.getLookVec().z;

    }

    public void shoot(double p_shoot_1_, double p_shoot_3_, double p_shoot_5_, float p_shoot_7_, float p_shoot_8_){}

    public int handleHookRetraction()
    {
        if (!this.world.isRemote && this.entityPlayer != null)
        {
            int i = 0;
            if (this.caughtEntity != null)
            {
                this.bringInHookedEntity();
                this.world.setEntityState(this, (byte)31);
                i = this.caughtEntity instanceof EntityItem ? 3 : 5;
            }
            else if (this.inGround)
            {
                i = 2;
            }

            this.setDead();
            return i;
        }
        else
        {
            return 0;
        }
    }

    protected void bringInHookedEntity()
    {
        if (this.entityPlayer != null)
        {
            double d0 = this.entityPlayer.posX - this.posX;
            double d1 = this.entityPlayer.posY - this.posY;
            double d2 = this.entityPlayer.posZ - this.posZ;
            double d3 = 0.1D;
            this.caughtEntity.motionX += d0 * 0.1D;
            this.caughtEntity.motionY += d1 * 0.1D;
            this.caughtEntity.motionZ += d2 * 0.1D;
        }
    }

    public void setDead()
    {
        super.setDead();
    }

    public EntityPlayer getAngler()
    {
        return this.entityPlayer;
    }

    private void init(EntityPlayer p_init_1_) {
        this.setSize(0.25F, 0.25F);
        this.ignoreFrustumCheck = true;
        this.entityPlayer = p_init_1_;
    }

    private void checkCollision() {
        Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false);
        vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (raytraceresult != null) {
            vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
            this.motionX=0;
            this.motionY=0;
            this.motionZ=0;
            entityPlayer.posX=this.posX;
            entityPlayer.posY=this.posY;
            entityPlayer.posZ=this.posZ;
        }

        Entity entity = null;
        List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
        double d0 = 0.0D;
        Iterator var8 = list.iterator();

        while(true) {
            Entity entity1;
            double d1;
            do {
                RayTraceResult raytraceresult1;
                do {
                    do {
                        do {
                            if (!var8.hasNext()) {
                                if (entity != null) {
                                    raytraceresult = new RayTraceResult(entity);
                                }

                                if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS) {
                                    if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY) {
                                        this.caughtEntity = raytraceresult.entityHit;
                                        this.setHookedEntity();
                                    } else {
                                        this.inGround = true;
                                    }
                                }

                                return;
                            }

                            entity1 = (Entity)var8.next();
                        } while(!this.canBeHooked(entity1));
                    } while(entity1 == this.entityPlayer && this.ticksInAir < 5);

                    AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
                    raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
                } while(raytraceresult1 == null);

                d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
            } while(d1 >= d0 && d0 != 0.0D);

            entity = entity1;
            d0 = d1;
        }
    }

    private void setHookedEntity() {
        this.getDataManager().set(DATA_HOOKED_ENTITY, this.caughtEntity.getEntityId() + 1);
    }

    protected boolean canBeHooked(Entity p_canBeHooked_1_) {
        return p_canBeHooked_1_.canBeCollidedWith() || p_canBeHooked_1_ instanceof EntityItem;
    }

    protected void entityInit() {
        this.getDataManager().register(DATA_HOOKED_ENTITY, 0);
    }

    @Override
    protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {

    }

    @Override
    protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {

    }

    static {
        DATA_HOOKED_ENTITY = EntityDataManager.createKey(Clawshot_Head.class, DataSerializers.VARINT);
    }

    @Override
    public void writeSpawnData(ByteBuf buffer) {
        buffer.writeBoolean(entityPlayer==null);
        if (entityPlayer!=null) {
            buffer.writeInt(entityPlayer.getEntityId());
        }
    }

    @Override
    public void readSpawnData(ByteBuf additionalData) {
        boolean nullPlayer = additionalData.readBoolean();
        if (!nullPlayer){
            EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt());
            if (entityByID!=null){
                entityPlayer=entityByID;
            }
            this.shoot(entityPlayer);
        }
    }

    static enum State {
        FLYING,
        HOOKED_IN_ENTITY;

        private State() {
        }
    }
}

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted
8 hours ago, _Cruelar_ said:

else if (this.world.isRemote) { if (this.inGround) { ++this.ticksInGround; motionX=0; motionY=0; motionZ=0; if (this.ticksInGround >= 1200) { this.setDead(); return; } }

 

In your update method you only set it dead on the client.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

With this:

public void onUpdate()
    {
        super.onUpdate();
        if (this.entityPlayer == null)
        {
            this.setDead();
        }
        else if (this.world.isRemote)
        {
            if (this.inGround) {
                ++this.ticksInGround;
                motionX = 0;
                motionY = 0;
                motionZ = 0;
            }


            if(this.getDistance(entityPlayer)>=64){
                this.setDead();
                return;
            }
            BlockPos blockpos = new BlockPos(this);
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            if (this.currentState == Clawshot_Head.State.FLYING)
            {
                if (this.caughtEntity != null)
                {
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                    this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY;
                    return;
                }

                if (!this.world.isRemote)
                {
                    this.checkCollision();
                }

                if (!this.inGround && !this.onGround && !this.collidedHorizontally)
                {
                    ++this.ticksInAir;
                }
                else
                {
                    this.ticksInAir = 0;
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                }

            }
            else
            {
                if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY)
                {
                    if (this.caughtEntity != null)
                    {
                        if (this.caughtEntity.isDead)
                        {
                            this.caughtEntity = null;
                            this.currentState = Clawshot_Head.State.FLYING;
                        }
                        else
                        {
                            this.posX = this.caughtEntity.posX;
                            double d2 = (double)this.caughtEntity.height;
                            this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D;
                            this.posZ = this.caughtEntity.posZ;
                            this.setPosition(this.posX, this.posY, this.posZ);
                        }
                    }

                    return;
                }
            }

            this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
            this.updateRotation();
            this.setPosition(this.posX, this.posY, this.posZ);
        }
        if (this.ticksInGround >= 1200)
        {
            this.setDead();
        }
        if (ticksInAir>=200){
            this.setDead();
            return;
        }
    }

I give the command to kill it on both sides,am I right? So why it doesn't works?

Also setting the motion to o doesn't works. Is this also a problem with sides.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted (edited)
3 minutes ago, _Cruelar_ said:

Yes.

And then it does a few things with if it's in the ground and then sets itself to be dead, but only if the above is true. Which setDead are you having a problem with exactly?

Edited by Animefan8888

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

This is interesting. None of my Breakpoints responds.

Code:

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Iterator;
import java.util.List;
import java.util.UUID;

public class Clawshot_Head extends Entity implements IEntityAdditionalSpawnData{
    private UUID entityPlayer;
    public Entity caughtEntity;
    public Clawshot_Head.State currentState;
    private static final DataParameter<Integer> DATA_HOOKED_ENTITY;
    private boolean inGround;
    private int ticksInAir;
    private int ticksInGround;
    public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png");

    public Clawshot_Head(World world){
        super(world);
    }

    public Clawshot_Head(World world, EntityPlayer entityPlayer){
        super(world);
        this.init(entityPlayer);
        this.currentState = Clawshot_Head.State.FLYING;
        this.setPosition((double)entityPlayer.posX,(double)entityPlayer.posY+entityPlayer.getEyeHeight(),(double)entityPlayer.posZ);
        this.shoot(entityPlayer);
    }

    @SideOnly(Side.CLIENT)
    public Clawshot_Head(World world, EntityPlayer entityPlayer, double posX, double posY, double posZ) {
        super(world);
        this.init(entityPlayer);
        this.setPosition(posX,posY,posZ);
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
    }

    public void notifyDataManagerChange(DataParameter<?> p_notifyDataManagerChange_1_) {
        if (DATA_HOOKED_ENTITY.equals(p_notifyDataManagerChange_1_)) {
            int i = (Integer)this.getDataManager().get(DATA_HOOKED_ENTITY);
            this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null;
        }

        super.notifyDataManagerChange(p_notifyDataManagerChange_1_);
    }

    public void onUpdate()
    {
        super.onUpdate();
        if (this.entityPlayer == null)
        {
            this.setDead();
            System.out.println("ln:69 got called");
        }
        else if (this.world.isRemote)
        {
            if (this.inGround) {
                ++this.ticksInGround;
                motionX = 0;
                motionY = 0;
                motionZ = 0;
            }

            if(this.collidedHorizontally){
                motionX=0;
                motionY=0;
                motionZ=0;
                ++this.ticksInGround;
            }

            if(this.getDistance(getEntityByUUID(entityPlayer,world))>=64){
                this.setDead();
                System.out.println("ln:89 got called");
            }

            BlockPos blockpos = new BlockPos(this);
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            if (this.currentState == Clawshot_Head.State.FLYING)
            {
                if (this.caughtEntity != null)
                {
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                    this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY;
                    return;
                }

                if (!this.world.isRemote)
                {
                    this.checkCollision();
                }

                if (!this.inGround && !this.onGround && !this.collidedHorizontally)
                {
                    ++this.ticksInAir;
                }
                else
                {
                    this.ticksInAir = 0;
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                }

            }
            else
            {
                if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY)
                {
                    if (this.caughtEntity != null)
                    {
                        if (this.caughtEntity.isDead)
                        {
                            this.caughtEntity = null;
                            this.currentState = Clawshot_Head.State.FLYING;
                        }
                        else
                        {
                            this.posX = this.caughtEntity.posX;
                            double d2 = (double)this.caughtEntity.height;
                            this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D;
                            this.posZ = this.caughtEntity.posZ;
                            this.setPosition(this.posX, this.posY, this.posZ);
                        }
                    }

                    return;
                }
            }

            this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
            this.updateRotation();
            this.setPosition(this.posX, this.posY, this.posZ);
        }
        if (this.ticksInGround >= 1200)
        {
            this.setDead();
            System.out.println("ln:155 got called");
        }
        if (ticksInAir>=200){
            this.setDead();
            System.out.println("ln:159 got called");
        }

    }

    private void updateRotation()
    {
        float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));

        for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
        {

        }

        while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
        {
            this.prevRotationPitch += 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw < -180.0F)
        {
            this.prevRotationYaw -= 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
        {
            this.prevRotationYaw += 360.0F;
        }

        this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
        this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    }

    public void shoot(Entity entity) {

        System.out.println(entity);
        this.motionX=0.6D*entity.getLookVec().x;
        this.motionY=0.6D*entity.getLookVec().y;
        this.motionZ=0.6D*entity.getLookVec().z;

    }

    public void shoot(double p_shoot_1_, double p_shoot_3_, double p_shoot_5_, float p_shoot_7_, float p_shoot_8_){}

    public int handleHookRetraction()
    {
        if (!this.world.isRemote && this.entityPlayer != null)
        {
            int i = 0;
            if (this.caughtEntity != null)
            {
                this.bringInHookedEntity();
                this.world.setEntityState(this, (byte)31);
                i = this.caughtEntity instanceof EntityItem ? 3 : 5;
            }
            else if (this.inGround)
            {
                i = 2;
            }

            this.setDead();
            return i;
        }
        else
        {
            return 0;
        }
    }

    protected void bringInHookedEntity()
    {
        if (this.getEntityByUUID(entityPlayer,world) != null)
        {
            double d0 = this.getEntityByUUID(entityPlayer,world).posX - this.posX;
            double d1 = this.getEntityByUUID(entityPlayer,world).posY - this.posY;
            double d2 = this.getEntityByUUID(entityPlayer,world).posZ - this.posZ;
            double d3 = 0.1D;
            this.caughtEntity.motionX += d0 * 0.1D;
            this.caughtEntity.motionY += d1 * 0.1D;
            this.caughtEntity.motionZ += d2 * 0.1D;
        }
    }

    public void setDead()
    {
        super.setDead();
    }

    public EntityPlayer getAngler()
    {
        return this.getEntityByUUID(entityPlayer,this.world);
    }

    private EntityPlayer getEntityByUUID(UUID entityUUID, World worldIn){
        int lenght =worldIn.getLoadedEntityList().size();
        List<Entity> loadedEntityList= worldIn.getLoadedEntityList();
        EntityPlayer foundEntity = null;
        for (int i = 0;i<lenght;i++){
            if (loadedEntityList.get(i).getUniqueID()==entityUUID){
                if (loadedEntityList.get(i) instanceof EntityPlayer) {
                    foundEntity = (EntityPlayer) loadedEntityList.get(i);
                }
            }
        }
        return foundEntity;
    }

    private void init(EntityPlayer p_init_1_) {
        this.setSize(0.25F, 0.25F);
        this.ignoreFrustumCheck = true;
        this.entityPlayer = p_init_1_.getUniqueID();
    }

    private void checkCollision() {
        Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false);
        vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (raytraceresult != null) {
            vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
            this.motionX=0;
            this.motionY=0;
            this.motionZ=0;
            getEntityByUUID(entityPlayer,this.world).posX=this.posX;
            getEntityByUUID(entityPlayer,this.world).posY=this.posY;
            getEntityByUUID(entityPlayer,this.world).posZ=this.posZ;
        }

        Entity entity = null;
        List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
        double d0 = 0.0D;
        Iterator var8 = list.iterator();

        while(true) {
            Entity entity1;
            double d1;
            do {
                RayTraceResult raytraceresult1;
                do {
                    do {
                        do {
                            if (!var8.hasNext()) {
                                if (entity != null) {
                                    raytraceresult = new RayTraceResult(entity);
                                }

                                if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS) {
                                    if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY) {
                                        this.caughtEntity = raytraceresult.entityHit;
                                        this.setHookedEntity();
                                    } else {
                                        this.inGround = true;
                                    }
                                }

                                return;
                            }

                            entity1 = (Entity)var8.next();
                        } while(!this.canBeHooked(entity1));
                    } while(entity1 == this.getEntityByUUID(entityPlayer,this.world) && this.ticksInAir < 5);

                    AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
                    raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
                } while(raytraceresult1 == null);

                d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
            } while(d1 >= d0 && d0 != 0.0D);

            entity = entity1;
            d0 = d1;
        }
    }

    private void setHookedEntity() {
        this.getDataManager().set(DATA_HOOKED_ENTITY, this.caughtEntity.getEntityId() + 1);
    }

    protected boolean canBeHooked(Entity p_canBeHooked_1_) {
        return p_canBeHooked_1_.canBeCollidedWith() || p_canBeHooked_1_ instanceof EntityItem;
    }

    protected void entityInit() {
        this.getDataManager().register(DATA_HOOKED_ENTITY, 0);
    }

    @Override
    protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {

    }

    @Override
    protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {

    }

    static {
        DATA_HOOKED_ENTITY = EntityDataManager.createKey(Clawshot_Head.class, DataSerializers.VARINT);
    }

    @Override
    public void writeSpawnData(ByteBuf buffer) {
        buffer.writeBoolean(getEntityByUUID(entityPlayer,this.world)==null);
        if (getEntityByUUID(entityPlayer,this.world)!=null) {
            buffer.writeInt(getEntityByUUID(entityPlayer,this.world).getEntityId());
        }
    }

    @Override
    public void readSpawnData(ByteBuf additionalData) {
        boolean nullPlayer = additionalData.readBoolean();
        if (!nullPlayer){
            EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt());
            if (entityByID!=null){
                entityPlayer=entityByID.getUniqueID();
            }
            this.shoot(getEntityByUUID(entityPlayer,this.world));
        }
    }

    static enum State {
        FLYING,
        HOOKED_IN_ENTITY;

        private State() {
        }
    }
}

I changed the code to mainly use the UUID of the Player after thinking over Problematic code #9

Didn't solved the Problem though

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted

I made some changes to improve its behavior. But Still it dies after a certain amount  of time that static. Also it then still respawns with the same motion speed as the moment it died.

Updated code:

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Iterator;
import java.util.List;
import java.util.UUID;

public class Clawshot_Head extends Entity implements IEntityAdditionalSpawnData{
    private UUID entityPlayer;
    public Entity caughtEntity;
    public Clawshot_Head.State currentState;
    private static final DataParameter<Integer> DATA_HOOKED_ENTITY;
    private boolean inGround;
    private int ticksInAir;
    private int ticksInGround;
    public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png");

    public Clawshot_Head(World world){
        super(world);
    }

    public Clawshot_Head(World world, EntityPlayer entityPlayer){
        super(world);
        this.init(entityPlayer);
        this.currentState = Clawshot_Head.State.FLYING;
        this.setPosition((double)entityPlayer.posX,(double)entityPlayer.posY+entityPlayer.getEyeHeight(),(double)entityPlayer.posZ);
        this.shoot(entityPlayer);
        this.setNoGravity(true);
    }

    @SideOnly(Side.CLIENT)
    public Clawshot_Head(World world, EntityPlayer entityPlayer, double posX, double posY, double posZ) {
        super(world);
        this.init(entityPlayer);
        this.setPosition(posX,posY,posZ);
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
    }

    public void notifyDataManagerChange(DataParameter<?> p_notifyDataManagerChange_1_) {
        if (DATA_HOOKED_ENTITY.equals(p_notifyDataManagerChange_1_)) {
            int i = (Integer)this.getDataManager().get(DATA_HOOKED_ENTITY);
            this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null;
        }

        super.notifyDataManagerChange(p_notifyDataManagerChange_1_);
    }

    public void onUpdate()
    {
        super.onUpdate();
        if (this.entityPlayer == null)
        {
            System.out.println("ln:70 got called");
            this.setDead();

        }
        else if (this.world.isRemote)
        {
            if (this.inGround) {
                ++this.ticksInGround;
                motionX = 0;
                motionY = 0;
                motionZ = 0;
            }

            if(this.collidedHorizontally){
                motionX=0;
                motionY=0;
                motionZ=0;
                ++this.ticksInGround;
            }

            if(this.getDistance(getEntityByUUID(entityPlayer,world))>=64){
                System.out.println("ln:92 got called");
                this.setDead();
            }

            BlockPos blockpos = new BlockPos(this);
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            if (this.currentState == Clawshot_Head.State.FLYING)
            {
                if (this.caughtEntity != null)
                {
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                    this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY;
                    return;
                }

                if (!this.world.isRemote)
                {
                    this.checkCollision();
                }

                if (!this.inGround && !this.onGround && !this.collidedHorizontally)
                {
                    ++this.ticksInAir;
                }
                else
                {
                    this.ticksInAir = 0;
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                }

            }
            else
            {
                if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY)
                {
                    if (this.caughtEntity != null)
                    {
                        if (this.caughtEntity.isDead)
                        {
                            this.caughtEntity = null;
                            this.currentState = Clawshot_Head.State.FLYING;
                        }
                        else
                        {
                            this.posX = this.caughtEntity.posX;
                            double d2 = (double)this.caughtEntity.height;
                            this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D;
                            this.posZ = this.caughtEntity.posZ;
                            this.setPosition(this.posX, this.posY, this.posZ);
                        }
                    }

                    return;
                }
            }

            this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
            this.updateRotation();
            this.setPosition(this.posX, this.posY, this.posZ);
        }
        if (this.ticksInGround >= 1200)
        {
            System.out.println("ln:157 got called");
            this.setDead();
        }
        if (ticksInAir>=200){
            System.out.println("ln:162 got called");
            this.setDead();
        }

    }

    private void updateRotation()
    {
        float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));

        for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
        {

        }

        while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
        {
            this.prevRotationPitch += 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw < -180.0F)
        {
            this.prevRotationYaw -= 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
        {
            this.prevRotationYaw += 360.0F;
        }

        this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
        this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    }

    public void shoot(Entity entity) {
        System.out.println(entity);
        this.motionX=0.6D*entity.getLookVec().x;
        this.motionY=0.6D*entity.getLookVec().y;
        this.motionZ=0.6D*entity.getLookVec().z;

    }

    public void shoot(double p_shoot_1_, double p_shoot_3_, double p_shoot_5_, float p_shoot_7_, float p_shoot_8_){}

    public int handleHookRetraction()
    {
        if (!this.world.isRemote && this.entityPlayer != null)
        {
            int i = 0;
            if (this.caughtEntity != null)
            {
                this.bringInHookedEntity();
                this.world.setEntityState(this, (byte)31);
                i = this.caughtEntity instanceof EntityItem ? 3 : 5;
            }
            else if (this.inGround)
            {
                i = 2;
            }

            this.setDead();
            return i;
        }
        else
        {
            return 0;
        }
    }

    protected void bringInHookedEntity()
    {
        if (this.getEntityByUUID(entityPlayer,world) != null)
        {
            double d0 = this.getEntityByUUID(entityPlayer,world).posX - this.posX;
            double d1 = this.getEntityByUUID(entityPlayer,world).posY - this.posY;
            double d2 = this.getEntityByUUID(entityPlayer,world).posZ - this.posZ;
            double d3 = 0.1D;
            this.caughtEntity.motionX += d0 * 0.1D;
            this.caughtEntity.motionY += d1 * 0.1D;
            this.caughtEntity.motionZ += d2 * 0.1D;
        }
    }

    public void setDead()
    {
        super.setDead();
    }

    public EntityPlayer getAngler()
    {
        return this.getEntityByUUID(entityPlayer,this.world);
    }

    private EntityPlayer getEntityByUUID(UUID entityUUID, World worldIn){
        int lenght =worldIn.getLoadedEntityList().size();
        List<Entity> loadedEntityList= worldIn.getLoadedEntityList();
        EntityPlayer foundEntity = null;
        for (int i = 0;i<lenght;i++){
            if (loadedEntityList.get(i).getUniqueID()==entityUUID){
                if (loadedEntityList.get(i) instanceof EntityPlayer) {
                    foundEntity = (EntityPlayer) loadedEntityList.get(i);
                }
            }
        }
        return foundEntity;
    }

    private void init(EntityPlayer p_init_1_) {
        this.setSize(0.25F, 0.25F);
        this.ignoreFrustumCheck = true;
        this.entityPlayer = p_init_1_.getUniqueID();
    }

    private void checkCollision() {
        Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        Vec3d vec3d1 = new Vec3d(this.posX + 0.2, this.posY + 0.2, this.posZ + 0.2);
        RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false);
        vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (raytraceresult != null) {
            vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
            this.inGround=true;
            this.motionX=0;
            this.motionY=0;
            this.motionZ=0;
            getEntityByUUID(entityPlayer,this.world).posX=this.posX;
            getEntityByUUID(entityPlayer,this.world).posY=this.posY;
            getEntityByUUID(entityPlayer,this.world).posZ=this.posZ;
        }

        Entity entity = null;
        List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
        double d0 = 0.0D;
        Iterator var8 = list.iterator();

        while(true) {
            Entity entity1;
            double d1;
            do {
                RayTraceResult raytraceresult1;
                do {
                    do {
                        do {
                            if (!var8.hasNext()) {
                                if (entity != null) {
                                    raytraceresult = new RayTraceResult(entity);
                                }

                                if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS) {
                                    if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY) {
                                        this.caughtEntity = raytraceresult.entityHit;
                                        this.setHookedEntity();
                                    } else {
                                        this.inGround = true;
                                    }
                                }

                                return;
                            }

                            entity1 = (Entity)var8.next();
                        } while(!this.canBeHooked(entity1));
                    } while(entity1 == this.getEntityByUUID(entityPlayer,this.world) && this.ticksInAir < 5);

                    AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
                    raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
                } while(raytraceresult1 == null);

                d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
            } while(d1 >= d0 && d0 != 0.0D);

            entity = entity1;
            d0 = d1;
        }
    }

    private void setHookedEntity() {
        this.getDataManager().set(DATA_HOOKED_ENTITY, this.caughtEntity.getEntityId() + 1);
    }

    protected boolean canBeHooked(Entity p_canBeHooked_1_) {
        return p_canBeHooked_1_.canBeCollidedWith() || p_canBeHooked_1_ instanceof EntityItem;
    }

    protected void entityInit() {
        this.getDataManager().register(DATA_HOOKED_ENTITY, 0);
    }

    @Override
    protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {

    }

    @Override
    protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {

    }

    static {
        DATA_HOOKED_ENTITY = EntityDataManager.createKey(Clawshot_Head.class, DataSerializers.VARINT);
    }

    @Override
    public void writeSpawnData(ByteBuf buffer) {
        buffer.writeBoolean(getEntityByUUID(entityPlayer,this.world)==null);
        if (getEntityByUUID(entityPlayer,this.world)!=null) {
            buffer.writeInt(getEntityByUUID(entityPlayer,this.world).getEntityId());
        }
    }

    @Override
    public void readSpawnData(ByteBuf additionalData) {
        boolean nullPlayer = additionalData.readBoolean();
        if (!nullPlayer){
            EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt());
            if (entityByID!=null){
                entityPlayer=entityByID.getUniqueID();
            }
            this.shoot(getEntityByUUID(entityPlayer,this.world));
        }
    }

    static enum State {
        FLYING,
        HOOKED_IN_ENTITY;

        private State() {
        }
    }
}

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted

I found something that might give a hint to the core of the problem:

I'm calling shoot in the constructor and in the readSpawnData()

If I remove it in the constructor the Entity can't move.

If I remove it in readSpawnData() the behavior doesn't change

I noticed it by reading the output of shoot() when I Right click to shoot:

Spoiler

[12:24:02] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:207]: EntityPlayerSP['Player200'/373, l='MpServer', x=224.65, y=93.19, z=279.93]
[12:24:02] [Server thread/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:207]: EntityPlayerMP['Player200'/373, l='Triforce Test', x=224.65, y=93.19, z=279.93]
[12:24:02] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:207]: EntityPlayerSP['Player200'/373, l='MpServer', x=224.65, y=93.19, z=279.93]

A minor thing would be that I want to have a chain or at least a line between the entity and the item and don't know how to do that.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted

So I just managed to set up the breakpoints. Seems like I've done something wrong before.

But still The Entity is only set dead when I reload the world. All other conditions than entityplayer==null seem to be false all the time.

I'll appreciate any help. (Code is in my older posts)

Also the Entity starts after a short time at its startposition with its new movement speed.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted

How can my Entity "die" without causing one of my Breakpoints? The only Output I get is on Loading a World cause off EntityPlayer being null

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted
9 hours ago, _Cruelar_ said:

How can my Entity "die" without causing one of my Breakpoints? The only Output I get is on Loading a World cause off EntityPlayer being null

Override set dead, return super & set a breakpoint there

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
On 7/28/2018 at 8:19 PM, _Cruelar_ said:

public void setDead() { super.setDead(); }

I did already. no results. that's why I used these ".

Edited by _Cruelar_

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted (edited)

I experimented a bit and now I have two one entity: One that behaves like before and one with the right size and almost the right behavior.

Here's my updated code:

Item:

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class Clawshot_TP extends Item {
    public Entity entity;

    public Clawshot_TP(){
        this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD);
        this.setRegistryName("clawshot_tp");
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".clawshot_tp");
        this.addPropertyOverride(new ResourceLocation("cast"), new IItemPropertyGetter() {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack p_apply_1_, @Nullable World p_apply_2_, @Nullable EntityLivingBase p_apply_3_) {
                if (p_apply_3_ == null) {
                    return 0.0F;
                } else {
                    boolean lvt_4_1_ = p_apply_3_.getHeldItemMainhand() == p_apply_1_;
                    boolean lvt_5_1_ = p_apply_3_.getHeldItemOffhand() == p_apply_1_;
                    if (p_apply_3_.getHeldItemMainhand().getItem() instanceof Clawshot_TP) {
                        lvt_5_1_ = false;
                    }

                    return (lvt_4_1_ || lvt_5_1_) && p_apply_3_ instanceof EntityPlayer && entity != null ? 1.0F : 0.0F;
                }
            }
        });
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer,EnumHand enumHand) {
        ItemStack itemStack = entityPlayer.getHeldItem(enumHand);
		if (world.isRemote){
            if (!this.getTagCompoundSafe(itemStack).hasKey("shot") || !this.getTagCompoundSafe(itemStack).getBoolean("shot") || this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack)!=null && this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack).isDead) {
                Clawshot_Head clawshot_head = new Clawshot_Head(world, entityPlayer);
                clawshot_head.shoot(entityPlayer);
                world.spawnEntity(clawshot_head);
                this.getTagCompoundSafe(itemStack).setBoolean("shot",true);
                this.getTagCompoundSafe(itemStack).setUniqueId("head",clawshot_head.getUniqueID());
            } else if (this.getEntityByUUID(this.getTagCompoundSafe(itemStack).getUniqueId("head"),world,itemStack)!=null){
                this.getEntityByUUID(this.getTagCompoundSafe(itemStack).getUniqueId("head"),world,itemStack).setDead();
                this.getTagCompoundSafe(itemStack).setBoolean("shot",false);
            }
        }
        return new ActionResult(EnumActionResult.SUCCESS,itemStack);
    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    private Entity getEntityByUUID(UUID entityUUID, World worldIn, ItemStack itemStack){
        int lenght =worldIn.loadedEntityList.size();
        List<Entity> loadedEntityList= worldIn.loadedEntityList;
        Entity foundEntity = null;
        for (int i = 0;i<lenght;i++){
            if (loadedEntityList.get(i).getUniqueID()==entityUUID){
                foundEntity = loadedEntityList.get(i);
            }
        }
        entity=foundEntity;
        return foundEntity;
    }
}

Entity:

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Iterator;
import java.util.List;
import java.util.UUID;

public class Clawshot_Head extends Entity implements IEntityAdditionalSpawnData{
    private UUID entityPlayer;
    public Entity caughtEntity;
    public Clawshot_Head.State currentState;
    private static final DataParameter<Integer> DATA_HOOKED_ENTITY;
    private boolean inGround;
    private int ticksInAir;
    private int ticksInGround;
    public static final ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png");

    public Clawshot_Head(World world){
        super(world);
    }

    public Clawshot_Head(World world, EntityPlayer entityPlayer){
        super(world);
        this.init(entityPlayer);
        this.currentState = Clawshot_Head.State.FLYING;
        this.setPosition((double)entityPlayer.posX,(double)entityPlayer.posY+entityPlayer.getEyeHeight(),(double)entityPlayer.posZ);
        //this.shoot(entityPlayer); // Changed that as it is called before readSpawnData and writeSpawnData
        this.setNoGravity(true);
    }

    @SideOnly(Side.CLIENT)
    public Clawshot_Head(World world, EntityPlayer entityPlayer, double posX, double posY, double posZ) {
        super(world);
        this.init(entityPlayer);
        this.setPosition(posX,posY,posZ);
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
    }

    public void notifyDataManagerChange(DataParameter<?> p_notifyDataManagerChange_1_) {
        if (DATA_HOOKED_ENTITY.equals(p_notifyDataManagerChange_1_)) {
            int i = (Integer)this.getDataManager().get(DATA_HOOKED_ENTITY);
            this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null;
        }

        super.notifyDataManagerChange(p_notifyDataManagerChange_1_);
    }

    public void onUpdate()
    {
        super.onUpdate();
        if (this.entityPlayer == null)
        {
            System.out.println("ln:70 got called");
            this.setDead();

        }
        else if (this.world.isRemote)
        {
            if (this.inGround) {
                ++this.ticksInGround;
                motionX = 0;
                motionY = 0;
                motionZ = 0;
            }

            if(this.collidedHorizontally){
                motionX=0;
                motionY=0;
                motionZ=0;
                ++this.ticksInGround;
            }

            if(this.getDistance(getEntityByUUID(entityPlayer,world))>=64){
                System.out.println("ln:92 got called");
                this.setDead();
            }

            BlockPos blockpos = new BlockPos(this);
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            if (this.currentState == Clawshot_Head.State.FLYING)
            {
                if (this.caughtEntity != null)
                {
                    this.motionX = 0.0D;
                    this.motionY = 0.0D;
                    this.motionZ = 0.0D;
                    this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY;
                    return;
                }

                if (!this.world.isRemote)
                {
                    this.checkCollision();
                }

            }
            else
            {
                if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY)
                {
                    if (this.caughtEntity != null)
                    {
                        if (this.caughtEntity.isDead)
                        {
                            this.caughtEntity = null;
                            this.currentState = Clawshot_Head.State.FLYING;
                        }
                        else
                        {
                            this.posX = this.caughtEntity.posX;
                            double d2 = (double)this.caughtEntity.height;
                            this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D;
                            this.posZ = this.caughtEntity.posZ;
                            this.setPosition(this.posX, this.posY, this.posZ);
                        }
                    }

                    return;
                }
            }

            this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
            this.updateRotation();
            this.setPosition(this.posX, this.posY, this.posZ);
        }
        if (this.ticksInAir>20){
            this.setDead();
        }
        if (this.ticksInGround >= 1200)
        {
            System.out.println("ln:147 got called");
            this.setDead();
        }

    }

    private void updateRotation()
    {
        float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));

        for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
        {

        }

        while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
        {
            this.prevRotationPitch += 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw < -180.0F)
        {
            this.prevRotationYaw -= 360.0F;
        }

        while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
        {
            this.prevRotationYaw += 360.0F;
        }

        this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
        this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    }

    public void shoot(Entity entity) {
        System.out.println(entity);
        this.motionX=0.6D*entity.getLookVec().x;
        this.motionY=0.6D*entity.getLookVec().y;
        this.motionZ=0.6D*entity.getLookVec().z;

    }

    public void shoot(double p_shoot_1_, double p_shoot_3_, double p_shoot_5_, float p_shoot_7_, float p_shoot_8_){}

    public int handleHookRetraction()
    {
        if (!this.world.isRemote && this.entityPlayer != null)
        {
            int i = 0;
            if (this.caughtEntity != null)
            {
                this.bringInHookedEntity();
                this.world.setEntityState(this, (byte)31);
                i = this.caughtEntity instanceof EntityItem ? 3 : 5;
            }
            else if (this.inGround)
            {
                i = 2;
            }

            this.setDead();
            return i;
        }
        else
        {
            return 0;
        }
    }

    protected void bringInHookedEntity()
    {
        if (this.getEntityByUUID(entityPlayer,world) != null)
        {
            double d0 = this.getEntityByUUID(entityPlayer,world).posX - this.posX;
            double d1 = this.getEntityByUUID(entityPlayer,world).posY - this.posY;
            double d2 = this.getEntityByUUID(entityPlayer,world).posZ - this.posZ;
            double d3 = 0.1D;
            this.caughtEntity.motionX += d0 * d3;
            this.caughtEntity.motionY += d1 * d3;
            this.caughtEntity.motionZ += d2 * d3;
        }
    }

    public void setDead()
    {
        super.setDead();
    }

    public EntityPlayer getAngler()
    {
        return this.getEntityByUUID(entityPlayer,this.world);
    }


    private EntityPlayer getEntityByUUID(UUID entityUUID, World worldIn){
        int lenght =worldIn.loadedEntityList.size();
        List<Entity> loadedEntityList= worldIn.loadedEntityList;
        EntityPlayer foundEntity = null;
        for (int i = 0;i<lenght;i++){
            if (loadedEntityList.get(i).getUniqueID()==entityUUID){
                if (loadedEntityList.get(i) instanceof EntityPlayer) {
                    foundEntity = (EntityPlayer) loadedEntityList.get(i);
                }
            }
        }
        return foundEntity;
    }

    private void init(EntityPlayer p_init_1_) {
        this.setSize(0.25F, 0.25F);
        this.ignoreFrustumCheck = true;
        this.entityPlayer = p_init_1_.getUniqueID();
    }

    private void checkCollision() {
        Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        Vec3d vec3d1 = new Vec3d(this.posX + 0.2, this.posY + 0.2, this.posZ + 0.2);
        RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false);
        vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (raytraceresult != null) {
            vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
            this.inGround=true;
            this.motionX=0;
            this.motionY=0;
            this.motionZ=0;
            getEntityByUUID(entityPlayer,this.world).posX=this.posX;
            getEntityByUUID(entityPlayer,this.world).posY=this.posY;
            getEntityByUUID(entityPlayer,this.world).posZ=this.posZ;
        }

        Entity entity = null;
        List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
        double d0 = 0.0D;
        Iterator var8 = list.iterator();

        while(true) {
            Entity entity1;
            double d1;
            do {
                RayTraceResult raytraceresult1;
                do {
                    do {
                        do {
                            if (!var8.hasNext()) {
                                if (entity != null) {
                                    raytraceresult = new RayTraceResult(entity);
                                }

                                if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS) {
                                    if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY) {
                                        this.caughtEntity = raytraceresult.entityHit;
                                        this.setHookedEntity();
                                    } else {
                                        this.inGround = true;
                                    }
                                }

                                return;
                            }

                            entity1 = (Entity)var8.next();
                        } while(!this.canBeHooked(entity1));
                    } while(entity1 == this.getEntityByUUID(entityPlayer,this.world) && this.ticksInAir < 5);

                    AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
                    raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
                } while(raytraceresult1 == null);

                d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
            } while(d1 >= d0 && d0 != 0.0D);

            entity = entity1;
            d0 = d1;
        }
    }

    private void setHookedEntity() {
        this.getDataManager().set(DATA_HOOKED_ENTITY, this.caughtEntity.getEntityId() + 1);
    }

    protected boolean canBeHooked(Entity p_canBeHooked_1_) {
        return p_canBeHooked_1_.canBeCollidedWith() || p_canBeHooked_1_ instanceof EntityItem;
    }

    protected void entityInit() {
        this.getDataManager().register(DATA_HOOKED_ENTITY, 0);
    }

    @Override
    protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {

    }

    @Override
    protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {

    }

    static {
        DATA_HOOKED_ENTITY = EntityDataManager.createKey(Clawshot_Head.class, DataSerializers.VARINT);
    }

    @Override
    public void writeSpawnData(ByteBuf buffer) {
        buffer.writeBoolean(getEntityByUUID(entityPlayer,this.world)==null);
        if (getEntityByUUID(entityPlayer,this.world)!=null) {
            buffer.writeInt(getEntityByUUID(entityPlayer,this.world).getEntityId());
        }
    }

    @Override
    public void readSpawnData(ByteBuf additionalData) {
        boolean nullPlayer = additionalData.readBoolean();
        if (!nullPlayer){
            EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt());
            if (entityByID!=null){
                entityPlayer=entityByID.getUniqueID();
            }
            //this.shoot(getEntityByUUID(entityPlayer,this.world)); //changed that because it is only called on one Side. Obviously the wrong side.
        }
    }

    static enum State {
        FLYING,
        HOOKED_IN_ENTITY;

        private State() {
        }
    }
}

New log output when shooting:

Spoiler

[11:13:43] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:209]: EntityPlayerSP['Player636'/283, l='MpServer', x=250.85, y=72.79, z=261.42]
[11:15:01] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:onUpdate:92]: ln:92 got called

It dies from me being to far away. Remaining Problems:

I can't retract it and can't use the Item more than one time.

I would like to have a line drawn between the Entity and me. Quite similar to the fishing hook.

Edited by _Cruelar_
More experimenting removed the 2nd entity, Updated code

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.