Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Creating an item, that has the function of a shield?
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
MikeZ

Creating an item, that has the function of a shield?

By MikeZ, June 1, 2014 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

MikeZ    1

MikeZ

MikeZ    1

  • Stone Miner
  • MikeZ
  • Members
  • 1
  • 77 posts
Posted June 1, 2014

Hi!

I want to make an Item, that if it's in your hand it's like a shield (less damage).

Please give me some tips for that.

 

Thanks,

Mike

  • Quote

Share this post


Link to post
Share on other sites

coolboy4531    66

coolboy4531

coolboy4531    66

  • Dragon Slayer
  • coolboy4531
  • Members
  • 66
  • 584 posts
Posted June 1, 2014

Check if the player is holding the shield, then use LivingHurtEvent to lower damage taken.

  • Quote

Share this post


Link to post
Share on other sites

MikeZ    1

MikeZ

MikeZ    1

  • Stone Miner
  • MikeZ
  • Members
  • 1
  • 77 posts
Posted June 1, 2014

Check if the player is holding the shield, then use LivingHurtEvent to lower damage taken.

 

Thanks for your answer ;)

At the moment I'm learning Java so i need some more help :)

Could you say me, how I can check if the player is holding the item?

 

Thanks,

Mike

  • Quote

Share this post


Link to post
Share on other sites

coolboy4531    66

coolboy4531

coolboy4531    66

  • Dragon Slayer
  • coolboy4531
  • Members
  • 66
  • 584 posts
Posted June 1, 2014

player.getCurrentEquippedItem()

  • Quote

Share this post


Link to post
Share on other sites

MikeZ    1

MikeZ

MikeZ    1

  • Stone Miner
  • MikeZ
  • Members
  • 1
  • 77 posts
Posted June 1, 2014

player.getCurrentEquippedItem()

 

Ok, thanks.

My code should like this:

If player.getCurrentEquippedItem() == OwnItem {

(How can I use the LivingHurtEvent to reduce dthe damage?)

 

Thanks,

Mike

  • Quote

Share this post


Link to post
Share on other sites

Flockshot    1

Flockshot

Flockshot    1

  • Tree Puncher
  • Flockshot
  • Members
  • 1
  • 22 posts
Posted June 2, 2014

Here is an example well it will add potion effect ressisstence for some seconds when you are holding the specific item.The seconds will not decrease until you dont have that specific item in hand

Its using ClientTickHandler

 

see here how to make 1. 

 

In the video he is using server proxy if you are using client proxy change do it in client proxy.

 

Then in TickHandler Class add this

 


package com.Flockshot.UltraDaimond.Proxy;

import java.util.EnumSet;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ClientTickHandler implements ITickHandler {

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

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

	onPlayerTick((EntityPlayer) tickData[0]);

}

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


}

@Override
public EnumSet<TickType> ticks() {

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

}


@Override
public String getLabel() {

	return null;
}


private void onPlayerTick(EntityPlayer player){

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

		ItemStack hand = player.getCurrentItemOrArmor(0);

		if(hand.getItem() == Your item here ){ //Your item here

			player.addPotionEffect(new PotionEffect(Potion.resistance.getId(), 10, 0 ) );

		}



	}

}



}


  • Quote

Share this post


Link to post
Share on other sites

MikeZ    1

MikeZ

MikeZ    1

  • Stone Miner
  • MikeZ
  • Members
  • 1
  • 77 posts
Posted June 2, 2014

Here is an example well it will add potion effect ressisstence for some seconds when you are holding the specific item.The seconds will not decrease until you dont have that specific item in hand

Its using ClientTickHandler

 

see here how to make 1. 

 

In the video he is using server proxy if you are using client proxy change do it in client proxy.

 

Then in TickHandler Class add this

 


package com.Flockshot.UltraDaimond.Proxy;

import java.util.EnumSet;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ClientTickHandler implements ITickHandler {

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

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

	onPlayerTick((EntityPlayer) tickData[0]);

}

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


}

@Override
public EnumSet<TickType> ticks() {

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

}


@Override
public String getLabel() {

	return null;
}


private void onPlayerTick(EntityPlayer player){

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

		ItemStack hand = player.getCurrentItemOrArmor(0);

		if(hand.getItem() == Your item here ){ //Your item here

			player.addPotionEffect(new PotionEffect(Potion.resistance.getId(), 10, 0 ) );

		}



	}

}



}


 

Ok, I added the code. But, if I hold the Item in my hand the potion effect is displayed but it has no effect :D

An if the potion effect is at 0 there is always the displayed potioneffec with duration 0 ;)

 

What should I do?

 

Here is my Main Class:

 

 

package MikesMod;

 

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.ItemStack;

import net.minecraftforge.common.DimensionManager;

import net.minecraftforge.common.EnumHelper;

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;

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

import cpw.mods.fml.relauncher.Side;

import MikesMod.items.*;

import MikesMod.blocks.*;

import MikesMod.dimension.MikesPortal;

import MikesMod.dimension.WorldProviderMainClass;

import MikesMod.world.gen.*;

 

@Mod(modid = "mike", name = "MikesMod", version = "1.0.0")

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class MainClass {

 

@Instance("MikesMod")

public static MainClass instance;

public static CreativeTabs tabMikesMod = new CreativeTabMikesMod(CreativeTabs.getNextID(), "mikesmod");

public static final int MikesDimension = 10;

 

//ID Variablen

private static int MikesIngotID = 4000;

private static int MikesOreID = 4001;

private static int MikesHelmetID = 4002;

private static int MikesChestplateID = 4003;

private static int MikesLeggingsID = 4004;

private static int MikesBootsID = 4005;

private static int MikesPickaxeID = 4006;

private static int MikesFASID = 4007;

private static int MikesPortalID = 4008;

private static int MikesFireID = 4009;

private static int MikesOreBlockID = 4010;

 

 

//Rüstung Material

public static EnumArmorMaterial MIKESARMORMATERIAL = EnumHelper.addArmorMaterial("MikesArmorMaterial", 100, new int[] {10, 22, 15, 17}, 10);

 

//Items

public static Item MikesIngot = new MikesIngot(MikesIngotID, "MikesIngot").setUnlocalizedName("mikesingot");

public static Item MikesHelmet = new MikesArmor(MikesHelmetID, MIKESARMORMATERIAL, 0, 0, "MikesArmor").setUnlocalizedName("mikeshelmet");

public static Item MikesChestplate = new MikesArmor(MikesChestplateID, MIKESARMORMATERIAL, 0, 1, "MikesArmor").setUnlocalizedName("mikeschestplate");

public static Item MikesLeggings = new MikesArmor(MikesLeggingsID, MIKESARMORMATERIAL, 0, 2, "MikesArmor").setUnlocalizedName("mikesleggings");

public static Item MikesBoots = new MikesArmor(MikesBootsID, MIKESARMORMATERIAL, 0, 3, "MikesArmor").setUnlocalizedName("mikesboots");

public static MikesTool MikesPickaxe = (MikesTool) new MikesPickaxe(MikesPickaxeID, MikesToolMaterial.MIKE, "MikesPickaxe").setUnlocalizedName("mikespickaxe");

public static Item MikesFAS = new MikesFAS(MikesFASID).setUnlocalizedName("mikesfas");

 

//Blocks

public static Block MikesOre = new MikesOre(MikesOreID, Material.rock, "MikesOre").setUnlocalizedName("mikesore");

public static Block MikesFire = new MikesFire(MikesFireID).setUnlocalizedName("mikesfire");

public static Block MikesPortal = new MikesPortal(MikesPortalID).setUnlocalizedName("mikesportal");

public static Block MikesOreBlock = new MikesOreBlock(MikesOreBlockID, Material.rock, "MikesOreBlock").setUnlocalizedName("mikesoreblock");

 

@EventHandler

public void preInit(FMLPreInitializationEvent event) {

Items();

Blocks();

Armor();

CraftingRecipes();

}

 

@EventHandler

public void load(FMLInitializationEvent event) {

GameRegistry.registerWorldGenerator(new OreGen());

DimensionManager.registerProviderType(this.MikesDimension, WorldProviderMainClass.class, false);

DimensionManager.registerDimension(this.MikesDimension, this.MikesDimension);

proxy.registerClientTickHandler();

}

 

@EventHandler

public static void postInit(FMLPostInitializationEvent event) {

 

}

 

private void Blocks() {

//MikesOre

GameRegistry.registerBlock(MikesOre, "mikesore");

LanguageRegistry.addName(MikesOre, "Mikes Ore");

MinecraftForge.setBlockHarvestLevel(MikesOre, "pickaxe", 2);

 

//MikesPortal

GameRegistry.registerBlock(MikesPortal, "mikesportal");

LanguageRegistry.addName(MikesPortal, "Mikes Portal");

 

//MikesOreBlock

GameRegistry.registerBlock(MikesOreBlock, "mikesoreblock");

LanguageRegistry.addName(MikesOreBlock, "Mikes Block");

 

//MikesFire

GameRegistry.registerBlock(MikesFire, "mikesfire");

LanguageRegistry.addName(MikesFire, "Mikes Fire");

}

 

private void Armor() {

GameRegistry.registerItem(MikesHelmet, "mikeshelmet");

LanguageRegistry.addName(MikesHelmet, "Mikes Helmet");

 

GameRegistry.registerItem(MikesChestplate, "mikeschestplate");

LanguageRegistry.addName(MikesChestplate, "Mikes Chestplate");

 

GameRegistry.registerItem(MikesLeggings, "mikesleggings");

LanguageRegistry.addName(MikesLeggings, "Mikes Leggings");

 

GameRegistry.registerItem(MikesBoots, "mikesboots");

LanguageRegistry.addName(MikesBoots, "Mikes Boots");

}

 

private void Items() {

//GreenDiamond

GameRegistry.registerItem(MikesIngot, "mikesingot");

LanguageRegistry.addName(MikesIngot, "Mikes Ingot");

 

//MikesPickaxe

GameRegistry.registerItem(MikesPickaxe, "mikespickaxe");

LanguageRegistry.addName(MikesPickaxe, "Mikes Pickaxe");

MinecraftForge.setToolClass(MikesPickaxe, "pickaxe", 3);

 

//MikesFAS

GameRegistry.registerItem(MikesFAS, "mikesfas");

LanguageRegistry.addName(MikesFAS, "Mikes Flint and Steel");

}

 

private void CraftingRecipes() {

GameRegistry.addRecipe(new ItemStack(MainClass.MikesHelmet, 1), "MMM", "MXM", "XXX", 'M', MainClass.MikesIngot);

GameRegistry.addRecipe(new ItemStack(MainClass.MikesChestplate, 1), "MXM", "MMM", "MMM", 'M', MainClass.MikesIngot);

GameRegistry.addRecipe(new ItemStack(MainClass.MikesLeggings, 1), "MMM", "MXM", "MXM", 'M', MainClass.MikesIngot);

GameRegistry.addRecipe(new ItemStack(MainClass.MikesBoots, 1), "XXX", "MXM", "MXM", 'M', MainClass.MikesIngot);

GameRegistry.addRecipe(new ItemStack(MainClass.MikesPickaxe, 1), "MMM", "XMX", "XMX", 'M', MainClass.MikesIngot);

GameRegistry.addRecipe(new ItemStack(MainClass.MikesOreBlock, 1), "MMM", "MDM", "MMM", 'M', MainClass.MikesIngot, 'D', Item.diamond);

}

 

@SidedProxy(clientSide = "MikesMod.items.ClientProxy", serverSide = "MikesMod.items.ServerProxy")

public static ClientProxy proxy;

}

 

 

 

