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

I have a block that should only be able to be powered by redstone on one side. Is there a way to check for a redstone signal on a specific side?

 

Here is my block:

package XFactHD.rfutilities.common.blocks.block;

import XFactHD.rfutilities.common.blocks.tileEntity.TileEntityTransistor;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockTransistor extends BlockBaseRFU
{
    public BlockTransistor()
    {
        super("blockTransistor", Material.iron, 1, ItemBlock.class, "");
    }

    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
    {
        int l = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
            world.setBlockMetadataWithNotify(x, y, z, 5, 2);
        }

        if (l == 1)
        {
            world.setBlockMetadataWithNotify(x, y, z, 2, 2);
        }

        if (l == 2)
        {
            world.setBlockMetadataWithNotify(x, y, z, 3, 2);
        }

        if (l == 3)
        {
            world.setBlockMetadataWithNotify(x, y, z, 4, 2);
        }
    }

    @Override
    public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
    {
        TileEntity te = world.getTileEntity(x, y, z);
        ForgeDirection fd;
        switch (side)
        {
            case -1: fd = ForgeDirection.UP; break;
            case  0: fd = ForgeDirection.NORTH; break;
            case  1: fd = ForgeDirection.EAST; break;
            case  2: fd = ForgeDirection.SOUTH; break;
            case  3: fd = ForgeDirection.WEST; break;
            default: fd = ForgeDirection.UNKNOWN; break;
        }
        return te instanceof TileEntityTransistor && ((TileEntityTransistor)te).canConnectRedstone(fd);
    }

    @Override
    public TileEntity createNewTileEntity(World world, int meta)
    {
        return new TileEntityTransistor();
    }

    @Override
    public int getRenderType()
    {
        return -1;
    }

    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }
}

 

Here is my tile entity:

public class TileEntityTransistor extends TileEntityBaseRFU implements IEnergyHandler
{
    private boolean isOn = false;
    private boolean ocConnected = false;

    public boolean canConnectRedstone(ForgeDirection fd)
    {
        switch (worldObj.getBlockMetadata(xCoord, yCoord, zCoord))
        {
            case 2: return (fd == ForgeDirection.WEST);
            case 3: return (fd == ForgeDirection.NORTH);
            case 4: return (fd == ForgeDirection.EAST);
            case 5: return (fd == ForgeDirection.SOUTH);
            default: return false;
        }
    }

    public boolean getIsOn()
    {
        return isOn;
    }

    private void setIsOn(boolean on)
    {
        isOn = on;
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    }

    @Override
    public void updateEntity()
    {
        super.updateEntity();
        boolean on = isOn;
        boolean redstone = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);

        if (RFUtilities.OC_LOADED)
        {

        }
        if (!ocConnected && on != redstone)
        {
            setIsOn(redstone);
        }
    }

    //IEnergyHandler
    @Override
    public boolean canConnectEnergy(ForgeDirection fd)
    {
        switch (worldObj.getBlockMetadata(xCoord, yCoord, zCoord))
        {
            case 2: return (fd == ForgeDirection.NORTH || fd == ForgeDirection.SOUTH);
            case 3: return (fd == ForgeDirection.EAST || fd == ForgeDirection.WEST);
            case 4: return (fd == ForgeDirection.NORTH || fd == ForgeDirection.SOUTH);
            case 5: return (fd == ForgeDirection.EAST || fd == ForgeDirection.WEST);
            default: return false;
        }
    }

    @Override
    public int receiveEnergy(ForgeDirection fd, int amount, boolean simulate)
    {
        ForgeDirection opposite = fd.getOpposite();
        TileEntity te = worldObj.getTileEntity(xCoord + opposite.offsetX, yCoord, zCoord + opposite.offsetZ);
        if (canConnectEnergy(fd) && te instanceof IEnergyReceiver && (((IEnergyReceiver)te).receiveEnergy(fd, amount, true) > 0) && isOn)
        {
            return ((IEnergyReceiver)te).receiveEnergy(fd, amount, simulate);
        }
        else
        {
            return 0;
        }
    }

    @Override
    public int extractEnergy(ForgeDirection fd, int amount, boolean simulate)
    {
        return 0;
    }

    @Override
    public int getEnergyStored(ForgeDirection fd)
    {
        return 0;
    }

    @Override
    public int getMaxEnergyStored(ForgeDirection fd)
    {
        return 0;
    }

    @Override
    public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket)
    {
        isOn = nbt.getBoolean("isOn");
    }
}

 

Before someone asks why I am still using 1.7.10: I am unable to setup my workspace for 1.8.9 and I didn't get any answer to my question in the gradle subforum for 25 days and my main dependency (CoFH Core) is only available for 1.7.10.

Question:

Why does your canConnectRedstone method ask your TileEntity if it can, when all the TE does is ask for block metadata?  Why not just check the block metadata?

 

return side == metadata

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

The side is not equal to the metadata (sides are 0-3 and meta is 2-5 - pretty random, I know).

I did find this out too by reading on the TGG's blog but this is 1.8 and I am using 1.7.10 for the above mentioned reasons.

The side is not equal to the metadata (sides are 0-3 and meta is 2-5 - pretty random, I know).

 

Unless you have a reason not to make them match, you should refactor to make them match, it simplifies a lot.

 

And even if you don't there's still no reason to make a request to the TE: you can do your entire current check inside the block and only the block.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

The reason is the renderer (TESR). It uses those values to rotate the model.

And even if you don't there's still no reason to make a request to the TE: you can do your entire current check inside the block and only the block.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

I will probably change that.

Nontheless, does anybody have an idea how this can be achieved in 1.7.10?

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.