Files
TinkersConstruct/src/main/java/tconstruct/blocks/EquipBlock.java
T

209 lines
6.2 KiB
Java
Raw Normal View History

package tconstruct.blocks;
2014-02-05 10:28:54 -05:00
import java.util.Random;
2013-09-08 18:51:19 +10:00
2013-12-01 12:19:43 +00:00
import mantle.blocks.abstracts.InventoryBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2013-12-31 15:30:34 -05:00
import net.minecraft.client.renderer.texture.IIconRegister;
2014-02-05 10:28:54 -05:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
2013-12-31 15:30:34 -05:00
import net.minecraft.init.Blocks;
2014-02-02 22:36:22 -05:00
import net.minecraft.item.Item;
2013-08-18 19:58:36 -07:00
import net.minecraft.item.ItemStack;
2014-02-05 10:28:54 -05:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
2014-02-05 10:28:54 -05:00
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.TConstruct;
import tconstruct.blocks.logic.EquipLogic;
import tconstruct.blocks.logic.FrypanLogic;
import tconstruct.client.block.FrypanRender;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class EquipBlock extends InventoryBlock
{
2013-12-31 15:30:34 -05:00
public EquipBlock(Material material)
{
2013-12-31 15:30:34 -05:00
super(material);
2014-02-05 08:28:53 -05:00
this.setHardness(0.3f);
this.setBlockBounds(0, 0, 0, 1, 0.25f, 1);
2014-02-16 14:23:50 -05:00
// this.setCreativeTab(ToolConstruct.materialTab);
}
@Override
public String[] getTextureNames ()
{
return new String[] { "toolstation_top" };
}
@Override
public String getTextureDomain (int textureNameIndex)
{
return "tinker";
}
2014-02-17 00:31:43 -05:00
@Override
2014-02-17 15:30:13 -05:00
@SideOnly(Side.CLIENT)
2014-02-05 08:28:53 -05:00
public IIcon getIcon (int side, int meta)
{
2014-02-05 08:28:53 -05:00
return Blocks.iron_block.getIcon(side, meta);
}
2014-02-17 00:31:43 -05:00
@Override
@SideOnly(Side.CLIENT)
2014-02-05 08:28:53 -05:00
public void registerBlockIcons (IIconRegister par1IconRegister)
{
2014-02-16 14:23:50 -05:00
// this.blockIcon =
// par1iconRegister.registerIcon(Block.blockIron.getUnlocalizedName());
}
@Override
2014-02-05 08:28:53 -05:00
public boolean renderAsNormalBlock ()
{
return false;
}
@Override
2014-02-05 08:28:53 -05:00
public boolean isOpaqueCube ()
{
return false;
}
@Override
2014-02-05 08:28:53 -05:00
public int getRenderType ()
{
return FrypanRender.frypanModelID;
}
@Override
2014-02-05 08:28:53 -05:00
public Item getItemDropped (int par1, Random par2Random, int par3)
{
2014-02-02 22:36:22 -05:00
return null;
}
@Override
2014-02-05 08:28:53 -05:00
public TileEntity createNewTileEntity (World world, int metadata)
{
return new FrypanLogic();
}
2014-02-17 00:31:43 -05:00
@Override
public void randomDisplayTick (World world, int x, int y, int z, Random random)
{
if (isActive(world, x, y, z))
{
float f = (float) x + 0.5F;
float f1 = (float) y + 0.25F + (random.nextFloat() * 6F) / 16F;
float f2 = (float) z + 0.5F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
world.spawnParticle("smoke", f, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
}
}
2013-08-31 05:13:31 -07:00
2014-02-17 00:31:43 -05:00
@Override
2014-02-05 08:28:53 -05:00
public void onBlockPlacedBy (World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
2013-08-31 05:13:31 -07:00
{
2014-02-05 08:28:53 -05:00
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
2013-08-31 05:13:31 -07:00
int i3 = MathHelper.floor_double((par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int newMeta = 0;
switch (i3)
{
case 3:
newMeta = 0;
break;
case 0:
newMeta = 3;
break;
case 1:
newMeta = 1;
break;
case 2:
newMeta = 2;
break;
}
par1World.setBlockMetadataWithNotify(par2, par3, par4, newMeta, 2);
2013-08-18 19:58:36 -07:00
}
2013-08-31 05:13:31 -07:00
2013-09-08 18:51:19 +10:00
@Override
2014-02-05 08:28:53 -05:00
public void breakBlock (World par1World, int x, int y, int z, Block par5, int meta)
2013-11-10 13:57:35 -08:00
{
2014-02-05 08:28:53 -05:00
TileEntity te = par1World.getTileEntity(x, y, z);
2013-09-08 18:51:19 +10:00
if (te != null && te instanceof EquipLogic)
{
EquipLogic logic = (EquipLogic) te;
for (int iter = 0; iter < logic.getSizeInventory(); ++iter)
{
ItemStack stack = iter == 0 ? logic.getEquipmentItem() : logic.getStackInSlot(iter);
if (stack != null && logic.canDropInventorySlot(iter))
{
float jumpX = rand.nextFloat() * 0.8F + 0.1F;
float jumpY = rand.nextFloat() * 0.8F + 0.1F;
float jumpZ = rand.nextFloat() * 0.8F + 0.1F;
while (stack.stackSize > 0)
{
int itemSize = rand.nextInt(21) + 10;
if (itemSize > stack.stackSize)
{
itemSize = stack.stackSize;
}
stack.stackSize -= itemSize;
2014-01-10 21:14:54 -05:00
EntityItem entityitem = new EntityItem(par1World, (double) ((float) x + jumpX), (double) ((float) y + jumpY), (double) ((float) z + jumpZ), new ItemStack(stack.getItem(),
2013-09-08 18:51:19 +10:00
itemSize, stack.getItemDamage()));
if (stack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
}
float offset = 0.05F;
entityitem.motionX = (double) ((float) rand.nextGaussian() * offset);
entityitem.motionY = (double) ((float) rand.nextGaussian() * offset + 0.2F);
entityitem.motionZ = (double) ((float) rand.nextGaussian() * offset);
par1World.spawnEntityInWorld(entityitem);
}
}
}
}
2014-02-05 08:28:53 -05:00
super.breakBlock(par1World, x, y, z, par5, meta);
2013-09-08 18:51:19 +10:00
}
2013-11-10 13:57:35 -08:00
2014-02-17 00:31:43 -05:00
@Override
public int getLightValue (IBlockAccess world, int x, int y, int z)
{
return !isActive(world, x, y, z) ? 0 : 9;
}
@Override
public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer)
{
return TConstruct.proxy.frypanGuiID;
}
@Override
public Object getModInstance ()
{
return TConstruct.instance;
}
2014-01-15 00:34:19 -05:00
2014-01-15 23:19:27 -05:00
@Override
public TileEntity createTileEntity (World world, int metadata)
{
return new FrypanLogic();
}
}