Jump to content

[1.14.4] Making a Trident like item


MineModder2000

Recommended Posts

37 minutes ago, MineModder2000 said:

this.world.setEntityState(this, (byte)3); this.remove();

This is the code that causes the particles and removes the entity from the world. But...it only happens if the Type is ENTITY.

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.

Link to comment
Share on other sites

5 minutes ago, Animefan8888 said:

This is the code that causes the particles and removes the entity from the world. But...it only happens if the Type is ENTITY.

Actually with this code as the check alone :

 

(result.getType() == RayTraceResult.Type.ENTITY)

 

That line causes the throwable to break against anything, dirt, sand, leaves, grass, flowers, etc. I want it to pass through grass and leaves. 

Edited by MineModder2000
Link to comment
Share on other sites

1 minute ago, MineModder2000 said:

Actually with this code as the check alone 

No you don't get it. You only ever "break" the item when it hits an entity. You do properly ignore grass blocks(not the grass blocks you want to ignore however). But that still leaves what happens with all the other blocks. You never tell it to break.

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.

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

No you don't get it. You only ever "break" the item when it hits an entity. You do properly ignore grass blocks(not the grass blocks you want to ignore however). But that still leaves what happens with all the other blocks. You never tell it to break.

Ah I got it now, i figured out the correct logic and it works as intended. 

 

1 hour ago, Animefan8888 said:

not the grass blocks you want to ignore however

Actually it is, Block.Grass, Block.Tall_Grass, etc. are the vegetation blocks that I need to be ignored, and now they are. Thanks for bearing with me. 

Link to comment
Share on other sites

On 8/28/2019 at 9:47 PM, TheMikeste1 said:

By "first constructor," I assume you mean "new Spear_Entity(null , null)" inside of Builder#create. Instead of giving it an Entity, give it an IFactory, like so:


Spear_Entity::new

 

 

I am having a java error with this, I am asking on java forums as I am not familiar with lambas and some other advanced concepts. I will report back here later. 

Link to comment
Share on other sites

Need help with this again. So my throwable entity works fine, some of the time, but I have it coded so that it can only thrown at certain intervals and not at the rapid pace that eggs and snowballs can be thrown at. However it still does the item chucking animation rapidly, which looks odd. I discovered that this was the result of the return type, which had to have a PASS rather than SUCCESS parameter whenever the item wasn't be thrown. But my code doesn't work all the time, and occasionally I can't throw the item anymore. Also the last item thrown from the stack is still an egg, instead of my custom entity / texture.

 

package mymod.thrown;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.world.World;

public class Throw_Stone extends Item { // Copies EggItem
	
	private int tick_last, delay;
	
    public Throw_Stone(Item.Properties builder) {
	   
        super(builder);
        
        delay = 16;
    }

    /**
     * Called to trigger the item's "innate" right click behavior. To handle when this item is used on a Block, see
     * {@link #onItemUse}.
     */
       
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
    	  
    	ItemStack itemstack = playerIn.getHeldItem(handIn);
	    
	    if (playerIn.ticksExisted - tick_last >= delay) {

	    	tick_last = playerIn.ticksExisted;
	    	
	        if (!playerIn.abilities.isCreativeMode) {
	    	   
	            itemstack.shrink(1);
	        }
	
	        worldIn.playSound((PlayerEntity) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
	    	  
		    Throw_Stone_Entity throw_stone_entity = new Throw_Stone_Entity(worldIn, playerIn);
		    throw_stone_entity.func_213884_b(itemstack);
		    throw_stone_entity.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.15F, 3.0F);
		    worldIn.addEntity(throw_stone_entity);
	       
	    playerIn.addStat(Stats.ITEM_USED.get(this));
	    
	    return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
      
	    }
	    
	    else return new ActionResult<>(ActionResultType.PASS, itemstack);
   }
}

 

package mymod.thrown;

import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class Throw_Stone_Entity extends ProjectileItemEntity { // Copies EggEntity
	
    private float damage = 2.5F;
	
    public Throw_Stone_Entity(EntityType<? extends Throw_Stone_Entity> p_i50154_1_, World p_i50154_2_) {
    	 
        super(p_i50154_1_, p_i50154_2_);
    }

    public Throw_Stone_Entity(World worldIn, LivingEntity throwerIn) {
	   
        super(EntityType.EGG, throwerIn, worldIn);
    }

    public Throw_Stone_Entity(World worldIn, double x, double y, double z) {
	   
        super(EntityType.EGG, x, y, z, worldIn);
    }

    /**
     * Handler for {@link World#setEntityState}
     */
    @OnlyIn(Dist.CLIENT)
    public void handleStatusUpdate(byte id) {
    	 
        if (id == 3) {
        	
        	for(int i = 0; i < 8; ++i) {
        		
        		this.world.addParticle(new ItemParticleData(ParticleTypes.ITEM, this.getItem()), this.posX, this.posY, this.posZ, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D);
        	}
        }
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
    */
    protected void onImpact(RayTraceResult result) {		
    	
    	if (result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.OAK_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.DARK_OAK_LEAVES||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.ACACIA_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.BIRCH_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.SPRUCE_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.JUNGLE_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.VINE || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.GRASS ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.TALL_GRASS || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.SEAGRASS || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.TALL_SEAGRASS || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.FERN ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.LARGE_FERN ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.SUGAR_CANE) {
    		
    		System.out.println("no");
    	}
    	
    	else {
        	
        	if (result.getType() == RayTraceResult.Type.ENTITY) {
        		
        		((EntityRayTraceResult)result).getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), damage);
        	}
        	
        	this.world.setEntityState(this, (byte)3);
        	this.remove();
        }
    }

    protected Item func_213885_i() {
    	   
        return Items.EGG;
    }
}

 

