Files
TinkersConstruct/src/main/java/tconstruct/blocks/slime/SlimeGrass.java
T

154 lines
4.9 KiB
Java
Raw Normal View History

2013-08-12 05:58:15 -07:00
package tconstruct.blocks.slime;
import java.util.List;
import java.util.Random;
import mantle.blocks.MantleBlock;
2013-08-12 05:58:15 -07:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2013-12-31 16:37:46 -05:00
import net.minecraft.client.renderer.texture.IIconRegister;
2013-08-12 05:58:15 -07:00
import net.minecraft.creativetab.CreativeTabs;
2013-12-31 16:37:46 -05:00
import net.minecraft.init.Blocks;
2014-01-07 13:50:35 -05:00
import net.minecraft.item.Item;
2013-08-12 05:58:15 -07:00
import net.minecraft.item.ItemStack;
2013-12-31 16:37:46 -05:00
import net.minecraft.util.IIcon;
2014-02-02 23:18:57 -05:00
import net.minecraft.world.IBlockAccess;
2013-08-12 05:58:15 -07:00
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;
2014-02-05 10:28:54 -05:00
import net.minecraftforge.common.util.ForgeDirection;
import tconstruct.TConstruct;
2013-08-12 05:58:15 -07:00
import tconstruct.library.TConstructRegistry;
import tconstruct.smeltery.TinkerSmeltery;
2014-06-04 21:44:48 -08:00
import tconstruct.tools.TinkerTools;
2013-08-12 05:58:15 -07:00
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import tconstruct.world.TinkerWorld;
2013-08-12 05:58:15 -07:00
public class SlimeGrass extends MantleBlock
2013-08-12 05:58:15 -07:00
{
2014-02-16 14:23:50 -05:00
public String[] textureNames = { "slimegrass_green_top", "slimedirt_blue", "slimegrass_green_blue_side", "slimegrass_green_dirt_side" };// green,
// purple
2013-12-31 16:37:46 -05:00
public IIcon[] icons;
2013-08-12 05:58:15 -07:00
2013-12-31 16:37:46 -05:00
public SlimeGrass()
2013-08-12 05:58:15 -07:00
{
2014-02-05 08:28:53 -05:00
super(Material.grass);
setHardness(0.6f);
this.setTickRandomly(true);
this.setCreativeTab(TConstructRegistry.blockTab);
2013-08-12 05:58:15 -07:00
}
@Override
2014-02-05 08:28:53 -05:00
public int damageDropped (int meta)
2013-08-12 05:58:15 -07:00
{
2014-02-16 14:23:50 -05:00
if (meta == 1) // dirt
return 0;
2013-08-31 05:13:31 -07:00
else
2014-02-16 14:23:50 -05:00
// slime dirt
return 5;
2013-08-12 05:58:15 -07:00
}
@Override
@SideOnly(Side.CLIENT)
2014-02-05 08:28:53 -05:00
public void registerBlockIcons (IIconRegister iconRegister)
2013-08-12 05:58:15 -07:00
{
2013-12-31 16:37:46 -05:00
this.icons = new IIcon[textureNames.length];
2013-08-12 05:58:15 -07:00
for (int i = 0; i < this.icons.length; ++i)
{
this.icons[i] = iconRegister.registerIcon("tinker:" + textureNames[i]);
}
}
@Override
@SideOnly(Side.CLIENT)
2014-02-05 08:28:53 -05:00
public IIcon getIcon (int side, int meta)
2013-08-12 05:58:15 -07:00
{
2013-08-31 05:13:31 -07:00
if (meta >= 2)
meta = 0;
2013-08-12 05:58:15 -07:00
if (side == 0)
{
2014-02-05 08:28:53 -05:00
return meta % 2 == 1 ? Blocks.dirt.getIcon(0, 0) : icons[1];
2013-08-12 05:58:15 -07:00
}
else if (side == 1)
{
return icons[0];
}
else
{
return icons[meta + 2];
}
}
@Override
2014-02-05 08:28:53 -05:00
public void getSubBlocks (Item b, CreativeTabs tab, List list)
2013-08-12 05:58:15 -07:00
{
for (int iter = 0; iter < 1; iter++)
{
2013-12-31 16:37:46 -05:00
list.add(new ItemStack(b, 1, iter));
2013-08-12 05:58:15 -07:00
}
}
@Override
2014-02-02 23:18:57 -05:00
public boolean canSustainPlant (IBlockAccess world, int x, int y, int z, ForgeDirection direction, IPlantable plant)
2013-08-12 05:58:15 -07:00
{
EnumPlantType plantType = plant.getPlantType(world, x, y + 1, z);
2014-01-29 00:41:17 -05:00
return plantType == EnumPlantType.Plains && plant.getPlant(world, x, y + 1, z) != Blocks.tallgrass;
2013-08-12 05:58:15 -07:00
}
2013-08-31 05:13:31 -07:00
2014-02-17 00:31:43 -05:00
@Override
2013-08-31 05:13:31 -07:00
public void onPlantGrow (World world, int x, int y, int z, int sourceX, int sourceY, int sourceZ)
2013-08-12 05:58:15 -07:00
{
2014-06-04 21:44:48 -08:00
world.setBlock(x, y, z, TinkerTools.craftedSoil, 5, 3);
2013-08-12 05:58:15 -07:00
}
2014-02-17 00:31:43 -05:00
@Override
public void updateTick (World world, int x, int y, int z, Random random)
2013-08-12 05:58:15 -07:00
{
if (!world.isRemote)
2013-08-12 05:58:15 -07:00
{
if (world.getBlockLightValue(x, y + 1, z) < 4 && world.getBlockLightOpacity(x, y + 1, z) > 2)
2013-08-12 05:58:15 -07:00
{
world.setBlock(x, y, z, TinkerTools.craftedSoil, 5, 3);
2013-08-12 05:58:15 -07:00
}
else if (world.getBlockLightValue(x, y + 1, z) >= 9)
2013-08-12 05:58:15 -07:00
{
for (int l = 0; l < 4; ++l)
{
int posX = x + random.nextInt(3) - 1;
int posY = y + random.nextInt(5) - 3;
int posZ = z + random.nextInt(3) - 1;
Block blockAbove = world.getBlock(posX, posY + 1, posZ);
2013-08-12 05:58:15 -07:00
if (world.getBlockLightValue(posX, posY + 1, posZ) >= 4 && world.getBlockLightOpacity(posX, posY + 1, posZ) <= 2
&& blockAbove != TinkerTools.craftedSoil && blockAbove != this)
2013-08-12 05:58:15 -07:00
{
Block block = world.getBlock(posX, posY, posZ);
2014-01-07 13:50:35 -05:00
if (block == Blocks.dirt)
2013-08-12 05:58:15 -07:00
{
world.setBlock(posX, posY, posZ, (Block) this, 1, 3);
2013-08-12 05:58:15 -07:00
return;
}
int blockMeta = world.getBlockMetadata(posX, posY, posZ);
2014-06-04 21:44:48 -08:00
if (block == TinkerTools.craftedSoil)
2013-08-12 05:58:15 -07:00
{
if (blockMeta == 5)
world.setBlock(posX, posY, posZ, (Block) this, 0, 3);
2013-08-12 05:58:15 -07:00
}
}
}
}
}
}
2013-08-31 05:13:31 -07:00
2014-02-01 14:18:17 -05:00
public Block blockDropped (int metadata, Random random, int fortune)
{
if (metadata == 1)
2014-02-01 14:18:17 -05:00
return Blocks.dirt;
2013-12-11 23:47:07 -05:00
else
2014-06-04 21:44:48 -08:00
return TinkerTools.craftedSoil;
}
2013-08-12 05:58:15 -07:00
}