Jump to content

[1.8 - Solved] Help in making custom ItemSeeds drop in specific biomes


Recommended Posts

Posted

Hello all,

 

I basically added a new type of Crop as well as Seeds and the Item harvested from the crop at final stage. By default, you just break tall grass till you get the new seeds, like wheat seeds. You plant them, they grow, you harvest the crop and maybe get more seeds.

 

Thing is, I would like to make the seeds dropping from the wild tall grass to only drop if the tall grass is in a specific biome. I thought of using getBiomeGenForCoords to return the biome for which the tall grass broken is in, but I just cannot get it to work.

 

I have taken basic tutorials on Java and most of the time I work alone till I figure out how to solve my coding problems, but I am not as experienced as you guys, so can you please point me into the right direction on this one?

 

I thought of checking addGrassSeed like this:

 

  Reveal hidden contents

 

Then calling it in in CommonProxy like this:

 

  Reveal hidden contents

 

Thing is that it needs the event and world arguments from the DropSeed class.

 

Any help would be appreciated. Sorry if the solution on this one is easy, I'm trying to get better at Java.  :D

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted

Instead wait for the item drop event, and if seeds drop and its the right biome, replace the seed with your seed.

 

addGrassSeed will permanently add it to the list of dropable seeds.

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.

Posted

Thanks for your quick reply, unlike this one. I have been trying for a couple of hours to make this work. Probably someone more experienced  could have done this in a matter of a minute.

 

A while back I have managed to make the custom seeds always drop in place of wheat seeds in swamps, and both types dropping anywhere else. I was happy since I figured out how to alter where the seeds drop. But I wanted the custom seeds to only drop in swamp (don't mind if wheat seeds also drop there), i.e. to not drop elsewhere.

 

I altered my code and introduced an Event like so:

 

  Reveal hidden contents

 

 

I also added this to the Init method of CommonProxy:

 

  Reveal hidden contents

 

 

Now I get only the custom seeds to drop everywhere. But I do not understand how does the above not work. Looks like as if it should work. Any heads up? I'll continue working on this. I'll update when I have made progress.

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted

Good stab at the problem.  But you're doing a few things wrong.

 

drops

is an array and it will never equal, or contain, your item.  You're going to want to loop through looking to see if any of the array items are

Items.seeds

and then remove that item and add yours.

 

Here's what I did:

	@SubscribeEvent
public void harvestGrass(BlockEvent.HarvestDropsEvent event) {
	if(event.block instanceof BlockTallGrass) { //cuts down on checking when the block destroyed was stone, logs, leaves, etc.
		BiomeGenBase bio = event.world.getBiomeGenForCoords(event.x, event.z);
		if(biomeTemps.get(bio.biomeID).temp <= 0.3) { //the condition you are interested in
			ArrayList<ItemStack> drps = new ArrayList<ItemStack>();
			for(ItemStack is:event.drops) {
				if(is.getItem() == Items.wheat_seeds) {
					drps.add(new ItemStack(WildlifeBase.winterWheatSeeds, is.stackSize)); //add the new item
				}
				else {
					drps.add(is); //add any other items that dropped, but which we're not replacing
				}
			}
			event.drops.clear(); //remove the old
			event.drops.addAll(drps);
		}
	}
}

 

The second array is for avoiding modifying the array during the loop, but there are other ways to do that as well, such as using an iterator.

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.

Posted

Oh I see. You are creating an array list of ItemStacks to pass on for drops.

 

I do not like replying that I still have a problem but this has been boggling  my brain for a couple of hours today.

I used the way you used your array and itemstack in a variety of ways, yet I still got problems. Currently it is like this:

 

  Reveal hidden contents

 

What I expect from the above is to check when do the custom seeds drop while in not a swamp. Then if they do change the drop to not include them. What I get is only the custom seeds dropping in swamps and no seeds dropping elsewhere.

 

Also, I wanted from before to be able to detect if it is tall grass that is broken. I was surprised to find out that I could not use event.block like you did. I was not sure of what to use instead from the available options, so for my first attempts I put:

 

  Reveal hidden contents

 

I removed it. But I cannot understand why does the first spoiler not work.

 

Also minor detail, when the event first fires from the very first seeds (can be either) dropping elsewhere than a swamp, they will drop instead of not. Cute detail.

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted

1) Don't use

addGrassSeed

, you want your seeds to ONLY drop in the swamp, so there's no point in adding them to the global drop list.

