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

Hello,

 

I'm trying to make a mod where a block (that I named "Terra Stone") speeds up the growth of plants around it, so how would I go about doing that? I'm new to Java and need help with this, so I would appreciate all the help I can get. So is there a way to do this? I would assume you need to make a TileEntity for the block, but I don't understand how, and probably screwed it up, big time.

 

Can someone help me? I'm using MCP and ModLoader on Minecraft 1.2.5. I'll post my codes below:

 

package net.minecraft.src;
import java.util.Random;

public class mod_TerraBlock extends BaseMod
{
public static final Block terraBlock = new BlockTerraStone(127,0).setHardness(50F).setResistance(2000.0F).setBlockName("mvas").setLightValue(0.80F);

public mod_TerraBlock()
{
	ModLoader.registerBlock(terraBlock);
	terraBlock.blockIndexInTexture = ModLoader.addOverride("/terrain.png","/terra.png");
	ModLoader.addName(terraBlock, "Terra Stone");

	ModLoader.addRecipe(new ItemStack(terraBlock, 1), new Object []{
		"*%*","*#*","***", Character.valueOf('%'), Item.bucketWater, Character.valueOf('#'), Block.obsidian, Character.valueOf('*'), Block.dirt,
	});
}

public String getVersion()
{
	return "3.14159265";
}
public void load()
{
}
}

 

package net.minecraft.src;
import java.util.Random;

public class BlockTerraStone extends Block
{
public BlockTerraStone(int i, int j)
{
	super(i,j,Material.rock);
}

public int idDropped(int i, Random random)
{
	return mod_TerraBlock.terraBlock.blockID;
}

public int quantityDropped(Random random)
{
	return 1;
}
}

 

and my murdered attempt at TileEntity

package net.minecraft.src;

import java.util.Random;

public class TileEntityTerraStone extends TileEntity
{
public mod_Block.terraStone;

public void checkForAdjacentCrops()

public boolean 
{
	worldObj.getBlockId(xCoord, yCoord, zCoord)

 

I obviously really need help on the last one, so thank you in advanced!

Since growth in MC is handled via a random tick, what you could do is in your tileentity's update loop use world.scheduleBlockUpdate on each crop block within range. OR you could manually increase the metadata for each crop block in range which should have the same effect. for wheat at least. The first solution is better as you are letting the crop do the update itself.

  • Author

Since growth in MC is handled via a random tick, what you could do is in your tileentity's update loop use world.scheduleBlockUpdate on each crop block within range. OR you could manually increase the metadata for each crop block in range which should have the same effect. for wheat at least. The first solution is better as you are letting the crop do the update itself.

 

Okay thank you, I think I can figure that out, but do you have any idea how it would read that crops are nearby? That's where I'm really stuck

try doing Block.blockList[world.getBlockID()) instanceof BlockCrop that should point you the right way

  • Author

try doing Block.blockList[world.getBlockID()) instanceof BlockCrop that should point you the right way

 

package net.minecraft.src;

import java.util.Random;

public class TileEntityTerraStone extends TileEntity
{
public mod_Block.terraStone;

public void checkForAdjacentCrops()
{
	Block.blockList[world.getBlockID()]
}

public boolean 
{
	worldObj.getBlockID(xCoord, yCoord, zCoord)
}

 

Like this?

You'll need to fix the method by doing

//This method should be run on each block around the stone that increases the growth
public void updateAdjacentCrop(World world, int x, int y, int z)
{
	if(Block.blockList[world.getBlockID(x,y,z)] instanceof BlockCrop)
{
     //schedule the update here. 
}
}

  • Author

package net.minecraft.src;

import java.util.Random;

public class TileEntityTerraStone extends TileEntity
{	
public void updateAdjacentCrop(World world, int x, int y, int z)
{
	if(Block.blockList[world.getBlockID(x,y,z)] instanceof BlockCrop)
	{
		if(random.nextInt(1) == 0)
	}
}
}

 

Did I do something extremely wrong?

  • Author

Ive run into errors

 

== ERRORS FOUND ==
src\minecraft\net\minecraft\src\TileEntityTerraStone.java:12: error: cannot find
symbol
if(Block.blockList[worldObj.getBlockId(xCoord ,yCoord ,zCoord)]
instanceof BlockCrops)
^
symbol: variable blockList
location: class Block
src\minecraft\net\minecraft\src\TileEntityTerraStone.java:14: error: non-static
method nextInt(int) cannot be referenced from a static context
if(Random.nextInt(1) == 0);
^
2 errors
==================

 

How can I resolve these?

 

here's where I've gotten in my code:

package net.minecraft.src;
import java.util.Random;
public class TileEntityTerraStone extends TileEntity
{
     public Block terraBlock;

     public void updateAdjacentCrop(World world, int x, int y, int z)
   {
       if(Block.blockList[worldObj.getBlockId(xCoord ,yCoord ,zCoord)] instanceof BlockCrops)
      {
         if(Random.nextInt(1) == 0);
      }
   }
}

use instead

if(Random.nextInt(1) == 0);

this:

if(world.rand.nextInt(1) == 0);

 

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

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.