Jump to content

SOLVED[1.6.4]need my block to disappear! how?


demand12

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.