Posted September 15, 20169 yr comment_226012 I'm trying to create a jar of sorts with one section being translucent and another part being opaque. The translucent part works fine, but from some angles the opaque section disappears. Any tips? Class package tustuff.blocks; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import tustuff.init.Init; import tustuff.init.ModItems; import tustuff.init.NameReg; import tustuff.other.TabTustuff; import tustuff.tileentities.TEPurpleJar; public class PurpleJar extends Block implements ITileEntityProvider { private static final AxisAlignedBB BoundingBox = new AxisAlignedBB(0.0625 * 4, 0, 0.0625 * 4, 0.0625*12, 0.0625*11, 0.0625*12); public PurpleJar(){ super(Material.IRON); setUnlocalizedName(NameReg.ModBlocks.PURPLEJAR.getUnlocalizedName()); setRegistryName(NameReg.ModBlocks.PURPLEJAR.getRegistryName()); setCreativeTab(TabTustuff.tabTustuff); setHardness(1.4F); setResistance(4.0F); setSoundType(SoundType.GLASS); setLightOpacity(0); setLightLevel(0.0F); isBlockContainer = true; } @Override public boolean isFullCube(IBlockState state){ return false; } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.TRANSLUCENT; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return BoundingBox; } @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn) { super.addCollisionBoxToList(pos, entityBox, collidingBoxes, BoundingBox); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TEPurpleJar(); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state){ super.breakBlock(worldIn, pos, state); worldIn.removeTileEntity(pos); } @Override public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param){ super.eventReceived(state, worldIn, pos, id, param); TileEntity tileentity = worldIn.getTileEntity(pos); return tileentity == null ? false : tileentity.receiveClientEvent(id, param); } @Override public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player){ if(!worldIn.isRemote){ EntityItem item = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModItems.cheesecracker, TEPurpleJar.itemamount)); worldIn.spawnEntityInWorld(item); } } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if(!worldIn.isRemote){ TileEntity tileentity = worldIn.getTileEntity(pos); if(tileentity instanceof TEPurpleJar){ TEPurpleJar tepurplejar = (TEPurpleJar) tileentity; if(heldItem != null){ if(heldItem.getItem() == ModItems.cheesecracker){ if(TEPurpleJar.addToJar() == true){ heldItem.stackSize--; return true; } } } TEPurpleJar.removeFromJar(playerIn); } } return true; } } Model { "parent": "block/cube", "textures": { "0": "tustuff:blocks/purpleblock", "1": "tustuff:blocks/purplejar-glass", "particle": "tustuff:blocks/purplejar-glass" }, "elements": [ { "name": "Base", "from": [ 4.0, 0.0, 4.0 ], "to": [ 12.0, 1.0, 12.0 ], "faces": { "north": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "east": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "south": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "west": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] } } }, { "name": "Glass", "from": [ 4.0, 1.0, 4.0 ], "to": [ 12.0, 9.0, 12.0 ], "faces": { "north": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "east": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "south": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "west": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "up": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "down": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] } } }, { "name": "LidA", "from": [ 4.0, 9.0, 4.0 ], "to": [ 12.0, 10.0, 12.0 ], "faces": { "north": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "east": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "south": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "west": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] } } }, { "name": "LidB", "from": [ 6.0, 10.0, 6.0 ], "to": [ 10.0, 11.0, 10.0 ], "faces": { "north": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "east": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "south": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "west": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "up": { "texture": "#0", "uv": [ 4.0, 5.0, 8.0, 9.0 ] }, "down": { "texture": "#0", "uv": [ 4.0, 5.0, 8.0, 9.0 ] } } } ] } ...
September 15, 20169 yr comment_226023 Mostly unrelated: Don't implement ITileEntityProvider, the Block class already has the methods hasTileEntity() and createTileEntity(), please use those as they have IBlockState as parameter instead of the metadata.
September 15, 20169 yr comment_226024 Mostly unrelated: Don't implement ITileEntityProvider, the Block class already has the methods hasTileEntity() and createTileEntity(), please use those as they have IBlockState as parameter instead of the metadata. To be more specific createTileEntity(IBlockAccess world, IBlockState state) hasTileEntitity(IBlockState state) I'm trying to create a jar of sorts with one section being translucent and another part being opaque. The translucent part works fine, but from some angles the opaque section disappears. Any tips? Class package tustuff.blocks; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import tustuff.init.Init; import tustuff.init.ModItems; import tustuff.init.NameReg; import tustuff.other.TabTustuff; import tustuff.tileentities.TEPurpleJar; public class PurpleJar extends Block implements ITileEntityProvider { private static final AxisAlignedBB BoundingBox = new AxisAlignedBB(0.0625 * 4, 0, 0.0625 * 4, 0.0625*12, 0.0625*11, 0.0625*12); public PurpleJar(){ super(Material.IRON); setUnlocalizedName(NameReg.ModBlocks.PURPLEJAR.getUnlocalizedName()); setRegistryName(NameReg.ModBlocks.PURPLEJAR.getRegistryName()); setCreativeTab(TabTustuff.tabTustuff); setHardness(1.4F); setResistance(4.0F); setSoundType(SoundType.GLASS); setLightOpacity(0); setLightLevel(0.0F); isBlockContainer = true; } @Override public boolean isFullCube(IBlockState state){ return false; } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.TRANSLUCENT; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return BoundingBox; } @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn) { super.addCollisionBoxToList(pos, entityBox, collidingBoxes, BoundingBox); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TEPurpleJar(); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state){ super.breakBlock(worldIn, pos, state); worldIn.removeTileEntity(pos); } @Override public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param){ super.eventReceived(state, worldIn, pos, id, param); TileEntity tileentity = worldIn.getTileEntity(pos); return tileentity == null ? false : tileentity.receiveClientEvent(id, param); } @Override public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player){ if(!worldIn.isRemote){ EntityItem item = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModItems.cheesecracker, TEPurpleJar.itemamount)); worldIn.spawnEntityInWorld(item); } } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if(!worldIn.isRemote){ TileEntity tileentity = worldIn.getTileEntity(pos); if(tileentity instanceof TEPurpleJar){ TEPurpleJar tepurplejar = (TEPurpleJar) tileentity; if(heldItem != null){ if(heldItem.getItem() == ModItems.cheesecracker){ if(TEPurpleJar.addToJar() == true){ heldItem.stackSize--; return true; } } } TEPurpleJar.removeFromJar(playerIn); } } return true; } } Model { "parent": "block/cube", "textures": { "0": "tustuff:blocks/purpleblock", "1": "tustuff:blocks/purplejar-glass", "particle": "tustuff:blocks/purplejar-glass" }, "elements": [ { "name": "Base", "from": [ 4.0, 0.0, 4.0 ], "to": [ 12.0, 1.0, 12.0 ], "faces": { "north": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "east": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "south": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "west": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] } } }, { "name": "Glass", "from": [ 4.0, 1.0, 4.0 ], "to": [ 12.0, 9.0, 12.0 ], "faces": { "north": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "east": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "south": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "west": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "up": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "down": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] } } }, { "name": "LidA", "from": [ 4.0, 9.0, 4.0 ], "to": [ 12.0, 10.0, 12.0 ], "faces": { "north": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "east": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "south": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "west": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }, "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }, "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] } } }, { "name": "LidB", "from": [ 6.0, 10.0, 6.0 ], "to": [ 10.0, 11.0, 10.0 ], "faces": { "north": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "east": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "south": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "west": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] }, "up": { "texture": "#0", "uv": [ 4.0, 5.0, 8.0, 9.0 ] }, "down": { "texture": "#0", "uv": [ 4.0, 5.0, 8.0, 9.0 ] } } } ] } I noticed you have getBlockLayer(...) set to translucent, what are the other options there as i do not remember (no IDE or code ATM). VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 15, 20169 yr comment_226025 I didn't see that detail but I would always return cutout mipped as not the complete block is translucent. That may even fix the problem.
September 16, 20169 yr comment_226148 Hi Translucent rendering is always a problem because the appearance of your model will change depending on which order the faces are drawn in (and which angle you're looking at the model from). I think that's probably what is happening to you. Usually, you should draw the opaque faces first, then the translucent faces second, and I don't think the block model guarantees that. But the same problem applies to translucent faces as well, i.e. if you look through one translucent face and see a second translucent face. In order to get it right you usually have to depth-sort the faces. This link explains it a bit better https://www.opengl.org/wiki/Transparency_Sorting I've implemented a jar similar to yours before (admittedly before 1.10.2), and I used a TileEntity to do it. The opaque parts I drew with a block model, then in the TileEntitySpecialRenderer, I draw the transparent faces in depth-sorted order. It worked but was pretty complicated and you would have to understand quite a bit about how depth buffering, culling, and depth-sorting work. Cutout_mipped is something different and will make your translucent panes go non-translucent. BlockRenderLayer.TRANSLUCENT is correct but is not enough. If you find a simpler way please let me know..! -TGG
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.