Jump to content

Getting different items from different stages, [Crops]


Kander16

Recommended Posts

Hello,

 

I was wondering if there was a way to have different items on different stages.

Like, when the paprika stage is at green you get green paprika, when it's at the yellow stage, yellow, etc...

 

So could anyone give me a hint/tell me how i need to get it done.

That would be very apprecciated ;-)

 

When you have questions, ask me

 

Here is my code of  my paprika food if needed (bell pepper):

http://pastebin.com/GB9dC6Bd

Creator of the Master Chef Mod and many more to come.

 

If I helped you, please click the 'thank you' button.

Link to comment
Share on other sites

What he means is that in the getDrops you can check in which state the plant curently is. Somthing like:

 

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
{
if (p_149650_1_ == stateofgreen){
  return modfile.greenpaprikaitem;
}
return null;
}

this code will probably not quite work but I hope you can figure it out yourself from here (haven't worked with crops since 1.3)

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Link to comment
Share on other sites

Not sure but I think you'll actualy have to use something like this:

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return p_149650_1_ == 7 ? this.func_149865_P() : item;

    }

 

where 7 is the metadata of the block and item is the item it should give. Just expland that for the 4 states (not grown, green, yellow, red)

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Link to comment
Share on other sites

Okey,

 

How do i expand it? like

 

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return p_149650_1_ == 7 ? this.func_149865_P() : Morefood.foodGreenPaprika: Morefood.foodYellowPaprika;

    }

Or how does it work?

I've tried several things and i can't get it to work, it always gives me 'green paprika' and at full growth 'wheat'.

Creator of the Master Chef Mod and many more to come.

 

If I helped you, please click the 'thank you' button.

Link to comment
Share on other sites

Okay, here's the thing, this is your own custom block so you can code anything you want in Java.  But it is also a Minecraft mod so you need to respond to those method calls that Minecraft Forge makes to your blocks.  As diesieben07 says, the real entry to your block code is the getDrops() method.  The other methods are used within your block and you can use those as well (like getItemDropped()), but not necessarily needed. In getDrops() you can do whatever you want -- it is your own Java code after all.  You could drop something, or spawn another entity, or add an achievement or whatever.

 

So the only thing you have to do is change the returned value based on the growth stage.  You already can tell the stage of the crop based on the metadata, and the nice thing about the getDrops() method is that the metadata is passed as one of the parameters.  So just do some conditional statements (like if statements) to check the metadata and return the type of item you want to drop.

 

Make sense?

 

In the end, the point is that you can code anything you want, but you need to put it in the getDrops() method because that is what will get called when Minecraft needs the drops.  After that it is just Java, the possibilities are endless.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

{

        return customGetDropFunction(p_149650_1_);

}

 

public Item customGetDropFunction(int p_149650_1_){

if (p_149650_1_ == 5){

  return modfile.greenpaprika;

}else if (p_149650_1_ == 6){

  return modfile.yellowpaprika;

}else if (p_149650_1_ == 7){

  return modfile.redpaprika

}else{

  return modfile.paprikaseeds;

}

}

 

This should work if you replace the Items. What the others are saying is correct as long as the getItemDropped is refering to those functions, this changes that so these functions are in theory not requered anymore.

 

You should also know how it works from the code but basicly what it does is if the user breaks the crop block it will run the getItemDropped function this function has the metadata as the variable  "p_149650_1_" which you pass to your custom getDrop function which than has if else statements to check the metadata and drop the correct item.

 

NOTE untested!

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Link to comment
Share on other sites

As I said. You need to override getDrops.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

As I said. You need to override getDrops.

 

Just tested the code I sent and it works! YOU DO NOT HAVE TO OVERRIDE getDrops!

 

If you're stupid enought to still belive so please get of the internet. If you want prove I can post the code I used so you could test it.

 

Here's reason you don't need getDrops:

getDrops is a function called within the getItemDropped. the function getItemDropped can not be repleaced as it´s a function Minecraft uses to see which item/block has to be dropped getDrops is a "easy" way of chaning the drop!

 

If you look at the getItemDropped of the minecraft block BlockCrops:

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return p_149650_1_ == 7 ? this.func_149865_P() : this.func_149866_i();

    }

 

As you can see if you know ANYTHING about java this only call the functions getDrop (this.func_149865_P() in the case of BlockCrops) and this.func_149866_i() is the drop of the seed this function only returns this item, thus it could be used if you want but in this specific case it would only call getDrop() if the metadata was 7 which would be useless this statment could either be changed in the "if statment" in getItemDropped or be replaced with a custom getDrops (which is easier in this case!).

 

Sorry if you got offended but please check your facts before telling that something will not work is necessary if it's not!

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Link to comment
Share on other sites

That only works if you want it to drop 1 item. If you want more control about your drops, you should override

getDrops(params)

.

 

this only call the functions getDrops (this.func_149865_P() in the case of BlockCrops)

BTW, I know Java. I atleast know that

getDrops(params)

isn't called

this.func_149865_P()

in the BlockCrops class...

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

That only works if you want it to drop 1 item. If you want more control about your drops, you should override

getDrops(params)

.

 

this only call the functions getDrops (this.func_149865_P() in the case of BlockCrops)

BTW, I know Java. I atleast know that

getDrops(params)

isn't called

this.func_149865_P()

in the BlockCrops class...

 

Good you know such a complicated function name!

 

But the amount of items is controlled by:

public int quantityDropped(Random p_149745_1_)

    {

        return 1;

    }

 

and can easliy be manipulated (depending on metadata!) So that shouldn't be a problem!

 

Also i could not find a way to specify a drop amount in the getDrops() function I will asume you're right and it is possible with it but just for my informaition could you tell me how to specify such a thing?

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Link to comment
Share on other sites

I mean, using

getItemDropped()

, you can only return 1 kind of item, and not 2 different items.

 

To specify the amount to be dropped using

getDrops(params)

, you need to return an ArrayList containing ItemStacks, in which you can specify the stacksize. If you use something like this:

public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
    ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
    drops.add(new ItemStack(Items.dye, 8, 3));
    return drops;
}

it will drop 8 dyes with a metadata of 3. So with

getDrops(params)

you can be alot more precise then with

getItemDropped()

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

