Jump to content

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


Recommended Posts

Posted (edited)

Hello guys, I'm relative new to Minecraft Modding and Java coding in general. I've tried to make a clawshot out of The Legend of Zelda: Twilight Princess (and plan a double clawshot). On use it shoots an Clawshot_Head and "drags" the player to the place where it hits a block, or "drags" enemies it hits to the player. For this it has a maximum range for all this. The normal clawshot shoots max. 1 head so if you try to use it while you hang somewhere you fall down.

 

So that was the theory.

 

Here's what it actually does. The clawshot does nothing. And if I spawn with /summon the head it's simply a 1 block tall and 0.5 block wide box colored White. The code of the Head is mostly based on the Fishing hook. I know you all Always struggle with that, so I tell you what I think the problem is and hope somebody can confirm this or at least say me that I  forgot something important:  

So what I found out is that there's no registration of the fishinghook. As I use the same concept but don't know how to registrate this could cause the problem.

 

My Clawshot.class:

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.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.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.Objects;

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.MAIN_HAND);
        Item item = entityPlayer.getHeldItemMainhand().getItem();
        if (item == this) {
            if (!world.isRemote) {
                    Clawshot_Head clawshot_head = new Clawshot_Head(world,entityPlayer);
                    world.spawnEntity(clawshot_head);
            }
        }
        return new ActionResult(EnumActionResult.SUCCESS,itemStack);
    }

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

 

And his head (Clawshot_Head.class):

import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityFishHook;
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.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
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{
    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;
    public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png");

    public Clawshot_Head(World world){
        super(world);
        this.shoot((EntityPlayer)null);

    }

    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.posX);
        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 shoot(Entity 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_){}

    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);
            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(EntityFishHook.class, DataSerializers.VARINT);
    }

    static enum State {
        FLYING,
        HOOKED_IN_ENTITY;

        private State() {
        }
    }
}

 

For Registration:

In ModItems:

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.items.*;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ModItems  {

				...

    @GameRegistry.ObjectHolder("cruelars_triforcemod:clawshot_tp")
    public static Clawshot_TP clawshot_tp;

				...

    @SideOnly(Side.CLIENT)
    public static void initModels(){
        		...
        clawshot_tp.initModel();
				...
    }
}

 

In CommonProxy:

import com.cruelar.cruelars_triforcemod.*;
import com.cruelar.cruelars_triforcemod.init.ModArmor;
import com.cruelar.cruelars_triforcemod.init.ModBlocks;
import com.cruelar.cruelars_triforcemod.init.ModEntities;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.blocks.*;
import com.cruelar.cruelars_triforcemod.items.*;
import com.cruelar.cruelars_triforcemod.tileentity.False_Block_TileEntity;
import com.cruelar.cruelars_triforcemod.tileentity.Hidden_Block_TileEntity;
import com.cruelar.cruelars_triforcemod.tileentity.Pedestal_Of_Time_TileEntity;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionType;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;

import java.io.File;
import java.util.Objects;

import static com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core.instance;

@Mod.EventBusSubscriber(modid = Cruelars_Triforcemod_Core.MODID)
public class CommonProxy {
    public static Configuration config;


    public void preInit(FMLPreInitializationEvent event) {
        File directory = event.getModConfigurationDirectory();
        config = new Configuration(new File(directory.getPath(),"cruelars_triforcemod.cfg"));
        Config.readConfig();
        ModEntities.init();

    }
    
			...

    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event){
      		...
        event.getRegistry().register(new Clawshot_TP());
      		...
        }

}

In Mod Entities:

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.entities.EntityBombPrimed;
import com.cruelar.cruelars_triforcemod.entities.boss.*;
import com.cruelar.cruelars_triforcemod.entities.monster.*;
import com.cruelar.cruelars_triforcemod.entities.passive.Fairy;
import com.cruelar.cruelars_triforcemod.entities.projectiles.*;
import com.cruelar.cruelars_triforcemod.renderer.*;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Biomes;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ModEntities {

    public static void init(){
        int id = 1;
        	... // current id is 14
        EntityRegistry.registerModEntity(Clawshot_Head.RESOURCE_LOCATION,Clawshot_Head.class,"cruelars_triforcemod:clawshot_head",id++,Cruelars_Triforcemod_Core.instance,64,3,true);
        		...

    }

    @SideOnly(Side.CLIENT)
    public static void initModels(){
				...
        RenderingRegistry.registerEntityRenderingHandler(Clawshot_Head.class,RenderClawshot.FACTORY);
        		...
    }
}

 

