Jump to content

[1.6.4] Updating a block every tick


Flenix

Recommended Posts

Hey guys.

 

I'm working on a block, which works with a Tile Entity. However, the block will emit redstone and I need to control that on a tick-by-tick basis.

 

What's the best way for me to update my blocks' redstone emission state every tick? I can do it fine in the tile entity side, but it's actually passing that info to the block that I'm a bit confused by.

 

Thanks :)

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

In the block constructor, setTickRandomly to false. Then add an onUpdate method. Then set the tickRate to 1. Hope this helped.

 

Couldn't find an "onUpdate" method in block, but found a "updateTick" one - is that what you mean?

 

Right now, here's my code (Very simple for testing). When I place my block in the world, however, I don't get any of the "Tick!" println =/

 

package co.uk.silvania.cities.research.blocks.advanced;

import java.util.Random;

import co.uk.silvania.cities.research.FlenixCities_Research;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;

public class PlayerDetectorBlock extends Block {

public PlayerDetectorBlock(int id) {
	super(id, Material.iron);
	this.setCreativeTab(FlenixCities_Research.tabCitiesResearch);
	this.setHardness(2.0F);
	this.setTickRandomly(false);
}

@Override
public void updateTick(World world, int x, int y, int z, Random random) {
	System.out.println("Tick!");
}

@Override
public int tickRate(World world) {
	return 2;
}

}

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

updateTick only gets called if you use true as parameter in setTickRandomly.

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.

Link to comment
Share on other sites

A lot of redstone logic is handled via notification of neighbors rather than update ticks, as well as using the isProvidingStrongPower and isProvidingWeakPower methods. Those both have x/y/z coordinates, so you can check your tile entity's data to return whatever power level you want, all without using update ticks. This way you provide real-time signal strength but only when requested.

Link to comment
Share on other sites

A lot of redstone logic is handled via notification of neighbors rather than update ticks, as well as using the isProvidingStrongPower and isProvidingWeakPower methods. Those both have x/y/z coordinates, so you can check your tile entity's data to return whatever power level you want, all without using update ticks. This way you provide real-time signal strength but only when requested.

 

I don't suppose you could inform me of any examples (either vanilla or open-source mod?) Not quite sure I follow, I've always been a bit confused by redstone for some reason =/

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

A lot of redstone logic is handled via notification of neighbors rather than update ticks, as well as using the isProvidingStrongPower and isProvidingWeakPower methods. Those both have x/y/z coordinates, so you can check your tile entity's data to return whatever power level you want, all without using update ticks. This way you provide real-time signal strength but only when requested.

 

I don't suppose you could inform me of any examples (either vanilla or open-source mod?) Not quite sure I follow, I've always been a bit confused by redstone for some reason =/

Yeah, all the vanilla redstone blocks, from wire to torches to levers etc., all provide excellent examples. I recommend looking through those respective block classes.

 

As a more immediate example, these are the two methods I needed to add to one of my blocks to get it to provide power. Note that it's just a simple on/off based on whether the master sword is in the pedestal, but you could return any amount based on any variable stored in your tile entity:

@Override
public boolean canProvidePower() {
return true;
}

@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
EDIT: oops, that's 1.7: TileEntity te = world.getTileEntity(x, y, z);
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityPedestal) {
	ItemStack sword = ((TileEntityPedestal) te).getSword();
	if (sword != null && sword.getItem() == ZSSItems.swordMaster) {
		return 15;
	}
}
return 0;
}

Link to comment
Share on other sites

If you need a method that ticks all the time, use updateEntity() provided in the TileEntity. That ticks all the time and you get access to the world from the worldObj in the TileEntity. This method is commonly used to make blocks have a cool down or a progress bar. If you need access to the block just use worldObj.getBlockId(x, y, z) (worldObj.getBlock(x, y, z) in 1.7.2).

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.