Jump to content

Recommended Posts

Posted

Hey guys Im looking for solutions/suggestions to improve very old code that doesn't work how I would expect it to anymore.

 

First Code problem

 

This code is used when the tent block has been clicked it builds a tent then re-clicked it destroys all blocks and drops the tent block depending which block to drop.

When the tent drops the tent block at the moment it's running this code twice causing two blocks to drop but only one is pickable.

 

Was wondering if anyone had a solution to make this code only run once when activated or an alternative code.

 

Code

 

 

public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9)
{
int l = world.getBlockMetadata(i, j, k);

[color=red]The build/foldup methods here[/color]

/**Drop Block code*/
		if (l == 0)
		{
		EntityItem entityitem = new EntityItem(world, (double)i, (double)j, (double)k, new ItemStack(blockID, 1, 0));
		entityitem.delayBeforeCanPickup = 10;
		world.spawnEntityInWorld(entityitem);
		System.out.println("testTentBlock 1");
		}
		else if (l == 1)
		{
		EntityItem entityitem = new EntityItem(world, (double)i, (double)j, (double)k, new ItemStack(blockID, 1, 1));
		entityitem.delayBeforeCanPickup = 10;
		world.spawnEntityInWorld(entityitem);
		System.out.println("testTentBlock 2");
		}
		else if (l == 2)
		{
		EntityItem entityitem = new EntityItem(world, (double)i, (double)j, (double)k, new ItemStack(blockID, 1, 2));
		entityitem.delayBeforeCanPickup = 10;
		world.spawnEntityInWorld(entityitem);
		System.out.println("testTentBlock 3");
		}
     }

 

 

 

Console message to show the code is running twice

2012-10-19 15:05:00 [iNFO] [sTDOUT] testTentBlock 1

2012-10-19 15:05:00 [iNFO] [sTDOUT] testTentBlock 1

2012-10-19 15:05:14 [iNFO] [sTDOUT] testTentBlock 2

2012-10-19 15:05:14 [iNFO] [sTDOUT] testTentBlock 2

2012-10-19 15:05:33 [iNFO] [sTDOUT] testTentBlock 3

2012-10-19 15:05:34 [iNFO] [sTDOUT] testTentBlock 3

 

 

Second Code problem

 

This code is used in my tileEntityAnvil, in 1.2.5 I had my tileEntity abstract "public abstract class TileEntityAnvil extends TileEntity implements IInventory, ISidedInventory" but in 1.3.2 having my tileEntity abstract caused a duplication glitch when placing items in the slots.

Changing the tileEntity to "public class TileEntityAnvil extends TileEntity implements IInventory, ISidedInventory" fixed the duplication error but every time the anvil repairs an item it destroys the iron hammer instead of causing damage to the hammer.

 

Wondering if anyone had a solution or suggestion on a way to cause the anvil hammer to take damage after every repair instead of being destroyed.

 

 

Code

 

 

public int getItemBurnTime(ItemStack itemStack)
    {
        if (itemStack == null)
        {
            return 0;
        }
        else
        {
            int var1 = itemStack.getItem().shiftedIndex;
            if(var1 == CampCraft.HammerIron.shiftedIndex)
            {
            		AnvilItemStacks[1].damageItem(15, minecraft.thePlayer); /**Damages the iron hammer after the repair*/
            }
            	return 200;	/**Number of ticks to burn for*/
        }
    }

 

 

Posted

The first one: I'm pretty sure that's runned twice, because it is executed on the client and server thread as well. So at the beginning do something like:

if(world.isRemote) { // check if it's the client thread)
    return true;
}

 

The second one, I dunno, but you could do something like this:

public int getItemBurnTime(ItemStack itemStack)
    {
        if (itemStack == null)
        {
            return 0;
        }
        else
        {
            int var1 = itemStack.getItem().shiftedIndex;
            if(var1 == CampCraft.HammerIron.shiftedIndex)
            {
            		/* either use this: */ AnvilItemStacks[1].setItemDamage(AnvilItemStacks[1].getItemDamage() + 15); /**Damages the iron hammer after the repair*/
		/*        or this        */ itemStack.setItemDamage(itemStack.getItemDamage() + 15);
            }
            	return 200;	/**Number of ticks to burn for*/
        }
    }

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.