Link to comment
Share on other sites

29 minutes ago, MineModder2000 said:

private int tick_last, delay;

You cant just store values like this in the Item. There is only one instance of your Item you need to store it in the ItemStack. Either via a capability or just the stacks CompoundNBT/tag.

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.

Link to comment
Share on other sites

18 hours ago, Animefan8888 said:

You cant just store values like this in the Item. There is only one instance of your Item you need to store it in the ItemStack. Either via a capability or just the stacks CompoundNBT/tag.

Okay I did it a different way, which seems to work. But I still have the problem of the last projectile thrown being an egg....

Link to comment
Share on other sites

40 minutes ago, MineModder2000 said:

But I still have the problem of the last projectile thrown being an egg....

That's caused by you using the EntityType.EGG instead of your EntityType

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.

Link to comment
Share on other sites

3 hours ago, Animefan8888 said:

That's caused by you using the EntityType.EGG instead of your EntityType

Hmm, but why only the last one. How was it actually rendering my entity without that? 

 

So I did this now (I renamed things) :

 

package mymod;

import mymod.thrown.Chert_Entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.registry.Registry;

public class My_Entity {
	
public static final EntityType<Chert_Entity> Chert_Entity = register("chert", EntityType.Builder.<Chert_Entity>create(Chert_Entity::new, EntityClassification.MISC).size(0.25F, 0.25F));
	
    @SuppressWarnings("deprecation")
	private static <T extends Entity> EntityType<T> register(String key, EntityType.Builder<T> builder) {
    	
        return Registry.register(Registry.ENTITY_TYPE, key, builder.build(key));
    }
}

 

package mymod.thrown;

import mymod.My_Entity;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class Chert_Entity extends ProjectileItemEntity { // Copies EggEntity
	
    private float damage = 2.5F;

    public Chert_Entity(EntityType<? extends Chert_Entity> p_i50154_1_, World p_i50154_2_) {
    	 
        super(p_i50154_1_, p_i50154_2_);
    }

    public Chert_Entity(World worldIn, LivingEntity throwerIn) {
	   
        super(My_Entity.Chert_Entity, throwerIn, worldIn);
    }

    public Chert_Entity(World worldIn, double x, double y, double z) {
	   
        super(My_Entity.Chert_Entity, x, y, z, worldIn);
    }

    /**
     * Handler for {@link World#setEntityState}
     */
    @OnlyIn(Dist.CLIENT)
    public void handleStatusUpdate(byte id) {
    	 
        if (id == 3) {
        	
        	for(int i = 0; i < 8; ++i) {
        		
        		this.world.addParticle(new ItemParticleData(ParticleTypes.ITEM, this.getItem()), this.posX, this.posY, this.posZ, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D);
        	}
        }
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
    */
    protected void onImpact(RayTraceResult result) {		
    	
    	if (result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.OAK_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.DARK_OAK_LEAVES||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.ACACIA_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.BIRCH_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.SPRUCE_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.JUNGLE_LEAVES ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.VINE || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.GRASS ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.TALL_GRASS || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.SEAGRASS || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.TALL_SEAGRASS || 
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.FERN ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.LARGE_FERN ||
    		result.getType() == RayTraceResult.Type.BLOCK && this.world.getBlockState(((BlockRayTraceResult)result).getPos()).getBlock() == Blocks.SUGAR_CANE) {
    		
    		System.out.println("no");
    	}
    	
    	else {
        	
        	if (result.getType() == RayTraceResult.Type.ENTITY) {
        		
        		((EntityRayTraceResult)result).getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), damage);
        	}
        	
        	this.world.setEntityState(this, (byte)3);
        	this.remove();
        }
    }

    protected Item func_213885_i() {
    	   
        return Items.EGG;
    }
}

 

My_Entity is initialized in my main mod file. It all works fine, except no entity / texture is thrown.......

 

And yes I have a model and texture file named chert.json. These were previously named throw_stone and worked when I had EntityType.EGG in the code, which I still don't understand.

Link to comment
Share on other sites

18 minutes ago, MineModder2000 said:

public static final EntityType<Chert_Entity> Chert_Entity = registe

Dont create registry values outside of a registry.

 

18 minutes ago, MineModder2000 said:

except no entity / texture is thrown.......

Have you registered a renderer for your entity? 

 

18 minutes ago, MineModder2000 said:

And yes I have a model and texture file named chert.json.

For the Item?

18 minutes ago, MineModder2000 said:

result.getType() == RayTraceResult.Type.BLOCK

Why do you check this over and over. Its unnecessary. Just check it once and check all of your blocks like this

(block == Block1 || block == Block2)

With the parentheses.

20 minutes ago, MineModder2000 said:

return Items.EGG;

You should return your Item here not the egg item.

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.

Link to comment
Share on other sites

2 minutes ago, Animefan8888 said:

Dont create registry values outside of a registry.

 

Have you registered a renderer for your entity? 

 

For the Item?

Why do you check this over and over. Its unnecessary. Just check it once and check all of your blocks like this

(block == Block1 || block == Block2)

With the parentheses.

You should return your Item here not the egg item.

 

I didn't register a renderer for the entity, because it was working without one (except for the egg issue). Actually I am not seeing any EggRenderer, I don't think it needs one...

Yes for the item.

Good question, I just fixed the redundancy.

Yeah I saw that initially but when I change it every toss was an egg, instead of just the last one. 

 

 
        @SubscribeEvent
        public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event) {
        	
            LOGGER.debug("Hello from Register Entities");
            
            event.getRegistry().registerAll(
            		
            	Chert_Entity = register("chert", EntityType.Builder.<Chert_Entity>create(Chert_Entity::new, EntityClassification.MISC).size(0.25F, 0.25F))
            	//EntityType.Builder.<Chert_Entity>create(Chert_Entity::new, EntityClassification.MISC).build("chert").setRegistryName("mymod", "chert")
            );
        }

        @SuppressWarnings("deprecation")
    	private static <T extends Entity> EntityType<T> register(String key, EntityType.Builder<T> builder) {
    	    	
    	    return Registry.register(Registry.ENTITY_TYPE, key, builder.build(key));
    	}

 

That's ^ in my main mode file, and yes I have "public static EntityType<Chert_Entity> Chert_Entity" above. I'm not what to do next, it's still not showing up. I don't see a renderer for the egg...

Link to comment
Share on other sites

 @SubscribeEvent
        public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event) {
        	
            LOGGER.debug("Hello from Register Entities");
            
            event.getRegistry().registerAll(
            		
            	EntityType.Builder.<Spear_Entity>create(Spear_Entity::new, EntityClassification.MISC).build("spear").setRegistryName("mymod", "spear"),          	
            );
            
        	RenderingRegistry.registerEntityRenderingHandler(Spear_Entity.class, Spear_Factory.INSTANCE);
        }

 

Did this, still chucking tridents instead of spears...

Link to comment
Share on other sites

42 minutes ago, MineModder2000 said:

I don't see a renderer for the egg...

It uses the SpriteRenderer class which you can use too.

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.

Link to comment
Share on other sites

39 minutes ago, MineModder2000 said:

Did this, still chucking tridents instead of spears...

First that's not where the RenderingRegistry goes. Second are you sure you are spawning your Spear Entity? What about your Renderer what does that look like? Is it using your model or is it using the Trident's model?

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.

Link to comment
Share on other sites

13 hours ago, Animefan8888 said:

First that's not where the RenderingRegistry goes. Second are you sure you are spawning your Spear Entity? What about your Renderer what does that look like? Is it using your model or is it using the Trident's model?

 

Oh right, I had in the correct place before but things got moved around. I put that line back inside the "setup" method. I'm just going to show you all of my classes :

 

Spear Entity 

Spoiler

package mymod.spear;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.EntityType.IFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class Spear_Entity extends TridentEntity implements IFactory<Spear_Entity> {
	
	public Spear_Entity(EntityType<? extends TridentEntity> p_i50148_1_, World p_i50148_2_) {
		
		super(p_i50148_1_, p_i50148_2_);
	}

	public Spear_Entity(World worldIn, PlayerEntity playerentity, ItemStack stack) {

		super(worldIn, playerentity, stack);
	}

	@Override
	public Spear_Entity create(EntityType<Spear_Entity> p_create_1_, World p_create_2_) {

		return null;
	}
}

 

 

Spear Factory

Spoiler

package mymod.spear;

import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraftforge.fml.client.registry.IRenderFactory;

public class Spear_Factory implements IRenderFactory<Spear_Entity> {
    
    public static final Spear_Factory INSTANCE = new Spear_Factory();
    private Spear_Renderer spear_Renderer;

    @Override
    public EntityRenderer<? super Spear_Entity> createRenderFor(EntityRendererManager manager) {
        
        spear_Renderer = new Spear_Renderer(manager);
        
        return spear_Renderer;
    }
}


 

 

Spear Model

Spoiler

package mymod.spear;

import net.minecraft.client.renderer.entity.model.RendererModel;
import net.minecraft.client.renderer.model.Model;
import net.minecraft.util.ResourceLocation;

public class Spear_Model extends Model {
	public static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("mymod", "spear");
	private final RendererModel modelRenderer;

	public Spear_Model() {
		
	     this.textureWidth = 32;
	     this.textureHeight = 32;
	     this.modelRenderer = new RendererModel(this, 0, 0);
	     this.modelRenderer.addBox(-0.5F, -4.0F, -0.5F, 1, 31, 1, 0.0F);
	     RendererModel renderermodel = new RendererModel(this, 4, 0);
	     renderermodel.addBox(-1.5F, 0.0F, -0.5F, 3, 2, 1);
	     this.modelRenderer.addChild(renderermodel);
	     RendererModel renderermodel1 = new RendererModel(this, 4, 3);
	     renderermodel1.addBox(-2.5F, -3.0F, -0.5F, 1, 4, 1);
	     this.modelRenderer.addChild(renderermodel1);
	     RendererModel renderermodel2 = new RendererModel(this, 4, 3);
	     renderermodel2.mirror = true;
	     renderermodel2.addBox(1.5F, -3.0F, -0.5F, 1, 4, 1);
	     this.modelRenderer.addChild(renderermodel2);
	}

	public void renderer() {
		
	     this.modelRenderer.render(0.0625F);
	}

}

 

 

Spear Renderer

Spoiler

package mymod.spear;

import com.mojang.blaze3d.platform.GLX;
import com.mojang.blaze3d.platform.GlStateManager;

