ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockPlant.java

142 lines
4.5 KiB
Java
Raw Normal View History

2019-05-02 10:47:21 +02:00
/*
2019-05-02 10:43:27 +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
* 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
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.BlockState;
import net.minecraft.block.CropsBlock;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.PlayerEntity;
2015-05-20 22:39:43 +02:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.IItemProvider;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
2015-05-20 22:39:43 +02:00
import net.minecraft.world.World;
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
import java.util.List;
public class BlockPlant extends CropsBlock {// implements ItemBlockBase.ICustomRarity, IHasModel {
2015-05-20 22:39:43 +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;
private Item returnItem;
private int returnMeta;
2015-05-20 22:39:43 +02:00
// todo: find the correct properties for crops
public BlockPlant(int minDropAmount, int addDropAmount) {
super(Properties.create(Material.PLANTS));
// this.name = name;
this.minDropAmount = minDropAmount;
this.addDropAmount = addDropAmount;
// this.register();
}
2016-01-16 14:14:39 +01:00
// todo: check what this is doing
2019-05-02 09:10:29 +02:00
public void doStuff(Item seedItem, Item returnItem, int returnMeta) {
this.seedItem = seedItem;
this.returnItem = returnItem;
this.returnMeta = returnMeta;
}
// private void register() {
// ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
// }
2016-01-08 20:51:03 +01:00
// protected String getBaseName() {
// return this.name;
// }
// protected ItemBlockBase getItemBlock() {
// return new ItemBlockBase(this);
// }
2019-05-02 09:10:29 +02:00
public boolean shouldAddCreative() {
return false;
2015-12-19 10:30:39 +01:00
}
// @Override
// public void registerRendering() {
// ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
// }
//
2016-02-01 17:49:55 +01:00
2015-05-20 22:39:43 +02:00
2015-06-28 21:28:58 +02:00
@Override
public PlantType getPlantType(IBlockReader world, BlockPos pos) {
return PlantType.Crop;
2015-06-28 21:28:58 +02:00
}
//
// @Override
// public int damageDropped(IBlockState state) {
// return this.getMetaFromState(state) >= 7 ? this.returnMeta : 0;
// }
2015-06-28 21:28:58 +02:00
2015-05-20 22:39:43 +02:00
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (getAge(state) > 7) {
2019-05-02 09:10:29 +02:00
if (!world.isRemote) {
List<ItemStack> drops = getDrops(state, (ServerWorld) world, pos, null);
2016-01-16 14:14:39 +01:00
2016-02-01 17:49:55 +01:00
boolean deductedSeedSize = false;
2019-05-02 09:10:29 +02:00
for (ItemStack drop : drops) {
if (StackUtil.isValid(drop)) {
if (drop.getItem() == this.seedItem && !deductedSeedSize) {
drop.shrink(1);
2016-02-01 17:49:55 +01:00
deductedSeedSize = true;
}
2019-05-02 10:43:27 +02:00
if (StackUtil.isValid(drop)) {
2019-05-02 09:13:05 +02:00
ItemHandlerHelper.giveItemToPlayer(player, drop);
2016-02-01 17:49:55 +01:00
}
}
}
world.setBlockState(pos, state.with(AGE, 0));
2016-02-01 17:49:55 +01:00
}
return ActionResultType.SUCCESS;
2016-02-01 17:49:55 +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
protected IItemProvider getSeedsItem() {
return this.seedItem;
2015-10-03 10:19:40 +02:00
}
// todo: this is likely handled by loot tables now
2016-02-01 17:49:55 +01:00
// @Override
// public int quantityDropped(IBlockState 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
// @Override
// public Item getCrop() {
// return this.returnItem;
// }
// @Override
// public Item getItemDropped(IBlockState state, Random rand, int par3) {
// 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
}