2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("BlockPlant.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 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-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.creative.CreativeTab;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
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-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.BlockPos;
|
2016-01-16 03:39:38 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-01-08 20:51:03 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
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;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-16 14:14:39 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
public class BlockPlant extends BlockCrops{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
public Item seedItem;
|
2015-06-21 02:28:49 +02:00
|
|
|
public Item returnItem;
|
|
|
|
public int returnMeta;
|
2015-10-03 10:16:18 +02:00
|
|
|
private String name;
|
2015-06-06 01:25:53 +02:00
|
|
|
private int minDropAmount;
|
|
|
|
private int addDropAmount;
|
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
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing facing, float hitX, float hitY, float hitZ){
|
|
|
|
if(getMetaFromState(state) >= 7){
|
|
|
|
if(!world.isRemote){
|
|
|
|
|
|
|
|
List<ItemStack> drops = getDrops(world, pos, state, 0);
|
|
|
|
for(ItemStack stack : drops){
|
|
|
|
if(stack != null && stack.getItem() == this.getSeed()){
|
|
|
|
stack.stackSize--;
|
|
|
|
}
|
|
|
|
EntityItem entity = new EntityItem(world, pos.getX()+.5, pos.getY()+.5, pos.getZ()+.5, stack);
|
|
|
|
world.spawnEntityInWorld(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
world.setBlockState(pos, getStateFromMeta(0));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-01-16 03:39:38 +01:00
|
|
|
}
|
2016-01-16 14:14:39 +01:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
private void register(){
|
2016-01-07 21:41:28 +01:00
|
|
|
this.setUnlocalizedName(ModUtil.MOD_ID_LOWER+"."+this.getBaseName());
|
2015-12-03 20:15:07 +01:00
|
|
|
GameRegistry.registerBlock(this, this.getItemBlock(), this.getBaseName());
|
|
|
|
if(this.shouldAddCreative()){
|
|
|
|
this.setCreativeTab(CreativeTab.instance);
|
|
|
|
}
|
2015-12-20 22:37:33 +01:00
|
|
|
else{
|
|
|
|
this.setCreativeTab(null);
|
|
|
|
}
|
2016-01-08 16:52:53 +01:00
|
|
|
|
2016-01-08 20:51:03 +01:00
|
|
|
this.registerRendering();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void registerRendering(){
|
|
|
|
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this), new ResourceLocation(ModUtil.MOD_ID_LOWER, this.getBaseName()));
|
2015-12-03 20:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected String getBaseName(){
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Class<? extends ItemBlockBase> getItemBlock(){
|
|
|
|
return ItemBlockBase.class;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-01-07 21:41:28 +01:00
|
|
|
public Item getSeed(){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.seedItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public Item getCrop(){
|
2015-06-21 02:28:49 +02:00
|
|
|
return this.returnItem;
|
|
|
|
}
|
2016-01-16 14:14:39 +01:00
|
|
|
|
2015-06-21 02:28:49 +02:00
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public Item getItemDropped(IBlockState state, Random rand, int par3){
|
|
|
|
return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public int damageDropped(IBlockState state){
|
|
|
|
return this.getMetaFromState(state) >= 7 ? this.returnMeta : 0;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public int getDamageValue(World world, BlockPos pos){
|
2015-10-03 10:19:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public int quantityDropped(IBlockState state, int fortune, Random random){
|
|
|
|
return this.getMetaFromState(state) >= 7 ? random.nextInt(addDropAmount)+minDropAmount : super.quantityDropped(state, fortune, random);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|