Jump to content

Recommended Posts

Posted

I'm trying to update my mod from 1.9 to 1.10.2 (forge version 12.16.1.1887 to 12.18.2.2098).

 

My Doors save all their information in metadata. When placing a new door it works fine, but after saving, quitting to title and reloading the world all metadata seems to be lost. I even tried to copy parts of my code into the vanilla doors code, but I get the same problem there...

 

It is NOT a problem of my doors having more than 16 possible values to store in their metadata. Each single door block only stores part of the combined data and gets the data it doesn't store itself from the blocks above or below it. That's the same as vanilla doors work.

 

This is the code of my BlockDoorOneByThree.java:

 

package net.roxa.tallDoors;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.audio.SoundList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.event.sound.SoundEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockDoorOneByThree extends Block
{
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
    public static final PropertyBool OPEN = PropertyBool.create("open");
    public static final PropertyEnum HINGE = PropertyEnum.create("hinge", BlockDoor.EnumHingePosition.class);
    public static final PropertyBool POWERED = PropertyBool.create("powered");
    public static final PropertyEnum HALF = PropertyEnum.create("half", BlockDoorOneByThree.EnumDoorHalf.class);
    
    protected BlockDoorOneByThree(Material materialIn, String material)
    {
        super(materialIn);
        
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.LOWER));
        this.setHardness(2.0F);
    	this.setResistance(1F);
    	if (material.equals("oak")) this.setUnlocalizedName("blockDoorOneByThreeOak");
    	else if (material.equals("birch")) this.setUnlocalizedName("blockDoorOneByThreeBirch");
    	else if (material.equals("spruce")) this.setUnlocalizedName("blockDoorOneByThreeSpruce");
    	else if (material.equals("jungle")) this.setUnlocalizedName("blockDoorOneByThreeJungle");
    	else if (material.equals("acacia")) this.setUnlocalizedName("blockDoorOneByThreeAcacia");
    	else if (material.equals("darkOak")) this.setUnlocalizedName("blockDoorOneByThreeDarkOak");
    	else this.setUnlocalizedName("blockDoorOneByThreeIron");
        if (material.equals("oak")) this.setRegistryName("blockDoorOneByThreeOak");
    	else if (material.equals("birch")) this.setRegistryName("blockDoorOneByThreeBirch");
    	else if (material.equals("spruce")) this.setRegistryName("blockDoorOneByThreeSpruce");
    	else if (material.equals("jungle")) this.setRegistryName("blockDoorOneByThreeJungle");
    	else if (material.equals("acacia")) this.setRegistryName("blockDoorOneByThreeAcacia");
    	else if (material.equals("darkOak")) this.setRegistryName("blockDoorOneByThreeDarkOak");
    	else this.setRegistryName("blockDoorOneByThreeIron");
        if(this.getDoorMaterial().equals("iron")) this.setSoundType(SoundType.METAL);
    	else this.setSoundType(SoundType.WOOD);
        
    }
    
    @Override
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

    @Override
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
    {
        return isOpen(combineMetadata(worldIn, pos));
    }

    @Override
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }

    @SideOnly(Side.CLIENT)
    @Override
    public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
    {
    	this.getBoundingBox(state, worldIn, pos);
        return super.getSelectedBoundingBox(state, worldIn, pos);
    }

    @Override
    public AxisAlignedBB getCollisionBoundingBox(IBlockState state, World worldIn, BlockPos pos)
    {
        this.getBoundingBox(state, worldIn, pos);
        return super.getCollisionBoundingBox(state, worldIn, pos);
    }
    
    @Override
    //public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        return this.setBoundBasedOnMeta(combineMetadata(source, pos));
    }

    private AxisAlignedBB setBoundBasedOnMeta(int combinedMeta)
    {
        float f = 0.1875F;
        AxisAlignedBB axis;
        axis = new AxisAlignedBB(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
        EnumFacing enumfacing = getFacing(combinedMeta);
        boolean open = isOpen(combinedMeta);
        boolean left = isHingeLeft(combinedMeta);

        if (open)
        {
            if (enumfacing == EnumFacing.EAST)
            {
                if (!left)
                {
                	axis = new AxisAlignedBB(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
                }
                else
                {
                	axis = new AxisAlignedBB(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
                }
            }
            else if (enumfacing == EnumFacing.SOUTH)
            {
                if (!left)
                {
                	axis = new AxisAlignedBB(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                }
                else
                {
                	axis = new AxisAlignedBB(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
                }
            }
            else if (enumfacing == EnumFacing.WEST)
            {
                if (!left)
                {
                	axis = new AxisAlignedBB(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
                }
                else
                {
                	axis = new AxisAlignedBB(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
                }
            }
            else if (enumfacing == EnumFacing.NORTH)
            {
                if (!left)
                {
                	axis = new AxisAlignedBB(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
                }
                else
                {
                	axis = new AxisAlignedBB(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                }
            }
        }
        else if (enumfacing == EnumFacing.EAST)
        {
        	axis = new AxisAlignedBB(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
        }
        else if (enumfacing == EnumFacing.SOUTH)
        {
        	axis = new AxisAlignedBB(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
        }
        else if (enumfacing == EnumFacing.WEST)
        {
        	axis = new AxisAlignedBB(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        else if (enumfacing == EnumFacing.NORTH)
        {
        	axis = new AxisAlignedBB(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
        }
        return axis;
    }
    
    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
    	return this.toggleDoor(worldIn, pos, state, playerIn, false);
    }
    
    public boolean toggleDoor(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, boolean powered)
    {
    	boolean returnValue = false;
    	/*
    	if (this.blockMaterial == Material.iron && powered == false)
        {
            return returnValue; //Allow items to interact with the door
        }
        */
        if (this.blockMaterial != Material.IRON || powered)
        {
        	boolean openNew;
        	IBlockState fullState = this.getActualState(state, worldIn, pos);
            BlockPos blockposLower;
            if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.LOWER) blockposLower = pos;
            else if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.MIDDLE) blockposLower = pos.down();
            else blockposLower = pos.down(2);
            
            IBlockState stateLower = pos.equals(blockposLower) ? state : worldIn.getBlockState(blockposLower);
            
            if (stateLower.getBlock() == this)
            {
            	openNew = (Boolean)stateLower.getValue(OPEN);
                openNew = openNew ? false : true;
                
            	worldIn.setBlockState(blockposLower, stateLower.withProperty(OPEN, openNew), 2);
    			worldIn.markBlockRangeForRenderUpdate(blockposLower, pos);
                //worldIn.playAuxSFXAtEntity(playerIn, 1003, pos, 0);
    			//worldIn.playAuxSFXAtEntity(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getSoundOpen() : this.getSoundOpen(), pos, 0);
    			worldIn.playSound(playerIn, (double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getSoundOpen() : this.getSoundOpen(), SoundCategory.BLOCKS, 1.0F, 1.0F);
    			returnValue = true;
            }
        }
        return returnValue;
    }
    
    @Override
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block neighborBlock)
    {
    	BlockPos blockposLower = pos;
    	BlockPos blockposMiddle = pos;
        BlockPos blockposUpper = pos;
        
        if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.LOWER)
        {
        	blockposMiddle = pos.up();
        	blockposUpper = pos.up(2);
        }
        else if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.MIDDLE)
        {
        	blockposLower = pos.down();
        	blockposUpper = pos.up();
        }
        else
        {
        	blockposLower = pos.down(2);
        	blockposMiddle = pos.down();
        }
        
        IBlockState iblockstateLower = worldIn.getBlockState(blockposLower);
        IBlockState iblockstateMiddle = worldIn.getBlockState(blockposMiddle);
        IBlockState iblockstateUpper = worldIn.getBlockState(blockposUpper);
        
        boolean destroyed = false;
        boolean dropItem = false;
        boolean links = false;
        boolean offen = false;
        EnumFacing facing = null;
        
    	if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.LOWER)
        {
    		if (iblockstateMiddle.getBlock() != this) //Wenn Mitte keine Tür ist
            {
            	if (iblockstateUpper.getBlock() == this) worldIn.setBlockToAir(blockposUpper); //Wenn oberer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos); 
                destroyed = true;
            }
            
            if (iblockstateUpper.getBlock() != this) //Wenn Oben keine Tür ist
            {
            	if (iblockstateMiddle.getBlock() == this) worldIn.setBlockToAir(blockposMiddle); //Wenn mittlerer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos); 
                destroyed = true;
            }

            if (!worldIn.getBlockState(pos.down()).isFullyOpaque()) //wenn drunter kein solider Block ist
            {
                worldIn.setBlockToAir(pos);
                destroyed = true;

                if (iblockstateMiddle.getBlock() == this) worldIn.setBlockToAir(blockposMiddle);//Wenn mittlerer Block Tür => Block entfernen
                if (iblockstateUpper.getBlock() == this) worldIn.setBlockToAir(blockposUpper);//Wenn oberer Block Tür => Block entfernen
                
                dropItem = true;
            }
            
            if (!destroyed)
            {
            	boolean powered = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockposMiddle) || worldIn.isBlockPowered(blockposUpper);
            	
            	if ((powered || neighborBlock.getDefaultState().canProvidePower()) && neighborBlock != this && powered != ((Boolean)iblockstateUpper.getValue(POWERED)).booleanValue())
            	{
            		worldIn.setBlockState(blockposUpper, iblockstateUpper.withProperty(POWERED, Boolean.valueOf(powered)), 2);

                    if (powered != ((Boolean)state.getValue(OPEN)).booleanValue()) this.toggleDoor(worldIn, blockposUpper, iblockstateUpper, (EntityPlayer)null, true);
                }
            }
        }
        else if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.MIDDLE)
        {
        	if (iblockstateLower.getBlock() != this) //Wenn unten keine Tür ist
            {
            	if (iblockstateUpper.getBlock() == this) worldIn.setBlockToAir(blockposUpper); //Wenn oberer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos);
            }
            else if (iblockstateUpper.getBlock() != this) //Wenn oben keine Tür ist
            {
            	worldIn.setBlockToAir(pos);
            }
        	
            else if (!destroyed)
            {
            	boolean powered = worldIn.isBlockPowered(blockposLower) || worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockposUpper);
            	if ((powered || neighborBlock.getDefaultState().canProvidePower()) && neighborBlock != this && powered != ((Boolean)iblockstateUpper.getValue(POWERED)).booleanValue())
                {
                	worldIn.setBlockState(blockposUpper, iblockstateUpper.withProperty(POWERED, Boolean.valueOf(powered)), 2);
                	if (powered != ((Boolean)iblockstateLower.getValue(OPEN)).booleanValue()) this.toggleDoor(worldIn, blockposUpper, iblockstateUpper, (EntityPlayer)null, true);
                }
            }
            
        }
        else //UPPER
        {
        	if (iblockstateLower.getBlock() != this) //Wenn unten keine Tür ist
            {
            	if (iblockstateMiddle.getBlock() == this) worldIn.setBlockToAir(blockposMiddle); //Wenn mittlerer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos);
            }
            else if (iblockstateMiddle.getBlock() != this) //Wenn mitte keine Tür ist
            {
            	if (iblockstateLower.getBlock() == this) worldIn.setBlockToAir(blockposLower); //Wenn unterer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos);
            }
            else if (neighborBlock != this)
            {
                this.neighborChanged(iblockstateMiddle,worldIn, blockposMiddle,  neighborBlock);
                this.neighborChanged(iblockstateLower, worldIn, blockposLower, neighborBlock);
            }
            else if (!destroyed)
            {
                boolean powered = worldIn.isBlockPowered(blockposLower) || worldIn.isBlockPowered(blockposMiddle) || worldIn.isBlockPowered(pos);

                if ((powered || neighborBlock.getDefaultState().canProvidePower()) && neighborBlock != this && powered != ((Boolean)state.getValue(POWERED)).booleanValue())
                {
                    worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(powered)), 2);

                    if (powered != ((Boolean)state.getValue(OPEN)).booleanValue()) this.toggleDoor(worldIn, blockposUpper, iblockstateUpper, (EntityPlayer)null, true);
                }
            }
        }
    	if (!worldIn.isRemote && dropItem) this.dropBlockAsItem(worldIn, pos, state, 0);
    }
    
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.getItem();
    }

    @Override
    public RayTraceResult collisionRayTrace(IBlockState state, World worldIn, BlockPos pos, Vec3d start, Vec3d end)
    {
    	this.getBoundingBox(state, worldIn, pos);
        return super.collisionRayTrace(state, worldIn, pos, start, end);
    }

    @Override
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return pos.getY() >= worldIn.getHeight() - 1 ? false : worldIn.getBlockState(pos.down()).isSideSolid(worldIn,  pos.down(), EnumFacing.UP) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up()) && super.canPlaceBlockAt(worldIn, pos.up(2));
    }

    @Override
    public EnumPushReaction getMobilityFlag(IBlockState state)
    {
        return EnumPushReaction.DESTROY;
    }

    public static int combineMetadata(IBlockAccess worldIn, BlockPos pos)
    {
    	int combinedMeta = 0;
        IBlockState iblockstate = worldIn.getBlockState(pos);
        int metaThis = iblockstate.getBlock().getMetaFromState(iblockstate);
        int metaLower = 0;
        int metaMiddle = 0;
        int metaUpper = 0;
        if ((metaThis &  == 0) //unterer Teil
        {
        	metaLower = metaThis;
        	IBlockState iblockstateMiddle = worldIn.getBlockState(pos.up());
        	metaMiddle = iblockstateMiddle.getBlock().getMetaFromState(iblockstateMiddle);
        	IBlockState iblockstateUpper = worldIn.getBlockState(pos.up(2));
        	metaUpper = iblockstateUpper.getBlock().getMetaFromState(iblockstateUpper);
        }
        else if ((metaThis & 4) == 0)
        {
        	metaMiddle = metaThis;
        	IBlockState iblockstateLower = worldIn.getBlockState(pos.down());
        	metaLower = iblockstateLower.getBlock().getMetaFromState(iblockstateLower);
        	IBlockState iblockstateUpper = worldIn.getBlockState(pos.up());
        	metaUpper = iblockstateUpper.getBlock().getMetaFromState(iblockstateUpper);
        }
        else
        {
        	metaUpper = metaThis;
        	IBlockState iblockstateLower = worldIn.getBlockState(pos.down(2));
        	metaLower = iblockstateLower.getBlock().getMetaFromState(iblockstateLower);
        	IBlockState iblockstateMiddle = worldIn.getBlockState(pos.down());
        	metaMiddle = iblockstateMiddle.getBlock().getMetaFromState(iblockstateMiddle);
        }
        
        int facing = (metaLower & 3);
        boolean open = (metaLower & 4) != 0;
        boolean upperHalf = (metaThis &  != 0;
        boolean middle = (metaThis &  != 0 && (metaThis & 4) == 0;
        boolean right = (metaMiddle & 1) != 0;
        boolean power = (metaUpper & 1) != 0;
        
        combinedMeta = facing | (open ? 4 : 0) | (upperHalf ? 8 : 0) | (middle ? 16 : 0) | (right ? 32 : 0) | (power ? 64 : 0);// | (distal ? 128 : 0);
        
        return combinedMeta;
    }

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

    private Item getItem()
    {
    	Item item;
    	if (getDoorMaterial().equals("oak")) item = RoxaTallDoorsMod.itemDoorOneByThreeOak;
    	else if (getDoorMaterial().equals("birch")) item = RoxaTallDoorsMod.itemDoorOneByThreeBirch;
    	else if (getDoorMaterial().equals("spruce")) item = RoxaTallDoorsMod.itemDoorOneByThreeSpruce;
    	else if (getDoorMaterial().equals("jungle")) item = RoxaTallDoorsMod.itemDoorOneByThreeJungle;
    	else if (getDoorMaterial().equals("acacia")) item = RoxaTallDoorsMod.itemDoorOneByThreeAcacia;
    	else if (getDoorMaterial().equals("darkOak")) item = RoxaTallDoorsMod.itemDoorOneByThreeDarkOak;
    	else item = RoxaTallDoorsMod.itemDoorOneByThreeIron;    	
        return item;
    }
    
    @Override
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
    {
        BlockPos blockposDown = pos.down();
        BlockPos blockposDown2 = pos.down(2);
        BlockPos blockposUp = pos.up();
        BlockPos blockposUp2 = pos.up(2);

        if (player.capabilities.isCreativeMode)
        {
        	if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.UPPER)
        	{
        		if(worldIn.getBlockState(blockposDown2).getBlock() == this) worldIn.setBlockToAir(blockposDown2);
        		if(worldIn.getBlockState(blockposDown).getBlock() == this) worldIn.setBlockToAir(blockposDown);
        	}
        	
        	if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.MIDDLE)
        	{
        		if(worldIn.getBlockState(blockposDown).getBlock() == this) worldIn.setBlockToAir(blockposDown);
        		if(worldIn.getBlockState(blockposUp).getBlock() == this) worldIn.setBlockToAir(blockposUp);
        	}
        	if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.LOWER)
        	{
        		if(worldIn.getBlockState(blockposUp).getBlock() == this) worldIn.setBlockToAir(blockposUp);
        		if(worldIn.getBlockState(blockposUp2).getBlock() == this) worldIn.setBlockToAir(blockposUp2);
        	}
        }
    }
    
    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        IBlockState iblockstateLower;
        IBlockState iblockstateMiddle;
        IBlockState iblockstateUpper;

        if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.LOWER)
        {
        	iblockstateMiddle = worldIn.getBlockState(pos.up());
        	iblockstateUpper = worldIn.getBlockState(pos.up(2));
            
            if (iblockstateMiddle.getBlock() == this)
            {
                state = state.withProperty(HINGE, iblockstateMiddle.getValue(HINGE));
                //state = state.withProperty(DISTAL, iblockstateMiddle.getValue(DISTAL));
            }
            if (iblockstateUpper.getBlock() == this)
            {
                state = state.withProperty(POWERED, iblockstateUpper.getValue(POWERED));
            }
        }
        else if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.MIDDLE)
        {
        	iblockstateUpper = worldIn.getBlockState(pos.up());
        	iblockstateLower = worldIn.getBlockState(pos.down());
        	
            if (iblockstateLower.getBlock() == this)
            {
                state = state.withProperty(OPEN, iblockstateLower.getValue(OPEN));
                state = state.withProperty(FACING, iblockstateLower.getValue(FACING));
            }
            if (iblockstateUpper.getBlock() == this)
            {
                state = state.withProperty(POWERED, iblockstateUpper.getValue(POWERED));
            }
        }
        else //HALF == UPPER
        {
        	iblockstateMiddle = worldIn.getBlockState(pos.down());
        	iblockstateLower = worldIn.getBlockState(pos.down(2));
        	
            if (iblockstateLower.getBlock() == this)
            {
                state = state.withProperty(OPEN, iblockstateLower.getValue(OPEN));
                state = state.withProperty(FACING, iblockstateLower.getValue(FACING));
            }
            if (iblockstateMiddle.getBlock() == this)
            {
                state = state.withProperty(HINGE, iblockstateMiddle.getValue(HINGE));
                //state = state.withProperty(DISTAL, iblockstateMiddle.getValue(DISTAL));
            }
        }

        return state;
    }
    
    public IBlockState getStateFromCombinedMeta(int combinedMeta)
    {
    	IBlockState state = this.getDefaultState();
    	
        state.withProperty(FACING, EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW());
        state.withProperty(OPEN, Boolean.valueOf((combinedMeta & 4) > 0));
        if ((combinedMeta &  == 0 && (combinedMeta & 16) == 0) state.withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.LOWER);
        //if ((combinedMeta &  == 0 && (combinedMeta & 16) != 0) state.withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.LOWERMIDDLE);
        if ((combinedMeta &  != 0 && (combinedMeta & 16) == 0) state.withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.UPPER);
        if ((combinedMeta &  != 0 && (combinedMeta & 16) != 0) state.withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.MIDDLE);//UPPERMIDDLE
        state.withProperty(HINGE, ((combinedMeta & 32) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT));
        state.withProperty(POWERED, Boolean.valueOf((combinedMeta & 64) > 0));
        //state.withProperty(DISTAL, Boolean.valueOf((combinedMeta & 128) > 0));
        
        return state;
    }
    
    @Override
    public IBlockState getStateFromMeta(int meta)
    {
    	IBlockState state = this.getDefaultState();
    	
        if ((meta &  == 0) //Unten
        {
        	state.withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.LOWER);
        	state.withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW());
        	state.withProperty(OPEN, Boolean.valueOf((meta & 4) > 0));
        }
        else //Oberer Teil
        {
        	if ((meta & 4) == 0) //Mitte
        	{
        		state.withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.MIDDLE);
        		state.withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT);
        		//state.withProperty(DISTAL, Boolean.valueOf((meta & 2) > 0));
        	}
        	else //Oben
        	{
        		//Bei 4 hohen Rüren kommt hier noch die Unterscheidung zw. UPPER und UPPERMIDDLE
        		state.withProperty(HALF, BlockDoorOneByThree.EnumDoorHalf.UPPER);
        		state.withProperty(POWERED, Boolean.valueOf((meta & 1) > 0));
        	}
        }
        return state;
    }
    
    @SideOnly(Side.CLIENT)
    @Override
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i;

        if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.LOWER)
        {
            i = b0 | ((EnumFacing)state.getValue(FACING)).rotateY().getHorizontalIndex();

            if (((Boolean)state.getValue(OPEN)).booleanValue())
            {
                i |= 4;
            }
        }
        else
        {
        	i = b0 | 8;
        	if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.MIDDLE)
            {
        		/*if (((Boolean)state.getValue(DISTAL)).booleanValue())
                {
                    i |= 2;
                }*/
                if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT)
                {
                    i |= 1;
                }
            }
        	else
        	{
        		i |= 4;
        		/* Noch Freie Variable
                if (((Boolean)state.getValue(FREI)).booleanValue())
                {
                    i |= 2;
                }
                */
        		if (((Boolean)state.getValue(POWERED)).booleanValue())
                {
                    i |= 1;
                }
        	}
        }

        return i;
    }

    public static boolean isOpen(IBlockAccess worldIn, BlockPos pos)
    {
        return isOpen(combineMetadata(worldIn, pos));
    }

    protected static boolean isOpen(int combinedMeta)
    {
        return (combinedMeta & 4) != 0;
    }

    public static EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos)
    {
        return getFacing(combineMetadata(worldIn, pos));
    }

    public static EnumFacing getFacing(int combinedMeta)
    {
        return EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW();
    }

    protected static boolean isLower(int meta)
    {
        return (meta &  == 0;
    }

    protected static boolean isHingeLeft(int combinedMeta)
    {
        return (combinedMeta & 32) != 0;
    }

    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {HALF, FACING, OPEN, HINGE, POWERED});
    }

    public static enum EnumDoorHalf implements IStringSerializable
    {
        UPPER,
        MIDDLE,
        LOWER;
        
        public String toString()
        {
            return this.getName();
        }

        public String getName()
        {
        	String name;
        	if (this == UPPER) name = "upper";
        	else if (this == MIDDLE) name = "middle";
        	else name = "lower";
            return name;
        }
    }
    
    public String getDoorMaterial()
    {
    	String material;
    	if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeOak")) material = "oak";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeBirch")) material = "birch";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeSpruce")) material = "spruce";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeJungle")) material = "jungle";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeAcacia")) material = "acacia";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeDarkOak")) material = "darkOak";
    	else material = "iron";
    	
    	return material;
    }
    
    private net.minecraft.util.SoundEvent getSoundClose()
    {
        return this.blockMaterial == Material.IRON ? SoundEvents.BLOCK_IRON_DOOR_CLOSE : SoundEvents.BLOCK_WOODEN_DOOR_CLOSE;
    }
    
    private net.minecraft.util.SoundEvent getSoundOpen()
    {
        return this.blockMaterial == Material.IRON ? SoundEvents.BLOCK_IRON_DOOR_OPEN : SoundEvents.BLOCK_WOODEN_DOOR_OPEN;
    }
}

 