My ClientTickHandlerClass:

 

 

 

package MikesMod.items;

 

import java.util.EnumSet;

 

import MikesMod.MainClass;

import net.minecraft.block.Block;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

 

public class ClientTickHandler implements ITickHandler {

 

@Override

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

 

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

 

onPlayerTick((EntityPlayer) tickData[0]);

}

}

 

@Override

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

 

 

}

 

@Override

public EnumSet<TickType> ticks() {

 

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

 

}

 

 

@Override

public String getLabel() {

 

return null;

}

 

 

private void onPlayerTick(EntityPlayer player){

 

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

 

ItemStack hand = player.getCurrentItemOrArmor(0);

 

if(hand.getItem() == MainClass.MikesIngot) {

 

player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 100, 1 ) );

 

}

 

 

 

}

 

}

 

 

 

}

 

 

 

And my ClientProxy Class:

 

 

package MikesMod.items;

 

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

import cpw.mods.fml.relauncher.Side;

 

public class ClientProxy {

 

public void registerClientTickHandler() {

TickRegistry.registerTickHandler(new ClientTickHandler(), Side.CLIENT);

}

}

 

 

 

Thanks,

Mike

  • Quote

Share this post


Link to post
Share on other sites

GotoLink    381

GotoLink

GotoLink    381

  • World Shaper
  • GotoLink
  • Members
  • 381
  • 2012 posts
