Various fixes to tomato plants and cereal

This commit is contained in:
Sollace 2019-01-09 15:29:08 +02:00
parent c89ac2419f
commit 1289ed16fd
4 changed files with 88 additions and 9 deletions

View file

@ -97,6 +97,10 @@ public class UItems {
.setTranslationKey("cereal")
.setRegistryName(Unicopia.MODID, "cereal");
public static final Item sugar_cereal = new ItemSoup(15)
.setTranslationKey("sugar_cereal")
.setRegistryName(Unicopia.MODID, "sugar_cereal");
public static final ItemTomato tomato = new ItemTomato(Unicopia.MODID, "tomato", 4, 34);
public static final ItemTomato cloudsdale_tomato = new ItemTomato(Unicopia.MODID, "cloudsdale_tomato", 16, 4);
public static final ItemTomatoSeeds tomato_seeds = new ItemTomatoSeeds(Unicopia.MODID, "tomato_seeds");
@ -114,7 +118,7 @@ public class UItems {
bag_of_holding, spell, curse,
alfalfa_seeds, alfalfa_leaves, cereal,
tomato_seeds, tomato);
cloudsdale_tomato, tomato_seeds, tomato);
if (UClient.isClientSide()) {
registerAllVariants(apple, apple.getVariants());
@ -132,6 +136,7 @@ public class UItems {
registerAllVariants(alfalfa_seeds, "alfalfa_seeds");
registerAllVariants(alfalfa_leaves, "alfalfa_leaves");
registerAllVariants(cereal, "cereal");
registerAllVariants(sugar_cereal, "sugar_cereal");
registerAllVariants(tomato, "tomato", "rotten_tomato");
registerAllVariants(cloudsdale_tomato, "cloudsdale_tomato", "rotten_cloudsdale_tomato");
registerAllVariants(tomato_seeds, "tomato_seeds");

View file

@ -5,6 +5,7 @@ import java.util.Random;
import com.minelittlepony.unicopia.UItems;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@ -16,20 +17,36 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable;
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);
setDefaultState(getDefaultState().withProperty(TYPE, Type.NORMAL));
setHardness(3);
setSoundType(SoundType.WOOD);
}
@Deprecated
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return BOUNDING_BOX.offset(getOffset(state, source, pos));
}
@Override
@ -52,21 +69,45 @@ public class BlockTomatoPlant extends BlockCrops {
return UItems.tomato;
}
public boolean canPlaceBlockAt(World world, BlockPos pos) {
if (world.getBlockState(pos.down()).getBlock() instanceof BlockTomatoPlant) {
return true;
}
return super.canPlaceBlockAt(world, pos);
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) {
if (direction == EnumFacing.UP && state.getBlock() instanceof BlockTomatoPlant) {
return true;
}
return super.canSustainPlant(state, world, pos, direction, plantable);
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (getAge(state) == 0) {
return;
}
if (state.getValue(TYPE) != Type.CLOUDSDALE) {
if (world.isAreaLoaded(pos, 1) && world.getBlockState(pos.down()).getBlock() instanceof BlockCloudFarm) {
state = state.withProperty(TYPE, Type.CLOUDSDALE);
checkAndDropBlock(world, pos, state);
world.setBlockState(pos, state);
if (world.isAreaLoaded(pos, 1) && world.getLightFromNeighbors(pos.up()) >= 9) {
int i = getAge(state);
if (i < getMaxAge()) {
float f = getGrowthChance(this, world, pos);
if(ForgeHooks.onCropsGrowPre(world, pos, state, rand.nextInt((int)(25 / f) + 1) == 0)) {
world.setBlockState(pos, state.withProperty(getAgeProperty(), i + 1), 2);
ForgeHooks.onCropsGrowPost(world, pos, state, world.getBlockState(pos));
}
}
}
super.updateTick(world, pos, state, rand);
}
@Override
@ -116,7 +157,9 @@ public class BlockTomatoPlant extends BlockCrops {
if (hand == EnumHand.MAIN_HAND && isMaxAge(state)) {
if (player.getHeldItem(hand).isEmpty()) {
Item crop = state.getValue(TYPE) == Type.CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
Type type = state.getValue(TYPE);
Item crop = type == Type.CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
spawnAsEntity(world, pos, new ItemStack(crop, getAge(state), 0));
world.setBlockState(pos, state.withProperty(getAgeProperty(), 0));
@ -127,6 +170,13 @@ public class BlockTomatoPlant extends BlockCrops {
return false;
}
@Override
public void grow(World worldIn, BlockPos pos, IBlockState state) {
int age = Math.min(getAge(state) + getBonemealAgeIncrease(worldIn), getMaxAge());
worldIn.setBlockState(pos, state.withProperty(getAgeProperty(), age), 2);
}
public boolean plant(World world, BlockPos pos, IBlockState state) {
if (getAge(state) == 0) {
world.setBlockState(pos, state.withProperty(getAgeProperty(), 1));
@ -136,6 +186,22 @@ public class BlockTomatoPlant extends BlockCrops {
return false;
}
@Override
public IBlockState getStateFromMeta(int meta) {
int age = meta % (getMaxAge() + 1);
int half = meta >> 3;;
return withAge(age).withProperty(TYPE, Type.values()[half]);
}
@Override
public int getMetaFromState(IBlockState state) {
int age = getAge(state);
int half = state.getValue(TYPE).ordinal();
return (half << 3) + age;
}
public static enum Type implements IStringSerializable {
NORMAL,
CLOUDSDALE;

View file

@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import com.minelittlepony.unicopia.block.BlockTomatoPlant.Type;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -16,6 +17,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -44,6 +46,10 @@ public class ItemStick extends ItemSeeds {
worldIn.setBlockState(pos.up(), cropState);
SoundType sound = state.getBlock().getSoundType(state, worldIn, pos, player);
worldIn.playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1) / 2, sound.getPitch());
if (player instanceof EntityPlayerMP) {
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos.up(), itemstack);
}

View file

@ -47,13 +47,15 @@ item.apple.zap_cooked.name=Cooked Zap Apple
item.tomato.name=Tomato
item.tomato.rotten.name=Rotten Tomato
item.tomato.cloud.name=Cloudsdale Tomato
item.tomato_seeds.name=Tomato Seeds
item.cloudsdale_tomato.name=Cloudsdale Tomato
item.alfalfa_leaves.name=Alfalfa
item.alfalfa_seeds.name=Grain
item.cereal.name=Breakfast Cereal
item.sugar_cereal.name=Boop 'o Roops
entity.racing_cloud.name=Bucking Bronco
entity.construction_cloud.name=Construction Cloud