Jump to content

Recommended Posts

Posted

Hey there Mannie here, recently got into modding Minecraft, already knew a little bit about Java and C++ (just the basic things, class, functions, loops, variables, etc.), got inspired by a few thoughts and decided to code it out. Everything basic seems to be working fine in mod, the recipes, textures, etc., but I needed a little bit of help with some mod-specific "features(?)." And this is where my questions come in:


 

Questions About Arrows:

- I haven't been able to find a good arrow-making tutorial, would anybody be kind enough to point me to one or explain to me how to make a custom arrow? (Don't forget I just got started with Forge + Java o_o)

- How would I go about making that arrow interact differently with certain entities? For example, if I shoot a pig with that arrow, it turns into a zombie pigman (without taking any damage), but any other mobs hit by that arrow take some damage and have a poisonous DoT applied to them.

- Would it be possible for me to use that arrow with the vanilla bow, or would I also need to learn how to make a custom bow?


 

Questions About Crafting:

- I have an item that acts as a "container" for other items (think water and lava buckets); I want it to be so, that when I craft an item with them, the "container" stays in the crafting area, and doesn't disappear.

- Lastly, I have a recipe in which I use shears to cut a piece of paper into smaller pieces, however, the shears disappear; I would like to go about keeping the shears in the crafting area (like the question above), BUT, I want to decrease the items durability a little. I believe the "Handsaw" in RedPower's MicroBlocks does what I'm looking for.


 

Yeah, not really a "few" questions really, but it'll be great if somebody can clear some things up or point me in the right direction. Thanks a lot!

Posted

Well then, I messed around with EntityThrowable, EntitySnowball, ItemSnowball, and RenderArrow, seemed to not have any errors, but nothing happens upon right-click:

 

EntityMyceliumArrow:

 

 

package raevox.doomShrooms.common.entity.projectile;

 

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.passive.EntityCow;

import net.minecraft.entity.projectile.EntityThrowable;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

 

public class EntityMyceliumArrow extends EntityThrowable

{

public EntityMyceliumArrow(World par1World)

{

super(par1World);

}

 

public EntityMyceliumArrow(World par1World, EntityLiving par2EntityLiving)

{

super(par1World, par2EntityLiving);

}

 

public EntityMyceliumArrow(World par1World, double par2, double par4, double par6)

{

super(par1World, par2, par4, par6);

}

 

private final EntityLiving entityliving = new EntityLiving(worldObj)

{

@Override

public int getMaxHealth()

{

return 0;

}

 

protected void onImpact(MovingObjectPosition par1MovingObjectPosition)

{

if (par1MovingObjectPosition.entityHit != null)

{

byte var2 = 2;

 

if (par1MovingObjectPosition.entityHit instanceof EntityCow)

{

setDead();

EntityCow entitycow = new EntityCow(worldObj);

entitycow.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);

entitycow.setEntityHealth(getHealth());

entitycow.renderYawOffset = renderYawOffset;

worldObj.spawnEntityInWorld(entitycow);

worldObj.spawnParticle("largeexplode", posX, posY + (double)(height / 2.0F), posZ, 0.0D, 0.0D, 0.0D);

}

 

par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(par1MovingObjectPosition.entityHit, getThrower()), var2);

}

 

if (!par1MovingObjectPosition.entityHit.worldObj.isRemote)

        {

par1MovingObjectPosition.entityHit.setDead();

        }

}

};

 

@Override

protected void onImpact(MovingObjectPosition var1)

{}

}

 

 

 

That's the Entity file, most of it is reused from EntitySnowball.

 


 

 

 

private final EntityLiving entityliving = new EntityLiving(worldObj)

{

 

...

 

if (par1MovingObjectPosition.entityHit instanceof EntityCow)

{

setDead();

EntityCow entitycow = new EntityCow(worldObj);

entitycow.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);

entitycow.setEntityHealth(getHealth());

entitycow.renderYawOffset = renderYawOffset;

worldObj.spawnEntityInWorld(entitycow);

worldObj.spawnParticle("largeexplode", posX, posY + (double)(height / 2.0F), posZ, 0.0D, 0.0D, 0.0D);

}

 

...

 

}

 

 

 

That part is me trying to use methods from both EntityLiving and ItemThrowable (would that lil' hack be the reason why I'm not able to spawn anything?), I tried to reverse the process in which a mooshroom turns into a cow when sheared, however, for that I needed to extend to EntityLiving. Is there a better way to do this?

 


 

ItemMyceliumArrow:

 

 

package raevox.doomShrooms.common.item;

 

import raevox.doomShrooms.common.entity.projectile.EntityMyceliumArrow;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class ItemMyceliumArrow extends Item

{

public ItemMyceliumArrow(int par1)

{

super(par1);

setTextureFile("/raevox/doomShrooms/items.png");

setItemName("myceliumArrow");

setCreativeTab(CreativeTabs.tabCombat);

}

 

@SideOnly(Side.CLIENT)

public int getIconFromDamage(int i)

{

return 6;

}

 

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

        if (!par3EntityPlayer.capabilities.isCreativeMode)

        {

            --par1ItemStack.stackSize;

        }

 

        par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

 

        if (!par2World.isRemote)

        {

            par2World.spawnEntityInWorld(new EntityMyceliumArrow(par2World, par3EntityPlayer));

        }

 

        return par1ItemStack;

    }

}

 

 

 

Just a little Item file with similar onItemRightClick() method as the ItemSnowball.

 


 

RenderMyceliumArrow:

 

 

package raevox.doomShrooms.common.renderer.entity;

 

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.entity.Render;

import net.minecraft.entity.Entity;

import net.minecraft.entity.projectile.EntityArrow;

import net.minecraft.util.MathHelper;

 

import org.lwjgl.opengl.GL11;

import org.lwjgl.opengl.GL12;

 

import raevox.doomShrooms.common.entity.projectile.EntityMyceliumArrow;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

@SideOnly(Side.CLIENT)

public class RenderMyceliumArrow extends Render

{

    public void renderMyceliumArrow(EntityMyceliumArrow par1EntityMyceliumArrow, double par2, double par4, double par6, float par8, float par9)

    {

        this.loadTexture("/raevox/doomShrooms/arrows.png");

        GL11.glPushMatrix();

        GL11.glTranslatef((float)par2, (float)par4, (float)par6);

        GL11.glRotatef(par1EntityMyceliumArrow.prevRotationYaw + (par1EntityMyceliumArrow.rotationYaw - par1EntityMyceliumArrow.prevRotationYaw) * par9 - 90.0F, 0.0F, 1.0F, 0.0F);

        GL11.glRotatef(par1EntityMyceliumArrow.prevRotationPitch + (par1EntityMyceliumArrow.rotationPitch - par1EntityMyceliumArrow.prevRotationPitch) * par9, 0.0F, 0.0F, 1.0F);

        Tessellator var10 = Tessellator.instance;

        byte var11 = 0;

        float var12 = 0.0F;

        float var13 = 0.5F;

        float var14 = (float)(0 + var11 * 10) / 32.0F;

        float var15 = (float)(5 + var11 * 10) / 32.0F;

        float var16 = 0.0F;

        float var17 = 0.15625F;

        float var18 = (float)(5 + var11 * 10) / 32.0F;

        float var19 = (float)(10 + var11 * 10) / 32.0F;

        float var20 = 0.05625F;

        GL11.glEnable(GL12.GL_RESCALE_NORMAL);

        float var21 = (float)par1EntityMyceliumArrow.throwableShake - par9;

 

        if (var21 > 0.0F)

        {

            float var22 = -MathHelper.sin(var21 * 3.0F) * var21;

            GL11.glRotatef(var22, 0.0F, 0.0F, 1.0F);

        }

 

        GL11.glRotatef(45.0F, 1.0F, 0.0F, 0.0F);

        GL11.glScalef(var20, var20, var20);

        GL11.glTranslatef(-4.0F, 0.0F, 0.0F);

        GL11.glNormal3f(var20, 0.0F, 0.0F);

        var10.startDrawingQuads();

        var10.addVertexWithUV(-7.0D, -2.0D, -2.0D, (double)var16, (double)var18);

        var10.addVertexWithUV(-7.0D, -2.0D, 2.0D, (double)var17, (double)var18);

        var10.addVertexWithUV(-7.0D, 2.0D, 2.0D, (double)var17, (double)var19);

        var10.addVertexWithUV(-7.0D, 2.0D, -2.0D, (double)var16, (double)var19);

        var10.draw();

        GL11.glNormal3f(-var20, 0.0F, 0.0F);

        var10.startDrawingQuads();

        var10.addVertexWithUV(-7.0D, 2.0D, -2.0D, (double)var16, (double)var18);

        var10.addVertexWithUV(-7.0D, 2.0D, 2.0D, (double)var17, (double)var18);

        var10.addVertexWithUV(-7.0D, -2.0D, 2.0D, (double)var17, (double)var19);

        var10.addVertexWithUV(-7.0D, -2.0D, -2.0D, (double)var16, (double)var19);

        var10.draw();

 

        for (int var23 = 0; var23 < 4; ++var23)

        {

            GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);

            GL11.glNormal3f(0.0F, 0.0F, var20);

            var10.startDrawingQuads();

            var10.addVertexWithUV(-8.0D, -2.0D, 0.0D, (double)var12, (double)var14);

            var10.addVertexWithUV(8.0D, -2.0D, 0.0D, (double)var13, (double)var14);

            var10.addVertexWithUV(8.0D, 2.0D, 0.0D, (double)var13, (double)var15);

            var10.addVertexWithUV(-8.0D, 2.0D, 0.0D, (double)var12, (double)var15);

            var10.draw();

        }

 

        GL11.glDisable(GL12.GL_RESCALE_NORMAL);

        GL11.glPopMatrix();

    }

 

    /**

    * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then

    * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic

    * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,

    * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.

    */

    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)

    {

        this.renderMyceliumArrow((EntityMyceliumArrow)par1Entity, par2, par4, par6, par8, par9);

    }

}

 

 

 

Duplicated (and edited) RenderArrow file.

 


 

What's in my CommonProxy:

 

public void registerRenders() // Using "proxy.registerRenders();" in my main mod file
{
RenderingRegistry.registerEntityRenderingHandler(EntityMyceliumArrow.class, new RenderMyceliumArrow());
}

 

 


 

Whenever I right-click with the item, I hear the bow noise, but no entity appears. Neither do I hear the sound of something jamming itself in a block either, nor do I hear myself pick the entity up.

 

Any help?

Thanks.

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.