2) You do not need your

biomeSwamp

variable.  If it's a swamp, do-the-thing, if it's not do-the-other-thing.  There's no point in setting the result of a boolean check and then if-checking that boolean again.

3)

if(is == Items.seeds) { drps.add(new ItemStack(riceSeeds)); }

4) Move the 

event.drops.clear();

and

event.drops.addAll(drps);

lines outside of the loop.

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.

Posted

I got it to work. And changed the code some more to alter drop rate in different biomes, for different custom seeds. But one thing is left. I still cannot understand how could you add the block field in your if statement: if(event.block instanceof BlockTallGrass)

There is no block field in HarvestDropsEvent. And when I tried to add a Block argument in the dropSeeds constructor, I could not register the event with the event bus of common proxy.

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted
  On 3/25/2015 at 10:19 PM, pH7 said:

There is no block field in HarvestDropsEvent. And when I tried to add a Block argument in the dropSeeds constructor, I could not register the event with the event bus of common proxy.

 

Yes there is.

 

public HarvestDropsEvent(int x, int y, int z, World world, Block block, int blockMetadata, int fortuneLevel, float dropChance, ArrayList<ItemStack> drops, EntityPlayer harvester, boolean isSilkTouching)

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.

Posted

public HarvestDropsEvent(World world, BlockPos pos, IBlockState state, int fortuneLevel, float dropChance, List<ItemStack> drops, EntityPlayer harvester, boolean isSilkTouching)

        {

            super(world, pos, state);

            this.fortuneLevel = fortuneLevel;

            this.dropChance = dropChance;

            this.drops = drops;

            this.isSilkTouching = isSilkTouching;

            this.harvester = harvester;

        }

 

forge1.8-11.14.0.1295-1.8

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted

I cannot use event.block to check if the block firing the HarvestDropEvent is Grass or not. Sorry if it seems to be asking for help constantly and bringing this post up again and again :< I just have very basic knowledge of java and have trouble figuring stuff out.

 

I stopped working on dropSeed for now, and doing something I'm better at; modeling some mobs in Techne to add later on.

I'll try to find a way to get the block type of the block that fires the Event a bit later on.

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted
  On 3/25/2015 at 11:09 PM, pH7 said:

public HarvestDropsEvent(World world, BlockPos pos, IBlockState state, int fortuneLevel, float dropChance, List<ItemStack> drops, EntityPlayer harvester, boolean isSilkTouching)

        {

            super(world, pos, state);

            this.fortuneLevel = fortuneLevel;

            this.dropChance = dropChance;

            this.drops = drops;

            this.isSilkTouching = isSilkTouching;

            this.harvester = harvester;

        }

 

forge1.8-11.14.0.1295-1.8

 

I think hes saying there is no block parameter...

 

But they do give you a BlockPos which you can use in the world.getBlockByPos(or something: not in an IDE right now) to get the block at the BlockPos and then you can check whether that block is a tall grass.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Posted

Yes. Sorry for not being clear on my previous previous post. I did use event.world and event.pos in order to try and find a parameter to help me get the block firing the event, yet I could not find any. I'll try again later on. Again, sorry for bringing this post up again. I know you guys are busy and I appreciate you being helpful. In fact Draco helped me a lot with the code.

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted

If you look more at the HarvestDropsEvent code it's

 

public class BlockEvent extends Event
{
    private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));

    public final World world;
    public final BlockPos pos;
    public final IBlockState state;
    public BlockEvent(World world, BlockPos pos, IBlockState state)
    {
        this.pos = pos;
        this.world = world;
        this.state = state;
    }

    // Comments
    public static class HarvestDropsEvent extends BlockEvent
    {
        public final int fortuneLevel;
        public final List<ItemStack> drops;
        public final boolean isSilkTouching;
        public float dropChance; // Change to e.g. 1.0f, if you manipulate the list and want to guarantee it always drops
        public final EntityPlayer harvester; // May be null for non-player harvesting such as explosions or machines

        public HarvestDropsEvent(World world, BlockPos pos, IBlockState state, int fortuneLevel, float dropChance, List<ItemStack> drops, EntityPlayer harvester, boolean isSilkTouching)
        {
            super(world, pos, state);
            this.fortuneLevel = fortuneLevel;
            this.dropChance = dropChance;
            this.drops = drops;
            this.isSilkTouching = isSilkTouching;
            this.harvester = harvester;
        }
    }

 

