• 0

    posted a message on NullPointerException in ModLoader.addRecipe()

    ok, thanks for solving that.


    It's one of those simple mistakes everyone makes at least once.
    I still remember the first time I encountered this problem...:mellow:
    Posted in: Modification Development
  • 0

    posted a message on NullPointerException in ModLoader.addRecipe()

    Yeah, i did think that, Crafting Manager doesn't seem to like different sorts of char's.

    Nope, didn't work. Same error.


    You used "Block.planks.blockID"

    Crafting recipes expect an Object, so just use "Block.planks"

    The ".blockID" portion turns the block into an integer value corresponding to its block ID in the code, whereas leaving it off will just input an instance of the specific Block.

    ".shiftedIndex" does the same thing for Items


    I'll show you a recipe from my code and break it into pieces for you to get a full grasp of:

    ModLoader.addRecipe(new ItemStack(rope, 1), new Object[] {"#", "#", "#", '#', Block.vine});


    "ModLoader.addRecipe()" -- runs the addRecipe(ItemStack, Object) method in ModLoader.java

    "new ItemStack(rope, 1)" -- creates a new instance of ItemStack.java with the given arguments passed into the constructor "ItemStack(item, quantityToProduce)

    ", new Object[] {}" -- creates a new array of Objects with the specified values

    " "#", "#", "#", '#', Block.vine" -- this specifies Characters that correspond to slots in the array of Objects, and then those Characters have their value specified with '#' (the same as Character.valueOf('#'), I just use this because it looks cleaner and takes less space), the " '#', Block.vine" portion states that each character with the value of # is equal to an instance of a Block.vine, or the vine block to be exact

    So it adds a recipe with the arguments of a new instance of the ItemStack class, and an array of Objects that correspond to different elements in the recipe, there are no integer arguments to be passed in. This is important because it means you'll be using "Item.itemNameHere" and "Block.blockNameHere" instead of "Item.itemNameHere.shiftedIndex" or "Block.blockNameHere.blockID" because ".blockID" and ".shiftedIndex" tell the code that those become numbers (integers) instead of objects, and you don't want to use integers as an argument here.


    Sorry if this is all a bit heady, I made an effort to make it as clear as I could.
    Posted in: Modification Development
  • 1

    posted a message on Problems Adding Custom Armor to Minecraft using ModLoader
    Honestly, without Forge API I don't think you can add fully-functional armor without modifying at least one base class. Your extension of ItemArmor shows you exactly why. If you extend ItemArmor you need an EnumToolMaterial, and if you make a copy of ItemArmor instead, then enchantments won't work.

    I've yet to hear of someone who's done this.
    Posted in: Modification Development
  • 0

    posted a message on mod won't run, recompiled without problem.

    ok, thx, to be honest, i've been spending my time playing the portal gun mod, as i had given up on for a little bit.


    NullPointerExceptions are a pain in the ass to debug yourself to be honest. The last time I had one I didn't have the slightest clue in hell what was wrong, until I actually asked for help and got the explanation I needed from one of the more experienced community members.
    Posted in: Modification Development
  • 0

    posted a message on PL
    Quote from Ilikepiepants

    Ok, so i've started making a mod and I found these tutorials that seemed very simple and easy but i was TOTALY WRONG. I got like 17 errors and I FLIPED out! so I was hoping for a Easy, working, and always up to date(Like updated every other day).PLEASE HELP!!!!
    Notes: I AM NOT TRYING TO FIX MY ERRORS!!!!!!!!!! I AM REQUESTING A GOOD TUTORIAL!!!, I am on a mac, i use eclipse



    1. Don't freak out about errors or you'll never get anywhere, hell, half of the time errors are extremely useful in that they cause you to go back over your thought process and potentially find critical bugs.

    2. http://www.minecraftforum.net/topic/1030464-creating-mods-125-advanced-modding-tutorials/ I can vouch for this person's video tutorials, and regularly follow this forum thread to assist people with problems and to suggest improvements. They've helped me a good bit so it's the least I can do for him.
    Posted in: Modification Development
  • 0

    posted a message on mod won't run, recompiled without problem.
    public static final Item Rice1 = new ItemRice(5000, null).setItemName("Rice1");


    You have a NullPointerException and this is telling the ItemRice class that the "spawnID" of the block that the placed item is supposed to spawn on is null. It needs to be the ID of the block that the rice item is supposed to be placed on, as far as I can tell. Also here's ItemRice with cleaned up names (too bad the forum ate the indentation):

    package net.minecraft.src;
    
    public class ItemRice extends Item
    {
    private int spawnID;
    public ItemRice(int id, Block block)
    {
    super(id);
    spawnID = block.blockID;
    }
    
    public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int side)
    {
    int IDOfBlockCheckedAtXYZ = world.getBlockId(x, y, z);
    
    if (IDOfBlockCheckedAtXYZ == Block.snow.blockID)
    {
    side = 1;
    }
    else if (IDOfBlockCheckedAtXYZ != Block.vine.blockID && IDOfBlockCheckedAtXYZ != Block.tallGrass.blockID && IDOfBlockCheckedAtXYZ != Block.deadBush.blockID)
    {
    if (side == 0)
    {
    y--;
    }
    
    if (side == 1)
    {
    y++;
    }
    
    if (side == 2)
    {
    z--;
    }
    
    if (side == 3)
    {
    z++;
    }
    
    if (side == 4)
    {
    x--;
    }
    
    if (side == 5)
    {
    x++;
    }
    }
    
    if (!entityplayer.canPlayerEdit(x, y, z))
    {
    return false;
    }
    
    if (itemstack.stackSize == 0)
    {
    return false;
    }
    
    if (world.canBlockBePlacedAt(spawnID, x, y, z, false, side))
    {
    /* Block block is equal to the block in the list of blocks that this item is suppose to be placed on,
    *  which is currently being assigned as "null" in the mod_File */
    Block block = Block.blocksList[spawnID];
    
    if (world.setBlockWithNotify(x, y, z, spawnID))
    {
    if (world.getBlockId(x, y, z) == spawnID)
    {
    Block.blocksList[spawnID].onBlockPlaced(world, x, y, z, side);
    Block.blocksList[spawnID].onBlockPlacedBy(world, x, y, z, entityplayer);
    }
    
    world.playSoundEffect((float)x + 0.5F, (float)y + 0.5F, (float)z + 0.5F, block.stepSound.getStepSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
    itemstack.stackSize--;
    }
    }
    
    return true;
    }
    
    }
    Posted in: Modification Development
  • 0

    posted a message on mod won't run, recompiled without problem.
    Give me a minute while I deobfuscate the names so I can read them without thinking.
    I'll be back.
    Posted in: Modification Development
  • 0

    posted a message on Sunken flowers
    Quote from Dougie1133

    Hello all!

    I seem to be having a small problem with my naturally generated custom flowers. they are all generating in holes in the ground. is there any way to get them to spawn ON the dirt or grass instead of IN the dirt or grass? I have posted the code and a screen of what I am talking about below.


    Thanks for any help you may be able to provide!


    par1World.setBlock(l1, i2, j2, minableBlockId);


    world.setBlock(x, y + 1, z, minableBlockId);


    The variable names are the same but I deobfuscated them to better illustrate the point. You're placing them at the XYZ of the grass/dirt block that it found to place the flower on, rather than above it (y + 1). This is in the WorldGen file.
    Posted in: Modification Development
  • 0

    posted a message on Having Issues with Fireball on Right Click
    Quote from lordofroosters

    I tried doing that already. **** ton of math, and I still can't figure it out. >_<


    Most of the time anything to do with camera position (rotationYaw, etc.) is irrelevant as long as you don't change it. That stuff is just a bunch of fancy trigonometry to determine what direction something is facing and how large its visible area is.

    I took a look into EntityBlaze myself just now, and these are the important parts:

    			double var3 = par1Entity.posX - this.posX;
    			double var5 = par1Entity.boundingBox.minY + (double)(par1Entity.height / 2.0F) - (this.posY + (double)(this.height / 2.0F));
    			double var7 = par1Entity.posZ - this.posZ;
    
    
    					float var9 = MathHelper.sqrt_float(par2) * 0.5F;
    					this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
    
    					for (int var10 = 0; var10 < 1; ++var10)
    					{
    						EntitySmallFireball var11 = new EntitySmallFireball(this.worldObj, this, var3 + this.rand.nextGaussian() * (double)var9, var5, var7 + this.rand.nextGaussian() * (double)var9);
    						var11.posY = this.posY + (double)(this.height / 2.0F) + 0.5D;
    						this.worldObj.spawnEntityInWorld(var11);
    					}


    Both are in attackEntity(Entity par1Entity, float par2)
    Posted in: Modification Development
  • 0

    posted a message on TheInstitution's Modding Tutorials + FORGE TUTS
    Quote from DaSnipeKid

    Hey can you make a tutorial on how to make an arrow?

    Also, how to add potion effect (Poison) to the arrow or any item.


    Poison damage can only be inflicted on interaction with an Entity, this is important to remember. It means that you have to do something like detecting when an Entity is hit by the item and applying the damage then, or detecting when an Entity collides with another Entity.

    I won't give you a fancy tutorial, but I will show you a portion of the file for the Entity of one of my poisonous throwable items.

    	protected void onImpact(MovingObjectPosition movingobjectposition)
    	{
    		int byte1 = 10 + rand.nextInt(10);
    
    		if (movingobjectposition.entityHit != null)
    		{
    			byte byte0 = 0;
    
    			if (movingobjectposition.entityHit instanceof EntityLiving)
    			{
    				byte0 = 2;
    			}
    
    			if (!movingobjectposition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, thrower), byte0));
    
    			if (byte0 > 0)
    			{
    				((EntityLiving)movingobjectposition.entityHit).addPotionEffect(new PotionEffect(Potion.poison.id, byte1 * 20, 0));
    			}
    
    			for (int i = 0; i < 8; i++)
    			{
    				worldObj.spawnParticle("snowballpoof", posX, posY, posZ, 0.0D, 0.0D, 0.0D);
    			}
    		}
    
    		if (!worldObj.isRemote)
    		{
    			setDead();
    		}
    	}


    byte1 is the number of ticks multiplied by 20 to produce the effect duration in seconds
    Posted in: Tutorials
  • 0

    posted a message on Having Issues with Fireball on Right Click
    Quote from lordofroosters

    Thanks for the help. I've got it working now, but it only fires in one direction. (Partially fix'd by reassigning the skill to an item.) Any fixes for this? It's really bugging me.

    Also, how would I bind a key to a command? As in: pressing Z would use an EnumMovingObjectType-style thing to determine if the player is looking at a block or not, and then ignite the block if true (or, if it was an entity, burn it).


    I don't know about keybinds currently, but to change the direction it fires in, look inside EntityBlaze at the code it uses when it fires the projectile, and figure out how it gets the direction to shoot in, then adapt that to this situation.
    Posted in: Modification Development
  • 0

    posted a message on Testing Mod Code Brings Up Strange Error
    Quote from irish_brigid

    Edit: I fixed the recompile problem, but now I'm back to loading a world with a black screen.

    *sigh* I'm starting to think I should wait until the next update. I mean, it's kinda crazy that when I try to use one of the base code's WorldGen files I get a recompile error that seems to indicate that it doesn't recognize the keyword 'new' (or maybe the base WorldGen, it's hard to tell).


    As far as I know nothing in the next update is going to help you make a vine grow upwards...?

    I guess I should just do this for you because I could probably figure it out easier that way, but that kind of defeats the point...

    Oh did you create a new world each time you tried it? If not, you should do so, but anyway...


    If you had problems with it not wanting to use the keyword "new" in your generateSurface() block then you had syntactic error there.

    Okay one thing I'm noticing in your Block file compared to the vines in the normal game, is that your updateTick() method is comparatively tiny , and uses a while() loop. I haven't actually used a while() myself yet, but try having it break after it places a new vine, this might be where it's looping infinitely and eating its own tail.

    Also like I've said, the black screen problem is being caused by something somewhere looping infinitely, and the best way to fix that is to use console output to determine how often a loop is being run.
    Posted in: Modification Development
  • 0

    posted a message on Testing Mod Code Brings Up Strange Error
    Quote from Karob

    What is the error, though? This is just where the error occured. It should have said "Segmentation fault" or "Divide by zero" or some other error type...


    You are generating 20 * 64 = 1280 vine blocks in every chunk. That's a lot. That could also be a problem.


    If you use a loop improperly it never stops. Errors in WorldGen can cause this exact problem, an errorless crashing bug, because the code is syntactically correct. The problem is, when you load the game WorldGen is refreshed, and the world generation code is also completely linear, every step has to finish in sequence for it to go on. If something causes it to "stick" on an infinite loop, the game won't crash with an error, but it will never load, and will slowly eat more and more memory.

    Normally when I encounter this problem I print a static number to the console that increments every time the loop is called; it can quickly soar into the 10s of thounsands without the game doing anything besides eating more memory.


    Oh also, 64 loops only means 64 attempts, that's not how many vines it generates, only how many times it tries to generate them.
    Posted in: Modification Development
  • 0

    posted a message on Testing Mod Code Brings Up Strange Error
    Quote from irish_brigid

    Sorry. It's just really frustrating. I've edited and re-edited this code and all I wanted to test is if I can make a vine that grows up.

    I didn't know about the alt+f4, I've used ctrl+alt+del to exit. I don't know if that's what happened, but I completely rewrote the generation code (several times) and now I get an error message.

    	at ko.a(ChunkProvider.java:204)
    	at ack.a(Chunk.java:1123)
    	at ko.c(ChunkProvider.java:113)
    	at ko.b(ChunkProvider.java:126)
    	at xd.d(World.java:647)
    	at xd.a(World.java:562)
    	at xd.i(World.java:575)
    	at WorldGenTestVine.a(WorldGenTestVine.java:19)
    	at mod_TestVine.generateSurface(mod_TestVine.java:30)
    	at ModLoader.populateChunk(ModLoader.java:1184)


    *sigh* I'm starting to wonder if I should wait until the next version of Minecraft.

    Anyway, the new code, in case someone can tell me where I've messed up.

    BlockGrowUp
    package net.minecraft.src;
    import java.util.ArrayList;
    import java.util.Random;
    public class BlockGrowUp extends Block
    {
    	public BlockGrowUp(int i)
    	{
    		super(i, 143, Material.vine);
    		this.setHardness(0F);
    		this.setResistance(0F);
    		this.setBlockName("GrowUp");
    		this.setTickRandomly(true);
    	}
    
    	public void setBlockBoundsForItemRender()
    	{
    		this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    	}
    
    	public boolean isOpaqueCube()
    	{
    		return false;
    	}
    
    	public boolean renderAsNormalBlock()
    	{
    		return false;
    	}
    
    	public int getRenderType()
    	{
    		return 20;
    	}
    
    	public void setBlockBoundsBasedOnState(IBlockAccess iBlockAccess, int x, int y, int z)
    	{
    		int i = iBlockAccess.getBlockMetadata(x, y, z);
    		int j = i & 7;
    		boolean flag = i > 0;
    		float f = 0.015625F;
    		float f1 = 0.5F;
    		if ((i & 2) != 0) //the vine attaches to the left block
    		{
    			this.setBlockBounds(0.0F, 0.5F - f1, 0.5F - f1, f, 0.5F + f1, 0.5F + f1);
    			flag = true;
    		}
    		else if ((i & 8) != 0)  //the vine attaches to the right block
    		{
    			this.setBlockBounds(f, 0.5F - f1, 0.5F - f1, 0.5F +f1, 0.5F + f1, 0.5F + f1);
    			flag = true;
    		}
    		else if ((i & 4) != 0) //the vine attaches to back block
    		{
    			this.setBlockBounds(0.0F, 0.0F, 0.5F - f1, 0.5F + f1, 0.5F + f1, f);
    			flag = true;
    		}
    		else if ((i & 1) != 0) //the vine attaches to front block
    		{
    			this.setBlockBounds(0.0F, 0.5F - f1, f, 0.5F + f1, 0.5F + f1, 0.5F + f1);
    			flag = true;
    		}
    	}
    
    	public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
    	{
    		return null;
    	}
    
    	public boolean canPlaceBlockOnSide(World world, int x, int y, int z)
    	{
    		int i = world.getBlockId(x, y - 1, z);
    		if (world.isBlockNormalCube(x, y, z + 1))
    		{
    			if(i == this.blockID)
    			{
    				return true;
    			}
    			else if(i != Block.grass.blockID && i != Block.dirt.blockID && i != Block.tilledField.blockID)
    			{
    				return false;
    			}
    		}
    		else if (world.isBlockNormalCube(x, y, z - 1))
    		{
    			if(i == this.blockID)
    			{
    				return true;
    			}
    			else if(i != Block.grass.blockID && i != Block.dirt.blockID && i != Block.tilledField.blockID)
    			{
    				return false;
    			}
    		}
    		else if (world.isBlockNormalCube(x + 1, y, z))
    		{
    			if(i == this.blockID)
    			{
    				return true;
    			}
    			else if(i != Block.grass.blockID && i != Block.dirt.blockID && i != Block.tilledField.blockID)
    			{
    				return false;
    			}
    		}
    		else if (world.isBlockNormalCube(x - 1, y, z))
    		{
    			if(i == this.blockID)
    			{
    				return true;
    			}
    			else if(i != Block.grass.blockID && i != Block.dirt.blockID && i != Block.tilledField.blockID)
    			{
    				return false;
    			}
    		}
    		return false;
    	}
    
    	private boolean canPlantStay(World world, int x, int y, int z)
    	{
    		return (world.getFullBlockLightValue(x, y, z) >= 6 && this.canPlaceBlockOnSide(world, x, y, z));
    	}
    
    	public void onNeighborBlockChange(World world, int x, int y, int z, int i)
    	{
    		super.onNeighborBlockChange(world, x, y, z, i);
    		this.checkPlantChange(world, x, y, z);
    	}
    	
    	protected final void checkPlantChange(World world, int x, int y, int z)
    	{
    		if (!this.canPlantStay(world, x, y, z))
    		{
    			this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
    			world.setBlockWithNotify(x, y, z, 0);
    		}
    	}
    
    	public void updateTick(World world, int x, int y, int z, Random random)
    	{
    		if (random.nextInt(6) == 0)
    		{
    			while(this.canPlantStay(world, x, y + 1, z) || this.canPlantStay(world, x + 1, y, z) || this.canPlantStay(world, x - 1, y, z) || this.canPlantStay(world, x, y, z + 1) || this.canPlantStay(world, x, y, z - 1))
    			{
    				if(world.isAirBlock(x, y + 1, z))
    				{
    					world.setBlockWithNotify(x, y, z, this.blockID);
    				}
    				else if(world.isAirBlock(x + 1, y, z))
    				{
    					world.setBlockWithNotify(x, y, z, this.blockID);
    				}
    				else if(world.isAirBlock(x - 1, y, z))
    				{
    					world.setBlockWithNotify(x, y, z, this.blockID);
    				}
    				else if(world.isAirBlock(x, y, z + 1))
    				{
    					world.setBlockWithNotify(x, y, z, this.blockID);
    				}
    				else if(world.isAirBlock(x, y, z - 1))
    				{
    					world.setBlockWithNotify(x, y, z, this.blockID);
    				}
    			}
    		}
    	}
    
    	public void onBlockPlaced(World world, int x, int y, int z, int i)
    	{
    		byte byte0 = 0;
    		switch (i)
    		{
    			case 2:
    				byte0 = 1;
    				break;
    			case 3:
    				byte0 = 4;
    				break;
    			case 4:
    				byte0 = 8;
    				break;
    			case 5:
    				byte0 = 2;
    		}
    		if (byte0 != 0)
    		{
    			world.setBlockMetadataWithNotify(x, y, z, byte0);
    		}
    	}
    
    	public int idDropped(int i, Random random, int j)
    	{
    		return mod_TestVine.GrowUp.blockID;
    	}
    
    	public int quantityDropped(Random random)
    	{
    		return 1;
    	}
    }

    WorldGenTestVine
    package net.minecraft.src;
    import java.util.Random;
    public class WorldGenTestVine extends WorldGenerator
    {
    	private int plantBlockId;
    
    	public WorldGenTestVine()
    	{
    		this.plantBlockId = mod_TestVine.GrowUp.blockID;
    	}
    
    	public boolean generate(World world, Random random, int x, int y, int z)
    	{
    		for (int i = 0; i < 64; ++i)
    		{
    			int x1 = x + random.nextInt(8) - random.nextInt(8);
    			int y1 = y + random.nextInt(4) - random.nextInt(4);
    			int z1 = z + random.nextInt(8) - random.nextInt(8);
    			if (world.isAirBlock(x1, y1, z1) && ((BlockGrowUp)Block.blocksList[this.plantBlockId]).canBlockStay(world, x1, y1, z1))
    			{
    				world.setBlock(x1, y1, z1, this.plantBlockId);
    			}
    		}
    		return true;
    	}
    }

    mod_TestVine
    package net.minecraft.src;
    import java.util.Random;
    public class mod_TestVine extends BaseMod
    {
    	public mod_TestVine()
    	{
    	}
    
    	public String getVersion()
    	{
    		return "Minecraft 1.2.#";
    	}
    	
    	public static final Block GrowUp = (new BlockGrowUp(130));
    
    	public void load()
    	{		
    		ModLoader.registerBlock(GrowUp);
    
    		ModLoader.addName(GrowUp, "Grow Up");
    	}
    
    	public void generateSurface(World world, Random random, int chunkX, int chunkZ)
    	{
    		for(int i = 0; i < 20; i++)
    		{
    			int x = chunkX + random.nextInt(16);
    			int y = random.nextInt(125);
    			int z = chunkZ + random.nextInt(16);
    			(new WorldGenTestVine()).generate(world, random, x, y, z);
    		}
    	}
    }


    Try making your WorldGen file a copy of WorldGenVines (that uses the new block) and make the new file generate in a specific biome that will make the vines easy to find (like the nether)

    If it still crashes after that then at least it'll eliminate the WorldGen file from the list of possible causes.
    Posted in: Modification Development
  • 0

    posted a message on Testing Mod Code Brings Up Strange Error
    Quote from irish_brigid

    There is no new error. Like I said, "I get a black screen with the cross-hairs and 'on hand' inventory visible." The game freezes. I get nothing. Nada. Zilch. Zero. No error. No nothing. So, there's still something wrong with my code. Probably involving the line that the original error referenced. I just can't tell what.


    Oh trust me, that was all I needed to know, that IS an error.
    My bet is you screwed up a for() loop and it's getting stuck looping infinitely, I've experienced this a good bit (Hell, actually, I think the first time I experienced this was when I was making WorldGen code for MY vines...ironically enough...).

    Can you kill the game with the keyboard via something like alt+f4? If not, do you know how to kill processes using the Windows command prompt?


    Also that world.setBlockWithNotify method has to return 4 integers, the 4th one being the ID of the block, so null will cause it to throw compile errors.
    Posted in: Modification Development
  • To post a comment, please .