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 a noob at coding, just to let u know.

 

i want to make a block. when placed in the world, after 6 sec, it disappears. i tried to come up with something my self. did not go well.

 

package Talimagics.blocks;

 

import Talimagics.mod.talibase;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.world.World;

 

public class wallblock extends Block {

 

public wallblock(int par1, Material par2Material) {

super(par1, par2Material);

 

this.setUnlocalizedName("wallblock");

this.setLightOpacity(1);

this.setLightValue(0.6f);

this.setBlockUnbreakable();

}

 

public boolean despawn(World world,int x,int y,int z){

 

if(world.setBlock(x, y, z, talibase.wallblock.blockID)== true){

 

try {

Thread.sleep(120);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

world.destroyBlock(x, y, z, false);

return true;

}else

return false;

 

}

 

@Override

public void registerIcons(IconRegister reg){

this.blockIcon = reg.registerIcon("talimagics:magicwall_block");

}

 

}

 

any ideas how to get this working? thanks in advance :)

You never ever put the client or server thread to sleep in a realtime game!!! You will cause major problems. Use tick events or a timer thread or almost anything else.

  • Author

Use world.scheduleBlockUpdate. It will trigger a call to the updateTick method of your block after the number of ticks you specify.

 

thanks for the tip. but i dont know what to do with it. could you explain what i need to do with it

Spoiler tags...

 

 

...Please use them for code. [ spoiler ][/ spoiler ] (without spaces)

 

 

We all stuff up sometimes... But I seem to be at the bottom of that pot.

  • Author

let me be more specific.

 

like i stated in my first post, i'm a noob.

 

1. there is 5 parameters in world.scheduleBlockUpdate(par1, par2, par3, par4, par5); i can guess its something with ticks. but what

 

2. do i just call world.scheduleBlockUpdate(); and then world.destroyBlock() or do i make a method for that?

 

i may have more questions but dont have any atm.

  • Author

ok here is what i have.

 

package Talimagics.blocks;

import Talimagics.mod.talibase;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.world.World;

public class wallblock extends Block {

public wallblock(int par1, Material par2Material) {
	super(par1, par2Material);

	this.setUnlocalizedName("wallblock");
	this.setLightOpacity(1);
	this.setLightValue(0.6f);
	this.setBlockUnbreakable();
}

public void despawn(World world,int x,int y,int z){
	world.scheduleBlockUpdate(x, y, z, talibase.wallblock.blockID, 120);
	this.updateTick(world, x, y, z, null);
}

@Override
public void registerIcons(IconRegister reg){
	this.blockIcon = reg.registerIcon("talimagics:magicwall_block");
}

}

 

i know this is wrong. i dont know updateTick() at all or how to use it, same with scheduleBlockUpdate but i guess that is right. is it?

  • Author

i figured it out. after 2 hours of emptying the internet for information

 

@Override
public void onBlockAdded(World world,int x,int y,int z){
	world.scheduleBlockUpdate(x, y, z, talibase.wallblock.blockID, 120);
}

@Override
public void updateTick(World world, int x, int y, int z, Random rand){
	world.destroyBlock(x, y, z, false);
}

 

that was all i needed. thanks for the help :)

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.