Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm looking for a script that when you mine a block it wont be (destoryed or it will get destroyed and recreate itself) and still drop materials. Anyone who got a clue? :)

I don't usually give code but anyway when I do I add comments.. It's your loss if you copy and paste without trying to understand so please don't if you're serious about modding.

	@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
{
	//Using random ints in the drops may cause a crash. Set amounts don't.
	//Loops through all drops.
	for(int i =  0; i < block.getDrops(world, x, y, z, meta, 0).size(); i++){
		//Breaks the loop if i == size.
		if(i == block.getDrops(world, x, y, z, meta, 0).size()){
			break;
		}
		//Spawns the drops into the world.
		world.spawnEntityInWorld(new EntityItem(world, x, y, z, block.getDrops(world, x, y, z, meta, 0).get(i)));
	}
	//Sets the block to the current block.
	world.setBlock(x, y, z, this);
}

If I helped please press the Thank You button.

I don't usually give code but anyway when I do I add comments.. It's your loss if you copy and paste without trying to understand so please don't if you're serious about modding.

	@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
{
	//Using random ints in the drops may cause a crash. Set amounts don't.
	//Loops through all drops.
	for(int i =  0; i < block.getDrops(world, x, y, z, meta, 0).size(); i++){
		//Breaks the loop if i == size.
		if(i == block.getDrops(world, x, y, z, meta, 0).size()){
			break;
		}
		//Spawns the drops into the world.
		world.spawnEntityInWorld(new EntityItem(world, x, y, z, block.getDrops(world, x, y, z, meta, 0).get(i)));
	}
	//Sets the block to the current block.
	world.setBlock(x, y, z, this);
}

So inefficient. You can 1) store the List<ItemStack> in the method. That way you don't need those repetetive calls to block.getDrops(*), and 2) you can iterate over a list way easier. You don't even need the

if (1 == size)

statement.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

So inefficient. You can 1) store the List<ItemStack> in the method. That way you don't need those repetetive calls to block.getDrops(*), and 2) you can iterate over a list way easier. You don't even need the

if (1 == size)

statement.

 

You're totally right :) I really shouldn't code while distracted. My new code probably isn't the best but it's better anyway, Here's the new code:

	@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
{
	super.breakBlock(world, x, y, z, block, meta);

	//List of drops
	List<ItemStack> drops = block.getDrops(world, x, y, z, meta, 0);

	//Loops through all drops.
	for(ItemStack itemstack : drops){
		//Spawns the drops into the world.
		world.spawnEntityInWorld(new EntityItem(world, x, y, z, itemstack));
	}
	//Sets the block to the current block.
	world.setBlock(x, y, z, this);
}

If I helped please press the Thank You button.

  • Author

Ah thanks for the help, I was into using onBlockDestroyedByPlayer and were mixing with this stuff but without any success.

If you have any experience with worker threads and queues, you could actually schedule a regrowth of each such destroyed block after a certain time has elapsed.

  • Author

Sadly I am pretty new and still learning so don't have much experience yet, and mostly I like to run through the referenced libraries for help to make some scripts ^^

  • Author

I am trying to add a creative mode into the script so you can destroy it without respawning in creative mode but cannot get it to work. :(

 

public void breakBlock(World world, int x, int y, int z, Block block, EntityPlayer player, int meta )

{

 

//Using random ints in the drops may cause a crash. Set amounts don't.

//Loops through all drops.

for(int i =  0; i < block.getDrops(world, x, y, z, meta, 0).size(); i++){

//Breaks the loop if i == size.

if(i == block.getDrops(world, x, y, z, meta, 0).size()){

break;

}

//Spawns the drops into the world.

world.spawnEntityInWorld(new EntityItem(world, x, y, z, block.getDrops(world, x, y, z, meta, 0).get(i)));

 

}

        if (!player.capabilities.isCreativeMode && (meta & 8) != 0 && world.getBlock(x, y - 1, z) == this)

        {

        world.setBlock(x, y, z, this);

        }

 

this is what i have ...

  • Author

still have no clue how to fix this one, tried plenty of different things.. :(

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.