Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey, i just made a projectile (based on the snowball, it has the same mechanics) now if i throw it it always faces north (even if i throw it west) since i have setrotation with just 0F ect.

 

what i want is that if the projectile is flying north it actually points north.

all the code:

item:

package com.walkingdead.walkingdeadmod.weapons;

import com.walkingdead.walkingdeadmod.WalkingDeadMod;
import com.walkingdead.walkingdeadmod.weapons.projectiles.BaseModItem;
import com.walkingdead.walkingdeadmod.weapons.projectiles.EntitySharpStick;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;

public class SharpStick extends BaseModItem{

	public SharpStick(ToolMaterial material, String unlocalizedName) {
		super(material, unlocalizedName);
		setMaxStackSize(1);
		setCreativeTab(WalkingDeadMod.WalkingDead);
	}
	
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
    {
        ItemStack itemstack = playerIn.getHeldItem(handIn);

        if (!playerIn.capabilities.isCreativeMode)
        {
            itemstack.shrink(1);
        }

        worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!worldIn.isRemote)
        {
        	EntitySharpStick entitysharpstick = new EntitySharpStick(worldIn, playerIn);
            entitysharpstick.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
            worldIn.spawnEntity(entitysharpstick);
        }


        playerIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
}


Client proxy:

 

package com.walkingdead.walkingdeadmod;

import com.walkingdead.walkingdeadmod.weapons.ModTools;
import com.walkingdead.walkingdeadmod.weapons.projectiles.EntitySharpStick;
import com.walkingdead.walkingdeadmod.weapons.projectiles.RenderSharpStick;

import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.client.registry.RenderingRegistry;

public class ClientProxyTestEnvironmentMod extends CommonProxyTestEnvironmentMod {

	@Override
	public void registerRenderers(WalkingDeadMod ins) {
		ins.Crawler.registerRenderers();
		ins.Runner.registerRenderers();
		ins.Anatomy.registerRenderers();
		ins.Medical.registerRenderers();
		ins.civ1.registerRenderers();
		ins.Police1.registerRenderers();
		ins.doctor.registerRenderers();
		ModTools.registerRenders();
		RenderingRegistry.registerEntityRenderingHandler(EntitySharpStick.class, new RenderSharpStick(Minecraft.getMinecraft().getRenderManager(), ModTools.sharpstick, Minecraft.getMinecraft().getRenderItem()));
	}
}

 

 

actual entity:

 

package com.walkingdead.walkingdeadmod.weapons.projectiles;

import com.walkingdead.walkingdeadmod.weapons.ModTools;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntitySharpStick extends EntityThrowable
{
    public EntitySharpStick(World worldIn)
    {
        super(worldIn);
    }

    public EntitySharpStick(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    }

    public EntitySharpStick(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }

    public static void registerFixesSharpStick(DataFixer fixer)
    {
        EntityThrowable.registerFixesThrowable(fixer, "SharpStick");
    }

    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            int i = 6;
            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
        }

        if (!this.world.isRemote)
        {
            this.world.setEntityState(this, (byte)3);
            this.setDead();
            
         
            EntityItem item = new EntityItem(this.world, this.lastTickPosX, this.lastTickPosY, this.lastTickPosZ, new ItemStack(ModTools.sharpstick, 1));
            this.world.spawnEntity(item);
         }
     }
}

 

model:

 

package com.walkingdead.walkingdeadmod.weapons.projectiles;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelSharpStick extends ModelBase {
	
ModelRenderer Shape1;
public ModelSharpStick()
	  {
	    textureWidth = 64;
	    textureHeight = 64;
	    
	    
	      
	      Shape1 = new ModelRenderer(this, 0, 0);
	      Shape1.addBox(-0.5F, -0.5F, 0F, 1, 1, 25);
	      Shape1.setRotationPoint(0F, 0F, 0F);
	      Shape1.setTextureSize(64, 64);
	      Shape1.mirror = true;
	      setRotation(Shape1, 0F, 0F, 0F);
	  }
	  
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
	  {
	    super.render(entity, f, f1, f2, f3, f4, f5);
	    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
	    Shape1.render(f5);
	  }
	  
private void setRotation(ModelRenderer model, float x, float y, float z)
	  {
	    model.rotateAngleX = x;
	    model.rotateAngleY = y;
	    model.rotateAngleZ = z;
	  }
	  
public void setRotationAngles(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
	  {
	    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
	  }

	}

 

renderer:

 

package com.walkingdead.walkingdeadmod.weapons.projectiles;

import org.lwjgl.opengl.GL11;

import com.walkingdead.walkingdeadmod.WalkingDeadMod;
import com.walkingdead.walkingdeadmod.weapons.SharpStick;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderSharpStick<T extends Entity> extends Render<T>
{
    protected final Item item;
    private final RenderItem itemRenderer;
	private static final ResourceLocation texture = new ResourceLocation(WalkingDeadMod.MODID, "textures/entities/projectiles/sharpstick.png");
	private ModelBase model;

    public RenderSharpStick(RenderManager renderManagerIn, Item itemIn, RenderItem itemRendererIn)
    {
        super(renderManagerIn);
		model = new ModelSharpStick();
        this.item = itemIn;
        this.itemRenderer = itemRendererIn;
    }


    public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
    	GL11.glPushMatrix();
    	bindTexture(texture);
    	GL11.glTranslated(x, y, z);
    	model.render(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
    	GL11.glPopMatrix();
    }

    public ItemStack getStackToRender(T entityIn)
    {
        return new ItemStack(this.item);
    }

  
    private ResourceLocation getCustomTexture(EntitySharpStick entity) {
    return texture;
    }

    protected ResourceLocation getEntityTexture(Entity entity)
    {
    return getCustomTexture((EntitySharpStick) entity);
    }
}

 

Try checking the snowball classes and see how the vanilla classes do it. I expect you already have, but still try...

 

On second note, you need to do something that detects your Players facing and then pass the values into the the entity.

Edited by Leomelonseeds

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

  • Author
6 hours ago, Leomelonseeds said:

Try checking the snowball classes and see how the vanilla classes do it. I expect you already have, but still try...

 

On second note, you need to do something that detects your Players facing and then pass the values into the the entity.

Have been working on this for the past 2 hours, cant figure it out, can you help me pls?

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.