Jump to content

[solved]Metadata not saving for directional block


vdvman1

Recommended Posts

I am trying to update redstone gate to 1.3.2 (unofficially, sorry) and i have managed to get the gate to render with the gui working and everything, but whenever i place the gate and then relog the metadata resets back to 0! Plus because the metadata isn't saving the gate does not even work, not even before reloging! Can someone please help.

Here is my code:

RedstoneGate.java

 

package redstoneGate.common;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "Darquan_RedstoneGate", name = "Redstone Gate", version = "v2 for 1.3.2")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class RedstoneGate {

public static int renderID;
    public static Configuration config;
    public static int blockID;
    public static int oldBlockID;
    public static int colourOn;
    public static int colourOff;
    public static int colourIO;
    public static Block blockRedstoneGate;
    public static Block oldGateBlock = null;
    
    @SidedProxy(clientSide = "redstoneGate.client.RedstoneGateClientProxy", serverSide = "redstoneGate.common.RedstoneGateCommonProxy")
    public static RedstoneGateCommonProxy proxy;
    
    @PreInit
    public void preInit(FMLPreInitializationEvent event) {
    	config = new Configuration(event.getSuggestedConfigurationFile());
    	config.load();
    	blockID = config.getOrCreateBlockIdProperty("blockID", 137).getInt();
    	oldBlockID = config.getOrCreateBlockIdProperty("oldBlockID", 137).getInt();
    	colourOn = config.getOrCreateIntProperty("colourOn", Configuration.CATEGORY_GENERAL, 6000).getInt();
    	colourOff = config.getOrCreateIntProperty("colourOff", Configuration.CATEGORY_GENERAL, 600000).getInt();
    	colourIO = config.getOrCreateIntProperty("colourInputOutput", Configuration.CATEGORY_GENERAL, 606000).getInt();
    	config.save();
    	proxy.registerRenderThings();
    }

@Init
public void load(FMLInitializationEvent event)
{
	blockRedstoneGate = (new BlockRedstoneGate(blockID)).setHardness(1.5F).setLightValue(0.0F).setBlockName("RedstoneGate");
	GameRegistry.registerTileEntity(redstoneGate.common.TileEntityRedstoneGate.class, "RedstoneGate");

	LanguageRegistry.addName(blockRedstoneGate, "Redstone Gate");
        GameRegistry.registerBlock(blockRedstoneGate);
        GameRegistry.addRecipe(new ItemStack(blockRedstoneGate, 1), new Object[]
                {
                    "rrr", "rrr", "rrr", 'r', Item.redstone
                });
        GameRegistry.addRecipe(new ItemStack(Item.redstone, 9), new Object[]
                {
                    "r", 'r', blockRedstoneGate
                });

        if (oldBlockID != blockID)
        {
            oldGateBlock = (new BlockOldRedstoneGate(oldBlockID)).setBlockName("OldRedstoneGate");
            GameRegistry.registerBlock(oldGateBlock);
        }
}

}

 

 

BlockRedstoneGate.java

 

package redstoneGate.common;

import java.util.Random;

import net.minecraft.src.BlockContainer;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.Material;
import net.minecraft.src.MathHelper;
import net.minecraft.src.ModLoader;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;

public class BlockRedstoneGate extends BlockContainer {

public Boolean renderAsItem;

public BlockRedstoneGate(int id) {
	super(id, Material.rock);
	setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
	renderAsItem = false;
}

/**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    public boolean renderAsNormalBlock()
    {
        return !renderAsItem;
    }
    
    /**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return renderAsItem ? 0 : RedstoneGate.renderID;
    }
    
    /**
     * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
     * coordinates.  Args: blockAccess, x, y, z, side
     */
    public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
    {
        return renderAsItem ? true : l != 1;
    }
    
    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public int getBlockTextureFromSideAndMetadata(int i, int j)
    {
        if (i == 0)
        {
            return 6;
        }

        if (i == 1)
        {
            return renderAsItem ? 131 : '\223';
        }
        else
        {
            return 5;
        }
    }
    