Rendering of the Head:

import com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderClawshot extends RenderEntity {
    public static final ResourceLocation RES_ARROW = new ResourceLocation("textures/entity/projectiles/arrow.png");
    public static final ResourceLocation RES_Bomb_ARROW = new ResourceLocation("textures/entity/projectiles/clawshot_head.png");
    public static final Factory FACTORY = new Factory();

    public RenderClawshot(RenderManager p_i46547_1_) {
        super(p_i46547_1_);
    }

    protected ResourceLocation getEntityTexture() {
        return Clawshot_Head.RESOURCE_LOCATION;
    }

    public static class Factory implements IRenderFactory<Clawshot_Head> {

        @Override
        public Render<? super Clawshot_Head> createRenderFor(RenderManager manager){
            return new RenderClawshot(manager);
        }
    }
}

 

Any advise on creating topics is also helpful, because I'm german and new to this.

Edited by _Cruelar_
Better Topictitle

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

  • 3 weeks later...
  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

Posted

Looking at it briefly, the fishhook along with other "entity objects" like minecart are spawned on the client side based on a packet called SPacketSpawnObject. You can see the processing of that received packet in NetHandlerPlayClient#handleSpawnObject() method. Basically the vanilla objects are hard-coded to a number of values (fishhook is 90).

 

So you won't be able to use the same packet, but you may have to try to replicate the same system. At the time you spawn the fishhook on the server side you probably need to send a custom packet that then spawns on client similarly.

 

However, it may be possible to be simpler than that. In your onItemRightClick() you're specifically checking for server side before spawning. What happens if you just allow it to spawn on both sides? I think the problem though is for other players -- even if this works for singleplayer I'm not sure that other people would see it without packets. 

 

I also think that doing a registered entity approach could work, but not entirely sure what modifications would be needed.

 

In any case, the most obvious way of copying the fishhook is to send a spawn packet from server. So check out how the SPacketSpawnObject is sent for fishhook and then send a similar custom packet for your claw.. 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
3 hours ago, diesieben07 said:

No need for a custom packet. This is the reason IEntityAdditionalSpawnData exists.

So how would I use this?

Also I've found an error while trying to use it (doesn't breaks the game)

[13:02:45] [main/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.RuntimeException: A severe problem occurred during the spawning of an entity at (194.78415135238228, 74.54834158954293, 194.78415135238228)
	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(SourceFile:47) [Util.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1086) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:397) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(SourceFile:123) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_152]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_152]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_152]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_152]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_152]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_152]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_152]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_152]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: java.lang.RuntimeException: A severe problem occurred during the spawning of an entity at (194.78415135238228, 74.54834158954293, 194.78415135238228)
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:136) ~[EntitySpawnHandler.class:?]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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(SourceFile:46) ~[Util.class:?]
	... 15 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.GeneratedConstructorAccessor60.newInstance(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_152]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_152]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:88) ~[EntitySpawnHandler.class:?]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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(SourceFile:46) ~[Util.class:?]
	... 15 more
Caused by: java.lang.NullPointerException
	at com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head.shoot(Clawshot_Head.java:89) ~[Clawshot_Head.class:?]
	at com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head.<init>(Clawshot_Head.java:33) ~[Clawshot_Head.class:?]
	at sun.reflect.GeneratedConstructorAccessor60.newInstance(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_152]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_152]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:88) ~[EntitySpawnHandler.class:?]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
	at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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(SourceFile:46) ~[Util.class:?]
	... 15 more

 

14 hours ago, jabelar said:

However, it may be possible to be simpler than that. In your onItemRightClick() you're specifically checking for server side before spawning. What happens if you just allow it to spawn on both sides?

Doesn't change anything.

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)
8 minutes ago, diesieben07 said:

You did not even show your code...

I've haven't changed anything so far (except trying once with out the if(world!=remote)) because I don't have any idea what to do

for example should my Entity implement the interface or the Renderer?

If the Entity should: what I'm supposed to write into the methods of the interface?

Same for the case the Renderer should implement it.

 

Some example code could really help me.

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
6 hours ago, diesieben07 said:

