Jump to content

Recommended Posts

Posted

Hello everyone, i am currently trying to register a TileEntity within my mod but am running into a few problems,

when i was in 1.8.9 i was able to use the method below to register my TE using just .json files

    @Override
    public int getRenderType()
    {
        return 3;
    }

that method no longer works though from when i have tried it,

so i tried using the method below, but still no luck,

    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
    }

i was wondering if i was doing something wrong with my .json files or if i am rendering the TE wrong, and just a note i do not want to render it using a TESR but if that is the only way, could someone point me to the right direction as i have never used a TESR before.

here is my code:

 

my Chest code that im trying to render:

public class StoneChest extends BlockContainer {


public StoneChest(Material material, String unlocalizedName) {
	super(material);
	this.setHardness(3.0F);
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(AE3.tabAE);
}

    public StoneChest(String unlocalisedName) {
        this(Material.rock, unlocalisedName);
    }
    
    @Override
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

    @Override
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
    
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
    }
    
    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState blockState, EntityLivingBase entityliving, ItemStack itemStack)
    {
        byte chestFacing = 0;
        int facing = MathHelper.floor_double((entityliving.rotationYaw * 4F) / 360F + 0.5D) & 3;
        if (facing == 0)
        {
            chestFacing = 2;
        }
        if (facing == 1)
        {
            chestFacing = 5;
        }
        if (facing == 2)
        {
            chestFacing = 3;
        }
        if (facing == 3)
        {
            chestFacing = 4;
        }
        TileEntity te = world.getTileEntity(pos);
        if (te != null && te instanceof TileEntityStoneChest)
        {
        	TileEntityStoneChest teic = (TileEntityStoneChest) te;
            teic.wasPlaced(entityliving, itemStack);
            teic.setFacing(chestFacing);
            world.notifyBlockUpdate(pos, blockState, blockState, 3);
        }
    }

public void dropContent(int newSize, IInventory chest, World world, BlockPos pos)
    {
        Random random = world.rand;

        for (int l = newSize; l < chest.getSizeInventory(); l++)
        {
            ItemStack itemstack = chest.getStackInSlot(l);
            if (itemstack == null)
            {
                continue;
            }
            float f = random.nextFloat() * 0.8F + 0.1F;
            float f1 = random.nextFloat() * 0.8F + 0.1F;
            float f2 = random.nextFloat() * 0.8F + 0.1F;
            while (itemstack.stackSize > 0)
            {
                int i1 = random.nextInt(21) + 10;
                if (i1 > itemstack.stackSize)
                {
                    i1 = itemstack.stackSize;
                }
                itemstack.stackSize -= i1;
                EntityItem entityitem = new EntityItem(world, pos.getX() + f, (float) pos.getY() + (newSize > 0 ? 1 : 0) + f1, pos.getZ() + f2,
                        new ItemStack(itemstack.getItem(), i1, itemstack.getMetadata()));
                float f3 = 0.05F;
                entityitem.motionX = (float) random.nextGaussian() * f3;
                entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
                entityitem.motionZ = (float) random.nextGaussian() * f3;
                if (itemstack.hasTagCompound())
                {
                    entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
                }
                world.spawnEntityInWorld(entityitem);
            }
        }
    }

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

 

my TE code:

 

public class TileEntityStoneChest extends TileEntity {


    private byte facing;

public void setFacing(byte facing2)
    {
        this.facing = facing2;
    }

  public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
    {
    }

}

 

my registers in my ModBlocks:

		GameRegistry.register(StoneChest.setRegistryName("StoneChest"));
	GameRegistry.register(new ItemBlockChest(StoneChest).setRegistryName(StoneChest.getRegistryName()));
        GameRegistry.registerTileEntity(TileEntityStoneChest.class, "TileEntityStoneChest");

 

My json files,

Item Model Json (this one works fine and renders fine);

{
    "parent": "block/block",
    "textures": {
        "texture": "sc:models/StoneChest"
    },
    "elements": [
        {   "from": [ 1, 0, 1 ],
            "to": [ 15, 10, 15 ],
            "faces": {
                "down":  { "uv": [ 7,    4.75, 10.5, 8.25 ], "texture": "#texture" },
                "up":    { "uv": [ 3.5,  4.75, 7,    8.25 ], "texture": "#texture" },
                "north": { "uv": [ 3.5,  8.25, 7,    10.75 ], "texture": "#texture" },
                "south": { "uv": [ 10.5, 8.25, 14,   10.75 ], "texture": "#texture" },
                "west":  { "uv": [ 7,    8.25, 10.5, 10.75 ], "texture": "#texture" },
                "east":  { "uv": [ 0,    8.25, 3.5,  10.75 ], "texture": "#texture" }
            }
        },
        {   "from": [ 1, 9, 1 ],
            "to": [ 15, 14, 15 ],
            "faces": {
                "down":  { "uv": [ 7,    0,   10.5, 3.5 ], "texture": "#texture" },
                "up":    { "uv": [ 3.5,  0,   7,    3.5 ], "texture": "#texture" },
                "north": { "uv": [ 3.5,  3.5, 7,    4.75 ], "texture": "#texture" },
                "south": { "uv": [ 10.5, 3.5, 14,   4.75 ], "texture": "#texture" },
                "west":  { "uv": [ 7,    3.5, 10.5, 4.75 ], "texture": "#texture" },
                "east":  { "uv": [ 0,    3.5, 3.5,  4.75 ], "texture": "#texture" }
            }
        },
        {   "from": [ 7, 7, 0 ],
            "to": [ 9, 11, 1 ],
            "faces": {
                "down":  { "uv": [ 0,    0.75, 1.25, 0.5 ], "texture": "#texture" },
                "up":    { "uv": [ 0,    0.25, 0.75, 0.5 ], "texture": "#texture" },
                "north": { "uv": [ 0.25, 0.25, 0.75, 1.25 ], "texture": "#texture" },
                "south": { "uv": [ 1,    0.25, 1.5,  1.25 ], "texture": "#texture" },
                "west":  { "uv": [ 0.75, 0.25, 1,    1.25 ], "texture": "#texture" },
                "east":  { "uv": [ 0,    0.25, 0.25, 1.25 ], "texture": "#texture" }
            }
        }
    ]
}

 

My BlockStates json;

{
    "variants": {
        "normal": { "model": "sc:models/StoneChest" }
    }
}

 

and my Block Model Json

{
    "parent": "block/block",
    "textures": {
        "texture": "sc:models/StoneChest"
    },
    "elements": [
        {   "from": [ 1, 0, 1 ],
            "to": [ 15, 10, 15 ],
            "faces": {
                "down":  { "uv": [ 7,    4.75, 10.5, 8.25 ], "texture": "#texture" },
                "up":    { "uv": [ 3.5,  4.75, 7,    8.25 ], "texture": "#texture" },
                "north": { "uv": [ 3.5,  8.25, 7,    10.75 ], "texture": "#texture" },
                "south": { "uv": [ 10.5, 8.25, 14,   10.75 ], "texture": "#texture" },
                "west":  { "uv": [ 7,    8.25, 10.5, 10.75 ], "texture": "#texture" },
                "east":  { "uv": [ 0,    8.25, 3.5,  10.75 ], "texture": "#texture" }
            }
        },
        {   "from": [ 1, 9, 1 ],
            "to": [ 15, 14, 15 ],
            "faces": {
                "down":  { "uv": [ 7,    0,   10.5, 3.5 ], "texture": "#texture" },
                "up":    { "uv": [ 3.5,  0,   7,    3.5 ], "texture": "#texture" },
                "north": { "uv": [ 3.5,  3.5, 7,    4.75 ], "texture": "#texture" },
                "south": { "uv": [ 10.5, 3.5, 14,   4.75 ], "texture": "#texture" },
                "west":  { "uv": [ 7,    3.5, 10.5, 4.75 ], "texture": "#texture" },
                "east":  { "uv": [ 0,    3.5, 3.5,  4.75 ], "texture": "#texture" }
            }
        },
        {   "from": [ 7, 7, 0 ],
            "to": [ 9, 11, 1 ],
            "faces": {
                "down":  { "uv": [ 0,    0.75, 1.25, 0.5 ], "texture": "#texture" },
                "up":    { "uv": [ 0,    0.25, 0.75, 0.5 ], "texture": "#texture" },
                "north": { "uv": [ 0.25, 0.25, 0.75, 1.25 ], "texture": "#texture" },
                "south": { "uv": [ 1,    0.25, 1.5,  1.25 ], "texture": "#texture" },
                "west":  { "uv": [ 0.75, 0.25, 1,    1.25 ], "texture": "#texture" },
                "east":  { "uv": [ 0,    0.25, 0.25, 1.25 ], "texture": "#texture" }
            }
        }
    ]
}

Posted

Ok i have removed BlockContainer and extended Block, and i added these methods

	@Override
public public boolean hasTileEntity() {
	return new TileEntityStoneChest();
};

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

 

they are erroring, so i was was  wondering if i was i was doing it wrong, and if so how should i change them

 

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.