Something like that ought to work.You can do a lot with enough knowledge of the various Minecraft and Forge classes, and that comes by scrupulously searching through both code sources whenever you run into a problem. If you want to get better, you need to spend lots of time reading and experimenting, with experimenting being the more important of the two.
When you experiment, use LOTS of println statements to see what is going on in your code, rather than typing some code and thinking 'oh, that didn't work' - why didn't it work? What, exactly, was it doing? Debugging should be your best friend.
Thanks, yea I have been doing exactly that, I have created a custom item, I can craft it, I made a simple function that will turn a grass block into dirt block, if clicked on top with an empty hand. but heres where I'm stuck now.
I can after this, get an item to spawn in the world, but I would like my created item to spawn but I cant find out how to do that since dropItem only accepts "Items". also it drops at my feet and I would like it to drop on the block I right clicked on, this is my code so far.....
@SubscribeEvent
public void onPlayerClickEvent(PlayerInteractEvent event) {
if (event.action == Action.RIGHT_CLICK_BLOCK) {
if (event.entityPlayer.getCurrentEquippedItem() == null) {
if (event.world.getBlockState(event.pos).getBlock() == Blocks.grass && event.face == event.face.UP) {
if (!event.world.isRemote) {
event.world.setBlockState(event.pos, Blocks.dirt.getDefaultState());
event.entity.dropItem(Items.stick, 1);
}
}
}
}
}
I want to replace event.entity.dropItem(Items.stick, 1); line with a line that can spawn my custom item (public class SharpStick extends Item) on top of the block I right clicked. any help with this? thanks.
Thanks, yea I have been doing exactly that, I have created a custom item, I can craft it, I made a simple function that will turn a grass block into dirt block, if clicked on top with an empty hand. but heres where I'm stuck now.
I can after this, get an item to spawn in the world, but I would like my created item to spawn but I cant find out how to do that since dropItem only accepts "Items". also it drops at my feet and I would like it to drop on the block I right clicked on, this is my code so far.....
@SubscribeEvent
public void onPlayerClickEvent(PlayerInteractEvent event) {
if (event.action == Action.RIGHT_CLICK_BLOCK) {
if (event.entityPlayer.getCurrentEquippedItem() == null) {
if (event.world.getBlockState(event.pos).getBlock() == Blocks.grass && event.face == event.face.UP) {
if (!event.world.isRemote) {
event.world.setBlockState(event.pos, Blocks.dirt.getDefaultState());
event.entity.dropItem(Items.stick, 1);
}
}
}
}
}
I want to replace event.entity.dropItem(Items.stick, 1); line with a line that can spawn my custom item (public class SharpStick extends Item) on top of the block I right clicked. any help with this? thanks.
You can spawn entities with a method in world. You'll want to declare a new EntityItem that contains your item first and then spawn that item in.
Rollback Post to RevisionRollBack
Matthew 11:28-30 Come to me, all you who are weary and burdened, and I will give you rest. Take my yoke upon you, and learn from me; for I am gentle and humble in heart: and you will find rest for your souls. For my yoke is light, and my burden is easy.
how exactly do i do this? been messing around a lot but cant work it out.
this compiles but error when attempting to drop the item.
@SubscribeEvent
public void onPlayerClickEvent(PlayerInteractEvent event) {
if (event.action == Action.RIGHT_CLICK_BLOCK) {
if (event.entityPlayer.getCurrentEquippedItem() == null) {
if (event.world.getBlockState(event.pos).getBlock() == Blocks.grass && event.face == event.face.UP) {
if (!event.world.isRemote) {
event.world.setBlockState(event.pos, Blocks.dirt.getDefaultState());
Item drop = new SharpStick();
Block.spawnAsEntity(event.world, event.pos, new ItemStack(drop));
}
}
}
}
}
You just have your item declared. You need to declare an EntityItem and within the parameters of the EntityItem you set your item to be the result. Also, Block.spawnAsEntity is the wrong method. You want event.world.spawnEntityInWorld(//YourEntityItemHere);
Rollback Post to RevisionRollBack
Matthew 11:28-30 Come to me, all you who are weary and burdened, and I will give you rest. Take my yoke upon you, and learn from me; for I am gentle and humble in heart: and you will find rest for your souls. For my yoke is light, and my burden is easy.
You just have your item declared. You need to declare an EntityItem and within the parameters of the EntityItem you set your item to be the result. Also, Block.spawnAsEntity is the wrong method. You want event.world.spawnEntityInWorld(//YourEntityItemHere);
I got told to use Block.spawnAsEntity in order to get it to spawn on the block I click on otherwise it spawns under my feed, I want to basically mimic the visual of wheat breaking from a mature wheat seed.
I got told to use Block.spawnAsEntity in order to get it to spawn on the block I click on otherwise it spawns under my feed, I want to basically mimic the visual of wheat breaking from a mature wheat seed.
but will try the rest of what you say, thanks.
The item spawns wherever you tell it to spawn in the parameters.
Rollback Post to RevisionRollBack
Matthew 11:28-30 Come to me, all you who are weary and burdened, and I will give you rest. Take my yoke upon you, and learn from me; for I am gentle and humble in heart: and you will find rest for your souls. For my yoke is light, and my burden is easy.
The Meaning of Life, the Universe, and Everything.
Join Date:
9/30/2011
Posts:
43
Minecraft:
statphantom
Member Details
I thought this forum was for help on eventhandlers? sure we have gone a bit off-topic from event handlers but I thought we were within the accepted parameters of discussion
I thought this forum was for help on eventhandlers? sure we have gone a bit off-topic from event handlers but I thought we were within the accepted parameters of discussion
While I don't mind, generally when your questions don't directly relate to the topic or go far beyond the original scope, you should start your own thread, which indeed you already have on Minecraftforge.net.
The reason for this is that people reading the comments are generally looking for information specifically related to the tutorial, not for long help threads. Speaking of which, if you encounter multiple issues, it's usually better to start a new topic for each specific issue - it makes it much easier for people to help you, and even for multiple people to help you with different problems, since they don't have to wade through a lot of mostly unrelated information.
While I don't mind, generally when your questions don't directly relate to the topic or go far beyond the original scope, you should start your own thread, which indeed you already have on Minecraftforge.net.
The reason for this is that people reading the comments are generally looking for information specifically related to the tutorial, not for long help threads. Speaking of which, if you encounter multiple issues, it's usually better to start a new topic for each specific issue - it makes it much easier for people to help you, and even for multiple people to help you with different problems, since they don't have to wade through a lot of mostly unrelated information.
certainly, I will keep my development discussion on my minecraftforge thread but will still reply to this one with a direct question about your event topics
[p]hey I have a question I'm still learning java so right now I'm screwing around to learn a few things but however I would like to get some assistance with making a vanilla block drop an item I made in my mod that I just screw around in to learn I would like obsidian to drop my custom item hear is the code I used.[/p]
package com.myfirst.myfirstmod.eventhandler;
hey I just want help on my code please I'll figure the random item drop later but this code doesn't seem to be working for me. I can't get obsidian to drop what I want it to drop can you please help me.
hey I just want help on my code please I'll figure the random item drop later but this code doesn't seem to be working for me. I can't get obsidian to drop what I want it to drop can you please help me.
Sure:
if (event.state instanceof BlockObsidian)
That right there will NEVER be true. Event.state is an IBlockState, not a Block, so how could it be an instanceof BlockObsidian?
ok so I'm still having issues with my problem in the link below is my mess around mod please I looked in the IBlockventState again I'm new to modding and I want to learn as much as I can so if you could help explaine to me how its not workingI would be greatfull also did I use the wrong bus kuz I feel like I did.
Thanks, yea I have been doing exactly that, I have created a custom item, I can craft it, I made a simple function that will turn a grass block into dirt block, if clicked on top with an empty hand. but heres where I'm stuck now.
I can after this, get an item to spawn in the world, but I would like my created item to spawn but I cant find out how to do that since dropItem only accepts "Items". also it drops at my feet and I would like it to drop on the block I right clicked on, this is my code so far.....
I want to replace event.entity.dropItem(Items.stick, 1); line with a line that can spawn my custom item (public class SharpStick extends Item) on top of the block I right clicked. any help with this? thanks.
You can spawn entities with a method in world. You'll want to declare a new EntityItem that contains your item first and then spawn that item in.
Matthew 11:28-30 Come to me, all you who are weary and burdened, and I will give you rest. Take my yoke upon you, and learn from me; for I am gentle and humble in heart: and you will find rest for your souls. For my yoke is light, and my burden is easy.
I made a thing:
Forum Thread: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2091787-1-7-2-tynkyn-v1-3-out-now-elementurtles
Website: https://sites.google.com/site/tynkynwiki/
how exactly do i do this? been messing around a lot but cant work it out.
this compiles but error when attempting to drop the item.
You just have your item declared. You need to declare an EntityItem and within the parameters of the EntityItem you set your item to be the result. Also, Block.spawnAsEntity is the wrong method. You want event.world.spawnEntityInWorld(//YourEntityItemHere);
Matthew 11:28-30 Come to me, all you who are weary and burdened, and I will give you rest. Take my yoke upon you, and learn from me; for I am gentle and humble in heart: and you will find rest for your souls. For my yoke is light, and my burden is easy.
I made a thing:
Forum Thread: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2091787-1-7-2-tynkyn-v1-3-out-now-elementurtles
Website: https://sites.google.com/site/tynkynwiki/
I got told to use Block.spawnAsEntity in order to get it to spawn on the block I click on otherwise it spawns under my feed, I want to basically mimic the visual of wheat breaking from a mature wheat seed.
but will try the rest of what you say, thanks.
The item spawns wherever you tell it to spawn in the parameters.
Matthew 11:28-30 Come to me, all you who are weary and burdened, and I will give you rest. Take my yoke upon you, and learn from me; for I am gentle and humble in heart: and you will find rest for your souls. For my yoke is light, and my burden is easy.
I made a thing:
Forum Thread: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2091787-1-7-2-tynkyn-v1-3-out-now-elementurtles
Website: https://sites.google.com/site/tynkynwiki/
Seems like you guys have hijacked this thread, maybe start your own thread or take it to PM?
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
I thought this forum was for help on eventhandlers? sure we have gone a bit off-topic from event handlers but I thought we were within the accepted parameters of discussion
While I don't mind, generally when your questions don't directly relate to the topic or go far beyond the original scope, you should start your own thread, which indeed you already have on Minecraftforge.net.
The reason for this is that people reading the comments are generally looking for information specifically related to the tutorial, not for long help threads. Speaking of which, if you encounter multiple issues, it's usually better to start a new topic for each specific issue - it makes it much easier for people to help you, and even for multiple people to help you with different problems, since they don't have to wade through a lot of mostly unrelated information.
certainly, I will keep my development discussion on my minecraftforge thread but will still reply to this one with a direct question about your event topics
package com.myfirst.myfirstmod.eventhandler;
import java.util.Random;
import com.myfirst.myfirstmod.init.MyFirstItems;
import net.minecraft.block.BlockObsidian;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class ObsidianEventHandler {
@SubscribeEvent
public void onDrops(BlockEvent.HarvestDropsEvent event, Random random) {
if (event.state instanceof BlockObsidian)
event.drops.add(new ItemStack(MyFirstItems.myfirst_item, 3 + random.nextInt(6)));
}
}
and re is where I called it
package com.myfirst.myfirstmod.init;[/p]
import com.myfirst.myfirstmod.Reference;[/p]
import com.myfirst.myfirstmod.eventhandler.GokuGavsObsidianEventHandler;[/p]
import net.minecraft.block.Block;[/p]
import net.minecraft.client.Minecraft;[/p]
import net.minecraft.client.resources.model.ModelResourceLocation;[/p]
import net.minecraft.item.Item;[/p]
import net.minecraftforge.common.MinecraftForge;[/p]
publicclass MyBlocks {[/p]
publicstaticvoid init(){[/p]
MinecraftForge.EVENT_BUS.register(new ObsidianEventHandler());[/p]
}[/p] publicstaticvoid register(){[/p]
}[/p]
publicstaticvoid registerRenders(){[/p]
}[/p]
publicstaticvoid registerRender(Block block){[/p]
Item item = Item.getItemFromBlock(block);[/p]
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));[/p]
}[/p]
}[/p]
any help please and I want to know if I used the random.nextInt correctly I want it to drop about 4-9 of my item
Java docs to the rescue. If you have a question about Java, always go there first.
thanks Ill check it out
hey I just want help on my code please I'll figure the random item drop later but this code doesn't seem to be working for me. I can't get obsidian to drop what I want it to drop can you please help me.
Sure:
That right there will NEVER be true. Event.state is an IBlockState, not a Block, so how could it be an instanceof BlockObsidian?
then how do I fix it
https://gist.github.com/anonymous/147cbc22c6346a0e21fa
You need to figure out a way to get a Block from the event. Hint: look at the IBlockState class methods.
do change it to (==)
sorry bout that last post I forgot to refresh the page and after posting I saw the reply you had posted ill go look at the class thanks for the hint
ok so I'm still having issues with my problem in the link below is my mess around mod please I looked in the IBlockventState again I'm new to modding and I want to learn as much as I can so if you could help explaine to me how its not workingI would be greatfull also did I use the wrong bus kuz I feel like I did.
https://gist.github.com/anonymous/ce708e3724d0eebb98e8
and if I am being annoying I am truly sorry.