K thanks for the reply that does seem more useful! I don't have any code for that so I can't send it but I would advice using this method if you need more than 1 type of items to drop though in the case of paprika's you might want only the paprika to drop as the seeds should be simmular to a melon where you can use the crafting table to get them! If you want you can use this code I wrote to test (otherwhise ask the others for further help if needed!):

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
            return customGetDropFunction(p_149650_1_);
    }
    
    private Item itemdropped;
    public Item customGetDropFunction(int p_149650_1_){
            //switch statment for the metadata
    switch (p_149650_1_) {
	    case 5:
                        //sets itemdropped so quantity can be changed latter
	    	 itemdropped = MT_mod.greenpaprika; //Has to be an Item!
                        //sets the item to drop
	      	return itemdropped;
	    case 6:
	    	 itemdropped = MT_mod.greenpaprika;
	    	 return itemdropped;
	    case 7:
	    	 itemdropped = MT_mod.greenpaprika;
	    	 return itemdropped;
	     default:
	    	 itemdropped = MT_mod.PaprikaSeeds;
	    	 return itemdropped;
    }
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    
    public int quantityDropped(Random p_149745_1_)
    {
    	int quant;
        if (itemdropped == MT_mod.PaprikaSeeds){
                //Gives only 1 seed (no dupe glitches that way!)
        	quant = 1;
        }else{
                //Gives min of 1 Paprika and max of 4. Min can be changed by the number before the + the max can be controlled by the number inbetween te () (Which it adds to the number before the + but thats basic math)
        	quant = 1 + p_149745_1_.nextInt(3);
        }
        return quant;
    }

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Link to comment
Share on other sites

I say you have to override getDrops when you extend BlockCrops. That is because BlockCrops overrides getDrops itself to drop the seeds at a random chance. If you want to change that, you HAVE to override getDrops.

That is true but if you want "true" full control over the block you wouldn't extend BlockCrops now would you?

 

OK maybe that was the No True Scotsman fallacy... (http://en.wikipedia.org/wiki/No_true_Scotsman)

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a tool that harvests multiple crops at once, that either replants or harvests the crops depending on an enchant on the tool. The harvesting and loot dropping works fine, but when it comes to updating what block is rendering, only the clicked block is updated properly, while the others drop the loot but appear to say as the fully grown crop, until right clicked again. The normal path for the tool is to just break the crop, as if the player harvested the crop. The other path is to reset the growth of the crop and drop the crop's loot, minus one seed. I have already tried all combinations of method parameters for setBlock() and destroyBlock(), and the updateing of the crop blocks still does not happen.  The code thus far: public class ScytheItem extends HoeItem { public ScytheItem(Tier tier, int atkBase, float atkSpeed) { super(tier, atkBase, atkSpeed, new Item.Properties().stacksTo(1)); } @Override public @NotNull InteractionResult useOn(@NotNull UseOnContext context) { Level level = context.getLevel(); Player player = context.getPlayer(); InteractionHand hand = context.getHand(); ItemStack stack = context.getItemInHand(); if (!level.isClientSide() && player != null) { BlockPos pos = context.getClickedPos(); Block block = level.getBlockState(pos).getBlock(); if(block instanceof CropBlock) { level.playSound(null, pos, block.getSoundType(level.getBlockState(pos), level, pos, player).getBreakSound(), SoundSource.BLOCKS, 1.0F, AOTMain.RANDOM.nextFloat()); Map<Enchantment, Integer> enchantments = stack.getAllEnchantments(); int harvestSize = 1 + enchantments.getOrDefault(EnchantmentInit.HARVESTING_SIZE.get(), 0); for (int xOff = -harvestSize; xOff <= harvestSize; xOff++) { for (int zOff = -harvestSize; zOff <= harvestSize; zOff++) { BlockPos newPos = pos.offset(xOff, 0, zOff); Block blockAt = level.getBlockState(newPos).getBlock(); if (blockAt instanceof CropBlock crop) { if (crop.isMaxAge(level.getBlockState(newPos))) { if (enchantments.containsKey(EnchantmentInit.AUTO_PLANTER.get())) { dropLoot(level, newPos, level.getBlockState(newPos), block); level.setBlock(newPos, crop.getStateForAge(0), Block.UPDATE_CLIENTS); // the broken bit } else level.destroyBlock(newPos, true); // the broken bit } } } } stack.hurtAndBreak(1, player, (p) -> p.broadcastBreakEvent(hand)); } } return super.useOn(context); } private void dropLoot(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull Block block) { List<ItemStack> drops = getDrops(level, pos, state); findSeeds(block, drops).ifPresent(seed -> seed.shrink(1)); drops.forEach((drop) -> Block.popResource(level, pos, drop)); } private List<ItemStack> getDrops(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state) { return Block.getDrops(state, (ServerLevel) level, pos, null); } private Optional<ItemStack> findSeeds(@NotNull Block block, final Collection<ItemStack> stacks) { Item seedsItem = block.asItem(); return stacks.stream().filter((stack) -> stack.getItem() == seedsItem).findAny(); } }  
    • Hello!  After I build e my mod in .jar, then when starting minecraft, it gives me an error that the dependency was not found. In the minecraft log the following is written:   java.lang.NoClassDefFoundError: org/json/simple/parser/JSONParser at com.example.examplemod.JsonUtil.getConfig(JsonUtil.java:14) In build.gradle I have next dependencies: dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'com.googlecode.json-simple:json-simple:1.1.1' } But if I run minecraft from IDE (using the runClient), then these dependencies are installed, and my mod is work. Please, help me with this problem. UPD: Full build.gradle file   plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' } version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(8) println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { // applies to all the run configs below configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' mods { "${mod_id}" { source sourceSets.main } } } client { // this block needs to be here for runClient to exist } server { args '--nogui' } data { // example of overriding the workingDirectory set in configureEach above workingDirectory project.file('run-data') // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'com.googlecode.json-simple:json-simple:1.1.1' } tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, forge_version: forge_version, forge_version_range: forge_version_range, loader_version_range: loader_version_range, mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, mod_authors: mod_authors, mod_description: mod_description, ] inputs.properties replaceProperties filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { expand replaceProperties + [project: project] } } tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } finalizedBy 'reobfJar' } //tasks.named('publish').configure { // dependsOn 'reobfJar' //} publishing { publications { register('mavenJava', MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation }  
    • I want to render shapes through blocks. I found this code in minecraft source  public static void renderShape(PoseStack poseStack, VertexConsumer vertexConsumer, VoxelShape shape, double minX, double minY, double minZ, float red, float green, float blue, float alpha) { PoseStack.Pose pose = poseStack.last(); shape.forAllEdges((x1, y1, z1, x2, y2, z2) -> { float dx = (float)(x2 - x1); float dy = (float)(y2 - y1); float dz = (float)(z2 - z1); float length = Mth.sqrt(dx * dx + dy * dy + dz * dz); dx /= length; dy /= length; dz /= length; vertexConsumer.vertex(pose.pose(), (float)(x1 + minX), (float)(y1 + minY), (float)(z1 + minZ)).color(red, green, blue, alpha).normal(pose.normal(), dx, dy, dz).endVertex(); vertexConsumer.vertex(pose.pose(), (float)(x2 + minX), (float)(y2 + minY), (float)(z2 + minZ)).color(red, green, blue, alpha).normal(pose.normal(), dx, dy, dz).endVertex(); }); } that draws a rectangle around the block, but it is not visible through other blocks. Could someone point me in the right direction on how one renders things through blocks? Thanks in advance 🙏
    • I wish I could replace optifine, when i remove optifine and put on Embeddium, the game crashes too with exit code 1, or could that also be a forge version problem?   edit: rubidium getsauto downloaded with embeddium and oculus, removing rubidium solved it, thanks
    • Looks like an issue with Optifine - to get Optifine to work, you will need Forge 43.2.14 You can downgrade Forge (which may break other mods) or replace Optifine With Embeddium + Oculus
  • Topics

×
×
  • Create New...

Important Information

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