-
-
Save izzyaxel/499e740203cc467f056d4efdf06c24ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CropChromatospore extends ChroCrop | |
{ | |
public static PropertyEnum<ChromatimancyColors> COLOR = PropertyEnum.<ChromatimancyColors>create("color", ChromatimancyColors.class); | |
public static PropertyInteger AGE = PropertyInteger.create("age", 0, 7); | |
//TODO real drops plz | |
private Item crop = Items.WHEAT; | |
public static final int MAXLIGHT = 4; | |
public CropChromatospore() | |
{ | |
super("cropChromatospore"); | |
this.setSoundType(SoundType.PLANT); | |
this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, ChromatimancyColors.WHITE).withProperty(AGE, 0)); | |
} | |
@Override | |
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) | |
{ | |
return new ItemStack(ChroItems.seedChromatospore, 1, state.getValue(COLOR).getDamage()); | |
} | |
@Override | |
public int getMetaFromState(IBlockState state) | |
{ | |
return (state != null) ? state.getValue(COLOR).getMetadata() : 0; | |
} | |
@Override | |
public IBlockState getStateFromMeta(int meta) | |
{ | |
return this.getDefaultState().withProperty(COLOR, ChromatimancyColors.getByMetadata(meta)); | |
} | |
@Override | |
protected BlockStateContainer createBlockState() | |
{ | |
return new BlockStateContainer(this, COLOR, AGE); | |
} | |
@Override | |
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) | |
{ | |
if(state != null) | |
{ | |
List<ItemStack> drops = new ArrayList<ItemStack>(); | |
drops.add(new ItemStack(ChroItems.seedChromatospore, 1, state.getValue(COLOR).getDamage())); | |
if(this.getAge(state) >= this.getMaxAge()) | |
{ | |
Random rand = new Random(); | |
drops.add(new ItemStack(this.crop, 1)); | |
for(int i = 0; i < 3 * fortune; i++) | |
{ | |
if(rand.nextInt(3) == 1) | |
{ | |
drops.add(new ItemStack(this.crop, 1)); | |
} | |
} | |
} | |
return drops; | |
} | |
return new ArrayList<ItemStack>(); | |
} | |
@Override | |
protected PropertyInteger getAgeProperty() | |
{ | |
return AGE; | |
} | |
@Override | |
public int getMaxAge() | |
{ | |
return 7; | |
} | |
@Override | |
protected int getAge(IBlockState state) | |
{ | |
return state.getValue(this.getAgeProperty()); | |
} | |
@Override | |
public IBlockState withAge(int age) | |
{ | |
return this.getDefaultState().withProperty(AGE, age); | |
} | |
@Override | |
public boolean isMaxAge(IBlockState state) | |
{ | |
return state.getValue(AGE) >= this.getMaxAge(); | |
} | |
@Override | |
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) | |
{ | |
if(worldIn.getLightFromNeighbors(pos.up()) < MAXLIGHT) | |
{ | |
int age = this.getAge(state); | |
if(age < this.getMaxAge()) | |
{ | |
float growthChance = getGrowthChance(this, worldIn, pos); | |
if(rand.nextInt((int)(25.0F / growthChance) + 1) == 0) | |
{ | |
if(age == this.getMaxAge() - 1) | |
{ | |
worldIn.setBlockState(pos, this.withAge(age + 1), 3); | |
} | |
else | |
{ | |
worldIn.setBlockState(pos, this.withAge(age + 1), 2); | |
} | |
} | |
} | |
} | |
else | |
{ | |
EntityItem ei = new EntityItem(worldIn, pos.getX(), pos.getY() + 0.2, pos.getZ(), new ItemStack(ChroItems.seedChromatospore, 1, state.getValue(COLOR).getDamage())); | |
worldIn.spawnEntityInWorld(ei); | |
worldIn.setBlockToAir(pos); | |
} | |
} | |
@Override | |
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) | |
{ | |
return worldIn.getLight(pos) < MAXLIGHT && !worldIn.canSeeSky(pos) && worldIn.getBlockState(pos.down()).getBlock() == Blocks.STONE && worldIn.getBlockState(pos.up()).getBlock() == Blocks.AIR; | |
} | |
@Nullable | |
@Override | |
public Item getItemDropped(IBlockState state, Random rand, int fortune) | |
{ | |
return null; | |
} | |
@Override | |
public int tickRate(World worldIn) | |
{ | |
return 6; | |
} | |
@Override | |
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) | |
{ | |
if(worldIn.isRemote) | |
{ | |
double x = pos.getX(), y = pos.getY(), z = pos.getZ(); | |
x += 0.5 + ((rand.nextInt(3) - 1) * rand.nextFloat()) / 1.5; | |
y += 0.5 + ((rand.nextInt(3) - 1) * rand.nextFloat()) / 1.5; | |
z += 0.5 + ((rand.nextInt(3) - 1) * rand.nextFloat()) / 1.5; | |
ChromatosporeFX particle = new ChromatosporeFX(worldIn, x, y, z, 0.003f, stateIn.getValue(COLOR), 60, 1); | |
Minecraft.getMinecraft().effectRenderer.addEffect(particle); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment