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.
309 lines
11 KiB
Java
309 lines
11 KiB
Java
package net.minecraft.block;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.inventory.Container;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.tileentity.TileEntityHopper;
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
import net.minecraft.util.Facing;
|
|
import net.minecraft.util.IIcon;
|
|
import net.minecraft.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
|
|
public class BlockHopper extends BlockContainer
|
|
{
|
|
private final Random field_149922_a = new Random();
|
|
@SideOnly(Side.CLIENT)
|
|
private IIcon field_149921_b;
|
|
@SideOnly(Side.CLIENT)
|
|
private IIcon field_149923_M;
|
|
@SideOnly(Side.CLIENT)
|
|
private IIcon field_149924_N;
|
|
private static final String __OBFID = "CL_00000257";
|
|
|
|
public BlockHopper()
|
|
{
|
|
super(Material.iron);
|
|
this.setCreativeTab(CreativeTabs.tabRedstone);
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
|
}
|
|
|
|
/**
|
|
* Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the
|
|
* mask.) Parameters: World, X, Y, Z, mask, list, colliding entity
|
|
*/
|
|
public void addCollisionBoxesToList(World worldIn, int x, int y, int z, AxisAlignedBB mask, List list, Entity collider)
|
|
{
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F);
|
|
super.addCollisionBoxesToList(worldIn, x, y, z, mask, list, collider);
|
|
float f = 0.125F;
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
|
|
super.addCollisionBoxesToList(worldIn, x, y, z, mask, list, collider);
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
|
|
super.addCollisionBoxesToList(worldIn, x, y, z, mask, list, collider);
|
|
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
|
super.addCollisionBoxesToList(worldIn, x, y, z, mask, list, collider);
|
|
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
|
|
super.addCollisionBoxesToList(worldIn, x, y, z, mask, list, collider);
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
|
}
|
|
|
|
/**
|
|
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
|
|
*/
|
|
public int onBlockPlaced(World worldIn, int x, int y, int z, int side, float subX, float subY, float subZ, int meta)
|
|
{
|
|
int j1 = Facing.oppositeSide[side];
|
|
|
|
if (j1 == 1)
|
|
{
|
|
j1 = 0;
|
|
}
|
|
|
|
return j1;
|
|
}
|
|
|
|
/**
|
|
* Returns a new instance of a block's tile entity class. Called on placing the block.
|
|
*/
|
|
public TileEntity createNewTileEntity(World worldIn, int meta)
|
|
{
|
|
return new TileEntityHopper();
|
|
}
|
|
|
|
/**
|
|
* Called when the block is placed in the world.
|
|
*/
|
|
public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn)
|
|
{
|
|
super.onBlockPlacedBy(worldIn, x, y, z, placer, itemIn);
|
|
|
|
if (itemIn.hasDisplayName())
|
|
{
|
|
TileEntityHopper tileentityhopper = func_149920_e(worldIn, x, y, z);
|
|
tileentityhopper.func_145886_a(itemIn.getDisplayName());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Called whenever the block is added into the world. Args: world, x, y, z
|
|
*/
|
|
public void onBlockAdded(World worldIn, int x, int y, int z)
|
|
{
|
|
super.onBlockAdded(worldIn, x, y, z);
|
|
this.func_149919_e(worldIn, x, y, z);
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
if (worldIn.isRemote)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
TileEntityHopper tileentityhopper = func_149920_e(worldIn, x, y, z);
|
|
|
|
if (tileentityhopper != null)
|
|
{
|
|
player.func_146093_a(tileentityhopper);
|
|
}
|
|
|
|
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)
|
|
{
|
|
this.func_149919_e(worldIn, x, y, z);
|
|
}
|
|
|
|
private void func_149919_e(World p_149919_1_, int p_149919_2_, int p_149919_3_, int p_149919_4_)
|
|
{
|
|
int l = p_149919_1_.getBlockMetadata(p_149919_2_, p_149919_3_, p_149919_4_);
|
|
int i1 = getDirectionFromMetadata(l);
|
|
boolean flag = !p_149919_1_.isBlockIndirectlyGettingPowered(p_149919_2_, p_149919_3_, p_149919_4_);
|
|
boolean flag1 = func_149917_c(l);
|
|
|
|
if (flag != flag1)
|
|
{
|
|
p_149919_1_.setBlockMetadataWithNotify(p_149919_2_, p_149919_3_, p_149919_4_, i1 | (flag ? 0 : 8), 4);
|
|
}
|
|
}
|
|
|
|
public void breakBlock(World worldIn, int x, int y, int z, Block blockBroken, int meta)
|
|
{
|
|
TileEntityHopper tileentityhopper = (TileEntityHopper)worldIn.getTileEntity(x, y, z);
|
|
|
|
if (tileentityhopper != null)
|
|
{
|
|
for (int i1 = 0; i1 < tileentityhopper.getSizeInventory(); ++i1)
|
|
{
|
|
ItemStack itemstack = tileentityhopper.getStackInSlot(i1);
|
|
|
|
if (itemstack != null)
|
|
{
|
|
float f = this.field_149922_a.nextFloat() * 0.8F + 0.1F;
|
|
float f1 = this.field_149922_a.nextFloat() * 0.8F + 0.1F;
|
|
float f2 = this.field_149922_a.nextFloat() * 0.8F + 0.1F;
|
|
|
|
while (itemstack.stackSize > 0)
|
|
{
|
|
int j1 = this.field_149922_a.nextInt(21) + 10;
|
|
|
|
if (j1 > itemstack.stackSize)
|
|
{
|
|
j1 = itemstack.stackSize;
|
|
}
|
|
|
|
itemstack.stackSize -= j1;
|
|
EntityItem entityitem = new EntityItem(worldIn, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
|
|
|
|
if (itemstack.hasTagCompound())
|
|
{
|
|
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
|
|
}
|
|
|
|
float f3 = 0.05F;
|
|
entityitem.motionX = (double)((float)this.field_149922_a.nextGaussian() * f3);
|
|
entityitem.motionY = (double)((float)this.field_149922_a.nextGaussian() * f3 + 0.2F);
|
|
entityitem.motionZ = (double)((float)this.field_149922_a.nextGaussian() * f3);
|
|
worldIn.spawnEntityInWorld(entityitem);
|
|
}
|
|
}
|
|
}
|
|
|
|
worldIn.func_147453_f(x, y, z, blockBroken);
|
|
}
|
|
|
|
super.breakBlock(worldIn, x, y, z, blockBroken, meta);
|
|
}
|
|
|
|
/**
|
|
* The type of render function that is called for this block
|
|
*/
|
|
public int getRenderType()
|
|
{
|
|
return 38;
|
|
}
|
|
|
|
/**
|
|
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
|
|
*/
|
|
public boolean renderAsNormalBlock()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* Gets the block's texture. Args: side, meta
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public IIcon getIcon(int side, int meta)
|
|
{
|
|
return side == 1 ? this.field_149923_M : this.field_149921_b;
|
|
}
|
|
|
|
public static int getDirectionFromMetadata(int p_149918_0_)
|
|
{
|
|
return p_149918_0_ & 7;
|
|
}
|
|
|
|
public static boolean func_149917_c(int p_149917_0_)
|
|
{
|
|
return (p_149917_0_ & 8) != 8;
|
|
}
|
|
|
|
/**
|
|
* If this returns true, then comparators facing away from this block will use the value from
|
|
* getComparatorInputOverride instead of the actual redstone signal strength.
|
|
*/
|
|
public boolean hasComparatorInputOverride()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
|
|
* strength when this block inputs to a comparator.
|
|
*/
|
|
public int getComparatorInputOverride(World worldIn, int x, int y, int z, int side)
|
|
{
|
|
return Container.calcRedstoneFromInventory(func_149920_e(worldIn, x, y, z));
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerBlockIcons(IIconRegister reg)
|
|
{
|
|
this.field_149921_b = reg.registerIcon("hopper_outside");
|
|
this.field_149923_M = reg.registerIcon("hopper_top");
|
|
this.field_149924_N = reg.registerIcon("hopper_inside");
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public static IIcon getHopperIcon(String p_149916_0_)
|
|
{
|
|
return p_149916_0_.equals("hopper_outside") ? Blocks.hopper.field_149921_b : (p_149916_0_.equals("hopper_inside") ? Blocks.hopper.field_149924_N : null);
|
|
}
|
|
|
|
public static TileEntityHopper func_149920_e(IBlockAccess p_149920_0_, int p_149920_1_, int p_149920_2_, int p_149920_3_)
|
|
{
|
|
return (TileEntityHopper)p_149920_0_.getTileEntity(p_149920_1_, p_149920_2_, p_149920_3_);
|
|
}
|
|
|
|
/**
|
|
* Gets the icon name of the ItemBlock corresponding to this block. Used by hoppers.
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public String getItemIconName()
|
|
{
|
|
return "hopper";
|
|
}
|
|
} |