No need for a custom packet. This is the reason IEntityAdditionalSpawnData exists.

 

He's not actually trying to send additional data though, he's trying to get the client-side entity to spawn in the first place. For the vanilla fish hook there is a dedicated packet type for this SServerSpawnObject that is distinct from other entities.

 

Now ultimately I asume he can rely on a regular registered entity type of spawn mechanism, but just that if the approach is to copy the fishhook approach it might be a bit different..

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Could anyone please tell me if the Problem results in the NPE in the error above and how to fix that. Cause I'm lost in Forge Javadoc and now completely confused. I've no idea what you mean with all this.

I copied from Fishing hook as I thought the fishingrod Fishinghook relation is quite similar to the Clawshot clawshot_head relation. But I see this is quite complicated so what should I do.

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)

@diesieben07

That may is right but it doesn't help me. I don't understand HOW this works, I don't want to know WHY this or the other thing is better. I've found something what might be the result of the Problem(see my post above) and hope that you guys can tell me how to solve this. Soory to be such an idiot that I don't understand what you mean with the posts above but I'm still quite new to forge and don't know much about networking. I simply tried to copy something from Vanilla and adapt to my needs what in the most cases works well.

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

So with classic System.out.println(entity) i got this

[11:07:49] [Server thread/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerMP['Player87'/318, l='Triforce Test', x=227.66, y=95.00, z=265.97]
[11:07:49] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: null

This means the code finds the Player on Serverside but not on Client, I think

 

On 7/19/2018 at 10:17 PM, jabelar said:

However, it may be possible to be simpler than that. In your onItemRightClick() you're specifically checking for server side before spawning. What happens if you just allow it to spawn on both sides?

Then I get this

[11:13:10] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerSP['Player636'/318, l='MpServer', x=227.66, y=95.00, z=265.97]
[11:13:10] [Server thread/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerMP['Player636'/318, l='Triforce Test', x=227.66, y=95.00, z=265.97]
[11:13:10] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: null

He seems to have touble to get the normal Player.

 

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

Now I understand what you mean, but what should I write into writeSpawnData? I think I have to add the Player somehow to the ByteBuf but how would I write an EntityPlayer to it?

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityFishHook;
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.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
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;
    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.posX);
        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 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_){}

    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);
            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(EntityFishHook.class, DataSerializers.VARINT);
    }

    @Override
    public void writeSpawnData(ByteBuf buffer) {
    }

    @Override
    public void readSpawnData(ByteBuf additionalData) {

    }

    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

Still doesn't work. What is wrong?

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityFishHook;
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.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
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;
    public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png");

    public Clawshot_Head(World world){
        super(world);
        this.shoot(entityPlayer);
    }

    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.posX);
        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 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_){}

    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);
            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(EntityFishHook.class, DataSerializers.VARINT);
    }

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

    @Override
    public void readSpawnData(ByteBuf additionalData) {
        entityPlayer=(EntityPlayer) world.getEntityByID(additionalData.readInt());
    }

    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

This means nothing has changed. Here the log:

Spoiler

[18:32:07] [Server thread/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:90]: EntityPlayerMP['Player671'/344, l='Triforce Test', x=237.23, y=97.87, z=265.72]
[18:32:07] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:90]: null
[18:32:07] [main/FATAL] [net.minecraft.client.Minecraft]: Error executing task
java.util.concurrent.ExecutionException: java.lang.RuntimeException: A severe problem occurred during the spawning of an entity at (237.23063243784554, 99.48859856618026, 237.23063243784554)
    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.client.Minecraft.runGameLoop(Minecraft.java:1176) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_152]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_152]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_152]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_152]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_152]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_152]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_152]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_152]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.RuntimeException: A severe problem occurred during the spawning of an entity at (237.23063243784554, 99.48859856618026, 237.23063243784554)
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:136) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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:?]
    ... 15 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_152]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_152]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_152]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_152]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:88) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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:?]
    ... 15 more
Caused by: java.lang.NullPointerException
    at com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head.shoot(Clawshot_Head.java:91) ~[Clawshot_Head.class:?]
    at com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head.<init>(Clawshot_Head.java:35) ~[Clawshot_Head.class:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_152]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_152]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_152]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_152]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:88) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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:?]
    ... 15 more

 

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
5 minutes ago, diesieben07 said:

