Created
March 21, 2016 13:19
-
-
Save anonymous/7856798aa7b17366e64a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mercenarymod.items.materiales; | |
//import mercenarymod.items.redstone.suspensionderedstone; | |
import java.util.List; | |
import mercenarymod.Mercenary; | |
import net.minecraft.creativetab.CreativeTabs; | |
import net.minecraft.enchantment.EnchantmentHelper; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.init.Enchantments; | |
import net.minecraft.init.Items; | |
import net.minecraft.item.EnumAction; | |
import net.minecraft.item.IItemPropertyGetter; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.util.ActionResult; | |
import net.minecraft.util.EnumActionResult; | |
import net.minecraft.util.EnumHand; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraft.world.World; | |
import net.minecraftforge.fml.common.registry.GameRegistry; | |
import net.minecraftforge.fml.relauncher.Side; | |
import net.minecraftforge.fml.relauncher.SideOnly; | |
import mercenarymod.items.MMMateriales; | |
import mercenarymod.utilidades.chat; | |
//############################################################################################3 | |
public class materialesSuspensionderedstone extends Item { | |
private static String name = "materialesSuspensionderedstone"; | |
// ############################################################################################3 | |
public materialesSuspensionderedstone() { | |
setUnlocalizedName(Mercenary.MODID + "_" + name); | |
GameRegistry.registerItem(this, name); | |
setCreativeTab(Mercenary.materiales); | |
this.setCreativeTab(CreativeTabs.tabRedstone); | |
this.setHasSubtypes(false); | |
this.maxStackSize = 1; | |
this.addPropertyOverride(new ResourceLocation("shake"), new IItemPropertyGetter() { | |
@SideOnly(Side.CLIENT) | |
public float apply(ItemStack stack, World worldIn, EntityLivingBase entityIn) { | |
if ((entityIn != null) && (entityIn.isHandActive()) && (entityIn.getActiveItemStack() == stack)) { | |
// System.out.println(" apply() Mundo="+worldIn.isRemote); | |
return 1.0F; | |
} else { | |
return 0.0F; | |
} | |
// return entityIn != null && entityIn.isHandActive() && | |
// entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F ; | |
} | |
}); | |
}// fin de contructor | |
// ############################################################################################3 | |
@Override | |
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, | |
EnumHand hand) { | |
boolean sePudo = true; | |
/* | |
* System.out.println("\n onItemRightClick(" | |
* +itemStackIn.getUnlocalizedName()+ "World="+worldIn.isRemote+ | |
* "EntityPlayer="+playerIn.getName()+ "EnumHand="+hand.name()+ ")\n"); | |
*/ | |
playerIn.setActiveHand(hand); | |
return sePudo ? new ActionResult(EnumActionResult.FAIL, itemStackIn) | |
: new ActionResult(EnumActionResult.PASS, itemStackIn); | |
} | |
// ############################################################################################3 | |
/** | |
* Called each tick as long the item is on a player inventory. Uses by maps | |
* to check if is on a player hand and update it's contents. | |
*/ | |
@Override | |
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { | |
if (isSelected && !worldIn.isRemote) { | |
if (entityIn instanceof EntityLivingBase) { | |
EntityLivingBase playerIn = (EntityLivingBase) entityIn; | |
EnumHand ManoActiva = playerIn.getActiveHand(); | |
// System.out.println("ManoActiva=" + ManoActiva); | |
} | |
} | |
} | |
// ############################################################################################3 | |
@Override | |
public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack itemStackIn) { | |
World worldIn = entityLiving.worldObj; | |
if (entityLiving instanceof EntityPlayer) { | |
EntityPlayer playerIn = (EntityPlayer) entityLiving; | |
EnumHand hand = playerIn.getActiveHand(); | |
ItemStack offHand = playerIn.getHeldItem(EnumHand.OFF_HAND); | |
ItemStack mainHand = playerIn.getHeldItem(EnumHand.MAIN_HAND); | |
/* | |
* System.out.println("\n onItemLeftClick(" | |
* +itemStackIn.getUnlocalizedName()+ "World="+worldIn.isRemote+ | |
* "EntityPlayer="+playerIn.getName()+ //"EnumHand="+hand.name()+ | |
* ")\n"); | |
*/ | |
} | |
return true; | |
} | |
// ############################################################################################3 | |
@Override | |
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) { | |
World worldIn = player.worldObj; | |
/* | |
* System.out.println("\n onUsingTick("+ | |
* | |
* "World="+worldIn.isRemote+ "count="+count+ | |
* | |
* "ManoActiva="+player.getActiveHand()+ | |
* | |
* ")\n"); | |
*/ | |
} | |
// ############################################################################################3 | |
/** | |
* Called when the player stops using an Item (stops holding the right mouse | |
* button). | |
*/ | |
@Override | |
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { | |
} | |
// ############################################################################################3 | |
@Override | |
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { | |
if (!worldIn.isRemote) { | |
if (entityLiving instanceof EntityPlayer) { | |
ItemStack replaceItemStack = new ItemStack(MMMateriales.materialesSuspensionderedstoneActivada, 1, 0); | |
Item comparationItem = MMMateriales.materialesSuspensionderedstone; | |
EntityPlayer playerIn = (EntityPlayer) entityLiving; | |
EnumHand ManoActiva = playerIn.getActiveHand(); | |
ItemStack leftHand = playerIn.getHeldItem(EnumHand.OFF_HAND); | |
ItemStack rightHand = playerIn.getHeldItem(EnumHand.MAIN_HAND); | |
int hand = playerIn.inventory.currentItem; | |
ItemStack itemstack = null; | |
itemstack = playerIn.inventory.getStackInSlot(hand); | |
if (ManoActiva != null && ManoActiva == EnumHand.MAIN_HAND && itemstack.getItem() == comparationItem) { | |
chat.chatm(playerIn, "replacing the Item in MAIN_HAND"); | |
playerIn.inventory.setInventorySlotContents(hand, replaceItemStack); | |
} | |
itemstack = playerIn.inventory.getStackInSlot(40); | |
if (ManoActiva != null && ManoActiva == EnumHand.OFF_HAND && itemstack.getItem() == comparationItem) { | |
chat.chatm(playerIn, "replacing the Item in OFF_HAND"); | |
playerIn.inventory.setInventorySlotContents(40, replaceItemStack); | |
} | |
int playerInvZise = playerIn.inventory.getSizeInventory(); | |
for (int i = 0; i < playerInvZise; ++i) { | |
itemstack = playerIn.inventory.getStackInSlot(i); | |
if (itemstack != null) { | |
System.out.println("SLOT[" + i + "]=" + itemstack.getUnlocalizedName()); | |
} | |
} | |
} | |
} | |
return stack; | |
} | |
// ############################################################################################3 | |
@Override | |
public int getMaxItemUseDuration(ItemStack stack) { | |
return 60; | |
} | |
// ############################################################################################3 | |
@Override | |
public EnumAction getItemUseAction(ItemStack stack) { | |
return EnumAction.NONE; | |
} | |
// ############################################################################################3 | |
@Override | |
public String getUnlocalizedName(ItemStack stack) { | |
// String name="suspensionderedstone"; | |
return name; | |
} | |
@SideOnly(Side.CLIENT) | |
public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) { | |
subItems.add(new ItemStack(itemIn, 1, 0)); | |
} | |
// #########################################################################3 | |
@SideOnly(Side.CLIENT) | |
public void addInformation(ItemStack suspencion, EntityPlayer playerIn, List list, boolean aBoolean) { | |
String lore = "Hold RigthClick to shake"; | |
list.add(lore); | |
} | |
// #########################################################################3 | |
@Override | |
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { | |
return !ItemStack.areItemStacksEqual(oldStack, newStack); | |
} | |
// ############################################################################################3 | |
}// fin de la classe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment