Jump to content

[SOLVED][1.9] Glass slab glitch


JimiIT92

Recommended Posts

I'm using this class to make some slabs. However one of this is a glass slab, and so it needs to be transparent. The texture it is, but when placed down it glitches the block below, but only the double or the bottom slab, doing this

Qs5B1kM.png

I've already tried adding the BlockGlass methods (isOpaque/isFullCube) but the glitch reamin :/

This is the class i use

package com.mwvanilla.blocks;

import java.util.List;
import java.util.Random;

import com.mineworld.blocks.ores.BlockOreSlab;
import com.mwvanilla.core.MWVanillaSlabs;
import com.mwvanilla.core.MWVanillaTabs;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BlockVanillaSlab extends BlockSlab
{
    public static final PropertyEnum<BlockVanillaSlab.Variant> VARIANT = PropertyEnum.<BlockVanillaSlab.Variant>create("variant", BlockVanillaSlab.Variant.class);
    private Block block;
    public BlockVanillaSlab(Block block)
    {
        super(block.getDefaultState().getMaterial());
        this.block = block;
        IBlockState iblockstate = this.blockState.getBaseState();

        if (!this.isDouble())
        {
            iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
            this.setCreativeTab(MWVanillaTabs.tabVanillaSlabs);
        }

        this.setDefaultState(iblockstate.withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT));
        this.setHardness(block.getBlockHardness(block.getDefaultState(), null, null));
        this.setResistance(block.getExplosionResistance(null));
        this.setStepSound(this.block.getStepSound());
        if(this.block.equals(Blocks.glowstone))
        	this.setLightLevel(0.75F);
        if(this.block.equals(Blocks.sea_lantern))
        	this.setLightLevel(1.0F);
	this.useNeighborBrightness = !this.isDouble();
    }
    
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
    }
            
    protected boolean canSilkHarvest()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass);
    }
    
    @Override
public boolean canProvidePower(IBlockState state) {
	return this.block.equals(Blocks.redstone_block);
}

@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	return  this.block.equals(Blocks.redstone_block) ? 15 : 0;
}

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? null : Item.getItemFromBlock(this);
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(Item.getItemFromBlock(this));
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT);

        if (!this.isDouble())
        {
            iblockstate = iblockstate.withProperty(HALF, (meta &  == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
        }

        return iblockstate;
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;

        if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
        {
            i |= 8;
        }

        return i;
    }

    protected BlockStateContainer createBlockState()
    {
        return this.isDouble() ? new BlockStateContainer(this, new IProperty[] {VARIANT}): new BlockStateContainer(this, new IProperty[] {HALF, VARIANT});
    }

    /**
     * Returns the slab block name with the type associated with it
     */
    public String getUnlocalizedName(int meta)
    {
        return super.getUnlocalizedName();
    }

    public IProperty<?> getVariantProperty()
    {
        return VARIANT;
    }

    public Comparable<?> getTypeForItem(ItemStack stack)
    {
        return BlockVanillaSlab.Variant.DEFAULT;
    }

    public static enum Variant implements IStringSerializable
    {
        DEFAULT;

        public String getName()
        {
            return "default";
        }
    }
}

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

I've already looked at that classes. Already added in the slab class the getBlockLayer function and the canSilkHarvest function. The only functions not added are the isFullCube, the isOpaque and the shouldSideBeRendered. Adding the isFullCube didn't change, overriding the shouldSideBeRendered to call the supermethod if the material isn't glass or running the same code of the BlockBreakable class if it is also didn't change. So i've added the last function, isOpaque, returning always false, but then the game crashes as i place a double slab (also the glitch persist). The class is now looking like this

package com.mwvanilla.blocks;

import java.util.List;
import java.util.Random;