Also, your writeSpawnData and readSpawnData are not symmetrical. You must write exactly the same data you read.

Why that? I use the Player to write his id and I get the Player by reading his Id.

7 minutes ago, diesieben07 said:

You are calling shoot in the constructor. readSpawnData will be called afterwards.

So where should I call it? in onItemRightClick?

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
11 minutes ago, diesieben07 said:

Not correct. You only sometimes write the ID, but always read it.

Is this better or would always write and always read be better?

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

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

 

Also I'm still not sure where shoot would be best. I've tried in onItemRightClick what resulted in this:

Spoiler

[19:13:37] [main/FATAL] [net.minecraft.client.Minecraft]: Error executing task
java.util.concurrent.ExecutionException: java.lang.RuntimeException: A severe problem occurred during the spawning of an entity at (237.23063243784554, 99.48859856618026, 237.23063243784554)
    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.client.Minecraft.runGameLoop(Minecraft.java:1176) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_152]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_152]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_152]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_152]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_152]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_152]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_152]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_152]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.RuntimeException: A severe problem occurred during the spawning of an entity at (237.23063243784554, 99.48859856618026, 237.23063243784554)
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:136) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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:?]
    ... 15 more
Caused by: java.lang.IndexOutOfBoundsException: readerIndex(99) + length(4) exceeds writerIndex(99): UnpooledSlicedByteBuf(ridx: 99, widx: 99, cap: 99/99, unwrapped: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 100, cap: 256))
    at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1396) ~[AbstractByteBuf.class:4.1.9.Final]
    at io.netty.buffer.AbstractByteBuf.readInt(AbstractByteBuf.java:766) ~[AbstractByteBuf.class:4.1.9.Final]
    at com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head.readSpawnData(Clawshot_Head.java:198) ~[Clawshot_Head.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:130) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:64) ~[EntitySpawnHandler.class:?]
    at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.lambda$channelRead0$0(EntitySpawnHandler.java:55) ~[EntitySpawnHandler.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:?]
    ... 15 more
[19:13:38] [main/INFO] [net.minecraft.client.gui.GuiNewChat]: [CHAT] §eJourneyMap:§f Press [§bJ§f]
[19:13:40] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerSP['Player394'/317, l='MpServer', x=237.23, y=97.87, z=265.72]
[19:13:40] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerSP['Player394'/317, l='MpServer', x=237.23, y=97.87, z=265.72]
[19:13:40] [Server thread/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerMP['Player394'/317, l='Triforce Test', x=237.23, y=97.87, z=265.72]
[19:13:40] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerSP['Player394'/317, l='MpServer', x=237.23, y=97.87, z=265.72]

 

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

Problem: this results in a NPE

@Override
    public void writeSpawnData(ByteBuf buffer) {
        buffer.writeInt(entityPlayer.getEntityId());
    }

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

the log:

Spoiler

[19:22:04] [Server thread/ERROR] [net.minecraft.server.MinecraftServer]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Exception ticking world
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:837) ~[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: io.netty.handler.codec.EncoderException: java.lang.NullPointerException
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106) ~[MessageToMessageEncoder.class:4.1.9.Final]
    at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:704) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1017) ~[DefaultChannelPipeline.class:4.1.9.Final]
    at io.netty.channel.AbstractChannel.write(AbstractChannel.java:286) ~[AbstractChannel.class:4.1.9.Final]
    at io.netty.channel.embedded.EmbeddedChannel.writeOutbound(EmbeddedChannel.java:341) ~[EmbeddedChannel.class:4.1.9.Final]
    at net.minecraftforge.fml.common.network.FMLEmbeddedChannel.generatePacketFrom(FMLEmbeddedChannel.java:72) ~[FMLEmbeddedChannel.class:?]
    at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.getEntitySpawningPacket(FMLNetworkHandler.java:134) ~[FMLNetworkHandler.class:?]
    at net.minecraft.entity.EntityTrackerEntry.createSpawnPacket(EntityTrackerEntry.java:523) ~[EntityTrackerEntry.class:?]
    at net.minecraft.entity.EntityTrackerEntry.updatePlayerEntity(EntityTrackerEntry.java:399) ~[EntityTrackerEntry.class:?]
    at net.minecraft.entity.EntityTracker.sendLeashedEntitiesInChunk(EntityTracker.java:401) ~[EntityTracker.class:?]
    at net.minecraft.server.management.PlayerChunkMapEntry.sendToPlayers(PlayerChunkMapEntry.java:166) ~[PlayerChunkMapEntry.class:?]
    at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:212) ~[PlayerChunkMap.class:?]
    at net.minecraft.world.WorldServer.tick(WorldServer.java:236) ~[WorldServer.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831) ~[MinecraftServer.class:?]
    ... 4 more