import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class Spear_Renderer extends EntityRenderer<Spear_Entity> {
   public static final ResourceLocation field_203087_a = new ResourceLocation("mymod", "spear");
   private final Spear_Model field_203088_f = new Spear_Model();

   public Spear_Renderer(EntityRendererManager p_i48828_1_) {
      super(p_i48828_1_);
   }

   public void doRender(Spear_Entity entity, double x, double y, double z, float entityYaw, float partialTicks) {
      this.bindEntityTexture(entity);
      GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
      GlStateManager.pushMatrix();
      GlStateManager.disableLighting();
      GlStateManager.translatef((float)x, (float)y, (float)z);
      GlStateManager.rotatef(MathHelper.lerp(partialTicks, entity.prevRotationYaw, entity.rotationYaw) - 90.0F, 0.0F, 1.0F, 0.0F);
      GlStateManager.rotatef(MathHelper.lerp(partialTicks, entity.prevRotationPitch, entity.rotationPitch) + 90.0F, 0.0F, 0.0F, 1.0F);
      this.field_203088_f.renderer();
      GlStateManager.popMatrix();
      this.func_203085_b(entity, x, y, z, entityYaw, partialTicks);
      super.doRender(entity, x, y, z, entityYaw, partialTicks);
      GlStateManager.enableLighting();
   }

   protected ResourceLocation getEntityTexture(Spear_Entity entity) {
      return field_203087_a;
   }

   protected void func_203085_b(Spear_Entity p_203085_1_, double p_203085_2_, double p_203085_4_, double p_203085_6_, float p_203085_8_, float p_203085_9_) {
      Entity entity = p_203085_1_.getShooter();
      if (entity != null && p_203085_1_.func_203047_q()) {
         Tessellator tessellator = Tessellator.getInstance();
         BufferBuilder bufferbuilder = tessellator.getBuffer();
         double d0 = (double)(MathHelper.lerp(p_203085_9_ * 0.5F, entity.rotationYaw, entity.prevRotationYaw) * ((float)Math.PI / 180F));
         double d1 = Math.cos(d0);
         double d2 = Math.sin(d0);
         double d3 = MathHelper.lerp((double)p_203085_9_, entity.prevPosX, entity.posX);
         double d4 = MathHelper.lerp((double)p_203085_9_, entity.prevPosY + (double)entity.getEyeHeight() * 0.8D, entity.posY + (double)entity.getEyeHeight() * 0.8D);
         double d5 = MathHelper.lerp((double)p_203085_9_, entity.prevPosZ, entity.posZ);
         double d6 = d1 - d2;
         double d7 = d2 + d1;
         double d8 = MathHelper.lerp((double)p_203085_9_, p_203085_1_.prevPosX, p_203085_1_.posX);
         double d9 = MathHelper.lerp((double)p_203085_9_, p_203085_1_.prevPosY, p_203085_1_.posY);
         double d10 = MathHelper.lerp((double)p_203085_9_, p_203085_1_.prevPosZ, p_203085_1_.posZ);
         double d11 = (double)((float)(d3 - d8));
         double d12 = (double)((float)(d4 - d9));
         double d13 = (double)((float)(d5 - d10));
         double d14 = Math.sqrt(d11 * d11 + d12 * d12 + d13 * d13);
         int i = p_203085_1_.getEntityId() + p_203085_1_.ticksExisted;
         double d15 = (double)((float)i + p_203085_9_) * -0.1D;
         double d16 = Math.min(0.5D, d14 / 30.0D);
         GlStateManager.disableTexture();
         GlStateManager.disableLighting();
         GlStateManager.disableCull();
         GLX.glMultiTexCoord2f(GLX.GL_TEXTURE1, 255.0F, 255.0F);
         bufferbuilder.begin(5, DefaultVertexFormats.POSITION_COLOR);
         @SuppressWarnings("unused")
         int j = 37;
         int k = 7 - i % 7;
         @SuppressWarnings("unused")
         double d17 = 0.1D;

         for(int l = 0; l <= 37; ++l) {
            double d18 = (double)l / 37.0D;
            float f = 1.0F - (float)((l + k) % 7) / 7.0F;
            double d19 = d18 * 2.0D - 1.0D;
            d19 = (1.0D - d19 * d19) * d16;
            double d20 = p_203085_2_ + d11 * d18 + Math.sin(d18 * Math.PI * 8.0D + d15) * d6 * d19;
            double d21 = p_203085_4_ + d12 * d18 + Math.cos(d18 * Math.PI * 8.0D + d15) * 0.02D + (0.1D + d19) * 1.0D;
            double d22 = p_203085_6_ + d13 * d18 + Math.sin(d18 * Math.PI * 8.0D + d15) * d7 * d19;
            float f1 = 0.87F * f + 0.3F * (1.0F - f);
            float f2 = 0.91F * f + 0.6F * (1.0F - f);
            float f3 = 0.85F * f + 0.5F * (1.0F - f);
            bufferbuilder.pos(d20, d21, d22).color(f1, f2, f3, 1.0F).endVertex();
            bufferbuilder.pos(d20 + 0.1D * d19, d21 + 0.1D * d19, d22).color(f1, f2, f3, 1.0F).endVertex();
            if (l > p_203085_1_.returningTicks * 2) {
               break;
            }
         }

         tessellator.draw();
         bufferbuilder.begin(5, DefaultVertexFormats.POSITION_COLOR);

         for(int i1 = 0; i1 <= 37; ++i1) {
            double d23 = (double)i1 / 37.0D;
            float f4 = 1.0F - (float)((i1 + k) % 7) / 7.0F;
            double d24 = d23 * 2.0D - 1.0D;
            d24 = (1.0D - d24 * d24) * d16;
            double d25 = p_203085_2_ + d11 * d23 + Math.sin(d23 * Math.PI * 8.0D + d15) * d6 * d24;
            double d26 = p_203085_4_ + d12 * d23 + Math.cos(d23 * Math.PI * 8.0D + d15) * 0.01D + (0.1D + d24) * 1.0D;
            double d27 = p_203085_6_ + d13 * d23 + Math.sin(d23 * Math.PI * 8.0D + d15) * d7 * d24;
            float f5 = 0.87F * f4 + 0.3F * (1.0F - f4);
            float f6 = 0.91F * f4 + 0.6F * (1.0F - f4);
            float f7 = 0.85F * f4 + 0.5F * (1.0F - f4);
            bufferbuilder.pos(d25, d26, d27).color(f5, f6, f7, 1.0F).endVertex();
            bufferbuilder.pos(d25 + 0.1D * d24, d26, d27 + 0.1D * d24).color(f5, f6, f7, 1.0F).endVertex();
            if (i1 > p_203085_1_.returningTicks * 2) {
               break;
            }
         }

         tessellator.draw();
         GlStateManager.enableLighting();
         GlStateManager.enableTexture();
         GlStateManager.enableCull();
      }
   }
}

 

 