import com.mineworld.blocks.ores.BlockOreSlab;
import com.mwvanilla.core.MWVanillaSlabs;
import com.mwvanilla.core.MWVanillaTabs;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BlockVanillaSlab extends BlockSlab
{
    public static final PropertyEnum<BlockVanillaSlab.Variant> VARIANT = PropertyEnum.<BlockVanillaSlab.Variant>create("variant", BlockVanillaSlab.Variant.class);
    private Block block;
    public BlockVanillaSlab(Block block)
    {
        super(block.getDefaultState().getMaterial());
        this.block = block;
        IBlockState iblockstate = this.blockState.getBaseState();

        if (!this.isDouble())
        {
            iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
            this.setCreativeTab(MWVanillaTabs.tabVanillaSlabs);
        }

        this.setDefaultState(iblockstate.withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT));
        this.setHardness(block.getBlockHardness(block.getDefaultState(), null, null));
        this.setResistance(block.getExplosionResistance(null));
        this.setStepSound(this.block.getStepSound());
        if(this.block.equals(Blocks.glowstone))
        	this.setLightLevel(0.75F);
        if(this.block.equals(Blocks.sea_lantern))
        	this.setLightLevel(1.0F);
	this.useNeighborBrightness = !this.isDouble();
    }
    
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
    
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
    
    @Override
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
    		EnumFacing side) {
    	if(this.block.getDefaultState().getMaterial().equals(Material.glass)) {
    		IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
            Block block = iblockstate.getBlock();
            if (blockState != iblockstate)
            {
                return true;
            }

            if (block == this)
            {
                return false;
            }
            
            return block == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    	}
    	return this.isDouble() ? true : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    }
    
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
    }
            
    protected boolean canSilkHarvest()
    {
        return !this.isDouble();
    }
    
    @Override
public boolean canProvidePower(IBlockState state) {
	return this.block.equals(Blocks.redstone_block);
}

@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	return  this.block.equals(Blocks.redstone_block) ? 15 : 0;
}

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? null : Item.getItemFromBlock(this);
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(Item.getItemFromBlock(this));
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT);

        if (!this.isDouble())
        {
            iblockstate = iblockstate.withProperty(HALF, (meta &  == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
        }

        return iblockstate;
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;

        if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
        {
            i |= 8;
        }

        return i;
    }

    protected BlockStateContainer createBlockState()
    {
        return this.isDouble() ? new BlockStateContainer(this, new IProperty[] {VARIANT}): new BlockStateContainer(this, new IProperty[] {HALF, VARIANT});
    }

    /**
     * Returns the slab block name with the type associated with it
     */
    public String getUnlocalizedName(int meta)
    {
        return super.getUnlocalizedName();
    }

    public IProperty<?> getVariantProperty()
    {
        return VARIANT;
    }

    public Comparable<?> getTypeForItem(ItemStack stack)
    {
        return BlockVanillaSlab.Variant.DEFAULT;
    }

    public static enum Variant implements IStringSerializable
    {
        DEFAULT;

        public String getName()
        {
            return "default";
        }
    }
}

 

And this is the crash i have

java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=half, clazz=class net.minecraft.block.BlockSlab$EnumBlockHalf, values=[top, bottom]} as it does not exist in BlockStateContainer{block=mw:glass_double_slab, properties=[variant]}
at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:192)
at net.minecraft.block.BlockSlab.doesSideBlockRendering(BlockSlab.java:67)
at net.minecraft.block.state.BlockStateContainer$StateImplementation.doesSideBlockRendering(BlockStateContainer.java:468)
at net.minecraft.block.Block.shouldSideBeRendered(Block.java:516)
at net.minecraft.block.state.BlockStateContainer$StateImplementation.shouldSideBeRendered(BlockStateContainer.java:408)
at net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer.render(ForgeBlockModelRenderer.java:113)
at net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer.renderModelSmooth(ForgeBlockModelRenderer.java:84)
at net.minecraft.client.renderer.BlockModelRenderer.renderModel(BlockModelRenderer.java:45)
at net.minecraft.client.renderer.BlockModelRenderer.renderModel(BlockModelRenderer.java:36)
at net.minecraft.client.renderer.BlockRendererDispatcher.renderBlock(BlockRendererDispatcher.java:81)
at net.minecraft.client.renderer.chunk.RenderChunk.rebuildChunk(RenderChunk.java:196)
at net.minecraft.client.renderer.chunk.ChunkRenderWorker.processTask(ChunkRenderWorker.java:124)
at net.minecraft.client.renderer.chunk.ChunkRenderDispatcher.updateChunkNow(ChunkRenderDispatcher.java:171)
at net.minecraft.client.renderer.RenderGlobal.setupTerrain(RenderGlobal.java:975)
at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1339)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1282)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1091)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1135)
at net.minecraft.client.Minecraft.run(Minecraft.java:401)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

 

