Jump to content

[Unsolved] After receiving redstone signal, wait for a couple second [1.6.2]


larsgerrits

Recommended Posts

As I mentioned in the title, I want my block to wait a couple seconds after receivong a redstone signal, and than continue with it's code. And howwould I go about doing that in a TileEntitySpecialRenderer class?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Well what do you currently have?

If you have everything except the wait in place then this is all you need to know:

 

Make the TileEntity keep track of if it's powered or not and a boolean to keep track of it's been powered for more than 3 seconds.

 

Then when the block gets powered by redstone, make it's TE's variable change to true.

Have a counter count the ticks from it got powered and when it reaches the value you want (i.e. 3 secs = 60 ticks) then change the other boolean to true. If the redstone power gets removed then set both to false again and reset the timer.

 

Inn the TileEntitySpecialRenderer check the boolean value, simple as that I'd guess?

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I already have a tile entity with both booleans, but how would I go about making a timer? Just a simple for loop or something else?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

int TICKS_NEEDED = 60;

int currentTick = 0;

 

at every update tick do:

 

currentTick++;

if currentTick >= TICKS_NEEDED

  thatBooleanValue = true;

 

It doesn't work. If I power it indirectly (that's what it has to if it's done) it doesn't change it state/texture. Here's my code:

 

the onNeighbourBlockChange method:

 

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockId)
    {
	TileEntityStoplight tileEntity = (TileEntityStoplight)world.getBlockTileEntity(x, y, z);

        if (!world.isRemote)
        {
        	if(tileEntity != null)
        	{
        		if(world.isBlockIndirectlyGettingPowered(x, y, z))
        		{
        			tileEntity.isPowered = true;
        		}
        		else
        		{
        			tileEntity.isPowered = false;
        			tileEntity.isPoweredFor3Seconds = false;
        		}
        	}
        }
    }

 

 

the TileEntity class:

 

package larsg310.mods.bd.tileentity;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityStoplight extends TileEntity
{
public int TICKS_NEEDED = 60;
public int currentTick = 0;

public boolean isPowered = false;
public boolean isPoweredFor3Seconds = false;

public TileEntityStoplight()
{
	if(isPowered)
	{
		currentTick++;
		if(currentTick == TICKS_NEEDED)
		{
			isPoweredFor3Seconds = true;
		}
	}
                else
        {
		currentTick = 0;
	}
}
public void writeToNBT(NBTTagCompound nbt)
{
	nbt.setBoolean("isPowered", isPowered);
}
public void readFromNBT(NBTTagCompound nbt)
{
	this.isPowered = nbt.getBoolean("isPowered");
}
}

 

 

and the TileEntitySpecialRenderer class:

 

package larsg310.mods.bd.render.tileentity;

import larsg310.mods.bd.lib.Textures;
import larsg310.mods.bd.model.ModelStoplight;
import larsg310.mods.bd.tileentity.TileEntityStoplight;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class TileEntityStoplightRenderer extends TileEntitySpecialRenderer
{
private ModelStoplight modelStoplight = new ModelStoplight();
private Minecraft mc;
public ResourceLocation stoplightRedResourceLocation = new ResourceLocation(Textures.MODEL_STOPLIGHT_RED);
public ResourceLocation stoplightYellowResourceLocation = new ResourceLocation(Textures.MODEL_STOPLIGHT_YELLOW);
public ResourceLocation stoplightGreenResourceLocation = new ResourceLocation(Textures.MODEL_STOPLIGHT_GREEN);

public TileEntityStoplightRenderer()
{
	this.mc = Minecraft.getMinecraft();
}
@Override
    public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick)
{
        if (tileEntity instanceof TileEntityStoplight)
        {
            TileEntityStoplight TileEntityStoplight = (TileEntityStoplight) tileEntity;
            ForgeDirection direction = null;
            if (TileEntityStoplight.getWorldObj() != null)
            {
                direction = ForgeDirection.getOrientation(TileEntityStoplight.getBlockMetadata());
            }
            if(((TileEntityStoplight) tileEntity).isPowered)
            {
            	if(((TileEntityStoplight)tileEntity).isPoweredFor3Seconds)
            	{
            		this.mc.renderEngine.func_110577_a(stoplightGreenResourceLocation);
            	}
            	this.mc.renderEngine.func_110577_a(stoplightYellowResourceLocation);
            }
            else
            {
            	this.mc.renderEngine.func_110577_a(stoplightRedResourceLocation);
            }
   		 	GL11.glPushMatrix();
            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
            GL11.glScalef(1.0F, -1.0F, -1.0F);
            GL11.glTranslatef(0.5F, 0.5F, 0.5F);
            int rotation = 180;
            switch(tileEntity.getBlockMetadata() % 4)
            {
                case 0:
                    rotation = 180;
                    break;
                case 3:
                    rotation = 90;
                    break;
                case 2:
                    rotation = 0;
                    break;
                case 1:
                    rotation = 270;
                    break;
            }
            GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
            GL11.glTranslatef(0F, -1F, 0F);
            modelStoplight.renderAll(0.0625F);
            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
            GL11.glPopMatrix();
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        }
    }
}

 

 

this is how I apply the redstone signal:

 

519da1.png

 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

In your renderer class:

            if(((TileEntityStoplight) tileEntity).isPowered)
            {
            	if(((TileEntityStoplight)tileEntity).isPoweredFor3Seconds)
            	{
            		this.mc.renderEngine.func_110577_a(stoplightGreenResourceLocation);
            	}
            	this.mc.renderEngine.func_110577_a(stoplightYellowResourceLocation);
            }
            else
            {
            	this.mc.renderEngine.func_110577_a(stoplightRedResourceLocation);
            }

Your missing an else statement before setting lightyellow texture.

Link to comment
Share on other sites

I've added that, but it doesn't change anything. I added some checklines and it doesn't seem to count the ticks. Anyone why?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.