Jump to content

Recommended Posts

Posted

I'm trying to make a check to see if the player has my sword in his/her hands. It doesn't print anything in the console when I start the client.

 

mod_deathman12e3 (It's in the postInit)

 

 

package deathman12e3;

 

import java.util.Arrays;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.EnumArmorMaterial;

import net.minecraft.item.EnumToolMaterial;

import net.minecraft.item.Item;

import net.minecraft.item.ItemArmor;

import net.minecraft.item.ItemAxe;

import net.minecraft.item.ItemHoe;

import net.minecraft.item.ItemPickaxe;

import net.minecraft.item.ItemSpade;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

import net.minecraftforge.common.Configuration;

import net.minecraftforge.common.EnumHelper;

import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.ModMetadata;

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

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

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

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

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 = "TrifectaOres", name = "Trifecta Ores", version = "1.0")

 

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

 

public class mod_deathman12e3

{

 

@Instance("mod_deathman12e3")

public static mod_deathman12e3 instance;

 

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

public static CommonProxy proxy;

 

@PreInit

public void preInit(FMLPreInitializationEvent event)

{

 

System.out.println("***************************************************************");

System.out.println("Loading 12e3Ores...");

System.out.println("***************************************************************");

 

ModMetadata modmeta = event.getModMetadata();

modmeta.authorList = Arrays.asList(new String [] { "deathman12e3" });

modmeta.autogenerated = false;

modmeta.credits = "";

modmeta.description = "Trifecta Ores adds Hellstone to the nether, Adamantite to the end, and Cobalt to the overworld.";

 

Configuration config = new Configuration(event.getSuggestedConfigurationFile());

 

config.load();

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

hellstoneOreID = config.get("Blocks", "Hellstone Ore", 3000).getInt();

hellstoneCompactID = config.get("Blocks", "Hellstone Compact", 3001).getInt();

 

hellstoneIngotID = config.get("Items", "Hellstone Ingot", 8000).getInt();

 

hellstoneSwordID = config.get("Items", "Hellstone Sword", 8001).getInt();

hellstonePickaxeID = config.get("Items", "Hellstone Pickaxe", 8002).getInt();

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

config.save();

 

}

 

@Init

public void Init(FMLInitializationEvent event)

{

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

hellstoneOre = (BlockHellstoneOre) new BlockHellstoneOre(hellstoneOreID, Material.rock).setUnlocalizedName("hellstoneOre");

hellstoneCompact = (BlockCompact12e3) new BlockCompact12e3(hellstoneCompactID, Material.iron).setUnlocalizedName("hellstoneCompact");

 

hellstoneIngot = (Item) new Item(hellstoneIngotID).setUnlocalizedName("hellstoneIngot");

 

hellstoneSword = (ItemSword12e3) new ItemSword12e3(hellstoneSwordID, HELLSTONE).setUnlocalizedName("hellstoneSword");

hellstonePickaxe = (ItemPickaxe12e3) new ItemPickaxe12e3(hellstonePickaxeID, HELLSTONE).setUnlocalizedName("hellstonePickaxe");

 

GameRegistry.addSmelting(hellstoneOre.blockID, new ItemStack(hellstoneIngot, 1), 1.0F);

 

GameRegistry.addShapelessRecipe(new ItemStack(hellstoneCompact, 1), hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot, hellstoneIngot);

 

GameRegistry.addShapedRecipe(new ItemStack(hellstoneSword, 1), " I ", " I ", " S ", 'I', hellstoneIngot, 'S', Item.stick);

GameRegistry.addShapedRecipe(new ItemStack(hellstonePickaxe, 1), "III", " S ", " S ", 'I', hellstoneIngot, 'S', Item.stick);

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

}

 

@PostInit

public void postInit(FMLPostInitializationEvent event)

{

 

proxy.registerServerTickHandler();

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

GameRegistry.registerBlock(hellstoneOre, "hellstoneOre");

GameRegistry.registerBlock(hellstoneCompact, "hellstoneCompact");

 

LanguageRegistry.addName(hellstoneOre, "Hellstone Ore");

LanguageRegistry.addName(hellstoneCompact, "Hellstone Compact");

 

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

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

 

LanguageRegistry.addName(hellstoneIngot, "Hellstone Ingot");

 

LanguageRegistry.addName(hellstoneSword,  "Hellstone Sword");

LanguageRegistry.addName(hellstonePickaxe, "Hellstone Pickaxe");

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

System.out.println("***************************************************************");

System.out.println("Finished loading 12e3Ores!");

System.out.println("***************************************************************");

 

}

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

public static EnumToolMaterial HELLSTONE = EnumHelper.addToolMaterial("HELLSTONE", 4, 2048, 8, 3, 5);

 

public static BlockHellstoneOre hellstoneOre;

public static BlockCompact12e3 hellstoneCompact;

 

public static Item hellstoneIngot;

 

public static ItemSword12e3 hellstoneSword;

public static ItemPickaxe12e3 hellstonePickaxe;

 

public static int hellstoneOreID = 3000;

public static int hellstoneCompactID = 3001;

 

public static int hellstoneIngotID = 8000;

 

public static int hellstoneSwordID = 8001;

public static int hellstonePickaxeID = 8002;

 

//HELLSTONE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

}

 

 

 

CommonProxy

 

 

package deathman12e3;

 

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

import cpw.mods.fml.relauncher.Side;

 

public class CommonProxy

{

 

    public void registerRenderers()

    {

    }

 

    public int addArmor(String string)

    {

   

        return 0;

       

    }

   

    public void registerServerTickHandler()

{

   

  TickRegistry.registerTickHandler(new ServerTickHandler12e3(), Side.SERVER);

 

}

   

}

 

 

 

 

ServerTickHandler12e3

 

 

package deathman12e3;

 

import java.util.EnumSet;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

 

public class ServerTickHandler12e3 implements ITickHandler

{

 

@Override

public void tickStart(EnumSet<TickType> type, Object... tickData) {

// TODO Auto-generated method stub

}

 

@Override

public void tickEnd(EnumSet<TickType> type, Object... tickData) {

// TODO Auto-generated method stub

}

 

@Override

public EnumSet<TickType> ticks() {

// TODO Auto-generated method stub

return null;

}

 

@Override

public String getLabel() {

// TODO Auto-generated method stub

return null;

}

 

private void onPlayerTick(EntityPlayer player)

{

 

if(player.getCurrentItemOrArmor(0) != null)

{

 

ItemStack hand = player.getCurrentItemOrArmor(0);

 

if(hand.getItem() == mod_deathman12e3.hellstoneSword)

{

 

//player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0)));

 

System.out.println("HI");

 

}

 

}

 

}

 

}

 

 

Kain

Posted

Ok, I changed my method to this one.

 

 

 

private void onPlayerTick(EntityPlayer player)

{

 

if(player.getCurrentEquippedItem() != null)

{

 

ItemStack hand = player.getCurrentEquippedItem();

 

if(hand == new ItemStack(mod_deathman12e3.hellstoneSword, 1))

{

 

//player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0)));

 

System.out.println("HI");

 

}

 

}

 

}

 

 

 

It still doesn't print anything :I

Kain

Posted

I tweaked my code to check for the item ID. But I don't really know anything about item meta data values. Sorry I'm a bit of a newb at Java. :|

 

 

 

private void onPlayerTick(EntityPlayer player)

{

 

if(player.getCurrentEquippedItem() != null)

{

 

ItemStack hand = player.getCurrentEquippedItem();

 

if(hand.getItem().itemID == mod_deathman12e3.hellstoneSword.itemID)

{

 

//player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0)));

 

System.out.println("HI");

 

}

 

}

 

}

 

 

Kain

Posted

Figured it out. :D

 

I never called the onPlayer method. I'll put my ServerTickHandler right here for anyone having the same problem.

 

ServerTickHandler12e3

 

 

 

package deathman12e3;

 

import java.util.EnumSet;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.src.ModLoader;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

 

public class ServerTickHandler12e3 implements ITickHandler

{

 

@Override

public void tickStart(EnumSet<TickType> type, Object... tickData)

{

 

  if (type.equals(EnumSet.of(TickType.PLAYER)))

  {

 

    playerTick((EntityPlayer)tickData[0]);

   

  }

 

}

 

@Override

public void tickEnd(EnumSet<TickType> type, Object... tickData) {

// TODO Auto-generated method stub

}

 

@Override

public EnumSet<TickType> ticks()

{

 

return EnumSet.of(TickType.PLAYER, TickType.SERVER);

 

}

 

@Override

public String getLabel() {

// TODO Auto-generated method stub

return null;

}

 

private void playerTick(EntityPlayer player)

{

 

if(player.getCurrentEquippedItem() != null)

{

 

ItemStack hand = player.getCurrentEquippedItem();

 

if(hand.getItem().itemID == mod_deathman12e3.hellstoneSword.itemID)

{

 

//player.addPotionEffect((new PotionEffect(Potion.nightVision.id, 100, 0)));

 

System.out.println("HI");

 

}

 

}

 

}

 

}

 

 

 

Kain

Posted

par5 boolean is what you need to check if item is held

 

if(par5 && (entity instanceof EntityPlayer)) {

EntityPlayer player = (EntityPlayer)entity;

if (!world.isRemote && !player.capabilities.isCreativeMode) {

if (player.getFoodStats().getFoodLevel() >= 0) {

player.getFoodStats().setFoodLevel(player.getFoodStats().getFoodLevel()-1);

                        player.getFoodStats().setFoodSaturationLevel(0);

}

}

}

 

my hunger item code

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 tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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