It says that it cannot set the half property to a double slab as it doesn't exixts, wich is correct but looking at the supermethod the doubleslab case is handled well

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

EDIT: the crash was cause by the doesSideBlockRendering, wich overriding properly as solved the problem. In case everyone want to look how this has been fixed, this is the complete class

package com.mwvanilla.blocks;

import java.util.List;
import java.util.Random;

import com.mineworld.blocks.ores.BlockOreSlab;
import com.mwvanilla.core.MWVanillaSlabs;
import com.mwvanilla.core.MWVanillaTabs;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BlockVanillaSlab extends BlockSlab
{
    public static final PropertyEnum<BlockVanillaSlab.Variant> VARIANT = PropertyEnum.<BlockVanillaSlab.Variant>create("variant", BlockVanillaSlab.Variant.class);
    private Block block;
    public BlockVanillaSlab(Block block)
    {
        super(block.getDefaultState().getMaterial());
        this.block = block;
        IBlockState iblockstate = this.blockState.getBaseState();

        if (!this.isDouble())
        {
            iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
            this.setCreativeTab(MWVanillaTabs.tabVanillaSlabs);
        }

        this.setDefaultState(iblockstate.withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT));
        this.setHardness(block.getBlockHardness(block.getDefaultState(), null, null));
        this.setResistance(block.getExplosionResistance(null));
        this.setStepSound(this.block.getStepSound());
        if(this.block.equals(Blocks.glowstone))
        	this.setLightLevel(0.75F);
        if(this.block.equals(Blocks.sea_lantern))
        	this.setLightLevel(1.0F);
	this.useNeighborBrightness = !this.isDouble();
    }
    
    @Override
    public boolean isOpaqueCube(IBlockState state) {
    	return false;
    }
    
    @Override
    public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face)
    {
        if(this.block.getDefaultState().getMaterial().equals(Material.glass))
        	return Blocks.glass.doesSideBlockRendering(state, world, pos, face);
        else
        	return super.doesSideBlockRendering(state, world, pos, face);
    }
    
    @Override
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
    		EnumFacing side) {
    	if(this.block.getDefaultState().getMaterial().equals(Material.glass)) {
    		IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
            Block block = iblockstate.getBlock();
            if (blockState != iblockstate)
            {
                return true;
            }

            if (block == this)
            {
                return false;
            }
            
            return block == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    	}
    	return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    }
    
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
    }
            
    protected boolean canSilkHarvest()
    {
        return !this.isDouble();
    }
    
    @Override
public boolean canProvidePower(IBlockState state) {
	return this.block.equals(Blocks.redstone_block);
}

@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	return  this.block.equals(Blocks.redstone_block) ? 15 : 0;
}

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.block.getDefaultState().getMaterial().equals(Material.glass) ? null : Item.getItemFromBlock(this);
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(Item.getItemFromBlock(this));
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockVanillaSlab.Variant.DEFAULT);

        if (!this.isDouble())
        {
            iblockstate = iblockstate.withProperty(HALF, (meta &  == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
        }

        return iblockstate;
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;

        if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
        {
            i |= 8;
        }

        return i;
    }

    protected BlockStateContainer createBlockState()
    {
        return this.isDouble() ? new BlockStateContainer(this, new IProperty[] {VARIANT}): new BlockStateContainer(this, new IProperty[] {HALF, VARIANT});
    }

    /**
     * Returns the slab block name with the type associated with it
     */
    public String getUnlocalizedName(int meta)
    {
        return super.getUnlocalizedName();
    }

    public IProperty<?> getVariantProperty()
    {
        return VARIANT;
    }

    public Comparable<?> getTypeForItem(ItemStack stack)
    {
        return BlockVanillaSlab.Variant.DEFAULT;
    }

    public static enum Variant implements IStringSerializable
    {
        DEFAULT;

        public String getName()
        {
            return "default";
        }
    }
}

 

Thank you diesieben for the help :)

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.