Jump to content

Item that increases plant growth?


gmod622

Recommended Posts

Well, bonemeal outright increases the plant's AGE state.

If you want to force-tick it, you'll want world.scheduleBlockUpdateTick()

But that'll only make it tick once, which may not make it grow at all.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

As Draco just pointed out, you can bone-meal it.

 

You cannot however really "fast forward" ticks

However, for example,

BlockStem

(Melons & Pumpkins) has a method called

updateTick

which you can call, to make it, shockingly enough, tick again. Coupled with it's own scheduled tick, it in effect, ticked twice. Once by you, once by itself. You need to find the equivalent classes for saplings etc.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

Well taken from example:

 

the Watering can, however, I want it so that right clicking the plant (Only CROPS) will constantly tick it, until it hits stage 7(the max stage).

I dont want the item to be like bone meal, just flat right increasing the stage, I want it to increase how fast it will grow.

 

Maybe I could use the bonemeal for reference, but instead of using it multiple times, just use it once and slowly increas the stage?

However, I cannot seem to find the bonemeal class?

 

Thanks!

Not new to java >> New to modding.

Link to comment
Share on other sites

Im by no means an expert but I noticed the way plants grow is they have random ticking enabled  and every random tick they calculate a growth chance and if growth chance is favourable they grow to next stage. Bonemeal works similarly  except it calculates a growth chance every time you use it.

 

Check the crop block to see how bonemeal or crops grow. 

 

Easiest way to simulate something like a watering can is to apply a bonemeal effect on the crops you are aiming at with the watering can at a certain regular interval as long as the watering can is being used ie hold right click and slowly damage the watering can (ie remove water from it)

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

You wanna look at BlockCrops class

 

updateTick  (every random tick..is not fixed but can be like 5 10 seconds maybe)

this function uses getGrowthChance to calculate a chance

if chance is good and less than certain percentage then grow

 

getBonemealAgeIncrease

this function sets the age increase per bonemeal use

 

getGrowthChance

this function  seems to check for nearby blocks if they can sustain plant life  and calculates a chance

 

grow

this function physically changes the look of the crop when the plant has jus grown

 

i don't fully understand the chances you need to study them on paper to understand but i think mc wiki will probably explain better the growing chances

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

So how would I get what I'm right clicking on, and to check if its a plant or not?

 

I have somewhat of an idea on how to update the ticks more often.

 

EDIT:

Maybe I could create some new soil? I just found some source code with how to update ticks of a block. Maybe I could look into that?

Not new to java >> New to modding.

Link to comment
Share on other sites

So how would I get what I'm right clicking on, and to check if its a plant or not?

 

I have somewhat of an idea on how to update the ticks more often.

 

You get the object you are aiming at and check if is instaceof BlockCrop  or instance of BlockBush something like that  then you just do a bonemeal like effect on it  or whatver idea you got.

 

to get the block is actually already provited for you there's a function called onItemUsed in Item class. You need to figure out how to use that. It has some variables that you can use to get the block you're aiming at but I think you can only point at things you can reach so not too far.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Don't check against BlockCrop or of BlockBush.  Check against IGrowable.  Its the interface that all bonemeal-able blocks implement somewhere in their higherarchy.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Just got finished creating the block, how would I go about texturing it?

.json and where to put the files:

 

here are some classes that could help:

soil class

 

 

package com.lambda.PlentifulMisc.main.block.individual;

import java.util.Random;

import com.lambda.PlentifulMisc.main.PlentifulMisc;
import com.lambda.PlentifulMisc.main.block.ModBlocks;
import com.lambda.PlentifulMisc.main.block.PMBlockBase;
import com.lambda.PlentifulMisc.main.item.ItemModelProvider;

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.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;

public class PMFertileSoil extends PMBlockBase implements ItemModelProvider{
static boolean tilled;

protected static final AxisAlignedBB TILLED_AABB = new AxisAlignedBB(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F);

public PMFertileSoil(boolean tilled) {
	super(Material.GROUND, "fertilizedDirt" + (tilled ? "Tilled" : ""));

	this.tilled = tilled;
	this.setTickRandomly(true);
	this.setHardness(0.6F);
	this.setSoundType(SoundType.GROUND);

	if (tilled)
	{
		this.setLightOpacity(255);
		this.setCreativeTab(null);
		this.useNeighborBrightness = true;
	}
}

@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
	if (tilled)
	{
		return TILLED_AABB;
	}
	else
	{
		return super.getBoundingBox(state, source, pos);
	}
}

@Override
public void registerItemModel(Item item) {
	PlentifulMisc.proxy.registerItemRenderer(item, 0, "pmfertilesoil");
}

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
	return new ItemStack(ModBlocks.FERTILESOIL, 1, 0);
}

@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
    {
        return FULL_BLOCK_AABB;
    }

@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
	return Item.getItemFromBlock(ModBlocks.FERTILESOIL);
}

@Override
public boolean isOpaqueCube(IBlockState state)
{
	return !tilled;
}

@Override
public boolean isFertile(World world, BlockPos pos)
{
	return true;
}

@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	EnumPlantType plantType = plantable.getPlantType(world, pos.up());

	switch (plantType)
	{
		case Desert:
			return !tilled;
		case Nether:
			return !tilled;
		case Crop:
			return tilled;
		case Cave:
			return !tilled;
		case Plains:
			return !tilled;
		case Water:
			return false;
		case Beach:
			return !tilled;
	}

	return false;
}
@Override
public void updateTick(World worldObj, BlockPos pos, IBlockState state, Random rand)
{
	if (!worldObj.isRemote)
	{
		IBlockState plantState = worldObj.getBlockState(pos.up());
		Block toBoost = plantState.getBlock();
		if (plantState != null && toBoost != null && toBoost != Blocks.AIR && toBoost instanceof IPlantable)
		{
			worldObj.playEvent(2005, pos.up(), 0);
		}
		for (int i = 0; i < 3; i++)
		{
			plantState = worldObj.getBlockState(pos.up());
			toBoost = plantState.getBlock();
			if (plantState != null && toBoost != null && toBoost != Blocks.AIR && toBoost instanceof IPlantable)
			{
				toBoost.updateTick(worldObj, pos.up(), plantState, rand);
			}
		}
	}
}

}

 

 

my registry

 

 

 

package com.lambda.PlentifulMisc.main.block;
import com.lambda.PlentifulMisc.main.PlentifulMisc;
import com.lambda.PlentifulMisc.main.block.individual.PMFertileSoil;
import com.lambda.PlentifulMisc.main.item.ItemModelProvider;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModBlocks {
//Ores
public static PMOreBase pmXIANITE;

//Decor

//Crops+Soil
public static PMRockcress CROP_ROCKCRESS;
public static PMFertileSoil FERTILESOIL;


public static void init() {
	pmXIANITE = register(new PMOreBase("pmXianite").setCreativeTab(CreativeTabs.MATERIALS));
	CROP_ROCKCRESS = register(new PMRockcress(), null);
	FERTILESOIL = register(new PMFertileSoil(true));
}

private static <T extends Block> T register(T block, ItemBlock itemBlock) {
	GameRegistry.register(block);
	if(itemBlock != null) {
	GameRegistry.register(itemBlock);
	}
	if (block instanceof ItemModelProvider) {
		((ItemModelProvider)block).registerItemModel(itemBlock);
	}

	return block;
}

private static <T extends Block> T register(T block) {
	ItemBlock itemBlock = new ItemBlock(block);
	itemBlock.setRegistryName(block.getRegistryName());
	return register(block, itemBlock);
}

}

 

 

 

Also, how could I make it so when I right click on a peice of dirt > into a peice of fertile soil?

 

Not new to java >> New to modding.

Link to comment
Share on other sites

Sooo...first off...neither CROP_ROCKCRESS nor FERTILESOIL appear to have a registry name set (it is definitely missing for FERTILESOIL, as it is in neither the constructor nor the register function).  This is bad.

 

VERY VERY BAD.

 

Until you fix that, I cannot help you with models.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Added, So what does the Registry Name even do in comparison to unlocalized name?

 

EDIT:

I'm going to create a new project and redo my entire mod. Everything is just jumbled and inefficient. Will repost when done.

Thanks for the help so far.

Not new to java >> New to modding.

Link to comment
Share on other sites

Added, So what does the Registry Name even do in comparison to unlocalized name?

 

This:

Item myItem = new Item();
myItem.setRegistryName("my_cool_item");
System.out.println(myItem.getRegistryName());

Will print:

mymodid:my_cool_item

 

Basically, it takes whatever string you input and prepends your mod ID so that Minecraft can locate all assets related to your item: blockstate files, model files, etc.

 

It's also good practice to set your items' unlocalized name to the registry name:

myItem.setUnlocalizedName(myItem.getRegistryName());

So that the unlocalized name contains your mod ID and prevents language translation collisions between mods (e.g. two mods using the same unlocalized name for unrelated items).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Also, if you do any tooltip stuff, or other text-on-screen that you translate, good practice to put your modID in those too.

 

e.g. from one of my items:

	@Override
@SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
	tooltip.add("+10 "+I18n.format("description.harderfarming:damagebonus"));
    }

 

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Draco is on point    his advice  about iGrowable is in fact better than what I suggested in fact i'm gonna do the same . thanks!

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.