Jump to content

Recommended Posts

Posted

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

Posted
  On 6/1/2014 at 5:48 PM, coolboy4531 said:

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

Posted
  On 6/1/2014 at 6:48 PM, coolboy4531 said:

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

Posted

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 ) );

		}



	}

}



}


Posted
  On 6/2/2014 at 6:33 AM, Flockshot said:

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:

 

  Reveal hidden contents

 

 

My ClientTickHandlerClass:

 

  Reveal hidden contents

 

 

And my ClientProxy Class:

 

  Reveal hidden contents

 

 

Thanks,

Mike

Posted

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.

 

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.