    /**
     * Returns the block texture based on the side being looked at.  Args: side
     */
    public int getBlockTextureFromSide(int i)
    {
        return getBlockTextureFromSideAndMetadata(i, 0);
    }
    
    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World world, int i, int j, int k, Random random)
    {
        TileEntityRedstoneGate tileentityredstonegate = (TileEntityRedstoneGate)world.getBlockTileEntity(i, j, k);
        byte byte0 = tileentityredstonegate.outputVector;
        tileentityredstonegate.RecomputeOutput(world, i, j, k);

        if (tileentityredstonegate.outputVector == byte0)
        {
            tileentityredstonegate.canUpdate = true;
        }
        else
        {
            world.notifyBlocksOfNeighborChange(i, j, k, blockID);
            world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
            world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
            world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
            world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
            world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
            world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
            int l = world.getBlockMetadata(i, j, k);
            world.scheduleBlockUpdate(i, j, k, blockID, l == 0 ? 2 : l * 2);
        }
    }
    
    /**
     * Is this block indirectly powering the block on the specified side
     */
    public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l)
    {
        return isPoweringTo(world, i, j, k, l);
    }

    /**
     * Is this block powering the block on the specified side
     */
    public boolean isPoweringTo(IBlockAccess iblockaccess, int i, int j, int k, int l)
    {
        TileEntityRedstoneGate tileentityredstonegate = (TileEntityRedstoneGate)iblockaccess.getBlockTileEntity(i, j, k);
        return (tileentityredstonegate.outputVector & 1 << l) != 0;
    }
    
    /**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor blockID
     */
    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        TileEntityRedstoneGate tileentityredstonegate = (TileEntityRedstoneGate)world.getBlockTileEntity(i, j, k);

        if (!canBlockStay(world, i, j, k))
        {
            dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0);
            world.setBlockWithNotify(i, j, k, 0);
            return;
        }

        if (tileentityredstonegate.canUpdate)
        {
            tileentityredstonegate.canUpdate = false;
            int i1 = world.getBlockMetadata(i, j, k);
            world.scheduleBlockUpdate(i, j, k, blockID, i1 * 2);
        }
    }
    
    /**
     * Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
     * block.
     */
    public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9)
    {
        TileEntityRedstoneGate tileentityredstonegate = (TileEntityRedstoneGate)world.getBlockTileEntity(i, j, k);
        ModLoader.openGUI(entityplayer, new GuiRedstoneGate(entityplayer, tileentityredstonegate));
        return true;
    }
    
    /**
     * Can this block provide power. Only wire currently seems to have this change based on its state.
     */
    public boolean canProvidePower()
    {
        return true;
    }
    
    /**
     * Called when the block is placed in the world.
     */
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
    {
        super.onBlockPlacedBy(world, i, j, k, entityliving);
        int l = ((MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3) + 2) % 4;
        ((TileEntityRedstoneGate)world.getBlockTileEntity(i, j, k)).inputMask |= l << 6;
    }
    
    /**
     * Called whenever the block is added into the world. Args: world, x, y, z
     */
    public void onBlockAdded(World world, int i, int j, int k)
    {
        super.onBlockAdded(world, i, j, k);
        world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
        world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
    }
    
    /**
     * Called upon the block being destroyed by an explosion
     */
    public void onBlockDestroyedByExplosion(World world, int i, int j, int k) {
    	super.onBlockDestroyedByExplosion(world, i, j, k);
        world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
        world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
    }
    
    /**
     * Called right before the block is destroyed by a player.  Args: world, x, y, z, metaData
     */
    public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l) {
    	this.onBlockDestroyedByExplosion(world, i, j, k);
    }
    
    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
        return false;
    }

@Override
public TileEntity createNewTileEntity(World var1) {
	return new TileEntityRedstoneGate();
}

}

 

 

TileEntityRedstoneGate.java

 

package redstoneGate.common;

import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;

