Jump to content

Getting a custom item to work in multiplayer


Athire

Recommended Posts

Hello! I posted on here a few days ago and you guys helped me out a lot, and now I'm having another issue so hopefully you guys can help me out again! So I'm still in the learning phases of my Minecraft mod, I'm really just testing how to add custom items and things right now. In single player I was able to make a "spellbook" sort of thing that would shoot fireballs when right clicked. Now that I'm trying to test it out for multiplayer, I can't get the right click functionality to work. I put breakpoints in the function and it never even seemed to hit them, unless I'm just using the breakpoints wrong. Over the last few days I've been searching the internet for some explanation as to what I need to change to get it working for multiplayer, but I haven't been able to find much. For awhile I suspected my issue was that the fireball entities weren't being recognized by the server, but looking through the minecraft source code I can't see any difference between how I call the function and how ghasts or blazes use it, and both of those work in multiplayer. Anyway, If any of you guys could help me figure out what I need to do differently, or can point me in the direction of a good article or tutorial, it would be much appreciated! And just like my last post, I can't get attachments to work so I will post the relevant bits of my code below! Thank you for taking the time to help me out!

Link to comment
Share on other sites

Ok here is my code, sorry if I'm not supposed to post it like this but I couldn't get the attachment thing working D:

 

//BaseClass ***************************************************************

 

package InnerPower;

//---------------------------------

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.*;

import net.minecraftforge.common.MinecraftForge;

//-----------------------------------

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.Mod.Instance;

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.network.NetworkMod;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

 

 

@Mod(modid= "AthInrPwr", name= "Inner Power", version= "Alpha 1.0")

@NetworkMod(clientSideRequired= true, serverSideRequired= false)

public class BaseClass

{

// The instance of your mod that Forge uses.

    @Instance(value = "AthInrPwr")

    public static BaseClass instance1;

 

 

//*********** Defining blocks/items

public static final Block InrPwrCrystal = new crystalBlock(550, Material.ground).setHardness(45.0f).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("crystalBlock").setCreativeTab(CreativeTabs.tabBlock).setTextureName("InnerPower_Block_Crystal");

public static final Item InrPwrWispEssence = new Item(5001).setCreativeTab(CreativeTabs.tabMisc).setUnlocalizedName("essenceWisp").setTextureName("InnerPower_Essence_WispyEssence");

public static final Item STFireball= new SpellTomeFireball(5000).setTextureName("InnerPower_SpellTome_Fireball");

//From new tutorial

 

 

//instance of mod forge uses

@Instance("AthInrPwr")

public static BaseClass instance;

 

//says where the client and server proxy code is loaded

@SidedProxy(clientSide= "InnerPower.client.ClientProxy",serverSide="InnerPower.CommonProxy")

public static CommonProxy proxy;

 

  @EventHandler

      public void preInit(FMLPreInitializationEvent event)

  {

     

  //Adding to registry

  GameRegistry.registerBlock(InrPwrCrystal, "crystal" );

  LanguageRegistry.addName(InrPwrCrystal, "crystal");

  MinecraftForge.setBlockHarvestLevel(InrPwrCrystal, "pickaxe", 3);

 

  LanguageRegistry.addName(InrPwrWispEssence, "Wispy Essence");

 

 

LanguageRegistry.addName(STFireball, "Spell Tome: Fireball");

  GameRegistry.addRecipe(new ItemStack(STFireball, 1), new Object[]{

  "xx","xx", 'x', Block.dirt

  });

 

  //test recipie

  GameRegistry.addRecipe(new ItemStack(Item.diamond, 1), new Object[]{

  "x x", " x ", "x x", 'x', Block.dirt

  });

      }

 

  @EventHandler

      public void postInit(FMLPostInitializationEvent event)

  {

  //Stub Method

  }

 

 

  @EventHandler

public void load(FMLInitializationEvent event)

{

  //block and item initializations moved to preInit()

 

}

 

 

 

 

}

 

//Spell book class ***********************************************************************

package InnerPower;

 

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.Vec3;

import net.minecraft.world.World;

import net.minecraft.block.Block;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.projectile.EntitySmallFireball;

 

import java.util.Random;

 

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

 

public class SpellTomeFireball extends Item

{

 

//Default Constructor

 

public SpellTomeFireball(int id)

{

super(id);

setMaxStackSize(1);

setCreativeTab(CreativeTabs.tabCombat);

setUnlocalizedName("STfireball");

 

}

 

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayerMP par3EntityPlayer)

    {

if (!par2World.isRemote)

        {

 

par3EntityPlayer.addChatMessage("This line is  being hit");

                                        Vec3 look = par3EntityPlayer.getLookVec();

                                        EntitySmallFireball fireball2 = new EntitySmallFireball(par2World, par3EntityPlayer, 500, 500, 500);

                                        fireball2.setPosition(par3EntityPlayer.posX + look.xCoord * par3EntityPlayer.getEyeHeight(), par3EntityPlayer.posY + look.yCoord * par3EntityPlayer.getEyeHeight()+1, par3EntityPlayer.posZ + look.zCoord * par3EntityPlayer.getEyeHeight());

                                        fireball2.accelerationX = look.xCoord * 0.5;

                                        fireball2.accelerationY = look.yCoord * 0.5;

                                        fireball2.accelerationZ = look.zCoord * 0.5;

                                        par2World.spawnEntityInWorld(fireball2);

                                       

                                       

 

 

        }

 

    return par1ItemStack;

 

 

    }

 

public String getVersion()

{

return "1.0";

}

 

 

}

 

// Common Proxy *************************************************************

 

package InnerPower;

 

public class CommonProxy

{

// Client stuff

    public void registerRenderers() {

            // Nothing here as the server doesn't render graphics or entities!

    }

}

 

//Client Proxy Class****************************

package InnerPower.client;

 

//extra imports were from expiraments i did trying to get my item to work in MP

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

import net.minecraft.block.Block;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraftforge.client.MinecraftForgeClient;

import InnerPower.CommonProxy;

import InnerPower.SpellTomeFireball;

 

public class ClientProxy extends CommonProxy {

     

        @Override

        public void registerRenderers() {

                // This is for rendering entities and so forth later on

       

        }

     

}

Link to comment
Share on other sites

Your onItemRightClick does not override anything and because of that never gets called (what should call it?) Always, always, always use @Override if you intend to override, it will tell you if you are not actually overriding.

 

In b4 "but that throws an error that tells me to remove the override!"

 

BECAUSE YOUR FUNCTION ISN'T THE SAME AS THE ONE IN ITEM.  Go get the correct function, including parameters, and try again.

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

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



×
×
  • Create New...

Important Information

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