Posted June 2, 2014

Either use the event as coolboy suggested, there is a tutorial on the wiki, or override Item#onUpdate(ItemStack, World, Entity, int, boolean) in your item.

The PotionEffect isn't going to work if you keep it on the client.

 

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • JetCobblestone
      [1.14] layout of a modpack

      By JetCobblestone · Posted 2 minutes ago

      I try to read the comments, but 95% are just people going on about how great and fantastic his tutorials are, which are of course the only ones he replies and likes. He doesn't bother helping people who can't it to work.
    • JetCobblestone
      [1.14] layout of a modpack

      By JetCobblestone · Posted 4 minutes ago

      Right. I'mt not good enough at java yet to be able to just look at the source and figure out what I can do yet, and I don't know all the commands I can use, but I'm sure I'll learn. The tutorials you sent me look really good!
    • solitone
      Distinguish singleplayer vs. multiplayer

      By solitone · Posted 20 minutes ago

      So doesn’t it cause the server to crash, in contrast to what Draco18s said?
    • shadowmaster530
      Unable to register Item texture can someone help?

      By shadowmaster530 · Posted 47 minutes ago

      So I am currently coding in a item and can’t get its texture to properly connect. Here is my code:   package assets.testmod.textures.items;   import com.shadowmaster.testmod.reference.Reference; import net.minecraft.item.Item; import net.minecraft.ItemStack;  import net.minecraftforge.fml.relauncher.Side;  import net.minecraftforge.fml.relauncher.SideOnly;     public class ItemSTM extends Item{      public ItemSTM(){            super();      }      @Override      public String getUnlocalizedName(){            return String.format(“item.%s%s”, Reference.MOD_ID.toLowerCase() + “:”, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));      }        @Override      public String getUnlocalizedName(ItemStack itemStack){            return String.format(“item.%s%s”, Reference.MOD_ID.toLowerCase() + “:”, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));      }        @Override      @SideOnly(Side.CLIENT)       public void registerIcons(IIconRegister iconRegister){             itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(getUnlocalizedName().indexOf(“.”) + 1);   \* This is the piece having the issue but I can’t figure out why or how to fix it *\       }      protected String getUnwrappedUnlocalizedName(String unlocalizedName){           return unlocalizedName.substring(unlocalizedName.indexOf(“.”) + 1);      } }
    • tdude0317
      Dragon Mounts:Reborn

      By tdude0317 · Posted 1 hour ago

      Hello there, I am the Lead developer for a WIP mod named Dragon Mounts:Reborn. Some of you may have heard of Dragon Mounts or Dragon mounts 2, both of which have been stopped. Dragon Mounts:Reborn is a spiritual successor  to these two mods and we are hoping to make it bigger and better. We are looking for anybody willing to help with the mod, especially coders. Please, if you have any interest joining our team, join our discord to learn more,meet the rest of us, and hopefully join us. https://discord.gg/RhgkQjp  
  • Topics

    • JetCobblestone
      6
      [1.14] layout of a modpack

      By JetCobblestone
      Started 13 hours ago

    • solitone
      4
      Distinguish singleplayer vs. multiplayer

      By solitone
      Started 11 hours ago

    • shadowmaster530
      0
      Unable to register Item texture can someone help?

      By shadowmaster530
      Started 47 minutes ago

    • tdude0317
      0
      Dragon Mounts:Reborn

      By tdude0317
      Started 1 hour ago

    • DragonITA
      2
      [1.14.4] Add a Tab to the Player Inventory Gui in Survival Modus

      By DragonITA
      Started 9 hours ago

  • Who's Online (See full list)

    • Choonster
    • Lea9ue
    • nze
    • BlockyPenguin
    • JetCobblestone
    • vaartis
    • Cerandior
    • KittRiderTV
    • solitone
    • SerpentDagger
    • bsrgin
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Creating an item, that has the function of a shield?
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community