public class TileEntityRedstoneGate extends TileEntity implements IInventory {

public static final int MAX_DELAY = 16;
    public static final int DELAY_DECR = 15;
    public static final int OP_AND = 0;
    public static final int OP_OR = 1;
    public static final int OP_XOR = 2;
    public static final int OP_NEG = 3;
    public static final int OP_ON = 4;
    public static final int OP_OFF = 5;
    public static final int wireID = Block.redstoneWire.blockID;
    public static final int HAMM_WEIGHT_3[] =
    {
        0, 1, 1, 2, 1, 2, 2, 3
    };
    public static final int relative_to_absolute_direction[][] =
    {
        {
            4, 5, 2, 3, 1, 0
        }, {
            2, 3, 5, 4, 1, 0
        }, {
            5, 4, 3, 2, 1, 0
        }, {
            3, 2, 4, 5, 1, 0
        }
    };
    public byte inputMask;
    public byte outputMask;
    public int truthTable;
    public byte outputVector;
    public boolean canUpdate;
    
    public TileEntityRedstoneGate()
    {
        inputMask = 0;
        outputMask = 63;
        truthTable = 0;
        outputVector = 0;
        canUpdate = true;
    }
    
    private boolean isInvalidConfig(int i, int j)
    {
        int k = hammingWeight(j & 0x3f);
        int l = (1 << hammingWeight(i & 0x3f)) * k;
        return k == 0 || 32 < l;
    }

    public String getConfigString()
    {
        int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
        return String.format("%02x%02x-%08x-%01x", new Object[]
                {
                    Integer.valueOf(inputMask & 0x3f), Integer.valueOf(outputMask & 0x3f), Integer.valueOf(truthTable), Integer.valueOf(i)
                });
    }
    
    public boolean setConfigString(String s)
    {
        try
        {
            int i = Integer.parseInt(s.substring(0, 2), 16) & 0x3f | inputMask & 0xc0;
            int j = Integer.parseInt(s.substring(2, 4), 16) & 0x3f | outputMask & 0xc0;
            long l = Long.parseLong(s.substring(5, 13), 16);
            int k = Integer.parseInt(s.substring(14, 15), 16);

            if (isInvalidConfig(i, j))
            {
                return false;
            }
            else
            {
                inputMask = (byte)i;
                outputMask = (byte)j;
                truthTable = (int)l;
                worldObj.setBlockMetadata(xCoord, yCoord, zCoord, k);
                return true;
            }
        }
        catch (NumberFormatException numberformatexception)
        {
            System.out.println(numberformatexception.getMessage());
        }

        return false;
    }
    
    private int hammingWeight(int i)
    {
        int j = 0;

        for (; 0 < i; i >>= 3)
        {
            j += HAMM_WEIGHT_3[i & 7];
        }

        return j;
    }
    
    private long segmentModifier(int i, int j, int k, int l)
    {
        long l1 = 0L;

        switch (l)
        {
            case 3:
            default:
                break;

            case 0:
                for (int i1 = k - 1; 0 <= i1; i1--)
                {
                    l1 = l1 << 1 | (long)((i & (i1 ^ j)) == i ? 1 : 0);
                }

                break;

            case 1:
                for (int j1 = k - 1; 0 <= j1; j1--)
                {
                    l1 = l1 << 1 | (long)((i & (j1 ^ j)) != 0 ? 1 : 0);
                }

                break;

            case 2:
                for (int k1 = k - 1; 0 <= k1; k1--)
                {
                    l1 = l1 << 1 | (long)(hammingWeight(i & (k1 ^ j)) % 2);
                }

                break;

            case 4:
                l1 = (1L << k) - 1L;
                break;
        }

        return l1;
    }
    
    public void performQuickConfig(byte byte0, byte byte1, int i, boolean flag)
    {
        byte byte2 = 0;
        byte byte3 = 0;
        byte byte4 = 1;
        byte byte5 = 0;
        byte byte6 = 0;

        for (int j = 32; 0 < j; j >>= 1)
        {
            byte byte7 = (byte)((byte0 & j) != 0 ? 1 : 0);
            byte byte8 = (byte)((byte1 & j) != 0 ? 1 : 0);

            if ((inputMask & j) != 0)
            {
                byte2 = (byte)(byte2 << 1 | byte7);
                byte5 = (byte)(byte5 << 1 | byte8);
                byte4 <<= 1;
            }

            if ((outputMask & j) != 0)
            {
                byte3 = (byte)(byte3 << 1 | byte7);
                byte6 = (byte)(byte6 << 1 | byte8);
            }
        }

        long l = truthTable & -1;
        long l1 = (1L << byte4) - 1L;

        if (i == 3)
        {
            int k = 0;

            for (; 0 < byte3; byte3 >>= 1)
            {
                if ((byte3 & 1) != 0)
                {
                    l ^= l1 << k;
                }

                k += byte4;
            }
        }
        else
        {
            long l2 = segmentModifier(byte2, byte5, byte4, i);
            long l3 = 0L;
            int i1 = 0;

            while (0 < byte3)
            {
                if ((byte3 & 1) != 0)
                {
                    long l4 = (byte6 & 1) != 0 ? l2 ^ l1 : l2;

                    if (flag)
                    {
                        l = l & ~(l1 << i1) | l4 << i1;
                    }
                    else
                    {
                        l |= l4 << i1;
                    }
                }

                i1 += byte4;
                byte3 >>= 1;
                byte6 >>= 1;
            }
        }

        truthTable = (int)l;
    }
    
    private boolean isPoweredWire(World world, int i, int j, int k)
    {
        return world.getBlockId(i, j, k) == wireID && world.getBlockMetadata(i, j, k) != 0;
    }
    
    private boolean isSidePowered(World world, int i, int j, int k, int l)
    {
        switch (l)
        {
            case 0:
                return isPoweredWire(world, i, j + 1, k) || world.isBlockIndirectlyProvidingPowerTo(i, j + 1, k, 1);

            case 1:
                return isPoweredWire(world, i, j - 1, k) || world.isBlockIndirectlyProvidingPowerTo(i, j - 1, k, 0);

            case 2:
                return isPoweredWire(world, i, j, k + 1) || world.isBlockIndirectlyProvidingPowerTo(i, j, k + 1, 3);

            case 3:
                return isPoweredWire(world, i, j, k - 1) || world.isBlockIndirectlyProvidingPowerTo(i, j, k - 1, 2);

            case 4:
                return isPoweredWire(world, i + 1, j, k) || world.isBlockIndirectlyProvidingPowerTo(i + 1, j, k, 5);

            case 5:
                return isPoweredWire(world, i - 1, j, k) || world.isBlockIndirectlyProvidingPowerTo(i - 1, j, k, 4);
        }

        return false;
    }
    
    public void RecomputeOutput(World world, int i, int j, int k)
    {
        int l = 0;
        byte byte0 = 1;
        int ai[] = relative_to_absolute_direction[(inputMask & 0xff) >> 6];

        for (int i1 = 5; 0 <= i1; i1--)
        {
            if ((inputMask & 1 << i1) != 0)
            {
                byte0 *= 2;
                l = l << 1 | (isSidePowered(world, i, j, k, ai[i1]) ? 1 : 0) | outputVector >> ai[i1] & 1;
            }
        }

        outputVector = 0;
        long l1 = truthTable & -1;

        for (int j1 = 0; j1 < 6; j1++)
        {
            if ((outputMask & 1 << j1) != 0)
            {
                outputVector |= (byte)(int)((l1 >> l & 1L) << ai[j1]);
                l += byte0;
            }
        }
    }
    
    /**
     * Writes a tile entity to NBT.
     */
    public void writeToNBT(NBTTagCompound nbttagcompound)
    {
        super.writeToNBT(nbttagcompound);
        nbttagcompound.setByte("inputs", inputMask);
        nbttagcompound.setByte("outputs", outputMask);
        nbttagcompound.setInteger("table", truthTable);
    }
    
    /**
     * Reads a tile entity from NBT.
     */
    public void readFromNBT(NBTTagCompound nbttagcompound)
    {
        super.readFromNBT(nbttagcompound);
        inputMask = nbttagcompound.getByte("inputs");
        truthTable = nbttagcompound.getInteger("table");

        if (nbttagcompound.hasKey("outputs"))
        {
            outputMask = nbttagcompound.getByte("outputs");
        }
        else
        {
            outputMask = (byte)(~inputMask & 0x3f);
        }
    }

    /**
     * Returns the number of slots in the inventory.
     */
    @Override
    public int getSizeInventory()
    {
        return 48;
    }

 /**
     * Returns the stack in slot i
     */
    @Override
    public ItemStack getStackInSlot(int i)
    {
        if (i == 45)
        {
            return new ItemStack(RedstoneGate.blockRedstoneGate);
        }
        else
        {
            return null;
        }
    }


/**
     * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
     * stack.
     */
    @Override
    public ItemStack decrStackSize(int i, int j)
    {
        if (i < 0 || getSizeInventory() < i)
        {
            return null;
        }

        if (i == 47)
        {
            String s = GuiRedstoneGate.copypastebuffer[j];
            GuiRedstoneGate.setStatusMessage(setConfigString(s) ? String.format("Pasted %s from slot %d", new Object[]
                    {
                        s, Integer.valueOf(j)
                    }) : "");
        }
        else if (i == 46)
        {
            String s1 = getConfigString();
            GuiRedstoneGate.copypastebuffer[j] = s1;
            GuiRedstoneGate.setStatusMessage(String.format("Copied %s to slot %d", new Object[]
                    {
                        s1, Integer.valueOf(j)
                    }));
        }
        else if (i == 44)
        {
            int k = (getBlockMetadata() + (j == 0 ? 1 : 15)) % 16;
            worldObj.setBlockMetadata(xCoord, yCoord, zCoord, k);
        }
        else if (38 <= i)
        {
            performQuickConfig(GuiRedstoneGate.selectedIO, GuiRedstoneGate.negatedIO, i - 38, j == 0);
        }
        else if (32 <= i)
        {
            byte byte0 = (byte)(1 << i - 32);

            if (j == 1)
            {
                byte byte1 = (byte)(GuiRedstoneGate.negatedIO ^ GuiRedstoneGate.selectedIO & byte0);
                GuiRedstoneGate.selectedIO ^= (GuiRedstoneGate.negatedIO | ~GuiRedstoneGate.selectedIO) & byte0;
                GuiRedstoneGate.negatedIO = byte1;
            }
            else
            {
                do
                {
                    inputMask ^= outputMask & byte0;
                    outputMask ^= byte0;
                }
                while (isInvalidConfig(inputMask, outputMask));
            }
        }
        else
        {
            truthTable ^= 1 << i;
        }

        return null;
    }

    /**
     * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
     * like when you close a workbench GUI.
     */
@Override
public ItemStack getStackInSlotOnClosing(int var1) {
	return null;
}

/**
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
     */
@Override
public void setInventorySlotContents(int var1, ItemStack var2) {}

/**
     * Returns the name of the inventory.
     */
@Override
    public String getInvName()
    {
        return "Redstone gate";
    }

/**
     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
     * this more of a set than a get?*
     */
@Override
    public int getInventoryStackLimit()
    {
        return 1;
    }

/**
     * Do not make give this method the name canInteractWith because it clashes with Container
     */
@Override
    public boolean isUseableByPlayer(EntityPlayer entityplayer)
    {
        if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
        {
            return false;
        }
        else
        {
            return entityplayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
        }
    }

@Override
public void openChest() {}

@Override
public void closeChest() {}

}

 

 

ContainerRedstoneGate.java

 

package redstoneGate.common;

import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot;

public class ContainerRedstoneGate extends Container {

private TileEntityRedstoneGate entityGate;

public ContainerRedstoneGate(InventoryPlayer inventoryplayer, TileEntityRedstoneGate tileentityredstonegate)
    {
        entityGate = tileentityredstonegate;
    }

@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
	return entityGate.isUseableByPlayer(entityplayer);
}

public ItemStack slotClick(int i, int j, boolean flag, EntityPlayer entityplayer)
    {
        if (i < 0 || inventorySlots.size() <= i)
        {
            return null;
        }

        Slot slot = (Slot)inventorySlots.get(i);

        if (slot == null)
        {
            return null;
        }
        else
        {
            return slot.decrStackSize(flag ? 1 : 0);
        }
    }

public void addSlot(Slot slot) {
	this.addSlotToContainer(slot);
}



}

 

 

EDIT: you probably need the renderer!

BlockRendererRedstoneGate.java

 

package redstoneGate.client;