Spear_TEISR

Spoiler

package mymod.spear;

import java.util.Arrays;
import java.util.Comparator;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.function.Supplier;

import org.apache.commons.lang3.StringUtils;

import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.platform.GlStateManager;

import lists.ItemList;
import net.minecraft.block.AbstractSkullBlock;
import net.minecraft.block.BedBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BannerTextures;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.entity.model.ShieldModel;
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
import net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.item.BannerItem;
import net.minecraft.item.BlockItem;
import net.minecraft.item.DyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.ShieldItem;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.tileentity.BannerTileEntity;
import net.minecraft.tileentity.BedTileEntity;
import net.minecraft.tileentity.ChestTileEntity;
import net.minecraft.tileentity.ConduitTileEntity;
import net.minecraft.tileentity.EnderChestTileEntity;
import net.minecraft.tileentity.ShulkerBoxTileEntity;
import net.minecraft.tileentity.SkullTileEntity;
import net.minecraft.tileentity.TrappedChestTileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;

public class Spear_TEISR implements Supplier<Callable<ItemStackTileEntityRenderer>>, Callable<ItemStackTileEntityRenderer> {
	private static final ShulkerBoxTileEntity[] SHULKER_BOXES = Arrays.stream(DyeColor.values()).sorted(Comparator.comparingInt(DyeColor::getId)).map(ShulkerBoxTileEntity::new).toArray((p_199929_0_) -> {
	return new ShulkerBoxTileEntity[p_199929_0_];});
	private static final ShulkerBoxTileEntity SHULKER_BOX = new ShulkerBoxTileEntity((DyeColor)null);
	public static final ItemStackTileEntityRenderer instance = new ItemStackTileEntityRenderer();
	private final ChestTileEntity chestBasic = new ChestTileEntity();
	private final ChestTileEntity chestTrap = new TrappedChestTileEntity();
	private final EnderChestTileEntity enderChest = new EnderChestTileEntity();
	private final BannerTileEntity banner = new BannerTileEntity();
	private final BedTileEntity bed = new BedTileEntity();
	@SuppressWarnings("unused")
	private final SkullTileEntity skull = new SkullTileEntity();
	private final ConduitTileEntity conduit = new ConduitTileEntity();
	private final ShieldModel modelShield = new ShieldModel();
	private final Spear_Model spear = new Spear_Model();

	@Override
	public Callable<ItemStackTileEntityRenderer> get() {
		
		return this;
	}

	@Override
	public ItemStackTileEntityRenderer call() throws Exception {
		
		return null;
	}
	
