Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Ivorius.psychedelicraft.Crops;
- import com.Ivorius.psychedelicraft.Items.ItemsInit;
- import net.minecraft.block.*;
- import net.minecraft.fluid.FluidState;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.state.IntegerProperty;
- import net.minecraft.state.StateContainer;
- import net.minecraft.tags.FluidTags;
- import net.minecraft.util.Direction;
- import net.minecraft.util.IItemProvider;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.math.shapes.ISelectionContext;
- import net.minecraft.util.math.shapes.VoxelShape;
- import net.minecraft.world.IBlockReader;
- import net.minecraft.world.IWorld;
- import net.minecraft.world.IWorldReader;
- import net.minecraft.world.World;
- import net.minecraft.world.server.ServerWorld;
- import javax.swing.text.html.BlockView;
- import java.util.Random;
- import static net.minecraft.state.properties.BlockStateProperties.AGE_7;
- public class Cannabisplant extends BushBlock implements IGrowable{
- public static final IntegerProperty AGE = AGE_7;
- private static final VoxelShape[] SHAPE_BY_AGE = new VoxelShape[]{Block.box(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 10.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)};
- public Cannabisplant(Properties builder) {
- super(builder);
- this.registerDefaultState(this.stateDefinition.any().setValue(AGE, Integer.valueOf(0)));
- }
- @Override
- public ItemStack getCloneItemStack(IBlockReader p_185473_1_, BlockPos p_185473_2_, BlockState p_185473_3_) {
- return new ItemStack(ItemsInit.cannabisseeds.get());
- }
- //@Override
- //protected IItemProvider getBaseSeedId() {
- // return ItemsInit.cannabisseeds.get().getItem();
- // }
- @Override
- public VoxelShape getShape(BlockState p_220053_1_, IBlockReader p_220053_2_, BlockPos p_220053_3_, ISelectionContext p_220053_4_) {
- return SHAPE_BY_AGE[p_220053_1_.getValue(this.getAgeProperty())];
- }
- @Override
- public BlockState updateShape(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_, IWorld p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) {
- if (!p_196271_1_.canSurvive(p_196271_4_, p_196271_5_)) {
- p_196271_4_.getBlockTicks().scheduleTick(p_196271_5_, this, 1);
- }
- return super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_);
- }
- @Deprecated
- public void tick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
- if (!state.isViewBlocking(world, pos)) {
- world.destroyBlock(pos, true);
- } else if (world.isEmptyBlock(pos.above())) {
- int i = 1;
- for (; world.getBlockState(pos.below(i)).getBlock() == this; ++i);
- if (i < 14) {
- int j = state.getValue(AGE);
- if (j == 7) {
- world.setBlock(pos, state.setValue(AGE, 7), 4);
- } else {
- world.setBlock(pos, state.setValue(AGE, j + 1), 4);
- }
- }
- }
- }
- @Override
- public BlockState getPlant(IBlockReader world, BlockPos pos) {
- return defaultBlockState();
- }
- @Override
- protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> p_206840_1_) {
- p_206840_1_.add(AGE);
- }
- @Override
- public boolean canSurvive(BlockState p_196260_1_, IWorldReader p_196260_2_, BlockPos p_196260_3_) {
- BlockState soil = p_196260_2_.getBlockState(p_196260_3_.below());
- if (soil.canSustainPlant(p_196260_2_, p_196260_3_.below(), Direction.UP, this)) return true;
- BlockState blockstate = p_196260_2_.getBlockState(p_196260_3_.below());
- if (blockstate.getBlock() == this) {
- return true;
- } else {
- if (blockstate.is(Blocks.DIRT) || blockstate.is(Blocks.COARSE_DIRT) || blockstate.is(Blocks.PODZOL)) {
- BlockPos blockpos = p_196260_3_.below();
- for(Direction direction : Direction.Plane.HORIZONTAL) {
- BlockState blockstate1 = p_196260_2_.getBlockState(blockpos.relative(direction));
- FluidState fluidstate = p_196260_2_.getFluidState(blockpos.relative(direction));
- if (fluidstate.is(FluidTags.WATER) || blockstate1.is(Blocks.FROSTED_ICE)|| blockstate.is(Blocks.DIRT)|| blockstate.is(Blocks.PODZOL)) {
- return true;
- }
- }
- }
- return false;
- }
- }
- public void randomTick(BlockState p_225542_1_, ServerWorld p_225542_2_, BlockPos p_225542_3_, Random p_225542_4_) {
- BlockPos blockpos = p_225542_3_.above();
- if (p_225542_2_.isEmptyBlock(blockpos)) {
- int i;
- for(i = 1; p_225542_2_.getBlockState(p_225542_3_.below(i)).is(this); ++i) {
- }
- if (i < 8) {
- int j = p_225542_1_.getValue(AGE);
- if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(p_225542_2_, blockpos, p_225542_1_, true)) {
- if (j == 7) {
- p_225542_2_.setBlockAndUpdate(blockpos, this.defaultBlockState());
- BlockState blockstate = p_225542_1_.setValue(AGE, Integer.valueOf(7));
- p_225542_2_.setBlock(p_225542_3_, blockstate, 7);
- blockstate.neighborChanged(p_225542_2_, blockpos, this, p_225542_3_, false);
- } else {
- p_225542_2_.setBlock(p_225542_3_, p_225542_1_.setValue(AGE, Integer.valueOf(j + 1)), 7);
- }
- net.minecraftforge.common.ForgeHooks.onCropsGrowPost(p_225542_2_, p_225542_3_, p_225542_1_);
- }
- }
- }
- }
- @Override
- public boolean isValidBonemealTarget(IBlockReader p_176473_1_, BlockPos p_176473_2_, BlockState p_176473_3_, boolean p_176473_4_) {
- return !this.isMaxAge(p_176473_3_);
- }
- public boolean isMaxAge(BlockState p_185525_1_) {
- return p_185525_1_.getValue(this.getAgeProperty()) >= this.getMaxAge();
- }
- @Override
- public boolean isBonemealSuccess(World p_180670_1_, Random p_180670_2_, BlockPos p_180670_3_, BlockState p_180670_4_) {
- return true;
- }
- @Override
- public void performBonemeal(ServerWorld p_225535_1_, Random p_225535_2_, BlockPos p_225535_3_, BlockState p_225535_4_) {
- this.growCrops(p_225535_1_, p_225535_3_, p_225535_4_);
- }
- protected int getAge(BlockState p_185527_1_) {
- return p_185527_1_.getValue(this.getAgeProperty());
- }
- public IntegerProperty getAgeProperty() {
- return AGE;
- }
- public int getMaxAge() {
- return 7;
- }
- public void growCrops(World p_176487_1_, BlockPos p_176487_2_, BlockState p_176487_3_) {
- int i = this.getAge(p_176487_3_) + this.getBonemealAgeIncrease(p_176487_1_);
- int j = this.getMaxAge();
- if (i > j) {
- i = j;
- }
- p_176487_1_.setBlock(p_176487_2_, this.getStateForAge(i), 2);
- }
- public BlockState getStateForAge(int p_185528_1_) {
- return this.defaultBlockState().setValue(this.getAgeProperty(), Integer.valueOf(p_185528_1_));
- }
- protected int getBonemealAgeIncrease(World p_185529_1_) {
- return MathHelper.nextInt(p_185529_1_.random, 2, 5);
- }
- protected static float getGrowthSpeed(Block p_180672_0_, IBlockReader p_180672_1_, BlockPos p_180672_2_) {
- float f = 1.0F;
- BlockPos blockpos = p_180672_2_.below();
- for (int i = -1; i <= 1; ++i) {
- for (int j = -1; j <= 1; ++j) {
- float f1 = 0.0F;
- BlockState blockstate = p_180672_1_.getBlockState(blockpos.offset(i, 0, j));
- if (blockstate.canSustainPlant(p_180672_1_, blockpos.offset(i, 0, j), net.minecraft.util.Direction.UP, (net.minecraftforge.common.IPlantable) p_180672_0_)) {
- f1 = 1.0F;
- if (blockstate.isFertile(p_180672_1_, p_180672_2_.offset(i, 0, j))) {
- f1 = 3.0F;
- }
- }
- if (i != 0 || j != 0) {
- f1 /= 4.0F;
- }
- f += f1;
- }
- }
- BlockPos blockpos1 = p_180672_2_.north();
- BlockPos blockpos2 = p_180672_2_.south();
- BlockPos blockpos3 = p_180672_2_.west();
- BlockPos blockpos4 = p_180672_2_.east();
- boolean flag = p_180672_0_ == p_180672_1_.getBlockState(blockpos3).getBlock() || p_180672_0_ == p_180672_1_.getBlockState(blockpos4).getBlock();
- boolean flag1 = p_180672_0_ == p_180672_1_.getBlockState(blockpos1).getBlock() || p_180672_0_ == p_180672_1_.getBlockState(blockpos2).getBlock();
- if (flag && flag1) {
- f /= 2.0F;
- } else {
- boolean flag2 = p_180672_0_ == p_180672_1_.getBlockState(blockpos3.north()).getBlock() || p_180672_0_ == p_180672_1_.getBlockState(blockpos4.north()).getBlock() || p_180672_0_ == p_180672_1_.getBlockState(blockpos4.south()).getBlock() || p_180672_0_ == p_180672_1_.getBlockState(blockpos3.south()).getBlock();
- if (flag2) {
- f /= 2.0F;
- }
- }
- return f;
- }
- private Item seed;
- public void setSeed(Item seed) {
- this.seed = seed;
- }
- protected IItemProvider getSeedsItem() {
- return ItemsInit.cannabisseeds.get().getItem();
- }
- protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) {
- return floor.is(Blocks.DIRT) || floor.is(Blocks.FARMLAND);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment