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

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

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

  • Author

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

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.

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.

  • Author

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

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;
}

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

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.