2013-08-23 16:59:50 +02:00
|
|
|
package com.pahimar.ee3.block;
|
|
|
|
|
2014-01-02 08:21:46 +01:00
|
|
|
import com.pahimar.ee3.lib.Strings;
|
|
|
|
import com.pahimar.ee3.tileentity.TileEE;
|
2013-12-28 01:54:31 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-12-27 02:59:51 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-08-23 16:59:50 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2013-12-28 01:54:31 +01:00
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
2014-01-02 08:21:46 +01:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2013-08-23 16:59:50 +02:00
|
|
|
|
2013-12-27 02:59:51 +01:00
|
|
|
public class BlockEE extends Block
|
2013-12-16 02:26:42 +01:00
|
|
|
{
|
2013-12-27 02:59:51 +01:00
|
|
|
public BlockEE(int id)
|
2013-12-16 02:26:42 +01:00
|
|
|
{
|
2013-12-28 01:54:31 +01:00
|
|
|
this(id, Material.rock);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockEE(int id, Material material)
|
|
|
|
{
|
|
|
|
super(id, material);
|
2014-01-02 08:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName()
|
|
|
|
{
|
|
|
|
return String.format("tile.%s%s", Strings.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
|
2013-12-28 01:54:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IconRegister iconRegister)
|
|
|
|
{
|
|
|
|
blockIcon = iconRegister.registerIcon(String.format("%s", getUnwrappedUnlocalizedName(this.getUnlocalizedName())));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getUnwrappedUnlocalizedName(String unlocalizedName)
|
|
|
|
{
|
|
|
|
return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
2014-01-02 08:21:46 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void breakBlock(World world, int x, int y, int z, int id, int meta)
|
|
|
|
{
|
|
|
|
dropInventory(world, x, y, z);
|
|
|
|
super.breakBlock(world, x, y, z, id, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
|
|
|
|
{
|
|
|
|
int direction = 0;
|
|
|
|
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
|
|
|
|
|
|
|
if (facing == 0)
|
|
|
|
{
|
|
|
|
direction = ForgeDirection.NORTH.ordinal();
|
|
|
|
}
|
|
|
|
else if (facing == 1)
|
|
|
|
{
|
|
|
|
direction = ForgeDirection.EAST.ordinal();
|
|
|
|
}
|
|
|
|
else if (facing == 2)
|
|
|
|
{
|
|
|
|
direction = ForgeDirection.SOUTH.ordinal();
|
|
|
|
}
|
|
|
|
else if (facing == 3)
|
|
|
|
{
|
|
|
|
direction = ForgeDirection.WEST.ordinal();
|
|
|
|
}
|
|
|
|
|
|
|
|
world.setBlockMetadataWithNotify(x, y, z, direction, 3);
|
|
|
|
|
|
|
|
if (itemStack.hasDisplayName())
|
|
|
|
{
|
|
|
|
((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
|
|
|
|
}
|
|
|
|
|
|
|
|
((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void dropInventory(World world, int x, int y, int z)
|
|
|
|
{
|
|
|
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
|
|
|
|
|
|
|
if (!(tileEntity instanceof IInventory))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IInventory inventory = (IInventory) tileEntity;
|
|
|
|
|
|
|
|
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
ItemStack itemStack = inventory.getStackInSlot(i);
|
|
|
|
|
|
|
|
if (itemStack != null && itemStack.stackSize > 0)
|
|
|
|
{
|
|
|
|
Random rand = new Random();
|
|
|
|
|
|
|
|
float dX = rand.nextFloat() * 0.8F + 0.1F;
|
|
|
|
float dY = rand.nextFloat() * 0.8F + 0.1F;
|
|
|
|
float dZ = rand.nextFloat() * 0.8F + 0.1F;
|
|
|
|
|
|
|
|
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
|
|
|
|
|
|
|
|
if (itemStack.hasTagCompound())
|
|
|
|
{
|
|
|
|
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
|
|
|
|
}
|
|
|
|
|
|
|
|
float factor = 0.05F;
|
|
|
|
entityItem.motionX = rand.nextGaussian() * factor;
|
|
|
|
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
|
|
|
|
entityItem.motionZ = rand.nextGaussian() * factor;
|
|
|
|
world.spawnEntityInWorld(entityItem);
|
|
|
|
itemStack.stackSize = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|