Implemented tomato plants

This commit is contained in:
Sollace 2019-01-08 22:23:22 +02:00
parent 7e8e860341
commit e8206a16e7
20 changed files with 391 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.block.BlockCloud;
import com.minelittlepony.unicopia.block.BlockCloudAnvil;
import com.minelittlepony.unicopia.block.BlockCloudSlab;
import com.minelittlepony.unicopia.block.BlockCloudStairs;
import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import com.minelittlepony.unicopia.block.BlockCloudDoor;
import com.minelittlepony.unicopia.block.BlockCloudFarm;
@ -25,10 +26,13 @@ public class UBlocks {
public static final BlockAlfalfa alfalfa = new BlockAlfalfa(Unicopia.MODID, "alfalfa");
public static final BlockTomatoPlant tomato_plant = new BlockTomatoPlant(Unicopia.MODID, "tomato_plant");
public static final BlockCloudFarm cloud_farmland = new BlockCloudFarm(Unicopia.MODID, "cloud_farmland");
static void registerBlocks(IForgeRegistry<Block> registry) {
registry.registerAll(cloud, cloud_stairs, double_cloud_slab, cloud_slab, mist_door, anvil, cloud_farmland,
alfalfa);
alfalfa,
tomato_plant);
}
}

View file

@ -5,7 +5,9 @@ import com.minelittlepony.unicopia.item.ItemCloud;
import com.minelittlepony.unicopia.item.ItemCurse;
import com.minelittlepony.unicopia.item.ItemOfHolding;
import com.minelittlepony.unicopia.item.ItemSpell;
import com.minelittlepony.unicopia.item.ItemStick;
import com.minelittlepony.unicopia.item.ItemTomato;
import com.minelittlepony.unicopia.item.ItemTomatoSeeds;
import com.minelittlepony.unicopia.item.UItemBlock;
import com.minelittlepony.unicopia.item.UItemMultiTexture;
import com.minelittlepony.unicopia.item.UItemSlab;
@ -29,7 +31,6 @@ import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.registries.IForgeRegistry;
@ -83,7 +84,10 @@ public class UItems {
public static final Item alfalfa_seeds = new ItemSeedFood(1, 4, UBlocks.alfalfa, Blocks.FARMLAND)
.setTranslationKey("alfalfa_seeds")
.setRegistryName(Unicopia.MODID, "alfalfa_seeds");
.setRegistryName(Unicopia.MODID, "alfalfa_seeds")
.setCreativeTab(CreativeTabs.MATERIALS);
public static final ItemStick stick = new ItemStick();
public static final Item alfalfa_leaves = new ItemFood(1, 3, false)
.setTranslationKey("alfalfa_leaves")
@ -95,18 +99,22 @@ public class UItems {
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");
static void registerItems(IForgeRegistry<Item> registry) {
RegistryLockSpinner.unlock(Item.REGISTRY);
Item.REGISTRY.register(Item.getIdFromItem(Items.APPLE), new ResourceLocation("apple"), apple);
RegistryLockSpinner.commit(Item.REGISTRY, Items.APPLE, apple, Items.class);
RegistryLockSpinner.commit(Item.REGISTRY, Items.STICK, stick, Items.class);
RegistryLockSpinner.lock(Item.REGISTRY);
registry.registerAll(cloud_spawner, dew_drop, cloud_matter, cloud_block,
cloud_stairs, cloud_slab, mist_door, anvil,
bag_of_holding, spell, curse,
alfalfa_seeds, alfalfa_leaves, cereal, tomato);
alfalfa_seeds, alfalfa_leaves, cereal,
tomato_seeds, tomato);
if (UClient.isClientSide()) {
registerAllVariants(apple, apple.getVariants());
@ -126,6 +134,7 @@ public class UItems {
registerAllVariants(cereal, "cereal");
registerAllVariants(tomato, "tomato", "rotten_tomato");
registerAllVariants(cloudsdale_tomato, "cloudsdale_tomato", "rotten_cloudsdale_tomato");
registerAllVariants(tomato_seeds, "tomato_seeds");
}
registerFuels();

View file

@ -0,0 +1,151 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.UItems;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
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.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class BlockTomatoPlant extends BlockCrops {
public static final PropertyEnum<Type> TYPE = PropertyEnum.create("type", Type.class);
public BlockTomatoPlant(String domain, String name) {
setRegistryName(domain, name);
setTranslationKey(name);
setDefaultState(getDefaultState().withProperty(TYPE, Type.NORMAL));
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, TYPE, AGE);
}
@Override
public EnumOffsetType getOffsetType() {
return EnumOffsetType.XZ;
}
@Override
protected Item getSeed() {
return UItems.tomato_seeds;
}
@Override
protected Item getCrop() {
return UItems.tomato;
}
@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);
world.setBlockState(pos, state);
}
}
super.updateTick(world, pos, state, rand);
}
@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;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Crop;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
if (getAge(state) == 0) {
return UItems.stick;
}
if (isMaxAge(state)) {
return state.getValue(TYPE) == Type.CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
}
return getSeed();
}
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
Random rand = world instanceof World ? ((World)world).rand : RANDOM;
Item item = getItemDropped(state, rand, fortune);
if (item != Items.AIR) {
drops.add(new ItemStack(item, 1, damageDropped(state)));
if (getAge(state) > 0) {
drops.add(new ItemStack(item, rand.nextInt(2), 1));
}
}
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (hand == EnumHand.MAIN_HAND && isMaxAge(state)) {
if (player.getHeldItem(hand).isEmpty()) {
Item crop = state.getValue(TYPE) == Type.CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
spawnAsEntity(world, pos, new ItemStack(crop, getAge(state), 0));
world.setBlockState(pos, state.withProperty(getAgeProperty(), 0));
return true;
}
}
return false;
}
public boolean plant(World world, BlockPos pos, IBlockState state) {
if (getAge(state) == 0) {
world.setBlockState(pos, state.withProperty(getAgeProperty(), 1));
return true;
}
return false;
}
public static enum Type implements IStringSerializable {
NORMAL,
CLOUDSDALE;
public String toString() {
return getName();
}
public String getName() {
return this == NORMAL ? "normal" : "cloudsdale";
}
}
}

