The Meaning of Life, the Universe, and Everything.
Location:
California
Join Date:
6/21/2013
Posts:
45
Location:
California, USA
Minecraft:
Creepinson101
Xbox:
Creepinson101
Member Details
Hello there. I want to make a fire extinguish itself when blaze powder is dropped on any fire that exists. After it gets extinguished, I want it to pop out my custom item called Fire Essence where the fire was originally. So basically, the player lights a fire, drops a piece of blaze powder on the fire, and it extinguishes itself, then spits out my "Fire Essence". Any help figuring out the code to do so would be appreciated. I am not completely new to Java and forge modding, but this thing is really advanced and I am not so advanced as some people are.
You will need to read up on EventHandling. You will need to check whether the item dropped in the world is a blaze powder then get the block it was dropped on. If it is a fire block, then cancel the fire event, and spawn in the Fire Essence.
Rollback Post to RevisionRollBack
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
The Meaning of Life, the Universe, and Everything.
Location:
California
Join Date:
6/21/2013
Posts:
45
Location:
California, USA
Minecraft:
Creepinson101
Xbox:
Creepinson101
Member Details
I don't know how to check that. Would I use ItemTossEvent? Also how would i get the block it was dropped on? Sorry if I am asking too much. I can most likely figure out the "if it is a fire block" and then cancel it, and spawn Fire Essence in. The only thing I don't know how to do is the first thing.
The Meaning of Life, the Universe, and Everything.
Location:
California
Join Date:
6/21/2013
Posts:
45
Location:
California, USA
Minecraft:
Creepinson101
Xbox:
Creepinson101
Member Details
I might have figured it out but I'm not completely sure. There is an error where my setblock/destroy method is. It says cannot make a static reference to the non-static method world.setBlock...
@Mod(modid = me.creepinson.lib.RefStrings.MODID, version = me.creepinson.lib.RefStrings.VERSION)
public class Main {
@SidedProxy(clientSide = RefStrings.CLIENTSIDE, serverSide = RefStrings.SERVERSIDE)
public static ServerProxy proxy;
//EVENTS
@SubscribeEvent
public void onDrop(net.minecraftforge.event.entity.item.ItemTossEvent event){
if(event.entityItem.getEntityItem().equals(Items.blaze_powder)){
Block block = event.entityItem.worldObj.getBlock((int)event.entityItem.posX,(int)event.entityItem.posY,(int)event.entityItem.posZ);
Material material = block.getMaterial();
if(material == Material.fire) {
public class EventHandlerMOD {
//EVENTS
@SubscribeEvent
public void onDrop(net.minecraftforge.event.entity.item.ItemTossEvent event){
if(event.entityItem.getEntityItem().equals(Items.blaze_powder)){
Block block = event.entityItem.worldObj.getBlock((int)event.entityItem.posX,(int)event.entityItem.posY,(int)event.entityItem.posZ);
Material material = block.getMaterial();
if(material == Material.fire) {
@Mod(modid = me.creepinson.lib.RefStrings.MODID, version = me.creepinson.lib.RefStrings.VERSION)
public class Main {
@SidedProxy(clientSide = RefStrings.CLIENTSIDE, serverSide = RefStrings.SERVERSIDE)
public static ServerProxy proxy;
//INITS
@EventHandler
public void preInit(FMLPreInitializationEvent PreEvent)
{
proxy.registerRenderInfo();
FireEssence.Main();
}
@EventHandler
public void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new EventHandlerMOD());
}
@EventHandler
public void postInit(FMLPostInitializationEvent PostEvent)
{
}
}
Now how do I fix the error?
Also my texture is not working for my Fire Essence item, here is my fire essence code:
manrockslikemc is doing the correct way of registering an event handler, passing an instance of the EventHandler inside MinecraftForge.EVENT_BUS.register.
manrockslikemc is doing the correct way of registering an event handler, passing an instance of the EventHandler inside MinecraftForge.EENT_BUS.register.
That's weird, I was taught that you need to pass in the class rather than an instance. But I will try that out, that might have been my mistake with events and hence why I could never get them to work.
Rollback Post to RevisionRollBack
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
The Meaning of Life, the Universe, and Everything.
Location:
California
Join Date:
6/21/2013
Posts:
45
Location:
California, USA
Minecraft:
Creepinson101
Xbox:
Creepinson101
Member Details
This code doesn't do anything when I drop the blaze powder (the code that is inside ItemDropEvent.) I want to know how to detect if the dropped item is blaze powder but I can't seem to figure it out.
Also did I make the right code to do what I wanted to do?
and about the texture not working - I did NOT fix it
You're trying to call a non-static method in a static way. You need to use the world instance in the event (or get the world from the player if the world isn't directly accessible).
As for why it might not be working, you're using an event which is called once when the player throws an item, so the blocks it's checking is probably the blockspace of where the player's head is. You need a method where you can detect when the item has collided with a fire block.
The Meaning of Life, the Universe, and Everything.
Location:
California
Join Date:
6/21/2013
Posts:
45
Location:
California, USA
Minecraft:
Creepinson101
Xbox:
Creepinson101
Member Details
What method would I use? I have a list of events with me but I don't know which one of them to use instead of itemtossevent. As for the texture, the video creator made a mistake that I followed. So I fixed it for real.
That's weird, I was taught that you need to pass in the class rather than an instance. But I will try that out, that might have been my mistake with events and hence why I could never get them to work.
It's not wrong, there are just multiple ways to register an event handler. You can register the class(The event handler methods need to be static in this case), an instance or annotate the class with Mod.EventBusSubscriber.
Rollback Post to RevisionRollBack
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
Hello there. I want to make a fire extinguish itself when blaze powder is dropped on any fire that exists. After it gets extinguished, I want it to pop out my custom item called Fire Essence where the fire was originally. So basically, the player lights a fire, drops a piece of blaze powder on the fire, and it extinguishes itself, then spits out my "Fire Essence". Any help figuring out the code to do so would be appreciated. I am not completely new to Java and forge modding, but this thing is really advanced and I am not so advanced as some people are.
Thanks,
Creepinson
You will need to read up on EventHandling. You will need to check whether the item dropped in the world is a blaze powder then get the block it was dropped on. If it is a fire block, then cancel the fire event, and spawn in the Fire Essence.
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
I don't know how to check that. Would I use ItemTossEvent? Also how would i get the block it was dropped on? Sorry if I am asking too much. I can most likely figure out the "if it is a fire block" and then cancel it, and spawn Fire Essence in. The only thing I don't know how to do is the first thing.
I might have figured it out but I'm not completely sure. There is an error where my setblock/destroy method is. It says cannot make a static reference to the non-static method world.setBlock...
Here is my code:
package me.creepinson.Main;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import me.creepinson.item.FireEssence;
import me.creepinson.lib.RefStrings;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@Mod(modid = me.creepinson.lib.RefStrings.MODID, version = me.creepinson.lib.RefStrings.VERSION)
public class Main {
@SidedProxy(clientSide = RefStrings.CLIENTSIDE, serverSide = RefStrings.SERVERSIDE)
public static ServerProxy proxy;
//EVENTS
@SubscribeEvent
public void onDrop(net.minecraftforge.event.entity.item.ItemTossEvent event){
if(event.entityItem.getEntityItem().equals(Items.blaze_powder)){
Block block = event.entityItem.worldObj.getBlock((int)event.entityItem.posX,(int)event.entityItem.posY,(int)event.entityItem.posZ);
Material material = block.getMaterial();
if(material == Material.fire) {
//ERRORED CODE
[b]World.func_147480_a((int)event.entityItem.posX,(int)event.entityItem.posY,(int)event.entityItem.posZ, false);[/b]
//END OF ERRORED CODE
World.spawnEntityInWorld();
}
}
}
//INITS
@EventHandler
public void preInit(FMLPreInitializationEvent PreEvent)
{
proxy.registerRenderInfo();
FireEssence.Main();
}
@EventHandler
public void init(FMLInitializationEvent event)
{
}
@EventHandler
public void postInit(FMLPostInitializationEvent PostEvent)
{
}
}
World.func_147480_a is equivalent to the not working world.destoryblock [/b]
Do you have your event registered? I don't see it registered.
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
I redid some stuff, and I think I registered it correctly:
EventHandlerMOD - Events:
package me.creepinson.Main;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Items;
import net.minecraft.world.World;
public class EventHandlerMOD {
//EVENTS
@SubscribeEvent
public void onDrop(net.minecraftforge.event.entity.item.ItemTossEvent event){
if(event.entityItem.getEntityItem().equals(Items.blaze_powder)){
Block block = event.entityItem.worldObj.getBlock((int)event.entityItem.posX,(int)event.entityItem.posY,(int)event.entityItem.posZ);
Material material = block.getMaterial();
if(material == Material.fire) {
World.func_147480_a((int)event.entityItem.posX,(int)event.entityItem.posY,(int)event.entityItem.posZ, false);
World.spawnEntityInWorld();
}
}
}
}
Main Class:
package me.creepinson.Main;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import me.creepinson.item.FireEssence;
import me.creepinson.lib.RefStrings;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
@Mod(modid = me.creepinson.lib.RefStrings.MODID, version = me.creepinson.lib.RefStrings.VERSION)
public class Main {
@SidedProxy(clientSide = RefStrings.CLIENTSIDE, serverSide = RefStrings.SERVERSIDE)
public static ServerProxy proxy;
//INITS
@EventHandler
public void preInit(FMLPreInitializationEvent PreEvent)
{
proxy.registerRenderInfo();
FireEssence.Main();
}
@EventHandler
public void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new EventHandlerMOD());
}
@EventHandler
public void postInit(FMLPostInitializationEvent PostEvent)
{
}
}
Now how do I fix the error?
Also my texture is not working for my Fire Essence item, here is my fire essence code:
package me.creepinson.item;
import cpw.mods.fml.common.registry.GameRegistry;
import me.creepinson.lib.RefStrings;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
public class FireEssence {
public static void Main(){
initializeIcon();
registerItem();
}
public static void initializeIcon(){
}
public static Item FireEssence;
public static void registerItem(){
FireEssence = new Item().setUnlocalizedName("FireEssence").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(RefStrings.MODID + ":" + "FireEssence");
GameRegistry.registerItem(FireEssence, FireEssence.getUnlocalizedName());
}
}
You need to register the event as such:
MinecraftForge.EVENT_BUS.register(EventHandlerMOD.class);
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
I think I realized I made a mistake in my fire essence code. LOL nevermind about the textures
manrockslikemc is doing the correct way of registering an event handler, passing an instance of the EventHandler inside MinecraftForge.EVENT_BUS.register.
That's weird, I was taught that you need to pass in the class rather than an instance. But I will try that out, that might have been my mistake with events and hence why I could never get them to work.
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
then what about this:
(the image file in this post)
Also did I make the right code to do what I wanted to do?
and about the texture not working - I did NOT fix it
I think it is because you use the world class. Instead you should get the world from the event and use that.
This code doesn't do anything when I drop the blaze powder (the code that is inside ItemDropEvent.) I want to know how to detect if the dropped item is blaze powder but I can't seem to figure it out.
You're trying to call a non-static method in a static way. You need to use the world instance in the event (or get the world from the player if the world isn't directly accessible).
As for why it might not be working, you're using an event which is called once when the player throws an item, so the blocks it's checking is probably the blockspace of where the player's head is. You need a method where you can detect when the item has collided with a fire block.
What method would I use? I have a list of events with me but I don't know which one of them to use instead of itemtossevent. As for the texture, the video creator made a mistake that I followed. So I fixed it for real.
It's not wrong, there are just multiple ways to register an event handler. You can register the class(The event handler methods need to be static in this case), an instance or annotate the class with Mod.EventBusSubscriber.
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
This is not the signature you are looking for.
Banners and such things