ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockWildPlant.java

135 lines
4.7 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BlockWildPlant.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
*
2017-01-01 16:23:26 +01:00
* © 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;
2015-06-28 03:12:32 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBushBase;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockPlant;
import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheWildPlants;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2015-06-28 03:12:32 +02:00
import net.minecraft.block.Block;
2018-06-23 18:37:41 +02:00
import net.minecraft.block.BlockCrops;
2016-03-18 23:47:22 +01:00
import net.minecraft.block.SoundType;
2015-06-28 03:12:32 +02:00
import net.minecraft.block.material.Material;
2016-11-21 16:23:48 +01:00
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
2015-06-28 03:12:32 +02:00
import net.minecraft.creativetab.CreativeTabs;
2021-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity;
2015-06-28 03:12:32 +02:00
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
2016-11-19 21:11:17 +01:00
import net.minecraft.util.NonNullList;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
2015-06-28 03:12:32 +02:00
import net.minecraft.world.World;
2019-05-02 09:10:29 +02:00
public class BlockWildPlant extends BlockBushBase {
2015-06-28 03:12:32 +02:00
2016-06-17 23:50:38 +02:00
public static final TheWildPlants[] ALL_WILD_PLANTS = TheWildPlants.values();
public static final PropertyEnum<TheWildPlants> TYPE = PropertyEnum.create("type", TheWildPlants.class);
2015-06-28 03:12:32 +02:00
public BlockWildPlant() {
super(this.name);
2016-04-20 21:39:03 +02:00
this.setSoundType(SoundType.PLANT);
2015-06-28 03:12:32 +02:00
}
@Override
2021-02-26 22:15:48 +01:00
public boolean canBlockStay(World world, BlockPos pos, BlockState state) {
2016-07-04 20:15:41 +02:00
BlockPos offset = pos.down();
2021-02-26 22:15:48 +01:00
BlockState offsetState = world.getBlockState(offset);
2016-07-04 20:15:41 +02:00
Block offsetBlock = offsetState.getBlock();
return state.getValue(TYPE) == TheWildPlants.RICE
? offsetState.getMaterial() == Material.WATER
: offsetBlock.canSustainPlant(offsetState, world, offset, Direction.UP, this);
2015-06-28 03:12:32 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
2021-02-26 22:15:48 +01:00
public ItemStack getPickBlock(BlockState state, RayTraceResult target, World world, BlockPos pos, PlayerEntity player) {
2018-08-04 04:34:52 +02:00
BlockPlant normal = (BlockPlant) state.getValue(TYPE).getNormalVersion();
return new ItemStack(normal.seedItem);
2015-10-03 10:19:40 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
for (int j = 0; j < ALL_WILD_PLANTS.length; j++) {
2017-06-17 00:48:49 +02:00
list.add(new ItemStack(this, 1, j));
2015-06-28 03:12:32 +02:00
}
}
2016-02-01 17:49:55 +01:00
@Override
2021-02-26 22:15:48 +01:00
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, BlockState state, int fortune) {
2018-08-04 04:34:52 +02:00
Block normal = state.getValue(TYPE).getNormalVersion();
normal.getDrops(drops, world, pos, normal.getDefaultState().withProperty(BlockCrops.AGE, 7), fortune);
2016-02-01 17:49:55 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
public boolean canSilkHarvest(World world, BlockPos pos, BlockState state, PlayerEntity player) {
2016-02-01 17:49:55 +01:00
return false;
}
@Override
2019-05-02 09:10:29 +02:00
protected ItemBlockBase getItemBlock() {
2016-04-20 21:39:03 +02:00
return new TheItemBlock(this);
}
@Override
2019-05-02 09:10:29 +02:00
public boolean shouldAddCreative() {
return false;
}
@Override
2019-05-02 09:10:29 +02:00
public void registerRendering() {
for (int i = 0; i < ALL_WILD_PLANTS.length; i++) {
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName() + "=" + ALL_WILD_PLANTS[i].getName());
}
}
2016-02-01 17:49:55 +01:00
@Override
2021-02-26 22:15:48 +01:00
public BlockState getStateFromMeta(int meta) {
2016-11-21 16:23:48 +01:00
return this.getDefaultState().withProperty(TYPE, TheWildPlants.values()[meta]);
}
@Override
2021-02-26 22:15:48 +01:00
public int getMetaFromState(BlockState state) {
2016-11-21 16:23:48 +01:00
return state.getValue(TYPE).ordinal();
2016-02-01 17:49:55 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
protected BlockStateContainer createBlockState() {
2016-11-21 16:23:48 +01:00
return new BlockStateContainer(this, TYPE);
}
@Override
2019-05-02 09:10:29 +02:00
public EnumRarity getRarity(ItemStack stack) {
return stack.getItemDamage() >= ALL_WILD_PLANTS.length
? EnumRarity.COMMON
: ALL_WILD_PLANTS[stack.getItemDamage()].getRarity();
2015-06-28 03:12:32 +02:00
}
2019-05-02 09:10:29 +02:00
public static class TheItemBlock extends ItemBlockBase {
2015-06-28 03:12:32 +02:00
2019-05-02 09:10:29 +02:00
public TheItemBlock(Block block) {
2015-06-28 03:12:32 +02:00
super(block);
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
2019-05-02 09:10:29 +02:00
public String getTranslationKey(ItemStack stack) {
return stack.getItemDamage() >= ALL_WILD_PLANTS.length
? StringUtil.BUGGED_ITEM_NAME
: this.getTranslationKey() + "_" + ALL_WILD_PLANTS[stack.getItemDamage()].getName();
2015-06-28 03:12:32 +02:00
}
}
}