2019-05-02 10:47:21 +02:00
|
|
|
/*
|
2021-02-26 22:15:48 +01: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
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
|
|
|
* © 2015-2017 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-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.block.CropsBlock;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.util.ActionResultType;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.util.Hand;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.util.IItemProvider;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
|
|
|
import net.minecraft.world.IBlockReader;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.world.World;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.world.server.ServerWorld;
|
|
|
|
import net.minecraftforge.common.PlantType;
|
2019-05-02 09:13:05 +02:00
|
|
|
import net.minecraftforge.items.ItemHandlerHelper;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
import java.util.List;
|
2021-02-26 22:15:48 +01:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
// CROP BLOCK DEFAULTS TO 7 YEARS OF AGE.
|
|
|
|
public class BlockPlant extends CropsBlock {
|
2016-06-01 00:39:35 +02:00
|
|
|
public Item seedItem;
|
2016-01-16 14:14:39 +01:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
// Stolen from potato for now
|
|
|
|
// PotatoBlock(AbstractBlock.Properties.create(Material.PLANTS).doesNotBlockMovement().tickRandomly().zeroHardnessAndResistance().sound(SoundType.CROP)));
|
|
|
|
public BlockPlant(Item seedItem) {
|
|
|
|
super(Properties.create(Material.PLANTS).doesNotBlockMovement().tickRandomly().zeroHardnessAndResistance().sound(SoundType.CROP));
|
2016-06-27 19:25:46 +02:00
|
|
|
this.seedItem = seedItem;
|
2015-12-03 20:15:07 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
// Remove
|
|
|
|
@Deprecated
|
|
|
|
public void doStuff(Item seedItem, Item returnItem, int returnMeta) {
|
|
|
|
this.seedItem = seedItem;
|
|
|
|
// this.returnItem = returnItem;
|
|
|
|
// this.returnMeta = returnMeta;
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2016-06-27 20:24:45 +02:00
|
|
|
@Override
|
2021-02-28 11:35:10 +01:00
|
|
|
public PlantType getPlantType(IBlockReader world, BlockPos pos) {
|
|
|
|
return PlantType.CROP;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2021-02-28 11:35:10 +01:00
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public int damageDropped(BlockState state) {
|
|
|
|
// return this.getMetaFromState(state) >= 7
|
|
|
|
// ? this.returnMeta
|
|
|
|
// : 0;
|
|
|
|
// }
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-06-28 21:28:58 +02:00
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2021-02-28 11:35:10 +01:00
|
|
|
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
|
|
|
if (this.getAge(state) < 7) {
|
|
|
|
return ActionResultType.PASS;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
if (!world.isRemote) {
|
|
|
|
List<ItemStack> drops = Block.getDrops(state, (ServerWorld) world, pos, null);
|
|
|
|
boolean deductedSeedSize = false;
|
|
|
|
for (ItemStack drop : drops) {
|
|
|
|
if (StackUtil.isValid(drop)) {
|
|
|
|
if (drop.getItem() == this.seedItem && !deductedSeedSize) {
|
|
|
|
drop.shrink(1);
|
|
|
|
deductedSeedSize = true;
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(drop)) {
|
2021-02-28 11:35:10 +01:00
|
|
|
ItemHandlerHelper.giveItemToPlayer(player, drop);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 11:35:10 +01:00
|
|
|
|
|
|
|
world.setBlockState(pos, this.getDefaultState().with(AGE, 0));
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
2021-02-28 11:35:10 +01:00
|
|
|
|
|
|
|
return super.onBlockActivated(state, world, pos, player, handIn, hit);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 20:39:11 +01:00
|
|
|
@Override
|
2021-02-28 11:35:10 +01:00
|
|
|
protected IItemProvider getSeedsItem() {
|
2016-02-01 20:32:49 +01:00
|
|
|
return this.seedItem;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
// @Override
|
|
|
|
// public int quantityDropped(BlockState state, int fortune, Random random) {
|
|
|
|
// return this.getMetaFromState(state) >= 7
|
|
|
|
// ? random.nextInt(this.addDropAmount) + this.minDropAmount
|
|
|
|
// : super.quantityDropped(state, fortune, random);
|
|
|
|
// }
|
2016-02-01 17:49:55 +01:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
// TODO: [port] move to data table
|
2016-02-01 17:49:55 +01:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
// @Override
|
|
|
|
// public Item getCrop() {
|
|
|
|
// return this.returnItem;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TODO: [port] move to data table
|
2016-02-01 17:49:55 +01:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
// @Override
|
|
|
|
// public Item getItemDropped(BlockState state, Random rand, int par3) {
|
|
|
|
// return this.getMetaFromState(state) >= 7
|
|
|
|
// ? this.getCrop()
|
|
|
|
// : this.getSeed();
|
|
|
|
// }
|
2021-02-26 22:15:48 +01:00
|
|
|
}
|