Caused by: java.lang.NullPointerException
    at com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head.writeSpawnData(Clawshot_Head.java:191) ~[Clawshot_Head.class:?]
    at net.minecraftforge.fml.common.network.internal.FMLMessage$EntitySpawnMessage.toBytes(FMLMessage.java:213) ~[FMLMessage$EntitySpawnMessage.class:?]
    at net.minecraftforge.fml.common.network.internal.FMLRuntimeCodec.encodeInto(FMLRuntimeCodec.java:42) ~[FMLRuntimeCodec.class:?]
    at net.minecraftforge.fml.common.network.internal.FMLRuntimeCodec.encodeInto(FMLRuntimeCodec.java:32) ~[FMLRuntimeCodec.class:?]
    at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.encode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?]
    at io.netty.handler.codec.MessageToMessageCodec$1.encode(MessageToMessageCodec.java:67) ~[MessageToMessageCodec$1.class:4.1.9.Final]
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:88) ~[MessageToMessageEncoder.class:4.1.9.Final]
    at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:704) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
    at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1017) ~[DefaultChannelPipeline.class:4.1.9.Final]
    at io.netty.channel.AbstractChannel.write(AbstractChannel.java:286) ~[AbstractChannel.class:4.1.9.Final]
    at io.netty.channel.embedded.EmbeddedChannel.writeOutbound(EmbeddedChannel.java:341) ~[EmbeddedChannel.class:4.1.9.Final]
    at net.minecraftforge.fml.common.network.FMLEmbeddedChannel.generatePacketFrom(FMLEmbeddedChannel.java:72) ~[FMLEmbeddedChannel.class:?]
    at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.getEntitySpawningPacket(FMLNetworkHandler.java:134) ~[FMLNetworkHandler.class:?]
    at net.minecraft.entity.EntityTrackerEntry.createSpawnPacket(EntityTrackerEntry.java:523) ~[EntityTrackerEntry.class:?]
    at net.minecraft.entity.EntityTrackerEntry.updatePlayerEntity(EntityTrackerEntry.java:399) ~[EntityTrackerEntry.class:?]
    at net.minecraft.entity.EntityTracker.sendLeashedEntitiesInChunk(EntityTracker.java:401) ~[EntityTracker.class:?]
    at net.minecraft.server.management.PlayerChunkMapEntry.sendToPlayers(PlayerChunkMapEntry.java:166) ~[PlayerChunkMapEntry.class:?]
    at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:212) ~[PlayerChunkMap.class:?]
    at net.minecraft.world.WorldServer.tick(WorldServer.java:236) ~[WorldServer.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831) ~[MinecraftServer.class:?]
    ... 4 more

 

 

minecraft crash report:

Spoiler

[19:22:05] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:629]: ---- Minecraft Crash Report ----
// There are four lights!

Time: 7/21/18 7:22 PM
Description: Exception ticking world

io.netty.handler.codec.EncoderException: java.lang.NullPointerException
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106)
    at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:704)
    at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1017)
    at io.netty.channel.AbstractChannel.write(AbstractChannel.java:286)
    at io.netty.channel.embedded.EmbeddedChannel.writeOutbound(EmbeddedChannel.java:341)
    at net.minecraftforge.fml.common.network.FMLEmbeddedChannel.generatePacketFrom(FMLEmbeddedChannel.java:72)
    at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.getEntitySpawningPacket(FMLNetworkHandler.java:134)
    at net.minecraft.entity.EntityTrackerEntry.createSpawnPacket(EntityTrackerEntry.java:523)
    at net.minecraft.entity.EntityTrackerEntry.updatePlayerEntity(EntityTrackerEntry.java:399)
    at net.minecraft.entity.EntityTracker.sendLeashedEntitiesInChunk(EntityTracker.java:401)
    at net.minecraft.server.management.PlayerChunkMapEntry.sendToPlayers(PlayerChunkMapEntry.java:166)
    at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:212)
    at net.minecraft.world.WorldServer.tick(WorldServer.java:236)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head.writeSpawnData(Clawshot_Head.java:191)
    at net.minecraftforge.fml.common.network.internal.FMLMessage$EntitySpawnMessage.toBytes(FMLMessage.java:213)
    at net.minecraftforge.fml.common.network.internal.FMLRuntimeCodec.encodeInto(FMLRuntimeCodec.java:42)
    at net.minecraftforge.fml.common.network.internal.FMLRuntimeCodec.encodeInto(FMLRuntimeCodec.java:32)
    at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.encode(FMLIndexedMessageToMessageCodec.java:77)
    at io.netty.handler.codec.MessageToMessageCodec$1.encode(MessageToMessageCodec.java:67)
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:88)
    ... 22 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106)
    at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:704)
    at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1017)
    at io.netty.channel.AbstractChannel.write(AbstractChannel.java:286)
    at io.netty.channel.embedded.EmbeddedChannel.writeOutbound(EmbeddedChannel.java:341)
    at net.minecraftforge.fml.common.network.FMLEmbeddedChannel.generatePacketFrom(FMLEmbeddedChannel.java:72)
    at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.getEntitySpawningPacket(FMLNetworkHandler.java:134)
    at net.minecraft.entity.EntityTrackerEntry.createSpawnPacket(EntityTrackerEntry.java:523)
    at net.minecraft.entity.EntityTrackerEntry.updatePlayerEntity(EntityTrackerEntry.java:399)
    at net.minecraft.entity.EntityTracker.sendLeashedEntitiesInChunk(EntityTracker.java:401)
    at net.minecraft.server.management.PlayerChunkMapEntry.sendToPlayers(PlayerChunkMapEntry.java:166)
    at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:212)
    at net.minecraft.world.WorldServer.tick(WorldServer.java:236)

-- Affected level --
Details:
    Level name: Triforce Test
    All players: 1 total; [EntityPlayerMP['Player527'/319, l='Triforce Test', x=237.23, y=97.87, z=265.72]]
    Chunk stats: ServerChunkCache: 788 Drop: 0
    Level seed: -7073363584905754142
    Level generator: ID 00 - default, ver 1. Features enabled: true
    Level generator options:
    Level spawn location: World: (172,64,212), Chunk: (at 12,4,4 in 10,13; contains blocks 160,0,208 to 175,255,223), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 1195402 game time, 33089 day time
    Level dimension: 0
    Level storage version: 0x04ABD - Anvil
    Level weather: Rain time: 59923 (now: false), thunder time: 117888 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:831)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_152, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 362175992 bytes (345 MB) / 854065152 bytes (814 MB) up to 1883242496 bytes (1796 MB)
    JVM Flags: 0 total;
    IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
    FML: MCP 9.42 Powered by Forge 14.23.4.2705 9 mods loaded, 9 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State              | ID                                        | Version            | Source                                                    | Signature |
    |:---------           |:--------------------             |:------------        |:--------------------------------                 |:---------       |
    | UCHIJAAAA | minecraft                         | 1.12.2              | minecraft.jar                                        | None          |
    | UCHIJAAAA | mcp                                   | 9.42                  | minecraft.jar                                        | None           |
    | UCHIJAAAA | FML                                    | 8.0.99.99        | forgeSrc-1.12.2-14.23.4.2705.jar  | None          |
    | UCHIJAAAA | forge                                  | 14.23.4.2705 | forgeSrc-1.12.2-14.23.4.2705.jar | None           |
    | UCHIJAAAA | cruelars_triforcemod | 0.4.1                 | Cruelars_Triforcemod_main        | None           |
    | UCHIJAAAA | journeymap                   | 1.12.2-5.5.2   | journeymap-1.12.2-5.5.2.jar          | None          |
    | UCHIJAAAA | baubles                            | 1.5.2                 | Baubles-Mod-1.12.2.jar                   | None          |
    | UCHIJAAAA | ichunutil                          | 7.1.4                 | iChunUtil-1.12.2-7.1.4.jar               | None           |
    | UCHIJAAAA | tabula                               | 7.0.0                 | Tabula-1.12.2-7.0.0-deobf.jar        | None          |

    Loaded coremods (and transformers):
    GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
    Profiler Position: N/A (disabled)
    Player Count: 1 / 8; [EntityPlayerMP['Player527'/319, l='Triforce Test', x=237.23, y=97.87, z=265.72]]
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'

 

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
1 minute ago, _Cruelar_ said:

