You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
6.1 KiB
Java
186 lines
6.1 KiB
Java
package net.minecraft.block;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
import net.minecraft.util.IIcon;
|
|
import net.minecraft.util.MathHelper;
|
|
import net.minecraft.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
|
|
public class BlockFenceGate extends BlockDirectional
|
|
{
|
|
private static final String __OBFID = "CL_00000243";
|
|
|
|
public BlockFenceGate()
|
|
{
|
|
super(Material.wood);
|
|
this.setCreativeTab(CreativeTabs.tabRedstone);
|
|
}
|
|
|
|
/**
|
|
* Gets the block's texture. Args: side, meta
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public IIcon getIcon(int side, int meta)
|
|
{
|
|
return Blocks.planks.getBlockTextureFromSide(side);
|
|
}
|
|
|
|
/**
|
|
* Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
|
|
*/
|
|
public boolean canPlaceBlockAt(World worldIn, int x, int y, int z)
|
|
{
|
|
return !worldIn.getBlock(x, y - 1, z).getMaterial().isSolid() ? false : super.canPlaceBlockAt(worldIn, x, y, z);
|
|
}
|
|
|
|
/**
|
|
* Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
|
|
* cleared to be reused)
|
|
*/
|
|
public AxisAlignedBB getCollisionBoundingBoxFromPool(World worldIn, int x, int y, int z)
|
|
{
|
|
int l = worldIn.getBlockMetadata(x, y, z);
|
|
return isFenceGateOpen(l) ? null : (l != 2 && l != 0 ? AxisAlignedBB.getBoundingBox((double)((float)x + 0.375F), (double)y, (double)z, (double)((float)x + 0.625F), (double)((float)y + 1.5F), (double)(z + 1)) : AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)((float)z + 0.375F), (double)(x + 1), (double)((float)y + 1.5F), (double)((float)z + 0.625F)));
|
|
}
|
|
|
|
/**
|
|
* Updates the blocks bounds based on its current state. Args: world, x, y, z
|
|
*/
|
|
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, int x, int y, int z)
|
|
{
|
|
int l = getDirection(worldIn.getBlockMetadata(x, y, z));
|
|
|
|
if (l != 2 && l != 0)
|
|
{
|
|
this.setBlockBounds(0.375F, 0.0F, 0.0F, 0.625F, 1.0F, 1.0F);
|
|
}
|
|
else
|
|
{
|
|
this.setBlockBounds(0.0F, 0.0F, 0.375F, 1.0F, 1.0F, 0.625F);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
|
|
* adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
|
|
*/
|
|
public boolean isOpaqueCube()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
|
|
*/
|
|
public boolean renderAsNormalBlock()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public boolean getBlocksMovement(IBlockAccess worldIn, int x, int y, int z)
|
|
{
|
|
return isFenceGateOpen(worldIn.getBlockMetadata(x, y, z));
|
|
}
|
|
|
|
/**
|
|
* The type of render function that is called for this block
|
|
*/
|
|
public int getRenderType()
|
|
{
|
|
return 21;
|
|
}
|
|
|
|
/**
|
|
* Called when the block is placed in the world.
|
|
*/
|
|
public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn)
|
|
{
|
|
int l = (MathHelper.floor_double((double)(placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) % 4;
|
|
worldIn.setBlockMetadataWithNotify(x, y, z, l, 2);
|
|
}
|
|
|
|
/**
|
|
* Called upon block activation (right click on the block.)
|
|
*/
|
|
public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ)
|
|
{
|
|
int i1 = worldIn.getBlockMetadata(x, y, z);
|
|
|
|
if (isFenceGateOpen(i1))
|
|
{
|
|
worldIn.setBlockMetadataWithNotify(x, y, z, i1 & -5, 2);
|
|
}
|
|
else
|
|
{
|
|
int j1 = (MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) % 4;
|
|
int k1 = getDirection(i1);
|
|
|
|
if (k1 == (j1 + 2) % 4)
|
|
{
|
|
i1 = j1;
|
|
}
|
|
|
|
worldIn.setBlockMetadataWithNotify(x, y, z, i1 | 4, 2);
|
|
}
|
|
|
|
worldIn.playAuxSFXAtEntity(player, 1003, x, y, z, 0);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
|
|
* their own) Args: x, y, z, neighbor Block
|
|
*/
|
|
public void onNeighborBlockChange(World worldIn, int x, int y, int z, Block neighbor)
|
|
{
|
|
if (!worldIn.isRemote)
|
|
{
|
|
int l = worldIn.getBlockMetadata(x, y, z);
|
|
boolean flag = worldIn.isBlockIndirectlyGettingPowered(x, y, z);
|
|
|
|
if (flag || neighbor.canProvidePower())
|
|
{
|
|
if (flag && !isFenceGateOpen(l))
|
|
{
|
|
worldIn.setBlockMetadataWithNotify(x, y, z, l | 4, 2);
|
|
worldIn.playAuxSFXAtEntity((EntityPlayer)null, 1003, x, y, z, 0);
|
|
}
|
|
else if (!flag && isFenceGateOpen(l))
|
|
{
|
|
worldIn.setBlockMetadataWithNotify(x, y, z, l & -5, 2);
|
|
worldIn.playAuxSFXAtEntity((EntityPlayer)null, 1003, x, y, z, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns if the fence gate is open according to its metadata.
|
|
*/
|
|
public static boolean isFenceGateOpen(int p_149896_0_)
|
|
{
|
|
return (p_149896_0_ & 4) != 0;
|
|
}
|
|
|
|
/**
|
|
* Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
|
|
* coordinates. Args: blockAccess, x, y, z, side
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, int side)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerBlockIcons(IIconRegister reg) {}
|
|
} |