Files
Mekanism-Community-Edition/src/mekanism/common/BlockGasTank.java
T
Aidan Brady 45b4510dc7 v5.0.1 Beta #2
*Updated to MC v1.4.6.
*Updated all APIs.
*Repackaged for new Forge.
*Added Metallurgic Infuser for making Steel and Bronze.
*Added Refined Steel Dust.
*Added Refined Steel Ingots.
*Made Refined Iron -> Steel Block.
*Maps instead of Vectors for recipes.
*New recipe managing for Metallurgic Infuser.
*Cleaned up imports.
*Added new Javadocs.
*Made Electrolytic Separator texture changed based on what gas it is
outputting.
*Other various bugfixes.
2012-12-20 16:53:39 -05:00

178 lines
4.9 KiB
Java

package mekanism.common;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockGasTank extends BlockContainer
{
public Random machineRand = new Random();
public BlockGasTank(int id)
{
super(id, Material.iron);
setBlockBounds(0.2F, 0.0F, 0.2F, 0.8F, 1.0F, 0.8F);
setCreativeTab(Mekanism.tabMekanism);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityliving)
{
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
int side = MathHelper.floor_double((double)(entityliving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int change = 3;
switch(side)
{
case 0: change = 2; break;
case 1: change = 5; break;
case 2: change = 3; break;
case 3: change = 4; break;
}
tileEntity.setFacing((short)change);
}
@Override
public int getBlockTextureFromSideAndMetadata(int side, int meta)
{
if(side == 3)
{
return 37;
}
else if(side == 0 || side == 1)
{
return 31;
}
else {
return 36;
}
}
@Override
@SideOnly(Side.CLIENT)
public int getBlockTexture(IBlockAccess world, int x, int y, int z, int side)
{
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
if(side == tileEntity.facing)
{
return 37;
}
else if(side == 0 || side == 1)
{
return 31;
}
else {
return 36;
}
}
@Override
public void breakBlock(World world, int x, int y, int z, int i1, int i2)
{
TileEntityContainerBlock tileEntity = (TileEntityContainerBlock)world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
for (int i = 0; i < tileEntity.getSizeInventory(); ++i)
{
ItemStack slotStack = tileEntity.getStackInSlot(i);
if (slotStack != null)
{
float xRandom = machineRand.nextFloat() * 0.8F + 0.1F;
float yRandom = machineRand.nextFloat() * 0.8F + 0.1F;
float zRandom = machineRand.nextFloat() * 0.8F + 0.1F;
while (slotStack.stackSize > 0)
{
int j = machineRand.nextInt(21) + 10;
if (j > slotStack.stackSize)
{
j = slotStack.stackSize;
}
slotStack.stackSize -= j;
EntityItem item = new EntityItem(world, (double)((float)x + xRandom), (double)((float)y + yRandom), (double)((float)z + zRandom), new ItemStack(slotStack.itemID, j, slotStack.getItemDamage()));
if (slotStack.hasTagCompound())
{
item.func_92014_d().setTagCompound((NBTTagCompound)slotStack.getTagCompound().copy());
}
float k = 0.05F;
item.motionX = (double)((float)machineRand.nextGaussian() * k);
item.motionY = (double)((float)machineRand.nextGaussian() * k + 0.2F);
item.motionZ = (double)((float)machineRand.nextGaussian() * k);
world.spawnEntityInWorld(item);
}
}
}
tileEntity.invalidate();
}
super.breakBlock(world, x, y, z, i1, i2);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int facing, float playerX, float playerY, float playerZ)
{
if(world.isRemote)
{
return true;
}
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if(!entityplayer.isSneaking())
{
entityplayer.openGui(Mekanism.instance, 10, world, x, y, z);
return true;
}
}
return false;
}
@Override
public String getTextureFile()
{
return "/resources/mekanism/textures/terrain.png";
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityGasTank();
}
}