Problem: this results in a NPE

Write two things, a boolean and the id, but the booleans value would be if the players id was written. Read and write the boolean first.

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

So like this?

 @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);
        }
    }

 

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

It doesn't crash but also doesn't seem to find the Player and therefor doesn't spawns the Entity

I've a System.out.println(player) in shoot. That's what I get

Spoiler

[19:38:10] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerSP['Player701'/319, l='MpServer', x=237.23, y=97.87, z=265.72]
[19:38:10] [Server thread/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerMP['Player701'/319, l='Triforce Test', x=237.23, y=97.87, z=265.72]
[19:38:10] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:89]: EntityPlayerSP['Player701'/319, l='MpServer', x=237.23, y=97.87, z=265.72]

 

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

Could anyone look for a solution please, I need this working.

Here's my code:

Clawshot:

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.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.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.Objects;

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.MAIN_HAND);
        Item item = entityPlayer.getHeldItemMainhand().getItem();
        if (item == this) {
            Clawshot_Head clawshot_head = new Clawshot_Head(world,entityPlayer);
            if (!world.isRemote) {
                    world.spawnEntity(clawshot_head);
            }
        }
        return new ActionResult(EnumActionResult.SUCCESS,itemStack);
    }

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

 

Clawshot_Head:

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityFishHook;
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.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
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;
    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.posX);
        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 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_){}

    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);
            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(EntityFishHook.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

Now it moves and I can fire it but it respawns after its "death" and starts to move again.

Clawshot_head:

package com.cruelar.cruelars_triforcemod.entities.projectiles;

import io.netty.buffer.ByteBuf;
import net.minecraft.block.material.Material;
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;
    private boolean shouldRetarct=false;
    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.posX);
        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;

                if (this.ticksInGround >= 1200)
                {
                    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.shouldRetarct=true;
                }
            }
            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;
                }
            }

            if (iblockstate.getMaterial() != Material.WATER)
            {
                this.motionY -= 0.03D;
            }

            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;

            net.minecraftforge.event.entity.player.ItemFishedEvent event = null;
            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 0;
        }
        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);
            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() {
        }
    }
}

Everything else is the same.

Do I need a Capability to allow only one Clawshot head per Player?

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
1 hour ago, _Cruelar_ said:

Do I need a Capability to allow only one Clawshot head per Player?

You need to store the entity in the ItemStack, and when the player switches hands or is right clicked while active you need to remove the entity and then delete the reference in the ItemStack. The reference should be the uuid. 

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

Problem this

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer, EnumHand enumHand) {
    ItemStack itemStack = entityPlayer.getHeldItem(EnumHand.MAIN_HAND);
    Item item = entityPlayer.getHeldItemMainhand().getItem();
    if (item == this) {
        if (clawshot_head==null) {
            Clawshot_Head clawshot_head1 = new Clawshot_Head(world, entityPlayer);
            clawshot_head=clawshot_head1;
            if (!world.isRemote) {
                world.spawnEntity(clawshot_head);
            }
        } else {
            clawshot_head.setDead();
            clawshot_head=null;
        }
    }
    return new ActionResult(EnumActionResult.SUCCESS,itemStack);
}

gets called multible times per use of item.

Would it be better to use onItemUseFinish?

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
  • Removed that.
  • Removed that.
  • So when checking for the head beeing not null also check for !world..isRemote ?

Like that:

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer, EnumHand enumHand) {
    ItemStack itemStack = entityPlayer.getHeldItem(EnumHand.MAIN_HAND);
        if (clawshot_head==null) {
            Clawshot_Head clawshot_head1 = new Clawshot_Head(world, entityPlayer);
            clawshot_head=clawshot_head1;
            if (!world.isRemote) {
                world.spawnEntity(clawshot_head);
            }
        } else if (!world.isRemote){
            clawshot_head.setDead();
            clawshot_head=null;
        }
    return new ActionResult(EnumActionResult.SUCCESS,itemStack);
}
  • So what should I use?

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.