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 everyone. i have a little problem with my code that i was tryin to slove for week and couldnt find anything helpful.

I'm creating mod were one block  after its placed checks types of surroind blocks and replace them if they are water. Actualy loop works from time to time. It depends where it is placed.  sometimes loop works fine placed on x,y,z cord but if i move block like  x+1 its stops working. I'm replacing existing blocks with customAirBlock. I've checked replacing loop with stone blocks and it works in 100%. But  when i put in if() else and i'm tryin to use my custom blocks things go wrong.

 

 

 

 

 

public class Sponge extends Block {

   

 

protected Sponge(Material material) {

super(material);

 

// TODO Auto-generated constructor stub

}

 

private Block BlockCustomAir=new BlockCustomAir(Material.air);

public void onBlockAdded(World world, int i, int j, int k)

{

for (int x=-1; x<2; x++)

{

for (int y=-1; y<2; y++)

{

for (int z=-1; z<2; z++)

{  int flag1=Block.getIdFromBlock(world.getBlock(i+y, j+x, k+z));

  int flag2=Block.getIdFromBlock(world.getBlock(i+x, j+y, k+z));

 

if( flag1==8 || flag2==9  )

{ world.setBlock(i+y, j+x, k+z, BlockCustomAir );

//world.setBlock(i+y, j+x, k+z, Block.getBlockById(1));

    //world.markBlockForUpdate(i+x, j+y, k+z);

}

//world.setBlock(i+y, j+x, k+z, Block.getBlockById(0));

 

}

 

}

}

}

 

}

 

Hi

 

It looks like you're converting code from 1.6.4 or before; don't use IDs any more, compare them to the blocks instead

 

eg

Block block = world.getBlock(x + i, y + j, z + k);

if (block == Blocks.flowing_water) //etc

 

BTW it looks like you're accidentally swapping x and y sometimes

int flag1=Block.getIdFromBlock(world.getBlock(i+y, j+x, k+z));

 

-TGG

  • Author

Thank you very much for your help. It worked perfectly but now i have other issue. My Sponge supose to switch water with custom air. But it do it after placing sponge in world. But you can see effect after you relaunch world. When i'm switching custom air to any vanilla block water is replaced instantly after you place the block. But when  i am trying to replace water with my custom air block i need to relaunch world to see the effect. I guess i'm making wrong reference to my custom air block and game is able to create it when the world is building.

 

 

 

 

public void onBlockAdded(World world, int i, int j, int k)

 

{

for (int x=-1; x<2; x++)

{

for (int y=-1; y<2; y++)

{

for (int z=-1; z<2; z++)

{  Block block=world.getBlock(i+y, j+x, k+z);

CustomAirMaterial material=new CustomAirMaterial();

Block BlockCustomAir=new BlockCustomAir(material);

 

if( block==Blocks.water || block==Blocks.flowing_water  )

{ world.setBlock(i+y, j+x, k+z,BlockCustomAir);

 

 

}

 

 

 

 

 

 

}

 

 

}

 

 

}

 

 

 

 

}

 

 

 

}

 

[\spoiler]

 

Also i tried to use.  The newly created custom air blocks were acting more likely vanilla air blocks not custom air blocks.

 

public static final Block BlockCustomAir = (Block)Block.blockRegistry.getObject("BlockCustomAir");[\spoiler]

 

  • Author

I added @SideOnly before calling method on placedOn. Its wierd because when i'm trying to replace water blocks with stone it works fine but when i change it to mine custom blocks it works but i need to relaunch game. I have no clue what is going wrong here. Is there any other way to refer to mine custom block?

 

  • Author

world.markBlockForUpdate()  solved my problem. I dont know why but i can replace water with stone without problem but when i  want to use my own blocks i need to mark them for  udpate.

diesieben07

I know its looks ugly. I'lll try to clear code after i finish testing it. And also i dont know how it was in 1.6. I will try to find some tutorials later and check it out. Thanks for advice.

 

  • Author

Yea i realized that when i tried to fill up space with water after the sponge is destroyed.  Right now i'm calling objects from core mod class

 

CoreTestMod.BlockCustomAir

 

it fixed few glitches for me. thanks for advice !:)

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.