2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BlockPlant.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks.base;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-08 20:51:03 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-03-18 18:38:39 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.block.BlockCrops;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-01-16 03:39:38 +01:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-01-16 03:39:38 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-06-28 21:28:58 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.world.World;
|
2015-06-28 21:28:58 +02:00
|
|
|
import net.minecraftforge.common.EnumPlantType;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-16 14:14:39 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2016-06-27 20:24:45 +02:00
|
|
|
public class BlockPlant extends BlockCrops implements ItemBlockBase.ICustomRarity{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
private final String name;
|
|
|
|
private final int minDropAmount;
|
|
|
|
private final int addDropAmount;
|
2016-06-01 00:39:35 +02:00
|
|
|
public Item seedItem;
|
2016-06-27 19:25:46 +02:00
|
|
|
private Item returnItem;
|
|
|
|
private int returnMeta;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-08 15:21:05 +01:00
|
|
|
public BlockPlant(String name, int minDropAmount, int addDropAmount){
|
2015-05-20 22:39:43 +02:00
|
|
|
this.name = name;
|
2015-06-06 01:25:53 +02:00
|
|
|
this.minDropAmount = minDropAmount;
|
|
|
|
this.addDropAmount = addDropAmount;
|
2015-12-03 20:15:07 +01:00
|
|
|
this.register();
|
|
|
|
}
|
2016-01-16 14:14:39 +01:00
|
|
|
|
2016-06-27 19:25:46 +02:00
|
|
|
public void doStuff(Item seedItem, Item returnItem, int returnMeta){
|
|
|
|
this.seedItem = seedItem;
|
|
|
|
this.returnItem = returnItem;
|
|
|
|
this.returnMeta = returnMeta;
|
|
|
|
}
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
private void register(){
|
2016-03-18 18:38:39 +01:00
|
|
|
ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
|
2016-01-08 16:52:53 +01:00
|
|
|
|
2016-01-08 20:51:03 +01:00
|
|
|
this.registerRendering();
|
|
|
|
}
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
protected String getBaseName(){
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2016-04-20 21:39:03 +02:00
|
|
|
protected ItemBlockBase getItemBlock(){
|
|
|
|
return new ItemBlockBase(this);
|
2015-12-03 20:15:07 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
public boolean shouldAddCreative(){
|
2016-01-10 15:29:44 +01:00
|
|
|
return false;
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
protected void registerRendering(){
|
2016-06-01 00:37:28 +02:00
|
|
|
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2016-06-27 20:24:45 +02:00
|
|
|
@Override
|
2015-12-03 20:15:07 +01:00
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 21:41:28 +01:00
|
|
|
return EnumRarity.RARE;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-06-28 21:28:58 +02:00
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos){
|
2015-06-28 21:28:58 +02:00
|
|
|
return EnumPlantType.Crop;
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2016-02-01 17:49:55 +01:00
|
|
|
public int damageDropped(IBlockState state){
|
|
|
|
return this.getMetaFromState(state) >= 7 ? this.returnMeta : 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 23:47:22 +01:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing facing, float hitX, float hitY, float hitZ){
|
2016-05-02 17:46:53 +02:00
|
|
|
if(this.getMetaFromState(state) >= 7){
|
2016-02-01 17:49:55 +01:00
|
|
|
if(!world.isRemote){
|
2016-01-16 14:14:39 +01:00
|
|
|
|
2016-05-02 17:46:53 +02:00
|
|
|
List<ItemStack> drops = this.getDrops(world, pos, state, 0);
|
2016-02-01 17:49:55 +01:00
|
|
|
boolean deductedSeedSize = false;
|
2016-03-18 23:47:22 +01:00
|
|
|
for(ItemStack drop : drops){
|
|
|
|
if(drop != null){
|
|
|
|
if(drop.getItem() == this.seedItem && !deductedSeedSize){
|
|
|
|
drop.stackSize--;
|
2016-02-01 17:49:55 +01:00
|
|
|
deductedSeedSize = true;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-03-18 23:47:22 +01:00
|
|
|
if(drop.stackSize > 0){
|
|
|
|
EntityItem entity = new EntityItem(world, pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, drop);
|
2016-02-01 17:49:55 +01:00
|
|
|
world.spawnEntityInWorld(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 17:46:53 +02:00
|
|
|
world.setBlockState(pos, this.getStateFromMeta(0));
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 20:39:11 +01:00
|
|
|
@Override
|
2016-02-01 20:32:49 +01:00
|
|
|
public Item getSeed(){
|
|
|
|
return this.seedItem;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public int quantityDropped(IBlockState state, int fortune, Random random){
|
2016-05-02 17:46:53 +02:00
|
|
|
return this.getMetaFromState(state) >= 7 ? random.nextInt(this.addDropAmount)+this.minDropAmount : super.quantityDropped(state, fortune, random);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
|
|
|
public Item getCrop(){
|
|
|
|
return this.returnItem;
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public Item getItemDropped(IBlockState state, Random rand, int par3){
|
2016-02-01 20:32:49 +01:00
|
|
|
return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|