“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
I was going to dump the work on Risugami, so that mods would be compatible, but it appears that everyone is adopting the fix so... time for me to update (and include the fix)!
I would like to note, you should also recommend the usage of configuration files for the entity IDs. Eventually, we are going to run into people having issues with conflicting IDs, so it would be logical (as a Vulcan would say ).
So here's another problem I'm having relating to Entities. Duplicated entities on spawn. My guess is that it is because world.isRemote now returns true all the time, and one must use a different method than world.spawnentity
So my question is, how do you do it now? I'd just like to spawn an itemstack on interaction. Here is my code:
world.spawnEntityInWorld(new EntityItem(world, i, j, k, new ItemStack(Alptraum.alpMultiItem, 3 +rand.nextInt(4), 2)));
I would like to note, you should also recommend the usage of configuration files for the entity IDs. Eventually, we are going to run into people having issues with conflicting IDs, so it would be logical (as a Vulcan would say ).
Never used configuration files, is this part of the API Forge? But yes there will be some issues with conflicting Ids. I made this thread to explain the problem so people could have a quick fix and understanding of it too. I stated some fixes but I don't know if ModLoader is making on too.
So my question is, how do you do it now? I'd just like to spawn an itemstack on interaction. Here is my code:
world.spawnEntityInWorld(new EntityItem(world, i, j, k, new ItemStack(Alptraum.alpMultiItem, 3 +rand.nextInt(4), 2)));
I don't exactly get your problem. I have used that method to spawn entities all the time, but never for EntityItems. You saying it spawns two Entities or all of them are the same when spawned?
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Never used configuration files, is this part of the API Forge? But yes there will be some issues with conflicting Ids. I made this thread to explain the problem so people could have a quick fix and understanding of it too. I stated some fixes but I don't know if ModLoader is making on too.
It's a part of ModLoader. It's MLProp for ModLoader, and Forge probably has another format available.
Ok, i made a Entity,render, and item file for my shuriken. i used add entity tracker to give the shuriken and id (101) and i think i put all the textures right. but all i get is a white box, i am seriously puzzled , im sure i just made a silly mistake.
all and any help would be very appreciated!
mod_Shuriken
package net.minecraft.src;
import java.util.Map;
public class mod_Shuriken extends BaseMod
{
public static final Item Shuriken = new ItemShuriken(410).setItemName("Shuriken").setIconIndex(ModLoader.addOverride("/gui/items.png", "/mods/Shuriken.png"));
public void load()
{
//ITEMS
ModLoader.addName(Shuriken, "Shuriken");
ModLoader.addRecipe(new ItemStack(Shuriken, 4), new Object [] {" @ ","@ @"," @ ", Character.valueOf('@'), Item.ingotIron});
ModLoader.addEntityTracker(this, EntityShuriken.class, 101, 64, 20,true);
}
//THROWABLE OBJECT RENDERING
public void addRenderer(Map map){
map.put(net.minecraft.src.EntityShuriken.class, new net.minecraft.src.RenderShuriken(101));
}
@Override
public Entity spawnEntity(int entityId, World worldClient, double x,
double y, double z) {
switch (entityId) {
case 101:
return new EntityShuriken(worldClient, x, y, z);
default:
return null;
}
}
@Override
public Packet23VehicleSpawn getSpawnPacket(Entity entity, int type) {
if (entity instanceof EntityShuriken)
return new Packet23VehicleSpawn(entity, type);
else
return null;
}
public String getVersion()
{
return "1.3.1";
}
}
ItemShuriken
package net.minecraft.src;
import java.util.Random;
public class ItemShuriken extends Item
{
public ItemShuriken(int par1)
{
super(par1);
this.maxStackSize = 16;
this.setTabToDisplayOn(CreativeTabs.tabCombat);
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
--par1ItemStack.stackSize;
}
public class RenderShuriken extends Render
{
/**
* Have the icon index (in items.png) that will be used to render the image. Currently, eggs and snowballs uses this
* classes.
*/
private int itemIconIndex;
public RenderShuriken(int par1)
{
this.itemIconIndex = par1;
}
/**
* 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)
{
GL11.glPushMatrix();
GL11.glTranslatef((float)par2, (float)par4, (float)par6);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glScalef(0.5F, 0.5F, 0.5F);
this.loadTexture("/mods/Shuriken.png");
Tessellator var10 = Tessellator.instance;
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
if (par1MovingObjectPosition.entityHit != null)
{
byte var2 = 8;
if (par1MovingObjectPosition.entityHit instanceof EntityBlaze)
{
var2 = 3;
}
I don't exactly get your problem. I have used that method to spawn entities all the time, but never for EntityItems. You saying it spawns two Entities or all of them are the same when spawned?
My problem is that it spawns two entities, one is collectible just like it should be. But the other one is a "ghost" and you can't collect it. If you close the world and reopen it it's gone.
Ok, i made a Entity,render, and item file for my shuriken. i used add entity tracker to give the shuriken and id (101) and i think i put all the textures right. but all i get is a white box, i am seriously puzzled , im sure i just made a silly mistake.
all and any help would be very appreciated!
In your EntityShuriken class you need to define the texture. Look at another entity to see how they do it.
In your EntityShuriken class you need to define the texture. Look at another entity to see how they do it.
I'm a beginner at mod making so pardon me if i'm sound noobish, but i was looking through egg, and snowball entity classes and i could find out how they textured it.
My problem is that it spawns two entities, one is collectible just like it should be. But the other one is a "ghost" and you can't collect it. If you close the world and reopen it it's gone.
I have the same issue only with mobs instead of items... One mob works normally, then another is there, but doesn't move and you cannot hurt it in anyway possible. I narrowed down the issue to the
world.spawnEntityInWorld()
or the
entity.setLocationAndAngles()
because when you spawn in a zombie using that method the same thing will happen where one is invisible and the other one is responsive... I am still trying to find a way to fix it, and if I find a way I will post it.
doeson't work for me. it says map cannot be resolved?
Import Map.
import java.util.Map;
Rollback Post to RevisionRollBack
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
So here's another problem I'm having relating to Entities. Duplicated entities on spawn. My guess is that it is because world.isRemote now returns true all the time, and one must use a different method than world.spawnentity
So my question is, how do you do it now? I'd just like to spawn an itemstack on interaction. Here is my code:
world.spawnEntityInWorld(new EntityItem(world, i, j, k, new ItemStack(Alptraum.alpMultiItem, 3 +rand.nextInt(4), 2)));
I think I found the solution for mobs, but there seems to be different solutions for different kinds of entities as I found the solution for entitylightning, and mobs so try these out:
1. mob solution - in the main mod class have your entity ID registered with the method in this topic. Then wherever you want to spawn the item put this in for it (I am using the default zombie as an example):
double x = vec3d.xCoord;// this can be whatever you want
double y = vec3d.yCoord;// this can be whatever you want
double z = vec3d.zCoord;// this can be whatever you want
EntityZombie zombie = new EntityZombie(world);
if (!world.isRemote)
{
zombie.setPosition(x, y, z);
world.spawnEntityInWorld(zombie);
}
That should work for items too just change the EntityZombie for whatever you need. Just in case it did not work though try this:
2. Entity Lightning solution - this is mostly for if your item that you want to spawn is already in the game and not modded in and/or has 3 doubles/int's for position when calling the class. It is the same steps above, except you need to delete the if statement, and everything in it should be reverse like this:
EntityLightningBolt entitybolt = new EntityLightningBolt(world, 0D, 0D, 0D);
world.spawnEntityInWorld(entitybolt);
entitybolt.setPosition(x, y, z);
For some reason if the setPosition is before the spawnInWorld, it still spawns 2 entities(tested on lightning). Also, if your item is custom made, then register the ID, and/or track it using modloader.
together they are powerful beyond imagination."
I would like to note, you should also recommend the usage of configuration files for the entity IDs. Eventually, we are going to run into people having issues with conflicting IDs, so it would be logical (as a Vulcan would say ).
So my question is, how do you do it now? I'd just like to spawn an itemstack on interaction. Here is my code:
Never used configuration files, is this part of the API Forge? But yes there will be some issues with conflicting Ids. I made this thread to explain the problem so people could have a quick fix and understanding of it too. I stated some fixes but I don't know if ModLoader is making on too.
I don't exactly get your problem. I have used that method to spawn entities all the time, but never for EntityItems. You saying it spawns two Entities or all of them are the same when spawned?
It's a part of ModLoader. It's MLProp for ModLoader, and Forge probably has another format available.
Looks like your EntityBouseSlime doesn't extend EntitySlime.
all and any help would be very appreciated!
mod_Shuriken
package net.minecraft.src;
import java.util.Map;
public class mod_Shuriken extends BaseMod
{
public static final Item Shuriken = new ItemShuriken(410).setItemName("Shuriken").setIconIndex(ModLoader.addOverride("/gui/items.png", "/mods/Shuriken.png"));
public void load()
{
//ITEMS
ModLoader.addName(Shuriken, "Shuriken");
ModLoader.addRecipe(new ItemStack(Shuriken, 4), new Object [] {" @ ","@ @"," @ ", Character.valueOf('@'), Item.ingotIron});
ModLoader.addEntityTracker(this, EntityShuriken.class, 101, 64, 20,true);
}
//THROWABLE OBJECT RENDERING
public void addRenderer(Map map){
map.put(net.minecraft.src.EntityShuriken.class, new net.minecraft.src.RenderShuriken(101));
}
@Override
public Entity spawnEntity(int entityId, World worldClient, double x,
double y, double z) {
switch (entityId) {
case 101:
return new EntityShuriken(worldClient, x, y, z);
default:
return null;
}
}
@Override
public Packet23VehicleSpawn getSpawnPacket(Entity entity, int type) {
if (entity instanceof EntityShuriken)
return new Packet23VehicleSpawn(entity, type);
else
return null;
}
public String getVersion()
{
return "1.3.1";
}
}
package net.minecraft.src;
import java.util.Random;
public class ItemShuriken extends Item
{
public ItemShuriken(int par1)
{
super(par1);
this.maxStackSize = 16;
this.setTabToDisplayOn(CreativeTabs.tabCombat);
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
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 EntityShuriken(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
}
package net.minecraft.src;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class RenderShuriken extends Render
{
/**
* Have the icon index (in items.png) that will be used to render the image. Currently, eggs and snowballs uses this
* classes.
*/
private int itemIconIndex;
public RenderShuriken(int par1)
{
this.itemIconIndex = par1;
}
/**
* 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)
{
GL11.glPushMatrix();
GL11.glTranslatef((float)par2, (float)par4, (float)par6);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glScalef(0.5F, 0.5F, 0.5F);
this.loadTexture("/mods/Shuriken.png");
Tessellator var10 = Tessellator.instance;
if (this.itemIconIndex == 101)
this.func_77026_a(var10, this.itemIconIndex);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
private void func_77026_a(Tessellator par1Tessellator, int par2)
{
float var3 = (float)(par2 % 16 * 16 + 0) / 256.0F;
float var4 = (float)(par2 % 16 * 16 + 16) / 256.0F;
float var5 = (float)(par2 / 16 * 16 + 0) / 256.0F;
float var6 = (float)(par2 / 16 * 16 + 16) / 256.0F;
float var7 = 1.0F;
float var8 = 0.5F;
float var9 = 0.25F;
GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
par1Tessellator.startDrawingQuads();
par1Tessellator.setNormal(0.0F, 1.0F, 0.0F);
par1Tessellator.addVertexWithUV((double)(0.0F - var8), (double)(0.0F - var9), 0.0D, (double)var3, (double)var6);
par1Tessellator.addVertexWithUV((double)(var7 - var8), (double)(0.0F - var9), 0.0D, (double)var4, (double)var6);
par1Tessellator.addVertexWithUV((double)(var7 - var8), (double)(var7 - var9), 0.0D, (double)var4, (double)var5);
par1Tessellator.addVertexWithUV((double)(0.0F - var8), (double)(var7 - var9), 0.0D, (double)var3, (double)var5);
par1Tessellator.draw();
}
}
package net.minecraft.src;
public class EntityShuriken extends EntityThrowable
{
public EntityShuriken(World par1World)
{
super(par1World);
}
public EntityShuriken(World par1World, EntityLiving par2EntityLiving)
{
super(par1World, par2EntityLiving);
}
public EntityShuriken(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
if (par1MovingObjectPosition.entityHit != null)
{
byte var2 = 8;
if (par1MovingObjectPosition.entityHit instanceof EntityBlaze)
{
var2 = 3;
}
par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.thrower), var2);
}
for (int var3 = 8; var3 < 8; ++var3)
{
this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
if (!this.worldObj.isRemote)
{
this.setDead();
}
}
}
My problem is that it spawns two entities, one is collectible just like it should be. But the other one is a "ghost" and you can't collect it. If you close the world and reopen it it's gone.
In your EntityShuriken class you need to define the texture. Look at another entity to see how they do it.
If you are using the ModLoader add Entity Tracker way than you don't have to edit any base classes.
I'm a beginner at mod making so pardon me if i'm sound noobish, but i was looking through egg, and snowball entity classes and i could find out how they textured it.
I have the same issue only with mobs instead of items... One mob works normally, then another is there, but doesn't move and you cannot hurt it in anyway possible. I narrowed down the issue to the or the because when you spawn in a zombie using that method the same thing will happen where one is invisible and the other one is responsive... I am still trying to find a way to fix it, and if I find a way I will post it.
I just changed
to
in the mod_Shuriken class, i didn't even have to create a RenderShuriken.
Import Map.
together they are powerful beyond imagination."
Then you did something wrong. You are talking java.util.Map right?
I think I found the solution for mobs, but there seems to be different solutions for different kinds of entities as I found the solution for entitylightning, and mobs so try these out:
1. mob solution - in the main mod class have your entity ID registered with the method in this topic. Then wherever you want to spawn the item put this in for it (I am using the default zombie as an example):
That should work for items too just change the EntityZombie for whatever you need. Just in case it did not work though try this:
2. Entity Lightning solution - this is mostly for if your item that you want to spawn is already in the game and not modded in and/or has 3 doubles/int's for position when calling the class. It is the same steps above, except you need to delete the if statement, and everything in it should be reverse like this: For some reason if the setPosition is before the spawnInWorld, it still spawns 2 entities(tested on lightning). Also, if your item is custom made, then register the ID, and/or track it using modloader.