import net.minecraft.src.Block;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.Tessellator;
import redstoneGate.common.BlockRedstoneGate;
import redstoneGate.common.RedstoneGate;
import redstoneGate.common.TileEntityRedstoneGate;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class BlockRendererRedstonGate implements ISimpleBlockRenderingHandler {

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
	if (modelID == getRenderId())
        {
            ((BlockRedstoneGate)block).renderAsItem = true;
            renderer.renderBlockAsItem(block, 0, 1.0F);
            ((BlockRedstoneGate)block).renderAsItem = false;
        }
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
	if (modelId != getRenderId())
        {
            return false;
        }
        else
        {
            TileEntityRedstoneGate tileentityredstonegate = (TileEntityRedstoneGate)world.getBlockTileEntity(x, y, z);
            int i1 = (tileentityredstonegate.inputMask & 0xff) >> 6;
            return renderBlockRedstoneGate(renderer, world, block, x, y, z, i1);
        }
}

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

@Override
public int getRenderId() {
	return RedstoneGate.renderID;
}

public boolean renderBlockRedstoneGate(RenderBlocks renderblocks, IBlockAccess iblockaccess, Block block, int i, int j, int k, int l)
    {
        renderblocks.renderStandardBlock(block, i, j, k);
        Tessellator tessellator = Tessellator.instance;
        tessellator.setBrightness(block.getMixedBrightnessForBlock(iblockaccess, i, j, k));
        tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
        int i1 = block.getBlockTextureFromSide(1);
        int j1 = (i1 & 0xf) << 4;
        int k1 = i1 & 0xf0;
        double d = (float)j1 / 256F;
        double d1 = ((float)j1 + 15.99F) / 256F;
        double d2 = (float)k1 / 256F;
        double d3 = ((float)k1 + 15.99F) / 256F;
        double d4 = 0.5D;
        double d5 = i + 1;
        double d6 = i + 1;
        double d7 = i + 0;
        double d8 = i + 0;
        double d9 = k + 0;
        double d10 = k + 1;
        double d11 = k + 1;
        double d12 = k + 0;
        double d13 = (double)j + d4;

        if (l == 2)
        {
            d5 = d6 = i + 0;
            d7 = d8 = i + 1;
            d9 = d12 = k + 1;
            d10 = d11 = k + 0;
        }
        else if (l == 3)
        {
            d5 = d8 = i + 0;
            d6 = d7 = i + 1;
            d9 = d10 = k + 0;
            d11 = d12 = k + 1;
        }
        else if (l == 1)
        {
            d5 = d8 = i + 1;
            d6 = d7 = i + 0;
            d9 = d10 = k + 1;
            d11 = d12 = k + 0;
        }

        tessellator.addVertexWithUV(d8, d13, d12, d, d2);
        tessellator.addVertexWithUV(d7, d13, d11, d, d3);
        tessellator.addVertexWithUV(d6, d13, d10, d1, d3);
        tessellator.addVertexWithUV(d5, d13, d9, d1, d2);
        return true;
    }

}

 

Link to comment
Share on other sites

  • 2 weeks later...

I am running into similar problems.  I'm using tile entity to store the orientation of my dyed stairs, and using the damage to determine their color.

 

When I place the block, everything renders fine.  When I log out and back in, the orientation of the stairs changes to what I set the value to initially, which makes all the stairs point in the same direction.  Am I missing something?

 

I'm using the details here on setting up Tile Entities (as well as what I see done by the original minecraft code)

http://www.minecraftforge.net/wiki/How_to_use_NBT_Tag_Compound#Making_the_TileEntity

 

You can find my code at:

https://github.com/Kyraleese/Mod-To-Dye-For-1.3.2.001

 

If someone could point me in the right direction for what I might be forgetting to do, I would greatly appreciate it.  I keep thinking that I need to do a readFromNBT instead of referencing ourEntity.orientation directly like I am.

Link to comment
Share on other sites

Hrm, I looked in your code above; I'm not finding anything that refers to packets.

 

I have been able to make use of the onActivate to see what was stored in the entity.  The strange thing is that the value of my data I'm storing is remaining;  IE: I place the stair and the entity data for its orientation is set to 3.  I log out, log back in, and it's still set to 3.  But it's rendering as if it's set to 2 (which is the arbitrary asignment I have made to it).

 

Could you show me some code with the fixes you made highlighted?

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.