I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
To take the test, check out https://minecraftnoobtest.com/test.php
Hey I have a bit of a problem, not with rendering though. I am making an item with item damage that drops itself after impact with an entity or block. I am using "this.dropItem(itemID, 1);" right before "this.setDead();" in the entity class, but when it drops, its not damaged (making it an infinite weapon). I have not figured out how to fix this. Any help is appreciated, I also hope you don't mind me putting this here even though this is a rendering tutorial.
Hey I have a bit of a problem, not with rendering though. I am making an item with item damage that drops itself after impact with an entity or block. I am using "this.dropItem(itemID, 1);" right before "this.setDead();" in the entity class, but when it drops, its not damaged (making it an infinite weapon). I have not figured out how to fix this. Any help is appreciated, I also hope you don't mind me putting this here even though this is a rendering tutorial.
An Item cannot impact an entity - an EntityItem can, but not an Item. Also, why are you still coding for 1.6.4?
Anyway, you need to drop an ItemStack with the appropriate damage, not a new Item which is of course not damaged.
Oh sorry I guess its an EntityItem. Its for a custom modpack I'm making for personal use I will be updating it to 1.7 or 1.8 depending on when I get to it. I understand that I need to drop the ItemStack with the damage done to it I'm just not sure of how to do it.
Oh sorry I guess its an EntityItem. Its for a custom modpack I'm making for personal use I will be updating it to 1.7 or 1.8 depending on when I get to it. I understand that I need to drop the ItemStack with the damage done to it I'm just not sure of how to do it.
new ItemStack(Item, quantity, damage)
If you already have a stack somewhere, just drop that.
I realized that its not an EntityItem its just an Item that spawns an EntityThrowable that drops the item(hopefully damaged)when it hits an entity. Here is the EntityThrowable code, am I using the right method? Or is there a different one I should be using that would allow me to get the ItemStacks damage?
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
@Override
protected void onImpact(MovingObjectPosition mop)
{
if (mop.entityHit != null)
{
float spearDamage = 10;
mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)spearDamage);
}
for (int i = 0; i < 8; ++i)
{
this.worldObj.spawnParticle("crit", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
if (!this.worldObj.isRemote)
{
this.dropItem(Rider.ElfSpear.itemID, 1);
this.setDead();
No - the EntityThrowable doesn't know about any ItemStack unless you tell it, i.e. create a class member for it:
public class EntityElfSpear extends EntityThrowable {
private ItemStack stack;
// constructors
// use this to set the stack when you spawn the entity from your Item#onRightClick method or wherever, passing in the stack from there
public void setItemStack(ItemStack stack) {
this.stack = stack;
}
// onImpact, you now have access to this.stack, which you can drop as an EntityItem and will automatically have the correct damage
// you could also damage the item before dropping it, possibly breaking it if that's what you want
}
Ok thanks, I just have one more question. How do I access the ItemStack from my Items onRightClick method? This is something I have tried to do multiple times before but I couldn't figure it out.
Ok thanks, I just have one more question. How do I access the ItemStack from my Items onRightClick method? This is something I have tried to do multiple times before but I couldn't figure it out.
Don't take this the wrong way, but the answer is "By learning Java."
This is the method:
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
If you don't know how to find the ItemStack that you should be using from that, then you need to stop modding for a week or two while you focus on learning the basics of Java - when you come back to modding, it will be so much easier.
Either I'm just completely wrong, or I think you misunderstood my question(more of I stated it badly). How do I get the ItemStack in that method over in the Entity class? If that is what you answered, then I guess I really should go back to the basics.
Either I'm just completely wrong, or I think you misunderstood my question(more of I stated it badly). How do I get the ItemStack in that method over in the Entity class? If that is what you answered, then I guess I really should go back to the basics.
Seems I misunderstood your question, but you misunderstood my earlier code snippet which showed how to make the ItemStack available to your Entity
The code is pretty basic:
- make a field in your Entity class to hold the ItemStack
- add a setter method so you can set that field's value
- when you create the entity, set the field to the value you want (i.e. the ItemStack from the method parameters)
All of those things should be very obvious about how to do them, why it's done that way, etc., which is why I will again suggest that you take some time to study Java. I know it's something that seems painful and annoying, but it will pay off 100-fold in time you will save with simple things like this.
Thanks for the help I'll see if I can figure it out, and also spend more time learning Java itself. Also could you make a tutorial on how to spawn buildings like Link's house in your Zelda Sword Skills mod?
Thanks for the help I'll see if I can figure it out, and also spend more time learning Java itself. Also could you make a tutorial on how to spawn buildings like Link's house in your Zelda Sword Skills mod? The closest I ever got to that was making a building that would spawn naturally, but way way too much.
Thanks for the help I'll see if I can figure it out, and also spend more time learning Java itself. Also could you make a tutorial on how to spawn buildings like Link's house in your Zelda Sword Skills mod? The closest I ever got to that was making a building that would spawn naturally, but way way too much.
Do you mean generate a structure from an item on right click? All you do is make a call to whatever code you have to generate the structure from Item#onItemUse (since that gives you x/y/z coordinates of the block clicked). The only tricky part is the code for the actual structure, and that's something that you have to think through for yourself, because every structure is different. Take a look at some vanilla structures or structures from open source code to see how others have done it.
Instead of it being killed how would i make it so it sticks into the ground and be able to be picked up? i looked into the arrow file but it seems a bit too confusing.
p.s. the rendering for a different projectile model is also somewhat confusing to me
Instead of it being killed how would i make it so it sticks into the ground and be able to be picked up? i looked into the arrow file but it seems a bit too confusing.
p.s. the rendering for a different projectile model is also somewhat confusing to me
If you already looked at the arrow class and couldn't understand that, then I recommend you spend more time learning Java as that will help you find the parts of the code you need - it's all in there. In a nutshell, you just don't setDead on your projectile when it impacts a block, and make sure that its position thereafter remains the same (otherwise it will be bouncing all over from block collisions).
For rendering models, it doesn't matter if it's a projectile, mob, or any other entity, the code is nearly identical: make your model class, create instance of your model in your render class, then call model.render when rendering your entity. Read more vanilla code and it will make sense.
If you already looked at the arrow class and couldn't understand that, then I recommend you spend more time learning Java as that will help you find the parts of the code you need - it's all in there. In a nutshell, you just don't setDead on your projectile when it impacts a block, and make sure that its position thereafter remains the same (otherwise it will be bouncing all over from block collisions).
For rendering models, it doesn't matter if it's a projectile, mob, or any other entity, the code is nearly identical: make your model class, create instance of your model in your render class, then call model.render when rendering your entity. Read more vanilla code and it will make sense.
Okay, I'm trying to render a bullet with a custom model in 1.7.10. The entity code itself works, but the model doesn't. Here are my main problems:
1. The bullet model's spawn position is dependent on pitch. When I shoot up, the bullet's model spawns to the right, but when I shoot down, the bullet's model spawns to the right.
2. The bullet's model displays no pitch and is always horizontal.
@SideOnly(Side.CLIENT)
public class RenderStdBullet extends Render{
// ResourceLocations are typically static and final, but that is not an absolute requirement
private static final ResourceLocation texture = new ResourceLocation("alexmodid:textures/models/ModelStdBullet.png");
// if you want a model, be sure to add it here:
private ModelBase model;
public RenderStdBullet() {
// we could have initialized it above, but here is fine as well:
model = new ModelStdBullet();
}
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
// this method should return your texture, which may be different based
// on certain characteristics of your custom entity; if that is the case,
// you may want to make a second method that takes your class:
return getCustomTexture((EntityStdBullet) entity);
}
private ResourceLocation getCustomTexture(EntityStdBullet entity) {
// now you have access to your custom entity fields and methods, if any,
// and can base the texture to return upon those
return texture;
}
// in whatever render method you are using; this one is from Render class:
@Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTick) {
// again, if you need some information from your custom entity class, you can cast to your
// custom class, either passing off to another method, or just doing it here
// in this example, it is not necessary
// if you are going to do any openGL matrix transformations, be sure to always Push and Pop
GL11.glPushMatrix();
// bind your texture:
bindTexture(texture);
// do whatever transformations you need, then render
// typically you will at least want to translate for x/y/z position:
GL11.glTranslated(x, y, z);
GL11.glRotatef(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTick, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTick, 0.0F, 0.0F, 1.0F);
// if you are using a model, you can do so like this:
model.render(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
// note all the values are 0 except the final argument, which is scale
// vanilla Minecraft almost excusively uses 0.0625F, but you can change it to whatever works
GL11.glPopMatrix();
}
}
ModelStdBullet.class:
// Date: 12/28/2014 3:56:59 PM
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX
public class ClientProxy extends CommonProxy
{
public void registerRenderers()
{
RenderingRegistry.registerEntityRenderingHandler(EntityTest.class, new RenderTest(new ModelBiped(), 0.5F));
RenderingRegistry.registerEntityRenderingHandler(EntityTwin.class, new RenderTwin(new ModelBiped(), 0.5F));
RenderingRegistry.registerEntityRenderingHandler(EntityStdBullet.class, new RenderStdBullet());
}
}
It seems to be rendering it as a 1x1x1 pixel cube, instead of a 1x1x16 pixel long bolt, which it's supposed to look like.
The attached picture is what I want to render.
I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!


To take the test, check out
https://minecraftnoobtest.com/test.php
Don't click this link, HE is haunting it...
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAn Item cannot impact an entity - an EntityItem can, but not an Item. Also, why are you still coding for 1.6.4?
Anyway, you need to drop an ItemStack with the appropriate damage, not a new Item which is of course not damaged.
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumnew ItemStack(Item, quantity, damage)
If you already have a stack somewhere, just drop that.
import java.util.Stack;
import cpw.mods.fml.common.registry.IThrowableEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import dragonrider.Rider;
import dragonrider.weapons.ElfSpear;
public class EntityElfSpear extends EntityThrowable{
public EntityElfSpear(World par1World)
{
super(par1World);
}
public EntityElfSpear(World par1World, EntityLivingBase par2EntityLivingBase)
{
super(par1World, par2EntityLivingBase);
}
public EntityElfSpear(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
@Override
protected void onImpact(MovingObjectPosition mop)
{
if (mop.entityHit != null)
{
float spearDamage = 10;
mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)spearDamage);
}
for (int i = 0; i < 8; ++i)
{
this.worldObj.spawnParticle("crit", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
if (!this.worldObj.isRemote)
{
this.dropItem(Rider.ElfSpear.itemID, 1);
this.setDead();
}
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumpublic class EntityElfSpear extends EntityThrowable { private ItemStack stack; // constructors // use this to set the stack when you spawn the entity from your Item#onRightClick method or wherever, passing in the stack from there public void setItemStack(ItemStack stack) { this.stack = stack; } // onImpact, you now have access to this.stack, which you can drop as an EntityItem and will automatically have the correct damage // you could also damage the item before dropping it, possibly breaking it if that's what you want }-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDon't take this the wrong way, but the answer is "By learning Java."
This is the method:
If you don't know how to find the ItemStack that you should be using from that, then you need to stop modding for a week or two while you focus on learning the basics of Java - when you come back to modding, it will be so much easier.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumSeems I misunderstood your question, but you misunderstood my earlier code snippet which showed how to make the ItemStack available to your Entity
The code is pretty basic:
- make a field in your Entity class to hold the ItemStack
- add a setter method so you can set that field's value
- when you create the entity, set the field to the value you want (i.e. the ItemStack from the method parameters)
All of those things should be very obvious about how to do them, why it's done that way, etc., which is why I will again suggest that you take some time to study Java. I know it's something that seems painful and annoying, but it will pay off 100-fold in time you will save with simple things like this.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDo you mean generate a structure from an item on right click? All you do is make a call to whatever code you have to generate the structure from Item#onItemUse (since that gives you x/y/z coordinates of the block clicked). The only tricky part is the code for the actual structure, and that's something that you have to think through for yourself, because every structure is different. Take a look at some vanilla structures or structures from open source code to see how others have done it.
p.s. the rendering for a different projectile model is also somewhat confusing to me
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf you already looked at the arrow class and couldn't understand that, then I recommend you spend more time learning Java as that will help you find the parts of the code you need - it's all in there. In a nutshell, you just don't setDead on your projectile when it impacts a block, and make sure that its position thereafter remains the same (otherwise it will be bouncing all over from block collisions).
For rendering models, it doesn't matter if it's a projectile, mob, or any other entity, the code is nearly identical: make your model class, create instance of your model in your render class, then call model.render when rendering your entity. Read more vanilla code and it will make sense.
thanks, will do.
1. The bullet model's spawn position is dependent on pitch. When I shoot up, the bullet's model spawns to the right, but when I shoot down, the bullet's model spawns to the right.
2. The bullet's model displays no pitch and is always horizontal.
EntityStdBullet.class:
package tutorial.alex.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class EntityStdBullet extends EntityThrowable{
public EntityStdBullet(World par1World) {
super(par1World);
setThrowableHeading(this.motionX, this.motionY, this.motionZ, 3.0F, 1.0F);
}
public EntityStdBullet(World par1World, EntityLivingBase par2EntityLivingBase){
super(par1World, par2EntityLivingBase);
setThrowableHeading(this.motionX, this.motionY, this.motionZ, 3.0F, 1.0F);
}
public EntityStdBullet(World par1World, double par2, double par4, double par6){
super(par1World, par2, par4, par6);
setThrowableHeading(this.motionX, this.motionY, this.motionZ, 3.0F, 1.0F);
}
@Override
protected void onImpact(MovingObjectPosition pos) {
if (pos.entityHit != null)
{
pos.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 2.5f);
}
for (int i = 0; i < 8; ++i)
{
this.worldObj.spawnParticle("snowballpoof", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
if (!this.worldObj.isRemote)
{
this.setDead();
}
}
@Override
protected float getGravityVelocity()
{
return 0.0f;
}
}
RenderStdBullet.class:
package tutorial.alex.Render;
import org.lwjgl.opengl.GL11;
import tutorial.alex.Entity.EntityStdBullet;
import tutorial.alex.Model.ModelStdBullet;
import net.minecraft.entity.Entity;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.relauncher.Side;
@SideOnly(Side.CLIENT)
public class RenderStdBullet extends Render{
// ResourceLocations are typically static and final, but that is not an absolute requirement
private static final ResourceLocation texture = new ResourceLocation("alexmodid:textures/models/ModelStdBullet.png");
// if you want a model, be sure to add it here:
private ModelBase model;
public RenderStdBullet() {
// we could have initialized it above, but here is fine as well:
model = new ModelStdBullet();
}
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
// this method should return your texture, which may be different based
// on certain characteristics of your custom entity; if that is the case,
// you may want to make a second method that takes your class:
return getCustomTexture((EntityStdBullet) entity);
}
private ResourceLocation getCustomTexture(EntityStdBullet entity) {
// now you have access to your custom entity fields and methods, if any,
// and can base the texture to return upon those
return texture;
}
// in whatever render method you are using; this one is from Render class:
@Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTick) {
// again, if you need some information from your custom entity class, you can cast to your
// custom class, either passing off to another method, or just doing it here
// in this example, it is not necessary
// if you are going to do any openGL matrix transformations, be sure to always Push and Pop
GL11.glPushMatrix();
// bind your texture:
bindTexture(texture);
// do whatever transformations you need, then render
// typically you will at least want to translate for x/y/z position:
GL11.glTranslated(x, y, z);
GL11.glRotatef(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTick, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTick, 0.0F, 0.0F, 1.0F);
// if you are using a model, you can do so like this:
model.render(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
// note all the values are 0 except the final argument, which is scale
// vanilla Minecraft almost excusively uses 0.0625F, but you can change it to whatever works
GL11.glPopMatrix();
}
}
ModelStdBullet.class:
// Date: 12/28/2014 3:56:59 PM
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX
package tutorial.alex.Model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import tutorial.alex.Entity.EntityStdBullet;
public class ModelStdBullet extends ModelBase
{
//fields
ModelRenderer Shape1;
ModelRenderer Shape2;
ModelRenderer Shape3;
ModelRenderer Shape4;
ModelRenderer Shape5;
public ModelStdBullet()
{
textureWidth = 64;
textureHeight = 32;
Shape1 = new ModelRenderer(this, 0, 0);
Shape1.addBox(0F, 0F, 0F, 5, 5, 5);
Shape1.setRotationPoint(0F, 114F, 0F);
Shape1.setTextureSize(64, 32);
Shape1.mirror = true;
setRotation(Shape1, 0F, 0F, 0F);
Shape2 = new ModelRenderer(this, 0, 0);
Shape2.addBox(0F, 0F, 0F, 4, 4, 4);
Shape2.setRotationPoint(0.5F, 115F, 2F);
Shape2.setTextureSize(64, 32);
Shape2.mirror = true;
setRotation(Shape2, 0F, 0F, 0F);
Shape3 = new ModelRenderer(this, 0, 0);
Shape3.addBox(0F, 0F, 0F, 3, 3, 3);
Shape3.setRotationPoint(1F, 115F, 4F);
Shape3.setTextureSize(64, 32);
Shape3.mirror = true;
setRotation(Shape3, 0F, 0F, 0F);
Shape4 = new ModelRenderer(this, 0, 0);
Shape4.addBox(0F, 0F, 0F, 2, 2, 2);
Shape4.setRotationPoint(1.5F, 115.5F, 6F);
Shape4.setTextureSize(64, 32);
Shape4.mirror = true;
setRotation(Shape4, 0F, 0F, 0F);
Shape5 = new ModelRenderer(this, 0, 0);
Shape5.addBox(0F, 0F, 0F, 1, 1, 1);
Shape5.setRotationPoint(2F, 116F, 8F);
Shape5.setTextureSize(64, 32);
Shape5.mirror = true;
setRotation(Shape5, 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);
Shape1.render(f5);
Shape2.render(f5);
Shape3.render(f5);
Shape4.render(f5);
Shape5.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(float f, float f1, float f2, float f3, float f4, float f5)
{
super.setRotationAngles(f, f1, f2, f3, f4, f5, null);
}
}
ClientProxy.class:
package tutorial.alex.client;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderSnowball;
import tutorial.alex.Entity.EntityStdBullet;
import tutorial.alex.Entity.EntityTest;
import tutorial.alex.Entity.EntityTwin;
import tutorial.alex.Render.CommonProxy;
import tutorial.alex.Render.RenderStdBullet;
import tutorial.alex.Render.RenderTest;
import tutorial.alex.Render.RenderTwin;
public class ClientProxy extends CommonProxy
{
public void registerRenderers()
{
RenderingRegistry.registerEntityRenderingHandler(EntityTest.class, new RenderTest(new ModelBiped(), 0.5F));
RenderingRegistry.registerEntityRenderingHandler(EntityTwin.class, new RenderTwin(new ModelBiped(), 0.5F));
RenderingRegistry.registerEntityRenderingHandler(EntityStdBullet.class, new RenderStdBullet());
}
}