Split tomato plants and sticks into separate blocks

This commit is contained in:
Sollace 2019-03-14 22:46:49 +02:00
parent 90635394a3
commit 503c1c9eea
6 changed files with 118 additions and 28 deletions

View file

@ -0,0 +1,91 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.init.UItems;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;
public class BlockStick extends Block implements IPlantable {
static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(
7/16F, -1/16F, 7/16F,
9/16F, 15/16F, 9/16F
);
public BlockStick(String domain, String name) {
super(Material.PLANTS);
setRegistryName(domain, name);
setTranslationKey(name);
setHardness(0.2F);
setSoundType(SoundType.WOOD);
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Deprecated
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Deprecated
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return BOUNDING_BOX.offset(state.getOffset(source, pos));
}
@Deprecated
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return state.getBoundingBox(world, pos);
}
@Override
public EnumOffsetType getOffsetType() {
return EnumOffsetType.XZ;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return UItems.stick;
}
public boolean canSustainPlant(IBlockAccess world, BlockPos pos, IPlantable plantable) {
pos = pos.down();
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof BlockStick) {
return ((BlockStick)block).canSustainPlant(world, pos, plantable);
}
return block.canSustainPlant(state, world, pos, EnumFacing.UP, plantable);
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Crop;
}
@Override
public IBlockState getPlant(IBlockAccess world, BlockPos pos) {
return getDefaultState();
}
}

View file

@ -4,6 +4,7 @@ import java.util.Random;
import com.minelittlepony.unicopia.init.UItems;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyEnum;
@ -30,11 +31,6 @@ public class BlockTomatoPlant extends BlockCrops {
public static final PropertyEnum<Type> TYPE = PropertyEnum.create("type", Type.class);
private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(
7/16F, -1/16F, 7/16F,
9/16F, 15/16F, 9/16F
);
public BlockTomatoPlant(String domain, String name) {
setRegistryName(domain, name);
setTranslationKey(name);
@ -47,7 +43,7 @@ public class BlockTomatoPlant extends BlockCrops {
@Deprecated
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return BOUNDING_BOX.offset(state.getOffset(source, pos));
return BlockStick.BOUNDING_BOX.offset(state.getOffset(source, pos));
}
@Deprecated
@ -96,10 +92,6 @@ public class BlockTomatoPlant extends BlockCrops {
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (getAge(state) == 0) {
return;
}
checkAndDropBlock(world, pos, state);
if (world.isAreaLoaded(pos, 1) && world.getLightFromNeighbors(pos.up()) >= 9) {
@ -117,11 +109,6 @@ public class BlockTomatoPlant extends BlockCrops {
}
}
@Override
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) {
return getAge(state) > 0 && super.canGrow(worldIn, pos, state, isClient);
}
@Override
public int quantityDropped(IBlockState state, int fortune, Random random) {
return 1;
@ -134,9 +121,6 @@ public class BlockTomatoPlant extends BlockCrops {
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
if (getAge(state) == 0) {
return Items.AIR;
}
if (isMaxAge(state)) {
return state.getValue(TYPE) == Type.CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
@ -195,9 +179,11 @@ public class BlockTomatoPlant extends BlockCrops {
}
public boolean plant(World world, BlockPos pos, IBlockState state) {
if (getAge(state) == 0) {
Block block = state.getBlock();
world.setBlockState(pos, state.withProperty(getAgeProperty(), 1));
if (block instanceof BlockStick && ((BlockStick)block).canSustainPlant(world, pos, this)) {
world.setBlockState(pos, getPlacedState(world, pos, state).withProperty(getAgeProperty(), 1));
SoundType sound = getSoundType(state, world, pos, null);
@ -217,7 +203,12 @@ public class BlockTomatoPlant extends BlockCrops {
return withAge(age).withProperty(TYPE, Type.values()[half]);
}
public IBlockState getPlacedState(IBlockState state) {
public IBlockState getPlacedState(World world, BlockPos pos, IBlockState state) {
if (state.getBlock() instanceof BlockStick) {
pos = pos.down();
return getPlacedState(world, pos, world.getBlockState(pos));
}
if (state.getBlock() instanceof BlockCloudFarm) {
return getDefaultState().withProperty(TYPE, Type.CLOUDSDALE);
}

View file

@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.block.BlockGlowingGem;
import com.minelittlepony.unicopia.block.BlockGrowingCuccoon;
import com.minelittlepony.unicopia.block.BlockHiveWall;
import com.minelittlepony.unicopia.block.BlockSlimeLayer;
import com.minelittlepony.unicopia.block.BlockStick;
import com.minelittlepony.unicopia.block.BlockCloudAnvil;
import com.minelittlepony.unicopia.block.BlockCloudBanister;
import com.minelittlepony.unicopia.block.BlockCloudSlab;
@ -70,6 +71,7 @@ public class UBlocks {
public static final BlockAlfalfa alfalfa = new BlockAlfalfa(Unicopia.MODID, "alfalfa");
public static final BlockStick stick = new BlockStick(Unicopia.MODID, "stick");
public static final BlockTomatoPlant tomato_plant = new BlockTomatoPlant(Unicopia.MODID, "tomato_plant");
public static final BlockCloudFarm cloud_farmland = new BlockCloudFarm(Unicopia.MODID, "cloud_farmland");
@ -104,7 +106,7 @@ public class UBlocks {
anvil, cloud_farmland,
sugar_block, flower_pot,
alfalfa,
tomato_plant,
stick, tomato_plant,
enchanted_torch,
apple_tree, apple_leaves);
}

View file

@ -33,9 +33,9 @@ public class ItemStick extends ItemSeeds {
ItemStack itemstack = player.getHeldItem(hand);
IBlockState state = worldIn.getBlockState(pos);
if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up())) {
if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && worldIn.isAirBlock(pos.up())) {
worldIn.setBlockState(pos.up(), UBlocks.tomato_plant.getPlacedState(state));
worldIn.setBlockState(pos.up(), UBlocks.stick.getDefaultState());
SoundType sound = state.getBlock().getSoundType(state, worldIn, pos, player);

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import com.minelittlepony.unicopia.block.BlockStick;
import com.minelittlepony.unicopia.init.UBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@ -28,8 +29,8 @@ public class ItemTomatoSeeds extends Item {
Block block = state.getBlock();
if (block instanceof BlockTomatoPlant) {
if (((BlockTomatoPlant)block).plant(world, pos, state)) {
if (block instanceof BlockStick) {
if (UBlocks.tomato_plant.plant(world, pos, state)) {
if (!player.capabilities.isCreativeMode) {
player.getHeldItem(hand).shrink(1);
}

View file

@ -0,0 +1,5 @@
{
"variants": {
"normal": { "model": "unicopia:tomato_plant/stage0" }
}
}