This is the BlockDoorOneByThree.java where I copied my code fragments into the vanilla door:

 

package net.roxa.tallDoors;

import java.util.Random;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockDoorOneByThreeCopiedIntoVanillaDoor extends Block
{
    public static final PropertyDirection FACING = BlockHorizontal.FACING;
    public static final PropertyBool OPEN = PropertyBool.create("open");
    public static final PropertyEnum<BlockDoor.EnumHingePosition> HINGE = PropertyEnum.<BlockDoor.EnumHingePosition>create("hinge", BlockDoor.EnumHingePosition.class);
    public static final PropertyBool POWERED = PropertyBool.create("powered");
    public static final PropertyEnum<BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf> HALF = PropertyEnum.<BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf>create("half", BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.class);
    protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.1875D);
    protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.8125D, 1.0D, 1.0D, 1.0D);
    protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.8125D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
    protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.1875D, 1.0D, 1.0D);

    protected BlockDoorOneByThreeCopiedIntoVanillaDoor(Material materialIn, String material)
    {
        super(materialIn);
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER));
        this.setHardness(2.0F);
    	this.setResistance(1F);
    	if (material.equals("oak")) this.setUnlocalizedName("blockDoorOneByThreeOak");
    	else if (material.equals("birch")) this.setUnlocalizedName("blockDoorOneByThreeBirch");
    	else if (material.equals("spruce")) this.setUnlocalizedName("blockDoorOneByThreeSpruce");
    	else if (material.equals("jungle")) this.setUnlocalizedName("blockDoorOneByThreeJungle");
    	else if (material.equals("acacia")) this.setUnlocalizedName("blockDoorOneByThreeAcacia");
    	else if (material.equals("darkOak")) this.setUnlocalizedName("blockDoorOneByThreeDarkOak");
    	else this.setUnlocalizedName("blockDoorOneByThreeIron");
        if (material.equals("oak")) this.setRegistryName("blockDoorOneByThreeOak");
    	else if (material.equals("birch")) this.setRegistryName("blockDoorOneByThreeBirch");
    	else if (material.equals("spruce")) this.setRegistryName("blockDoorOneByThreeSpruce");
    	else if (material.equals("jungle")) this.setRegistryName("blockDoorOneByThreeJungle");
    	else if (material.equals("acacia")) this.setRegistryName("blockDoorOneByThreeAcacia");
    	else if (material.equals("darkOak")) this.setRegistryName("blockDoorOneByThreeDarkOak");
    	else this.setRegistryName("blockDoorOneByThreeIron");
        if(this.getDoorMaterial().equals("iron")) this.setSoundType(SoundType.METAL);
    	else this.setSoundType(SoundType.WOOD);
    }
    
    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        state = state.getActualState(source, pos);
        EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
        boolean flag = !((Boolean)state.getValue(OPEN)).booleanValue();
        boolean flag1 = state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT;

        switch (enumfacing)
        {
            case EAST:
            default:
                return flag ? EAST_AABB : (flag1 ? NORTH_AABB : SOUTH_AABB);
            case SOUTH:
                return flag ? SOUTH_AABB : (flag1 ? EAST_AABB : WEST_AABB);
            case WEST:
                return flag ? WEST_AABB : (flag1 ? SOUTH_AABB : NORTH_AABB);
            case NORTH:
                return flag ? NORTH_AABB : (flag1 ? WEST_AABB : EAST_AABB);
        }
    }

    /**
     * Gets the localized name of this block. Used for the statistics page.
     */
    @Override
    public String getLocalizedName()
    {
        return I18n.translateToLocal((this.getUnlocalizedName() + ".name").replaceAll("tile", "item"));
    }

    /**
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
     */
    @Override
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
    
    @Override
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
    {
        return isOpen(combineMetadata(worldIn, pos));
    }
    
    @Override
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
    private int getCloseSound()
    {
        return this.blockMaterial == Material.IRON ? 1011 : 1012;
    }

    private int getOpenSound()
    {
        return this.blockMaterial == Material.IRON ? 1005 : 1006;
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    @Override
    public MapColor getMapColor(IBlockState state)
    {
    	String material = this.getDoorMaterial();
        return material.equals("iron") ? MapColor.IRON : (material.equals("oak") ? BlockPlanks.EnumType.OAK.getMapColor() : (material.equals("spruce") ? BlockPlanks.EnumType.SPRUCE.getMapColor() : (material.equals("birch") ? BlockPlanks.EnumType.BIRCH.getMapColor() : (material.equals("jungle") ? BlockPlanks.EnumType.JUNGLE.getMapColor() : (material.equals("acacia") ? BlockPlanks.EnumType.ACACIA.getMapColor() : (material.equals("darkOak") ? BlockPlanks.EnumType.DARK_OAK.getMapColor() : super.getMapColor(state)))))));
    }
    
    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
    	/* Original Door 1.10
        if (this.blockMaterial == Material.IRON)
        {
            return false; //Allow items to interact with the door
        }
        else
        {
            BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
            IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);

            if (iblockstate.getBlock() != this)
            {
                return false;
            }
            else
            {
                state = iblockstate.cycleProperty(OPEN);
                worldIn.setBlockState(blockpos, state, 10);
                worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
                worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getOpenSound() : this.getCloseSound(), pos, 0);
                return true;
            }
        }*/
    	return this.toggleDoor(worldIn, pos, state, playerIn, false);
    }
    
    public boolean toggleDoor(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, boolean powered)
    {
    	/* Original Door 1.10
    	public void toggleDoor(World worldIn, BlockPos pos, boolean open){
        IBlockState iblockstate = worldIn.getBlockState(pos);

        if (iblockstate.getBlock() == this)
        {
            BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
            IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);

            if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open)
            {
                worldIn.setBlockState(blockpos, iblockstate1.withProperty(OPEN, Boolean.valueOf(open)), 10);
                worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
                worldIn.playEvent((EntityPlayer)null, open ? this.getOpenSound() : this.getCloseSound(), pos, 0);
            }
        }
        */
    	boolean returnValue = false;
    	/*
    	if (this.blockMaterial == Material.iron && powered == false)
        {
            return returnValue; //Allow items to interact with the door
        }
        */
        if (this.blockMaterial != Material.IRON || powered)
        {
        	boolean openNew;
        	IBlockState fullState = this.getActualState(state, worldIn, pos);
            BlockPos blockposLower;
            if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER) blockposLower = pos;
            else if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.MIDDLE) blockposLower = pos.down();
            else blockposLower = pos.down(2);
            
            IBlockState stateLower = pos.equals(blockposLower) ? state : worldIn.getBlockState(blockposLower);
            
            if (stateLower.getBlock() == this)
            {
            	openNew = (Boolean)stateLower.getValue(OPEN);
                openNew = openNew ? false : true;
                
            	worldIn.setBlockState(blockposLower, stateLower.withProperty(OPEN, openNew), 2);
    			worldIn.markBlockRangeForRenderUpdate(blockposLower, pos);
                //worldIn.playAuxSFXAtEntity(playerIn, 1003, pos, 0);
    			//worldIn.playAuxSFXAtEntity(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getSoundOpen() : this.getSoundOpen(), pos, 0);
    			//worldIn.playSound(playerIn, (double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getSoundOpen() : this.getSoundOpen(), SoundCategory.BLOCKS, 1.0F, 1.0F);
    			worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getOpenSound() : this.getCloseSound(), pos, 0);
    			returnValue = true;
            }
        }
        return returnValue;
    }

    /**
     * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
     * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
     * block, etc.
     */
    @Override
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block neighborBlock)
    {
    	/*Original Door 1.10.2
        if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
        {
            BlockPos blockpos = pos.down();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getBlock() != this)
            {
                worldIn.setBlockToAir(pos);
            }
            else if (blockIn != this)
            {
                iblockstate.neighborChanged(worldIn, blockpos, blockIn);
            }
        }
        else
        {
            boolean flag1 = false;
            BlockPos blockpos1 = pos.up();
            IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);

            if (iblockstate1.getBlock() != this)
            {
                worldIn.setBlockToAir(pos);
                flag1 = true;
            }

            if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn,  pos.down(), EnumFacing.UP))
            {
                worldIn.setBlockToAir(pos);
                flag1 = true;

                if (iblockstate1.getBlock() == this)
                {
                    worldIn.setBlockToAir(blockpos1);
                }
            }

            if (flag1)
            {
                if (!worldIn.isRemote)
                {
                    this.dropBlockAsItem(worldIn, pos, state, 0);
                }
            }
            else
            {
                boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);

                if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue())
                {
                    worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);

                    if (flag != ((Boolean)state.getValue(OPEN)).booleanValue())
                    {
                        worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
                        worldIn.markBlockRangeForRenderUpdate(pos, pos);
                        worldIn.playEvent((EntityPlayer)null, flag ? this.getOpenSound() : this.getCloseSound(), pos, 0);
                    }
                }
            }
        }
        */
    	BlockPos blockposLower = pos;
    	BlockPos blockposMiddle = pos;
        BlockPos blockposUpper = pos;
        
        if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER)
        {
        	blockposMiddle = pos.up();
        	blockposUpper = pos.up(2);
        }
        else if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.MIDDLE)
        {
        	blockposLower = pos.down();
        	blockposUpper = pos.up();
        }
        else
        {
        	blockposLower = pos.down(2);
        	blockposMiddle = pos.down();
        }
        
        IBlockState iblockstateLower = worldIn.getBlockState(blockposLower);
        IBlockState iblockstateMiddle = worldIn.getBlockState(blockposMiddle);
        IBlockState iblockstateUpper = worldIn.getBlockState(blockposUpper);
        
        boolean destroyed = false;
        boolean dropItem = false;
        boolean links = false;
        boolean offen = false;
        EnumFacing facing = null;
        
    	if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER)
        {
    		if (iblockstateMiddle.getBlock() != this) //Wenn Mitte keine Tür ist
            {
            	if (iblockstateUpper.getBlock() == this) worldIn.setBlockToAir(blockposUpper); //Wenn oberer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos); 
                destroyed = true;
            }
            
            if (iblockstateUpper.getBlock() != this) //Wenn Oben keine Tür ist
            {
            	if (iblockstateMiddle.getBlock() == this) worldIn.setBlockToAir(blockposMiddle); //Wenn mittlerer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos); 
                destroyed = true;
            }

            if (!worldIn.getBlockState(pos.down()).isFullyOpaque()) //wenn drunter kein solider Block ist
            {
                worldIn.setBlockToAir(pos);
                destroyed = true;

                if (iblockstateMiddle.getBlock() == this) worldIn.setBlockToAir(blockposMiddle);//Wenn mittlerer Block Tür => Block entfernen
                if (iblockstateUpper.getBlock() == this) worldIn.setBlockToAir(blockposUpper);//Wenn oberer Block Tür => Block entfernen
                
                dropItem = true;
            }
            
            if (!destroyed)
            {
            	boolean powered = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockposMiddle) || worldIn.isBlockPowered(blockposUpper);
            	
            	if ((powered || neighborBlock.getDefaultState().canProvidePower()) && neighborBlock != this && powered != ((Boolean)iblockstateUpper.getValue(POWERED)).booleanValue())
            	{
            		worldIn.setBlockState(blockposUpper, iblockstateUpper.withProperty(POWERED, Boolean.valueOf(powered)), 2);

                    if (powered != ((Boolean)state.getValue(OPEN)).booleanValue()) this.toggleDoor(worldIn, blockposUpper, iblockstateUpper, (EntityPlayer)null, true);
                }
            }
        }
        else if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.MIDDLE)
        {
        	if (iblockstateLower.getBlock() != this) //Wenn unten keine Tür ist
            {
            	if (iblockstateUpper.getBlock() == this) worldIn.setBlockToAir(blockposUpper); //Wenn oberer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos);
            }
            else if (iblockstateUpper.getBlock() != this) //Wenn oben keine Tür ist
            {
            	worldIn.setBlockToAir(pos);
            }
        	
            else if (!destroyed)
            {
            	boolean powered = worldIn.isBlockPowered(blockposLower) || worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockposUpper);
            	if ((powered || neighborBlock.getDefaultState().canProvidePower()) && neighborBlock != this && powered != ((Boolean)iblockstateUpper.getValue(POWERED)).booleanValue())
                {
                	worldIn.setBlockState(blockposUpper, iblockstateUpper.withProperty(POWERED, Boolean.valueOf(powered)), 2);
                	if (powered != ((Boolean)iblockstateLower.getValue(OPEN)).booleanValue()) this.toggleDoor(worldIn, blockposUpper, iblockstateUpper, (EntityPlayer)null, true);
                }
            }
            
        }
        else //UPPER
        {
        	if (iblockstateLower.getBlock() != this) //Wenn unten keine Tür ist
            {
            	if (iblockstateMiddle.getBlock() == this) worldIn.setBlockToAir(blockposMiddle); //Wenn mittlerer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos);
            }
            else if (iblockstateMiddle.getBlock() != this) //Wenn mitte keine Tür ist
            {
            	if (iblockstateLower.getBlock() == this) worldIn.setBlockToAir(blockposLower); //Wenn unterer Block Tür => Block entfernen
                worldIn.setBlockToAir(pos);
            }
            else if (neighborBlock != this)
            {
                this.neighborChanged(iblockstateMiddle,worldIn, blockposMiddle,  neighborBlock);
                this.neighborChanged(iblockstateLower, worldIn, blockposLower, neighborBlock);
            }
            else if (!destroyed)
            {
                boolean powered = worldIn.isBlockPowered(blockposLower) || worldIn.isBlockPowered(blockposMiddle) || worldIn.isBlockPowered(pos);

                if ((powered || neighborBlock.getDefaultState().canProvidePower()) && neighborBlock != this && powered != ((Boolean)state.getValue(POWERED)).booleanValue())
                {
                    worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(powered)), 2);

                    if (powered != ((Boolean)state.getValue(OPEN)).booleanValue()) this.toggleDoor(worldIn, blockposUpper, iblockstateUpper, (EntityPlayer)null, true);
                }
            }
        }
    	if (!worldIn.isRemote && dropItem) this.dropBlockAsItem(worldIn, pos, state, 0);
    }

    /**
     * Get the Item that this Block should drop when harvested.
     */
    @Nullable
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return this.getItem();
    }
    
    @Override
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
    	return pos.getY() >= worldIn.getHeight() - 1 ? false : worldIn.getBlockState(pos.down()).isSideSolid(worldIn,  pos.down(), EnumFacing.UP) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up()) && super.canPlaceBlockAt(worldIn, pos.up(2));
    }
    
    @Override
    public EnumPushReaction getMobilityFlag(IBlockState state)
    {
        return EnumPushReaction.DESTROY;
    }
    
    public static int combineMetadata(IBlockAccess worldIn, BlockPos pos)
    {
    	/*Original Door 1.10
        IBlockState iblockstate = worldIn.getBlockState(pos);
        int i = iblockstate.getBlock().getMetaFromState(iblockstate);
        boolean flag = isTop(i);
        IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
        int j = iblockstate1.getBlock().getMetaFromState(iblockstate1);
        int k = flag ? j : i;
        IBlockState iblockstate2 = worldIn.getBlockState(pos.up());
        int l = iblockstate2.getBlock().getMetaFromState(iblockstate2);
        int i1 = flag ? i : l;
        boolean flag1 = (i1 & 1) != 0;
        boolean flag2 = (i1 & 2) != 0;
        return removeHalfBit(k) | (flag ? 8 : 0) | (flag1 ? 16 : 0) | (flag2 ? 32 : 0);
        */
    	int combinedMeta = 0;
        IBlockState iblockstate = worldIn.getBlockState(pos);
        int metaThis = iblockstate.getBlock().getMetaFromState(iblockstate);
        int metaLower = 0;
        int metaMiddle = 0;
        int metaUpper = 0;
        if ((metaThis &  == 0) //unterer Teil
        {
        	metaLower = metaThis;
        	IBlockState iblockstateMiddle = worldIn.getBlockState(pos.up());
        	metaMiddle = iblockstateMiddle.getBlock().getMetaFromState(iblockstateMiddle);
        	IBlockState iblockstateUpper = worldIn.getBlockState(pos.up(2));
        	metaUpper = iblockstateUpper.getBlock().getMetaFromState(iblockstateUpper);
        }
        else if ((metaThis & 4) == 0)
        {
        	metaMiddle = metaThis;
        	IBlockState iblockstateLower = worldIn.getBlockState(pos.down());
        	metaLower = iblockstateLower.getBlock().getMetaFromState(iblockstateLower);
        	IBlockState iblockstateUpper = worldIn.getBlockState(pos.up());
        	metaUpper = iblockstateUpper.getBlock().getMetaFromState(iblockstateUpper);
        }
        else
        {
        	metaUpper = metaThis;
        	IBlockState iblockstateLower = worldIn.getBlockState(pos.down(2));
        	metaLower = iblockstateLower.getBlock().getMetaFromState(iblockstateLower);
        	IBlockState iblockstateMiddle = worldIn.getBlockState(pos.down());
        	metaMiddle = iblockstateMiddle.getBlock().getMetaFromState(iblockstateMiddle);
        }
        
        int facing = (metaLower & 3);
        boolean open = (metaLower & 4) != 0;
        boolean upperHalf = (metaThis &  != 0;
        boolean middle = (metaThis &  != 0 && (metaThis & 4) == 0;
        boolean right = (metaMiddle & 1) != 0;
        boolean power = (metaUpper & 1) != 0;
        
        combinedMeta = facing | (open ? 4 : 0) | (upperHalf ? 8 : 0) | (middle ? 16 : 0) | (right ? 32 : 0) | (power ? 64 : 0);// | (distal ? 128 : 0);
        
        return combinedMeta;
    }
    
    @Override
    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(this.getItem());
    }
    
    private Item getItem()
    {
    	Item item;
    	if (getDoorMaterial().equals("oak")) item = RoxaTallDoorsMod.itemDoorOneByThreeOak;
    	else if (getDoorMaterial().equals("birch")) item = RoxaTallDoorsMod.itemDoorOneByThreeBirch;
    	else if (getDoorMaterial().equals("spruce")) item = RoxaTallDoorsMod.itemDoorOneByThreeSpruce;
    	else if (getDoorMaterial().equals("jungle")) item = RoxaTallDoorsMod.itemDoorOneByThreeJungle;
    	else if (getDoorMaterial().equals("acacia")) item = RoxaTallDoorsMod.itemDoorOneByThreeAcacia;
    	else if (getDoorMaterial().equals("darkOak")) item = RoxaTallDoorsMod.itemDoorOneByThreeDarkOak;
    	else item = RoxaTallDoorsMod.itemDoorOneByThreeIron;    	
        return item;
    }
    
    @Override
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
    {
    	BlockPos blockposDown = pos.down();
        BlockPos blockposDown2 = pos.down(2);
        BlockPos blockposUp = pos.up();
        BlockPos blockposUp2 = pos.up(2);

        if (player.capabilities.isCreativeMode)
        {
        	if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.UPPER)
        	{
        		if(worldIn.getBlockState(blockposDown2).getBlock() == this) worldIn.setBlockToAir(blockposDown2);
        		if(worldIn.getBlockState(blockposDown).getBlock() == this) worldIn.setBlockToAir(blockposDown);
        	}
        	
        	if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.MIDDLE)
        	{
        		if(worldIn.getBlockState(blockposDown).getBlock() == this) worldIn.setBlockToAir(blockposDown);
        		if(worldIn.getBlockState(blockposUp).getBlock() == this) worldIn.setBlockToAir(blockposUp);
        	}
        	if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER)
        	{
        		if(worldIn.getBlockState(blockposUp).getBlock() == this) worldIn.setBlockToAir(blockposUp);
        		if(worldIn.getBlockState(blockposUp2).getBlock() == this) worldIn.setBlockToAir(blockposUp2);
        	}
        }
    }

    @SideOnly(Side.CLIENT)
    @Override
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }

    /**
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
     * metadata, such as fence connections.
     */
    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
    	IBlockState iblockstateLower;
        IBlockState iblockstateMiddle;
        IBlockState iblockstateUpper;

        if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER)
        {
        	iblockstateMiddle = worldIn.getBlockState(pos.up());
        	iblockstateUpper = worldIn.getBlockState(pos.up(2));
            
            if (iblockstateMiddle.getBlock() == this)
            {
                state = state.withProperty(HINGE, iblockstateMiddle.getValue(HINGE));
                //state = state.withProperty(DISTAL, iblockstateMiddle.getValue(DISTAL));
            }
            if (iblockstateUpper.getBlock() == this)
            {
                state = state.withProperty(POWERED, iblockstateUpper.getValue(POWERED));
            }
        }
        else if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.MIDDLE)
        {
        	iblockstateUpper = worldIn.getBlockState(pos.up());
        	iblockstateLower = worldIn.getBlockState(pos.down());
        	
            if (iblockstateLower.getBlock() == this)
            {
                state = state.withProperty(OPEN, iblockstateLower.getValue(OPEN));
                state = state.withProperty(FACING, iblockstateLower.getValue(FACING));
            }
            if (iblockstateUpper.getBlock() == this)
            {
                state = state.withProperty(POWERED, iblockstateUpper.getValue(POWERED));
            }
        }
        else //HALF == UPPER
        {
        	iblockstateMiddle = worldIn.getBlockState(pos.down());
        	iblockstateLower = worldIn.getBlockState(pos.down(2));
        	
            if (iblockstateLower.getBlock() == this)
            {
                state = state.withProperty(OPEN, iblockstateLower.getValue(OPEN));
                state = state.withProperty(FACING, iblockstateLower.getValue(FACING));
            }
            if (iblockstateMiddle.getBlock() == this)
            {
                state = state.withProperty(HINGE, iblockstateMiddle.getValue(HINGE));
                //state = state.withProperty(DISTAL, iblockstateMiddle.getValue(DISTAL));
            }
        }

        return state;
    }

    /**
     * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    //TODO Versteh ich noch nicht ganz...
    @Override
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.getValue(HALF) != BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER ? state : state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }

    /**
     * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    @Override
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
    {
        return mirrorIn == Mirror.NONE ? state : state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING))).cycleProperty(HINGE);
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    @Override
    public IBlockState getStateFromMeta(int meta)
    {
IBlockState state = this.getDefaultState();
    	
        if ((meta &  == 0) //Unten
        {
        	state.withProperty(HALF, BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.LOWER);
        	state.withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW());
        	state.withProperty(OPEN, Boolean.valueOf((meta & 4) > 0));
        }
        else //Oberer Teil
        {
        	if ((meta & 4) == 0) //Mitte
        	{
        		state.withProperty(HALF, BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.MIDDLE);
        		state.withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT);
        		//state.withProperty(DISTAL, Boolean.valueOf((meta & 2) > 0));
        	}
        	else //Oben
        	{
        		//Bei 4 hohen Rüren kommt hier noch die Unterscheidung zw. UPPER und UPPERMIDDLE
        		state.withProperty(HALF, BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.UPPER);
        		state.withProperty(POWERED, Boolean.valueOf((meta & 1) > 0));
        	}
        }
        return state;
    }

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

        if (state.getValue(HALF) == BlockDoorOneByThreeCopiedIntoVanillaDoor.EnumDoorHalf.UPPER)
        {
            i = i | 8;

            if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT)
            {
                i |= 1;
            }

            if (((Boolean)state.getValue(POWERED)).booleanValue())
            {
                i |= 2;
            }
        }
        else
        {
            i = i | ((EnumFacing)state.getValue(FACING)).rotateY().getHorizontalIndex();

            if (((Boolean)state.getValue(OPEN)).booleanValue())
            {
                i |= 4;
            }
        }

        return i;
    }

    protected static int removeHalfBit(int meta)
    {
        return meta & 7;
    }

    public static boolean isOpen(IBlockAccess worldIn, BlockPos pos)
    {
        return isOpen(combineMetadata(worldIn, pos));
    }

    public static EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos)
    {
        return getFacing(combineMetadata(worldIn, pos));
    }

    public static EnumFacing getFacing(int combinedMeta)
    {
        return EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW();
    }

    protected static boolean isOpen(int combinedMeta)
    {
        return (combinedMeta & 4) != 0;
    }

    protected static boolean isTop(int meta)
    {
        return (meta &  != 0;
    }
    
    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {HALF, FACING, OPEN, HINGE, POWERED});
    }

    public static enum EnumDoorHalf implements IStringSerializable
    {
        UPPER,
        MIDDLE,
        LOWER;
        
        public String toString()
        {
            return this.getName();
        }

        public String getName()
        {
        	String name;
        	if (this == UPPER) name = "upper";
        	else if (this == MIDDLE) name = "middle";
        	else name = "lower";
            return name;
        }
    }
    
    public String getDoorMaterial()
    {
    	String material;
    	if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeOak")) material = "oak";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeBirch")) material = "birch";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeSpruce")) material = "spruce";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeJungle")) material = "jungle";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeAcacia")) material = "acacia";
    	else if (this.getUnlocalizedName().substring(5).equals("blockDoorOneByThreeDarkOak")) material = "darkOak";
    	else material = "iron";
    	
    	return material;
    }
}

 

 

The whole code can be found here:

GitHub Repo

Posted

I assume the following properties have the following amount of possibilities:

- HALF: 3 possibilities (lower, middle and upper)

- FACING: 4 possibilities (north, south, east, west)

- OPEN: 2 possibilities (open or closed)

 

This makes for a total of 3x4x2=24 possibilities you can have. Now, metadata can only have 16 different values (0-15), which is not enough to store the 24 possibilities you have. You probably want to use a

TileEntity

for your blocks.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

I assume the following properties have the following amount of possibilities:

- HALF: 3 possibilities (lower, middle and upper)

- FACING: 4 possibilities (north, south, east, west)

- OPEN: 2 possibilities (open or closed)

 

This makes for a total of 3x4x2=24 possibilities you can have. Now, metadata can only have 16 different values (0-15), which is not enough to store the 24 possibilities you have. You probably want to use a

TileEntity

for your blocks.

That's why I store some of the data in the upper part, some of the data in the middle part and the rest of the data in the lower part. Each part knows its height/position and fetches the things it doesn't store itself from the other parts. Just as vanilla doors do (they have HALF, FACING, HINGE and OPEN resulting in 32 possibilities). That worked fine in the 1.9 version and works on vanilla doors, so that's not the cause of the problem.

Posted

I assume the following properties have the following amount of possibilities:

- HALF: 3 possibilities (lower, middle and upper)

- FACING: 4 possibilities (north, south, east, west)

- OPEN: 2 possibilities (open or closed)

 

This makes for a total of 3x4x2=24 possibilities you can have. Now, metadata can only have 16 different values (0-15), which is not enough to store the 24 possibilities you have. You probably want to use a

TileEntity

for your blocks.

That's why I store some of the data in the upper part, some of the data in the middle part and the rest of the data in the lower part. Each part knows its height/position and fetches the things it doesn't store itself from the other parts. Just as vanilla doors do (they have HALF, FACING, HINGE and OPEN resulting in 32 possibilities). That worked fine in the 1.9 version and works on vanilla doors, so that's not the cause of the problem.

Ok but vanilla doors only have two halfs 2 * 4 (the facing) * 2 (open or closed) = 16 which is the exact number for metadata. How ever yours would have more than thirteen so i would make three different blocks one for each part of the door atleast for your 1 by 3 door otherwise you will need a TileEntity.

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.

Posted

No, the metadata IN WHOLE being more than 16 possibilities is not the cause of the problem. Each SINGLE door block only has a max of 16 possibilities and gets the rest of the nessecary data from the door blocks below or above itself. Thats why doors (mine as well as the vanilla ones) have this combineMeta thingy. This worked since I started this mod back in version 1.6.

Even vanilla doors have 32 possibilities in whole! They don't only store the half, the facing and the state (open or closed) but also if the hinge is on the left or on the right!

 

The getMetafromState Method will never return a value > 15:

 

@Override
    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i;

        if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.LOWER)
        {
            i = b0 | ((EnumFacing)state.getValue(FACING)).rotateY().getHorizontalIndex();

            if (((Boolean)state.getValue(OPEN)).booleanValue())
            {
                i |= 4;
            }
        }
        else
        {
        	i = b0 | 8;
        	if (state.getValue(HALF) == BlockDoorOneByThree.EnumDoorHalf.MIDDLE)
            {
        		/*if (((Boolean)state.getValue(DISTAL)).booleanValue())
                {
                    i |= 2;
                }*/
                if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT)
                {
                    i |= 1;
                }
            }
        	else
        	{
        		i |= 4;
        		/* Noch Freie Variable
                if (((Boolean)state.getValue(FREI)).booleanValue())
                {
                    i |= 2;
                }
                */
        		if (((Boolean)state.getValue(POWERED)).booleanValue())
                {
                    i |= 1;
                }
        	}
        }

        return i;
    }

 

 

I guess my problem is more like not overwriting the correct super method or something stupid like this... Just something that is so stupidly simple that I didn't see it.

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.