Jump to content

Recommended Posts

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

Posted

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

Posted

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.

Posted

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.

Posted

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?

Posted

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

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