Jump to content

[1.11] Missing texture but only if my head is near to the block


Recommended Posts

Posted

Hi

 

I have a very strange problem. I have a block, its not a full cube, textures and model works perfectly. But if my head is at the block, i have a missing texture at my whole screen. I dont get any error or something else. I searched a long time but i only found problems where the block had a missing texture, nothing to my problem.

 

My Block class:

package me.haffel.cr.block;

import java.io.FileNotFoundException;

import me.haffel.cr.client.gui.GuiCashRegisterSeeBuy;
import me.haffel.cr.client.gui.GuiCashRegisterSetCode;
import me.haffel.cr.json.CrFiles;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockCashRegister extends Block
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
/** Size of bounding Box*/
protected static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.875D, 0.9375D);
/**	Block position for other classes */
public static BlockPos crPos;

public BlockCashRegister(Material materialIn)
{
	super(materialIn);
	this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
	this.setBlockUnbreakable();
}

/**
 * Called when block is added in the World
 */
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
	this.setDefaultFacing(worldIn, pos, state);
	this.crPos = pos;

	Minecraft.getMinecraft().displayGuiScreen(new GuiCashRegisterSetCode());
}

@Override
/**
 * Fired when a Player destroys the cash register, used to delete it's file
 * 
 * @param worldIn
 * @param pos
 * @param state
 */
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
{
	super.onBlockDestroyedByPlayer(worldIn, pos, state);
	try
	{
		CrFiles.deleteCrFile(Minecraft.getMinecraft().mcDataDir + "/saves/" + Minecraft.getMinecraft().getIntegratedServer().getFolderName() + "/cash_registers/" + pos.getX() + " - " + pos.getY() + " - " + pos.getZ() + ".json");
	} catch (FileNotFoundException e)
	{
		e.printStackTrace();
	}
}

private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
	if(!worldIn.isRemote)
	{
		IBlockState iblockstate = worldIn.getBlockState(pos.north());
		IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
		IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
		IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
		EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

		if(enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
		{
			enumfacing = EnumFacing.SOUTH;

		} else if(enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
		{
			enumfacing = EnumFacing.NORTH;

		} else if(enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
		{
			enumfacing = EnumFacing.EAST;

		} else if(enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
		{
			enumfacing = EnumFacing.WEST;
		}
		worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
	}
}

public static void setState(World worldIn, BlockPos pos)
{
	IBlockState iblockstate = worldIn.getBlockState(pos);

	worldIn.setBlockState(pos, _Block.cash_register.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
	worldIn.setBlockState(pos, _Block.cash_register.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
}

/**
 * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
 * IBlockstate
 */
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX,
		float hitY, float hitZ, int meta, EntityLivingBase placer)
{
	return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}

public IBlockState getStateFromMeta(int meta)
{
	EnumFacing enumfacing = EnumFacing.getFront(meta);

	if(enumfacing.getAxis() == EnumFacing.Axis.Y)
	{
		enumfacing = EnumFacing.NORTH;
	}
	return this.getDefaultState().withProperty(FACING, enumfacing);
}

/**
 * Convert the BlockState into the correct metadata value
 */
public int getMetaFromState(IBlockState state)
{
	return ((EnumFacing)state.getValue(FACING)).getIndex();
}

/**
 * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
 * blockstate.
 */
public IBlockState withRotation(IBlockState state, Rotation rot)
{
	return 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.
 */
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
	return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}

protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[] {FACING});
}

/**
 * Set bounding Box
 */
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
	return AABB;
}

public boolean isFullBlock()
{
	return false;
}

public boolean isOpaqueCube(IBlockState state)
{
	return false;
}

@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
	return EnumBlockRenderType.MODEL;
}

@Override
/**
 * Fired when the player makes a rightclick on the block
 */
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY)
{
	this.crPos = pos;

	if(!worldIn.isRemote)
	{
		Minecraft.getMinecraft().displayGuiScreen(new GuiCashRegisterSeeBuy(I18n.format("cr.gui.seebuy.titel",
				new Object[0]), I18n.format("cr.gui.seebuy.description", new Object[0]), 0));
	}
	return true;
}
}

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.