Brilliant explanation! I knew about the problem stemming from entities being registered too high/low and was wondering why the error came up as a nullpointerexception instead of arrayoutofbounds.
Brilliant explanation! I knew about the problem stemming from entities being registered too high/low and was wondering why the error came up as a nullpointerexception instead of arrayoutofbounds.
Thanks. Last time I checked, ModLoader hasn't fixed the issue but Forge has made progress on it. At the time I made this thread I never used Forge but now I changed my mind because of this. I might do a small NPC and non-living entity tutorial for Forge on here.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
dont use getUniqueID , use a number from -128 to 127..... for Example: 121.
When did this become a problem? Should i always use my own numbers when making mods? The tutorial I used reccomended that function(it was causing me an error too) I just want to know why it's causing the error.
When did this become a problem? Should i always use my own numbers when making mods? The tutorial I used reccomended that function(it was causing me an error too) I just want to know why it's causing the error.
Um did you actually read this thread? It explains everything. As for using numbers you can but I also made a method that will correctly get a Unique Id. http://pastebin.com/TSLCaD48 In that class there are is a method called getUniqueEntityId.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Um did you actually read this thread? It explains everything. As for using numbers you can but I also made a method that will correctly get a Unique Id. http://pastebin.com/TSLCaD48 In that class there are is a method called getUniqueEntityId.
I apologize, i got mixed up in the thread. You properly explained this previously, I just missed it. Thanks for the further explanation!
package whiteghoul.common;
import java.util.Random;
import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Material;
import net.minecraftforge.client.MinecraftForgeClient;
public class BlockExplosionCir extends Block
{
public BlockExplosionCir(int par1, int par2)
{
super(par1, par2, Material.tnt);
this.setCreativeTab(CreativeTabs.tabBlock);
}
/**
* Returns the block texture based on the side being looked at. Args: side
*/
@Override
public int getBlockTextureFromSide(int side)
{
switch (side)
{
//Bottom
case 0:
return 2;
//Top
case 1:
return 2;
//Side of all Blocks
case 2:
return 4;
case 3:
return 4;
case 4:
return 4;
case 5:
return 4;
}
return 2;
}
@Override
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
super.onBlockAdded(par1World, par2, par3, par4);
if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
{
this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
par1World.setBlockWithNotify(par2, par3, par4, 0);
}
}
@Override
/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
* their own) Args: x, y, z, neighbor blockID
*/
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
{
if (par5 > 0 && Block.blocksList[par5].canProvidePower() && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
{
this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
par1World.setBlockWithNotify(par2, par3, par4, 0);
}
}
@Override
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random par1Random)
{
return 1;
}
@Override
/**
* Called upon the block being destroyed by an explosion
*/
public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4)
{
if (!par1World.isRemote)
{
EntityExplosionNoSpawnBlockPrimed var5 = new EntityExplosionNoSpawnBlockPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F));
var5.fuse = par1World.rand.nextInt(var5.fuse / 4) + var5.fuse / 8;
par1World.spawnEntityInWorld(var5);
}
}
@Override
/**
* Called right before the block is destroyed by a player. Args: world, x, y, z, metaData
*/
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5)
{
if (par1World.isRemote)
{
return;
}
if ((par5 & 1) == 0)
{
dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(mod_whiteghoul.blockexplosioncir.blockID, 1, 0));
}
else
{
EntityExplosionNoSpawnBlockPrimed var6 = new EntityExplosionNoSpawnBlockPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F));
par1World.spawnEntityInWorld(var6);
par1World.playSoundAtEntity(var6, "random.fuse", 1.0F, 1.0F);
}
}
@Override
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.shiftedIndex)
{
this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
par1World.setBlockWithNotify(par2, par3, par4, 0);
return true;
}
else
{
return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
}
}
@Override
public String getTextureFile()
{
return "/BlockSprite.png";
}
/**
* Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
* and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
*/
protected ItemStack createStackedBlock(int par1)
{
return null;
}
}
mod_ file
package whiteghoul.common;
///Basic importing
import java.util.Map;
import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.Packet23VehicleSpawn;
import net.minecraft.src.World;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
//Basic needed forge stuff
@Mod(modid="whiteghoul_mod",name="whiteghoul mod",version="1.3.2")
@NetworkMod(clientSideRequired=true,serverSideRequired=false)
public class mod_whiteghoul
{
//Telling forge that we are creating these
public static Block blockironred;
public static Block blockironblack;
public static Block blockironwhite;
public static Block blockirongray;
public static Block blockexplosioncir;
@SidedProxy(clientSide="whiteghoul.client.ClientProxy", serverSide= "WhiteGhoul.ClientProxy")
public static CommonProxy proxy;
//Declaring Init
@Init
public void load(FMLInitializationEvent event)
{
//declaring these
blockironred = new BlockIronRed(230, 0).setHardness(3F).setResistance(100F).setLightValue(1F).setBlockName("blockironred");
blockironblack = new BlockIronBlack(231, 1).setHardness(3F).setResistance(100F).setLightValue(1F).setBlockName("blockironblack");
blockironwhite = new BlockIronWhite(232, 2).setHardness(3F).setResistance(100F).setLightValue(1F).setBlockName("blockironwhite");
blockirongray = new BlockIronGray(233, 3).setHardness(3F).setResistance(100F).setLightValue(1F).setBlockName("blockirongray");
blockexplosioncir = new BlockExplosionCir(234, 4).setHardness(3F).setResistance(100F).setLightValue(1F).setBlockName("blockexplosioncir");
//Registering Block
GameRegistry.registerBlock(blockironred);
GameRegistry.registerBlock(blockironblack);
GameRegistry.registerBlock(blockironwhite);
GameRegistry.registerBlock(blockirongray);
GameRegistry.registerBlock(blockexplosioncir);
//Register Block Generation
GameRegistry.registerWorldGenerator(new BlockGeneration());
GameRegistry.registerWorldGenerator(new BlockGenerationSurface());
GameRegistry.registerWorldGenerator(new BlockGenerateHigh());
//Adding in-game Name
LanguageRegistry.addName(blockironred, "Block Iron Red");
LanguageRegistry.addName(blockironblack, "Block Iron Black");
LanguageRegistry.addName(blockironwhite, "Block Iron White");
LanguageRegistry.addName(blockirongray, "Block Iron Gray");
LanguageRegistry.addName(blockexplosioncir, "Block Explosion Cir");
EntityRegistry.findGlobalUniqueEntityId();
EntityRegistry.registerModEntity(EntityExplosionNoSpawnBlockPrimed.class, "entityexplosionnospawnblockprimed", 101, this, 64, 20, true);
proxy.registerRenderThings();
}
public void addRenderer(Map map)
{
map.put(EntityExplosionNoSpawnBlockPrimed.class, new RenderExplosionPrimed());
}
}
Hey guys,
I saw this post and realized that this has been my problem all along. My mod was at a standstill. Thanks! Btw, I tried using this method for the entity register and spawn:
[/spoiler]
public void load()
{
ModLoader.registerEntityID(EntityCustomCow.class, "CustomCow", -127);
ModLoader.addSpawn(EntityCustomCow.class, 15, 3, 10, EnumCreatureType.creature);
}
[spoiler/] too bad spoilers don't work
Apparently, Id -127 is not taken, so if you're planning on only adding only one mob to the game, use that number. I'm not sure if this fix is very reliable, but it kept me from recoding everything and it works (I know because I tested it in-game). Hopefully there will be an eventual fix, but for now I'm gonna use -127.
Thanks for the help
blockhead7777.
Ok, i know now, what the problem is. As other users said, in 1.3.1/1.3.2 , Minecraft spawns Mobs on both client and server in SMP. The Client Mob is only a Model which doesnt move, and the Server Mob is the real instance. So... i tried to look, where my Mod only calls the client side to spawn a mob.
At my GUI it printed true.
At onBlockActivated it also printed true.
So it seems, something is wrong with my GUI.
Here is the important Code:
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
TileEntityRobotCreator obj = (TileEntityRobotCreator)par1World.getBlockTileEntity(par2,par3,par4);
EntityPlayerMP emp = null;
EntityPlayerSP smp = null;
if (par5EntityPlayer instanceof EntityPlayerMP)
{
emp = (EntityPlayerMP)par5EntityPlayer;
ModLoader.serverOpenWindow(emp, new CreatorContainer(emp.inventory, obj),10, obj.xCoord, obj.yCoord, obj.zCoord);
}
else
{
smp = (EntityPlayerSP)par5EntityPlayer;
ModLoader.openGUI(smp, new GuiRobotSlot(smp.inventory,(TileEntityRobotCreator)obj));
}
return true;
}
dont use getUniqueID , use a number from -128 to 127..... for Example: 121.
OMG thank you so much for this (give it an id). i have been having problems spawning my mob for days, and i never thought of doing this thank you! because of you my hermit crabs may live
at asv.a(NetClientHandler.java:737)
at bk.a(Packet24MobSpawn.java:131)
at ba.b(SourceFile:51)
at asv.d(NetClientHandler.java:89)
at atd.b(SourceFile:51)
So you only edited the packet class and that stack trace comes up? I see you have some mods installed, are those yours?
What exactly did you edit? Did you do this? http://www.minecraft.../#entry17289084
-snip-
So you only edited the packet class and that stack trace comes up? I see you have some mods installed, are those yours?
I did 'do this,' but I don't know how to change that
ModLoader.getUniqueEntityId()
thingy to a number from 0-255
Also, I just changed the packet class to the edited copy you put on pastbin.
Double check:
package net.minecraft.src;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.List;
public class Packet24MobSpawn extends Packet {
/** The entity ID. */
public int entityId;
/** The type of mob. */
public int type;
/** The X position of the entity. */
public int xPosition;
/** The Y position of the entity. */
public int yPosition;
/** The Z position of the entity. */
public int zPosition;
public int velocityX;
public int velocityY;
public int velocityZ;
/** The yaw of the entity. */
public byte yaw;
/** The pitch of the entity. */
public byte pitch;
/** The yaw of the entity's head. */
public byte headYaw;
/** Indexed metadata for Mob, terminated by 0x7F */
private DataWatcher metaData;
private List metadata;
public Packet24MobSpawn() {
}
public Packet24MobSpawn(EntityLiving par1EntityLiving) {
this.entityId = par1EntityLiving.entityId;
this.type = (byte) EntityList.getEntityID(par1EntityLiving) & 255;
this.xPosition = par1EntityLiving.myEntitySize
.multiplyBy32AndRound(par1EntityLiving.posX);
this.yPosition = MathHelper.floor_double(par1EntityLiving.posY * 32.0D);
this.zPosition = par1EntityLiving.myEntitySize
.multiplyBy32AndRound(par1EntityLiving.posZ);
this.yaw = (byte) ((int) (par1EntityLiving.rotationYaw * 256.0F / 360.0F));
this.pitch = (byte) ((int) (par1EntityLiving.rotationPitch * 256.0F / 360.0F));
this.headYaw = (byte) ((int) (par1EntityLiving.rotationYawHead * 256.0F / 360.0F));
double var2 = 3.9D;
double var4 = par1EntityLiving.motionX;
double var6 = par1EntityLiving.motionY;
double var8 = par1EntityLiving.motionZ;
if (var4 < -var2) {
var4 = -var2;
}
if (var6 < -var2) {
var6 = -var2;
}
if (var8 < -var2) {
var8 = -var2;
}
if (var4 > var2) {
var4 = var2;
}
if (var6 > var2) {
var6 = var2;
}
if (var8 > var2) {
var8 = var2;
}
this.velocityX = (int) (var4 * 8000.0D);
this.velocityY = (int) (var6 * 8000.0D);
this.velocityZ = (int) (var8 * 8000.0D);
this.metaData = par1EntityLiving.getDataWatcher();
}
/**
* Abstract. Reads the raw packet data from the data stream.
*/
public void readPacketData(DataInputStream par1DataInputStream)
throws IOException {
this.entityId = par1DataInputStream.readInt();
this.type = par1DataInputStream.readByte() & 255;
this.xPosition = par1DataInputStream.readInt();
this.yPosition = par1DataInputStream.readInt();
this.zPosition = par1DataInputStream.readInt();
this.yaw = par1DataInputStream.readByte();
this.pitch = par1DataInputStream.readByte();
this.headYaw = par1DataInputStream.readByte();
this.velocityX = par1DataInputStream.readShort();
this.velocityY = par1DataInputStream.readShort();
this.velocityZ = par1DataInputStream.readShort();
this.metadata = DataWatcher.readWatchableObjects(par1DataInputStream);
}
/**
* Abstract. Writes the raw packet data to the data stream.
*/
public void writePacketData(DataOutputStream par1DataOutputStream)
throws IOException {
par1DataOutputStream.writeInt(this.entityId);
par1DataOutputStream.writeByte(this.type & 255);
par1DataOutputStream.writeInt(this.xPosition);
par1DataOutputStream.writeInt(this.yPosition);
par1DataOutputStream.writeInt(this.zPosition);
par1DataOutputStream.writeByte(this.yaw);
par1DataOutputStream.writeByte(this.pitch);
par1DataOutputStream.writeByte(this.headYaw);
par1DataOutputStream.writeShort(this.velocityX);
par1DataOutputStream.writeShort(this.velocityY);
par1DataOutputStream.writeShort(this.velocityZ);
this.metaData.writeWatchableObjects(par1DataOutputStream);
}
/**
* Passes this Packet on to the NetHandler for processing.
*/
public void processPacket(NetHandler par1NetHandler) {
par1NetHandler.handleMobSpawn(this);
}
/**
* Abstract. Return the size of the packet (not counting the header).
*/
public int getPacketSize() {
return 26;
}
public List getMetadata() {
if (this.metadata == null) {
this.metadata = this.metaData.func_75685_c();
}
return this.metadata;
}
}
EDIT: The mods I have are recipebook, which is risugami's mod. Never makes me crash, doesn't edit entity stuff. The more stuff mods are mine. Have 2 cuz I hit the item limit lol
I just made a simple Throwable item that looks like a Slimball.
ModEntityHelper
ItemExtremeSlim
EntityExtremeSlim
mod_Test
That's a basic example You don't have to use that ModEntityHelper class but it will help you out by getting unique Entity and Vehicle Ids.
Anything that extends EntityLiving or implements IAnimals use the following methods.
Use this method for getting an unique Entity Id
Look at that same class for adding spawns as well.
For other non living entities you do the same as above but you have to set the entity tracking.
I haven't tried this out so I don't know if it's %100 correct.
but not now, maybe next day.
thanks for this
Thanks. Last time I checked, ModLoader hasn't fixed the issue but Forge has made progress on it. At the time I made this thread I never used Forge but now I changed my mind because of this. I might do a small NPC and non-living entity tutorial for Forge on here.
When did this become a problem? Should i always use my own numbers when making mods? The tutorial I used reccomended that function(it was causing me an error too) I just want to know why it's causing the error.
Um did you actually read this thread? It explains everything. As for using numbers you can but I also made a method that will correctly get a Unique Id. http://pastebin.com/TSLCaD48 In that class there are is a method called getUniqueEntityId.
I apologize, i got mixed up in the thread. You properly explained this previously, I just missed it. Thanks for the further explanation!
now my problem is
my block is turn white color after right-click using flint and steel
it seems the texture cannot find,
I'm using spritesheet.png
here's my code:
RenderExplosionPrimed class file
BlockExplosionCir class file
mod_ file
I saw this post and realized that this has been my problem all along. My mod was at a standstill. Thanks! Btw, I tried using this method for the entity register and spawn:
[/spoiler]
public void load()
{
ModLoader.registerEntityID(EntityCustomCow.class, "CustomCow", -127);
ModLoader.addSpawn(EntityCustomCow.class, 15, 3, 10, EnumCreatureType.creature);
}
[spoiler/]
too bad spoilers don't workApparently, Id -127 is not taken, so if you're planning on only adding only one mob to the game, use that number. I'm not sure if this fix is very reliable, but it kept me from recoding everything and it works (I know because I tested it in-game). Hopefully there will be an eventual fix, but for now I'm gonna use -127.
Thanks for the help
blockhead7777.
I will recommend you read this post in the thread. http://www.minecraftforum.net/topic/1417041-mod-entity-problem/page__st__100#entry17786787
It explains why using negative numbers for ids isn't a good idea and has a Class that will help get unique Ids. Or you could switch to Forge,
http://www.minecraftforum.net/topic/1417041-mod-entity-problem/page__st__120#entry18153982
OMG thank you so much for this (give it an id). i have been having problems spawning my mob for days, and i never thought of doing this thank you! because of you my hermit crabs may live
What exactly did you edit? Did you do this? http://www.minecraft.../#entry17289084
So you only edited the packet class and that stack trace comes up? I see you have some mods installed, are those yours?
I did 'do this,' but I don't know how to change that
thingy to a number from 0-255
Also, I just changed the packet class to the edited copy you put on pastbin.
Double check:
EDIT: The mods I have are recipebook, which is risugami's mod. Never makes me crash, doesn't edit entity stuff. The more stuff mods are mine. Have 2 cuz I hit the item limit lol
What? You don't, instead of using that method just input a integer from 0 to 255. Just to make sure ids don't collide you could use this class I made http://pastebin.com/6hkaGeE1 There are methods for getting unique ids. Or use Forge http://www.minecraftforum.net/topic/1417041-mod-entity-problem/page__st__120#entry18153982
The Packet class doesn't have any problems.