View file

@ -20,6 +20,21 @@ public class RegistryLockSpinner {
}
}
public static <K, V> void commit(RegistryNamespaced<K, V> registry, V from, V to, Class<?> inClass) {
registry.register(registry.getIDForObject(from), registry.getNameForObject(from), to);
for (Field i : inClass.getDeclaredFields()) {
try {
if (i.get(null) == from) {
i.set(null, to);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
public static void lock(RegistryNamespaced<?, ?> registry) {
if (registry instanceof ILockableRegistry) {
((ILockableRegistry) registry).lock();

View file

@ -0,0 +1,57 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.block.BlockCloudFarm;
import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import com.minelittlepony.unicopia.block.BlockTomatoPlant.Type;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemStick extends ItemSeeds {
public ItemStick() {
super(UBlocks.tomato_plant, Blocks.FARMLAND);
setFull3D();
setTranslationKey("stick");
setCreativeTab(CreativeTabs.MATERIALS);
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
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())) {
IBlockState cropState = UBlocks.tomato_plant.getDefaultState();
if (state.getBlock() instanceof BlockCloudFarm) {
cropState = cropState.withProperty(BlockTomatoPlant.TYPE, Type.CLOUDSDALE);
}
worldIn.setBlockState(pos.up(), cropState);
if (player instanceof EntityPlayerMP) {
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos.up(), itemstack);
}
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}
}

View file

@ -0,0 +1,36 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemTomatoSeeds extends Item {
public ItemTomatoSeeds(String domain, String name) {
setTranslationKey(name);
setRegistryName(domain, name);
setCreativeTab(CreativeTabs.MATERIALS);
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockTomatoPlant) {
if (((BlockTomatoPlant)state.getBlock()).plant(world, pos, state)) {
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
}

View file

@ -0,0 +1,20 @@
{
"variants": {
"age=0,type=normal": { "model": "unicopia:tomato_plant/stage0" },
"age=1,type=normal": { "model": "unicopia:tomato_plant/stage1" },
"age=2,type=normal": { "model": "unicopia:tomato_plant/stage1" },
"age=3,type=normal": { "model": "unicopia:tomato_plant/stage2" },
"age=4,type=normal": { "model": "unicopia:tomato_plant/stage2" },
"age=5,type=normal": { "model": "unicopia:tomato_plant/stage3" },
"age=6,type=normal": { "model": "unicopia:tomato_plant/stage4" },
"age=7,type=normal": { "model": "unicopia:tomato_plant/stage4" },
"age=0,type=cloudsdale": { "model": "unicopia:tomato_plant/stage0" },
"age=1,type=cloudsdale": { "model": "unicopia:tomato_plant/stage1" },
"age=2,type=cloudsdale": { "model": "unicopia:tomato_plant/stage1" },
"age=3,type=cloudsdale": { "model": "unicopia:tomato_plant/stage2" },
"age=4,type=cloudsdale": { "model": "unicopia:tomato_plant/stage2" },
"age=5,type=cloudsdale": { "model": "unicopia:tomato_plant/stage3" },
"age=6,type=cloudsdale": { "model": "unicopia:tomato_plant/stage4" },
"age=7,type=cloudsdale": { "model": "unicopia:tomato_plant/stage4" }
}
}

View file

@ -48,10 +48,13 @@ 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.alfalfa_leaves.name=Alfalfa
item.alfalfa_seeds.name=Grain
item.cereal.name=Breakfast Cereal
entity.racing_cloud.name=Bucking Bronco
entity.construction_cloud.name=Construction Cloud
entity.cloud.name=Cloud

View file

@ -0,0 +1,20 @@
{
"textures": {
"stick_top": "minecraft:blocks/log_oak_top",
"stick_side": "minecraft:blocks/log_oak",
"particle": "#stick_side"
},
"elements": [
{ "from": [ 7, -1, 7 ],
"to": [ 9, 15, 9 ],
"faces": {
"up": { "uv": [ 7, 7, 9, 9 ], "texture": "#stick_top", "cullface": "up" },
"down": { "uv": [ 7, 7, 9, 9 ], "texture": "#stick_top", "cullface": "down" },
"north": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "north" },
"south": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "south" },
"west": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "west" },
"east": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "east" }
}
}
]
}

View file

@ -0,0 +1,47 @@
{
"parent": "unicopia:block/tomato_plant/stage0",
"textures": {
"crop": "unicopia:blocks/tomato_plant/stage_1"
},
"elements": [
{ "from": [ 7, -1, 7 ],
"to": [ 9, 15, 9 ],
"faces": {
"up": { "uv": [ 7, 7, 9, 9 ], "texture": "#stick_top", "cullface": "up" },
"down": { "uv": [ 7, 7, 9, 9 ], "texture": "#stick_top", "cullface": "down" },
"north": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "north" },
"south": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "south" },
"west": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "west" },
"east": { "uv": [ 0, 0, 2, 16 ], "texture": "#stick_side", "cullface": "east" }
}
},
{ "from": [ 0.8, 0, 8 ],
"to": [ 15.2, 16, 8 ],
"rotation": {
"origin": [ 8, 8, 8 ],
"axis": "y",
"angle": 45,
"rescale": true
},
"shade": false,
"faces": {
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#crop" },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#crop" }
}
},
{ "from": [ 8, 0, 0.8 ],
"to": [ 8, 16, 15.2 ],
"rotation": {
"origin": [ 8, 8, 8 ],
"axis": "y",
"angle": 45,
"rescale": true
},
"shade": false,
"faces": {
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#crop" },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#crop" }
}
}
]
}

View file

@ -0,0 +1,6 @@
{
"parent": "unicopia:block/tomato_plant/stage1",
"textures": {
"crop": "unicopia:blocks/tomato_plant/stage_2"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "unicopia:block/tomato_plant/stage1",
"textures": {
"crop": "unicopia:blocks/tomato_plant/stage_3"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "unicopia:block/tomato_plant/stage1",
"textures": {
"crop": "unicopia:blocks/tomato_plant/stage_4"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:items/tomato_seeds"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB