Add the Spark Tinkerer.

This commit is contained in:
Lizbeth Rika committed 2015-06-28 22:57:05 +01:00
1 parent 0a6d9a6b68
commit 3d1212bd8e
11 files changed
+323 -2

No files matched your search

@@ -0,0 +1,160 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Jun 28, 2015, 10:01:01 PM (GMT)]
*/
package vazkii.botania.common.block;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
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.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.common.block.tile.TileSimpleInventory;
import vazkii.botania.common.block.tile.TileSparkChanger;
import vazkii.botania.common.block.tile.TileTerraPlate;
import vazkii.botania.common.block.tile.string.TileRedStringDispenser;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibBlockNames;
public class BlockSparkChanger extends BlockModContainer {
IIcon[] icons;
Random random;
public BlockSparkChanger() {
super(Material.rock);
setBlockBounds(0F, 0F, 0F, 1F, 3F / 16F, 1F);
setHardness(2.0F);
setResistance(10.0F);
setStepSound(soundTypeStone);
setBlockName(LibBlockNames.SPARK_CHANGER);
random = new Random();
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean getBlocksMovement(IBlockAccess p_149655_1_, int p_149655_2_, int p_149655_3_, int p_149655_4_) {
return false;
}
@Override
public void registerBlockIcons(IIconRegister par1IconRegister) {
icons = new IIcon[3];
for(int i = 0; i < icons.length; i++)
icons[i] = IconHelper.forBlock(par1IconRegister, this, i);
}
@Override
public IIcon getIcon(int par1, int par2) {
return icons[Math.min(2, par1)];
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
boolean power = world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z);
int meta = world.getBlockMetadata(x, y, z);
boolean powered = (meta & 8) != 0;
if(power && !powered) {
((TileSparkChanger) world.getTileEntity(x, y, z)).doSwap();
world.setBlockMetadataWithNotify(x, y, z, meta | 8, 4);
} else if(!power && powered)
world.setBlockMetadataWithNotify(x, y, z, meta & -9, 4);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int s, float xs, float ys, float zs) {
TileSparkChanger changer = (TileSparkChanger) world.getTileEntity(x, y, z);
ItemStack cstack = changer.getStackInSlot(0);
ItemStack pstack = player.getCurrentEquippedItem();
if(pstack != null && pstack.getItem() == ModItems.sparkUpgrade) {
changer.setInventorySlotContents(0, pstack.copy());
changer.markDirty();
pstack.stackSize--;
if(pstack.stackSize == 0)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
if(cstack != null && !player.inventory.addItemStackToInventory(cstack))
player.dropPlayerItemWithRandomChoice(cstack, false);
return true;
} else if(cstack != null) {
changer.setInventorySlotContents(0, null);
changer.markDirty();
if(!player.inventory.addItemStackToInventory(cstack))
player.dropPlayerItemWithRandomChoice(cstack, false);
return true;
}
return false;
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6) {
TileSimpleInventory inv = (TileSimpleInventory) par1World.getTileEntity(par2, par3, par4);
if (inv != null) {
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
ItemStack itemstack = inv.getStackInSlot(j1);
if (itemstack != null) {
float f = random.nextFloat() * 0.8F + 0.1F;
float f1 = random.nextFloat() * 0.8F + 0.1F;
EntityItem entityitem;
for (float f2 = random.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; par1World.spawnEntityInWorld(entityitem)) {
int k1 = random.nextInt(21) + 10;
if (k1 > itemstack.stackSize)
k1 = itemstack.stackSize;
itemstack.stackSize -= k1;
entityitem = new EntityItem(par1World, par2 + f, par3 + f1, par4 + f2, new ItemStack(itemstack.getItem(), k1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (float)random.nextGaussian() * f3;
entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float)random.nextGaussian() * f3;
if (itemstack.hasTagCompound())
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
}
}
par1World.func_147453_f(par2, par3, par4, par5);
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileSparkChanger();
}
}