It's extending BlockEvent, all BlockEvent's a state parameter which is an instance of IBlockState, IBlockState has a method getBlock. You can get the block this way.

Posted

woohoo!

 

if(biome instanceof BiomeGenSwamp && event.state.getBlock() instanceof BlockTallGrass) { //...

 

Indeed I can get the block that way. event.state.getBlock() works to perfection. I read a big tutorial on Events in general so I can know what fields and methods to use on different occasions.

 

This post can finally start sinking down in the forums. Might  be useful for someone who is making custom crops and wants to know how to make biome specific seed drops, though.

 

Thanks everyone for helping. May karma be with you. NOW I CAN FINALLY MODEL IN PEACE    :3

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Posted

Sorry for bringing this up again, I just want to add that I found an easier way to set this up (for 1.8 Forge. I've been told told that for 1.7 Forge if(biome instanceof BiomeGenSwamp) { includes the swampland variant, yet this was not the case for me):

 

  Reveal hidden contents

 

This effectively adds the seeds as a new drop. Also, by using Biome Dictionary, you also include the Swampland variant (Swamp M in F3) instead of just the Swamp biome. I was lucky that my world had both Swamp and Swamp M side by side to check that by using 'instanceof BiomeGenSwamp'.

 

If one wants to mess around with details then they can code additional lines if they do not want both types of seeds to drop at the same time from the same block of tall grass (or not wanting both types to drop in general).

 

Sorry for necroing, edited some ambiguities and corrected something unnecessary in the code. Thanks Draco18s.

'Everyone is a genius,

But if you judge a fish by its ability to climb trees, it will live its whole life believing that it is stupid.'

 

-Albert Einstein

----------------------------------------------------------

If Arthas's horse is named "Invincible", then why can I clearly see him?

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • One fateful day, my life took an unexpected turn when I received a phone call that would change everything. The voice on the other end claimed to be from my bank, delivering alarming news: my account had been frozen due to suspicious activity. Panic surged through me as I listened, my heart racing at the thought of losing my hard-earned savings. At that moment, I had about 130,000 USD in my bank, equivalent to around 2 BTC. The caller spoke with such authority and urgency that I felt compelled to act immediately. They insisted that the only way to protect my funds was to transfer Bitcoin BTC to them for "safekeeping. In my fear and confusion, I believed I was making a wise decision to secure my finances. Without fully grasping the implications, I complied and transferred the equivalent of my savings in Bitcoin, convinced I was safeguarding my money. It wasn’t until later that the reality of my situation hit me like a ton of bricks. I had been duped, and the weight of my mistake was unbearable. Shame and disbelief washed over me as I realized how easily I had been manipulated. How could I have let this happen? The feeling of vulnerability was overwhelming, and I was left grappling with the consequences of my actions. I learned about a recovery expert named RAPID DIGITAL RECOVERY. Desperate to reclaim what I had lost, I reached out for help. RAPID DIGITAL RECOVERY was knowledgeable and reassuring, explaining that there was a chance to trace the Bitcoin I had sent. With their expertise, they tracked the stolen funds to a peer-to-peer (P2P) exchanger based in the United Kingdom. This revelation sparked a glimmer of hope within me, a sense that perhaps justice could be served. RAPID DIGITAL RECOVERY collaborated with Action Fraud, the UK's national reporting center for fraud and cybercrime, to take decisive action against the scammers. Knowing that law enforcement was involved provided me with a sense of relief. The thought that the culprits behind my suffering could be brought to justice was comforting. In an incredible turn of events, RAPID DIGITAL RECOVERY successfully recovered all my funds, restoring my faith in the possibility of justice and recovery.
    • My game crashed in 1.12.2 here is the crash log https://pastebin.com/6MYu4mGy
    • I created a Modpack Forge in 1.20.1 for my friend and I. There are 135 mods including "Essential". I was able to play an 8 hour session without problem but when I relaunch my world, I crashed when I opened the menu of the game "ESC" or after about 15 minutes of session. I can't find the source of the problem. Latest.log and Debug.log : https://paste.ee/p/B0npvlRw
    • Hello! Faced with the same problem. Can you please describe in more detail how you rewrote the toNetwork and fromNetwork methods?
    • Why not?   Please explain what you have tried, in detail. Step by step is installing the server, placing mod .jar files in the mods folder within the folder you installed the server, and running the run.bat file. If this is not working for you, please post the debug.log from the logs folder to a site like https://mclo.gs and post the link to it here.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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