	public void renderByItem(ItemStack itemStackIn) {
	      Item item = itemStackIn.getItem();
	      if (item instanceof BannerItem) {
	         this.banner.loadFromItemStack(itemStackIn, ((BannerItem)item).getColor());
	         TileEntityRendererDispatcher.instance.renderAsItem(this.banner);
	      } else if (item instanceof BlockItem && ((BlockItem)item).getBlock() instanceof BedBlock) {
	         this.bed.setColor(((BedBlock)((BlockItem)item).getBlock()).getColor());
	         TileEntityRendererDispatcher.instance.renderAsItem(this.bed);
	      } else if (item == Items.SHIELD) {
	         if (itemStackIn.getChildTag("BlockEntityTag") != null) {
	            this.banner.loadFromItemStack(itemStackIn, ShieldItem.getColor(itemStackIn));
	            Minecraft.getInstance().getTextureManager().bindTexture(BannerTextures.SHIELD_DESIGNS.getResourceLocation(this.banner.getPatternResourceLocation(), this.banner.getPatternList(), this.banner.getColorList()));
	         } else {
	            Minecraft.getInstance().getTextureManager().bindTexture(BannerTextures.SHIELD_BASE_TEXTURE);
	         }

	         GlStateManager.pushMatrix();
	         GlStateManager.scalef(1.0F, -1.0F, -1.0F);
	         this.modelShield.render();
	         if (itemStackIn.hasEffect()) {
	            this.renderEffect(this.modelShield::render);
	         }

	         GlStateManager.popMatrix();
	      } else if (item instanceof BlockItem && ((BlockItem)item).getBlock() instanceof AbstractSkullBlock) {
	         GameProfile gameprofile = null;
	         if (itemStackIn.hasTag()) {
	            CompoundNBT compoundnbt = itemStackIn.getTag();
	            if (compoundnbt.contains("SkullOwner", 10)) {
	               gameprofile = NBTUtil.readGameProfile(compoundnbt.getCompound("SkullOwner"));
	            } else if (compoundnbt.contains("SkullOwner", 8) && !StringUtils.isBlank(compoundnbt.getString("SkullOwner"))) {
	               GameProfile gameprofile1 = new GameProfile((UUID)null, compoundnbt.getString("SkullOwner"));
	               gameprofile = SkullTileEntity.updateGameProfile(gameprofile1);
	               compoundnbt.remove("SkullOwner");
	               compoundnbt.put("SkullOwner", NBTUtil.writeGameProfile(new CompoundNBT(), gameprofile));
	            }
	         }

	         if (SkullTileEntityRenderer.instance != null) {
	            GlStateManager.pushMatrix();
	            GlStateManager.disableCull();
	            SkullTileEntityRenderer.instance.render(0.0F, 0.0F, 0.0F, (Direction)null, 180.0F, ((AbstractSkullBlock)((BlockItem)item).getBlock()).getSkullType(), gameprofile, -1, 0.0F);
	            GlStateManager.enableCull();
	            GlStateManager.popMatrix();
	         }
	      } else if (item == ItemList.spear) {
	         Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("mymod", "spear"));
	         GlStateManager.pushMatrix();
	         GlStateManager.scalef(1.0F, -1.0F, -1.0F);
	         this.spear.renderer();
	         if (itemStackIn.hasEffect()) {
	            this.renderEffect(this.spear::renderer);
	         }

	         GlStateManager.popMatrix();
	      } else if (item instanceof BlockItem && ((BlockItem)item).getBlock() == Blocks.CONDUIT) {
	         TileEntityRendererDispatcher.instance.renderAsItem(this.conduit);
	      } else if (item == Blocks.ENDER_CHEST.asItem()) {
	         TileEntityRendererDispatcher.instance.renderAsItem(this.enderChest);
	      } else if (item == Blocks.TRAPPED_CHEST.asItem()) {
	         TileEntityRendererDispatcher.instance.renderAsItem(this.chestTrap);
	      } else if (Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
	         DyeColor dyecolor = ShulkerBoxBlock.getColorFromItem(item);
	         if (dyecolor == null) {
	            TileEntityRendererDispatcher.instance.renderAsItem(SHULKER_BOX);
	         } else {
	            TileEntityRendererDispatcher.instance.renderAsItem(SHULKER_BOXES[dyecolor.getId()]);
	         }
	      } else {
	         TileEntityRendererDispatcher.instance.renderAsItem(this.chestBasic);
	      }

	   }

	   private void renderEffect(Runnable renderModelFunction) {
	      GlStateManager.color3f(0.5019608F, 0.2509804F, 0.8F);
	      Minecraft.getInstance().getTextureManager().bindTexture(ItemRenderer.RES_ITEM_GLINT);
	      ItemRenderer.renderEffect(Minecraft.getInstance().getTextureManager(), renderModelFunction, 1);
	   }
}

 

 

Spear

Spoiler

package mymod.spear;

import com.google.common.collect.Multimap;

import net.minecraft.block.BlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.UseAction;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class Spear extends Item { // copies TridentItem 
   public Spear(Properties builder) {
      super(builder);
      this.addPropertyOverride(new ResourceLocation("throwing"), (p_210315_0_, p_210315_1_, p_210315_2_) -> {
         return p_210315_2_ != null && p_210315_2_.isHandActive() && p_210315_2_.getActiveItemStack() == p_210315_0_ ? 1.0F : 0.0F;
      });
   }

   public boolean canPlayerBreakBlockWhileHolding(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
      return !player.isCreative();
   }

   /**
    * returns the action that specifies what animation to play when the items is being used
    */
   public UseAction getUseAction(ItemStack stack) {
      return UseAction.SPEAR;
   }

   /**
    * How long it takes to use or consume an item
    */
   public int getUseDuration(ItemStack stack) {
      return 72000;
   }

   /**
    * Returns true if this item has an enchantment glint. By default, this returns <code>stack.isItemEnchanted()</code>,
    * but other items can override it (for instance, written books always return true).
    *  
    * Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
    * the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
    */
   @OnlyIn(Dist.CLIENT)
   public boolean hasEffect(ItemStack stack) {
      return false;
   }

   /**
    * Called when the player stops using an Item (stops holding the right mouse button).
    */
   public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
      if (entityLiving instanceof PlayerEntity) {
         PlayerEntity playerentity = (PlayerEntity)entityLiving;
         int i = this.getUseDuration(stack) - timeLeft;
         if (i >= 10) {
            int j = EnchantmentHelper.getRiptideModifier(stack);
            if (j <= 0 || playerentity.isWet()) {
               if (!worldIn.isRemote) {
                  stack.damageItem(1, playerentity, (p_220047_1_) -> {
                     p_220047_1_.sendBreakAnimation(entityLiving.getActiveHand());
                  });
                  if (j == 0) {
                     Spear_Entity spear_entity = new Spear_Entity(worldIn, playerentity, stack);
                     spear_entity.shoot(playerentity, playerentity.rotationPitch, playerentity.rotationYaw, 0.0F, 2.5F + (float)j * 0.5F, 1.0F);
                     if (playerentity.abilities.isCreativeMode) {
                    	 spear_entity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
                     }

                     worldIn.addEntity(spear_entity);
                     worldIn.playMovingSound((PlayerEntity)null, spear_entity, SoundEvents.ITEM_TRIDENT_THROW, SoundCategory.PLAYERS, 1.0F, 1.0F);
                     if (!playerentity.abilities.isCreativeMode) {
                         playerentity.inventory.deleteStack(stack);
                     }
                  }
               }

               playerentity.addStat(Stats.ITEM_USED.get(this));
               if (j > 0) {
                  float f7 = playerentity.rotationYaw;
                  float f = playerentity.rotationPitch;
                  float f1 = -MathHelper.sin(f7 * ((float)Math.PI / 180F)) * MathHelper.cos(f * ((float)Math.PI / 180F));
                  float f2 = -MathHelper.sin(f * ((float)Math.PI / 180F));
                  float f3 = MathHelper.cos(f7 * ((float)Math.PI / 180F)) * MathHelper.cos(f * ((float)Math.PI / 180F));
                  float f4 = MathHelper.sqrt(f1 * f1 + f2 * f2 + f3 * f3);
                  float f5 = 3.0F * ((1.0F + (float)j) / 4.0F);
                  f1 = f1 * (f5 / f4);
                  f2 = f2 * (f5 / f4);
                  f3 = f3 * (f5 / f4);
                  playerentity.addVelocity((double)f1, (double)f2, (double)f3);
                  playerentity.startSpinAttack(20);
                  if (playerentity.onGround) {
                    @SuppressWarnings("unused")
					float f6 = 1.1999999F;
                     playerentity.move(MoverType.SELF, new Vec3d(0.0D, (double)1.1999999F, 0.0D));
                  }

                  SoundEvent soundevent;
                  if (j >= 3) {
                     soundevent = SoundEvents.ITEM_TRIDENT_RIPTIDE_3;
                  } else if (j == 2) {
                     soundevent = SoundEvents.ITEM_TRIDENT_RIPTIDE_2;
                  } else {
                     soundevent = SoundEvents.ITEM_TRIDENT_RIPTIDE_1;
                  }

                  worldIn.playMovingSound((PlayerEntity)null, playerentity, soundevent, SoundCategory.PLAYERS, 1.0F, 1.0F);
               }

            }
         }
      }
   }

   /**
    * Called to trigger the item's "innate" right click behavior. To handle when this item is used on a Block, see
    * {@link #onItemUse}.
    */
   public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
      ItemStack itemstack = playerIn.getHeldItem(handIn);
      if (itemstack.getDamage() >= itemstack.getMaxDamage()) {
         return new ActionResult<>(ActionResultType.FAIL, itemstack);
      } else if (EnchantmentHelper.getRiptideModifier(itemstack) > 0 && !playerIn.isWet()) {
         return new ActionResult<>(ActionResultType.FAIL, itemstack);
      } else {
         playerIn.setActiveHand(handIn);
         return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
      }
   }

   /**
    * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
    * the damage on the stack.
    */
   public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) {
      stack.damageItem(1, attacker, (p_220048_0_) -> {
         p_220048_0_.sendBreakAnimation(EquipmentSlotType.MAINHAND);
      });
      return true;
   }

   /**
    * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
    */
   public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) {
      if ((double)state.getBlockHardness(worldIn, pos) != 0.0D) {
         stack.damageItem(2, entityLiving, (p_220046_0_) -> {
            p_220046_0_.sendBreakAnimation(EquipmentSlotType.MAINHAND);
         });
      }

      return true;
   }

   /**
    * Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
    */
   public Multimap<String, AttributeModifier> getAttributeModifiers(EquipmentSlotType equipmentSlot) {
    @SuppressWarnings("deprecation")
	Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(equipmentSlot);
      if (equipmentSlot == EquipmentSlotType.MAINHAND) {
         multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Tool modifier", 8.0D, AttributeModifier.Operation.ADDITION));
         multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool modifier", (double)-2.9F, AttributeModifier.Operation.ADDITION));
      }

      return multimap;
   }

   /**
    * Return the enchantability factor of the item, most of the time is based on material.
    */
   public int getItemEnchantability() {
      return 1;
   }
   
   public Item.Properties maxStackSize(int maxStackSizeIn) {
	   
	   
	   return null;
   }
}

 

 

 @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
    	
        @SubscribeEvent
        public static void registerItems(final RegistryEvent.Register<Item> event) {
        	
        	LOGGER.info("HELLO from Register Items");
        	
        		event.getRegistry().registerAll(

        		ItemList.spear = new Spear(new Item.Properties().maxDamage(10).setTEISR(teisr).group(ItemGroup.COMBAT)).setRegistryName(location("spear")),
        	);
        }
        
        @SubscribeEvent
        public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event) {
        	
            LOGGER.debug("Hello from Register Entities");
            
            event.getRegistry().registerAll(
            		
            	EntityType.Builder.<Spear_Entity>create(Spear_Entity::new, EntityClassification.MISC).build("spear").setRegistryName("mymod", "spear"),
            );
        }
        
        private static ResourceLocation location(String name) {
        	
        	return new ResourceLocation("mymod", name);
        }

 

Link to comment
Share on other sites

16 minutes ago, MineModder2000 said:

public static final ResourceLocation field_203087_a = new ResourceLocation("mymod", "spear");

What does this file look like?

 

17 minutes ago, MineModder2000 said:

protected void func_203085_b

What does this function do?

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.

Link to comment
Share on other sites

2 minutes ago, MineModder2000 said:

And then make a factory and register the Entity class with it?

Yes? Should look something like this.

clientSetupEvent(FMLClientSetupEvent event)

   RenderingRegistry.registerEntityRenderingHandler(YourEntity.class, manager -> new SpriteRenderer<YourEntity>(manager, Minecraft.getInstance().getItemRenderer());

  • Thanks 1

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.

Link to comment
Share on other sites

3 minutes ago, Animefan8888 said:

What does this file look like?

 

What does this function do?

 

The trident had 3 jsons, so I coped them and changed appropriate names / paths :

 

spear_in_hand

Spoiler

{
    "parent": "builtin/entity",
    "textures": {
        "mymod:item/spear"
    },
    "display": {
        "thirdperson_righthand": {
            "rotation": [ 0, 60, 0 ],
            "translation": [ 11, 17, -2 ],
            "scale": [ 1, 1, 1 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 0, 60, 0 ],
            "translation": [ 3, 17, 12 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, -90, 25 ],
            "translation": [ -3, 17, 1],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 90, -25 ],
            "translation": [ 13, 17, 1],
            "scale": [ 1, 1, 1 ]
        },
        "gui": {
            "rotation": [ 15, -25, -5 ],
            "translation": [ 2, 3, 0 ],
            "scale": [ 0.65, 0.65, 0.65 ]
        },
        "fixed": {
            "rotation": [ 0, 180, 0 ],
            "translation": [ -2, 4, -5],
            "scale":[ 0.5, 0.5, 0.5]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 4, 4, 2],
            "scale":[ 0.25, 0.25, 0.25]
        }
    },
    "overrides": [
        {
            "predicate": {
                "throwing": 1
            },
            "model": "mymod:item/spear_throwing"
        }
    ]
}

 

spear_throwing

Spoiler

{
    "parent": "builtin/entity",
    "textures": {
        "mymod:item/spear"
    },
    "display": {
        "thirdperson_righthand": {
            "rotation": [ 0, 90, 180 ],
            "translation": [ 8, -17, 9 ],
            "scale": [ 1, 1, 1 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 0, 90, 180 ],
            "translation": [ 8, -17, -7 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, -90, 25 ],
            "translation": [ -3, 17, 1],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 90, -25 ],
            "translation": [  13, 17, 1],
            "scale": [ 1, 1, 1 ]
        },
        "gui": {
            "rotation": [ 15, -25, -5 ],
            "translation": [ 2, 3, 0 ],
            "scale": [ 0.65, 0.65, 0.65 ]
        },
        "fixed": {
            "rotation": [ 0, 180, 0 ],
            "translation": [ -2, 4, -5],
            "scale":[ 0.5, 0.5, 0.5]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 4, 4, 2],
            "scale":[ 0.25, 0.25, 0.25]
        }
    }
}

 

spear

Spoiler

{
    "parent": "item/generated",
    "textures": {
    
        "layer0": "mymod:item/spear"
    }
}

 

As for what that function does, it's better to ask Mojand, I just copied their Trident_Renderer class. It looks though, that it performs necessary transformations to make the spear do its spear thing when its held back and then tossed. 

Link to comment
Share on other sites

Just now, MineModder2000 said:

The trident had 3 jsons, so I coped them and changed appropriate names / paths :

If you look at the TridentRenderer you'll notice that the same field name actually points to a texture(png) file that the renderer uses.

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.

Link to comment
Share on other sites

24 minutes ago, Animefan8888 said:

Yes? Should look something like this.

clientSetupEvent(FMLClientSetupEvent event)

   RenderingRegistry.registerEntityRenderingHandler(YourEntity.class, manager -> new SpriteRenderer<YourEntity>(manager, Minecraft.getInstance().getItemRenderer());

 

Okay did it....

 private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
        LOGGER.info("HELLO FROM PREINIT");
        
        RenderingRegistry.registerEntityRenderingHandler(Spear_Entity.class, Spear_Factory.INSTANCE);
        RenderingRegistry.registerEntityRenderingHandler(Chert_Entity.class, manager -> new SpriteRenderer<Chert_Entity>(manager, Minecraft.getInstance().getItemRenderer()));
    }

 

Still no visible projectiles, it just makes the noise....

Link to comment
Share on other sites

51 minutes ago, Animefan8888 said:

If you look at the TridentRenderer you'll notice that the same field name actually points to a texture(png) file that the renderer uses.

Oh right, but it since it's still rendering the trident, it's not even using my SpearRenderer class. I changed the path to this : "mymod/textures/entity/spear.png", after creating that package, I already had the texture file ready. The classes I made aren't being used at all....

Link to comment
Share on other sites

22 hours ago, MineModder2000 said:

Oh right, but it since it's still rendering the trident

This is because the EntityType field in your entity called type is being set to the TRIDENT EntityType. You need to make sure that it is set to yours. Also you will need to override createSpawnPacket in your Entity class because the vanilla one is only set up to handle the creation of vanilla entities. To implement your own look at SSpawnObjectPacket which handles the vanilla entities. This is the same problem with your ThrowableEntity so do that too.

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.

Link to comment
Share on other sites

5 hours ago, Animefan8888 said:

This is because the EntityType field in your entity called type is being set to the TRIDENT EntityType. You need to make sure that it is set to yours. Also you will need to override createSpawnPacket in your Entity class because the vanilla one is only set up to handle the creation of vanilla entities. To implement your own look at SSpawnObjectPacket which handles the vanilla entities. This is the same problem with your ThrowableEntity so do that too.

Okay changed the EntityType field. I found the method, but I'm not seeing anything in SSpawnObjectPacket that stands out...

 

package mymod.spear;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EntityType.IFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.IPacket;
import net.minecraft.network.play.server.SSpawnObjectPacket;
import net.minecraft.world.World;

public class Spear_Entity extends TridentEntity implements IFactory<Spear_Entity>{
	
	SSpawnObjectPacket gl;
	
	public Spear_Entity(EntityType<Spear_Entity> p_i50148_1_, World p_i50148_2_) {
		
		super(p_i50148_1_, p_i50148_2_);
	}

	public Spear_Entity(World worldIn, PlayerEntity playerentity, ItemStack stack) {

		super(worldIn, playerentity, stack);
	}

	@Override
	public Spear_Entity create(EntityType<Spear_Entity> p_create_1_, World p_create_2_) {

		return null;
	}
	
	@Override
	public IPacket<?> createSpawnPacket() {
		
		Entity entity = this.getShooter();
	    return new SSpawnObjectPacket(this, entity == null ? 0 : entity.getEntityId());
	}
}

 

Edited by MineModder2000
Link to comment
Share on other sites

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




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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