I want to make my custom shears to be able to be enchanted with the silk touch enchantment only --- Here is the code in the EnchantmentUntouching file (the silk touch class) and the part regarding making the regular shears enchantable:
What are you trying to do exactly? Enchant your shears with silk touch? Why do you need a mod for this
No, in my code it has my custom shears there, they are just a better form of standard shears but using my custom materials. I am trying to make mine enchantable with silk touch because they aren't at the moment. I looked at how the original shears were enchanted, but that is done in the actual enchantment, and I'm trying to find a way to add my shears to be able to enchant. I wrote this late at night and had kinda been waiting for a response; but right now i thought maybe to extend the ItemShears instead of just items. I'll try that now
Edit* Just checked, they already extend ItemShears
Also, I just want to be able to add specifically "silk touch". I don't want to make it enchantable with all of them and I have tried making it similar to how books get enchanted, but changing the array from "enchantmentList" to the specific enchantment, but it didn't work--unless i did something wrong, but now i just have the code stated above and would like to know if anyone has a fix for making it work.
my shears code just in case
package limpcraft.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
//Basic SHEARS class
public class limpToolShears extends ItemShears
{
public limpToolShears(int par1)
{
super(par1);
this.setMaxStackSize(1);
this.setMaxDamage(800);
this.setCreativeTab(limpCreativeTab.tabLimpCraft);
}
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving)
{
if (par3 != Block.leaves.blockID && par3 != Block.web.blockID && par3 != Block.tallGrass.blockID && par3 != Block.vine.blockID && par3 != Block.tripWire.blockID && !(Block.blocksList[par3] instanceof IShearable))
{
return super.onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLiving);
}
else
{
return true;
}
}
//Returns if the item (tool) can harvest results from the block type.
public boolean canHarvestBlock(Block par1Block)
{
return par1Block.blockID == Block.web.blockID || par1Block.blockID == Block.redstoneWire.blockID || par1Block.blockID == Block.tripWire.blockID;
}
//Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
//sword
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
{
return par2Block.blockID != Block.web.blockID && par2Block.blockID != Block.leaves.blockID ? (par2Block.blockID == Block.cloth.blockID ? 5.0F : super.getStrVsBlock(par1ItemStack, par2Block)) : 15.0F;
}
@Override
public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity)
{
if (entity.worldObj.isRemote)
{
return false;
}
if (entity instanceof IShearable)
{
IShearable target = (IShearable)entity;
if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ))
{
ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ,
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
Random rand = new Random();
for(ItemStack stack : drops)
{
EntityItem ent = entity.entityDropItem(stack, 1.0F);
ent.motionY += rand.nextFloat() * 0.05F;
ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
}
itemstack.damageItem(1, entity);
}
return true;
}
return false;
}
@Override
public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player)
{
if (player.worldObj.isRemote)
{
return false;
}
int id = player.worldObj.getBlockId(x, y, z);
if (Block.blocksList[id] instanceof IShearable)
{
IShearable target = (IShearable)Block.blocksList[id];
if (target.isShearable(itemstack, player.worldObj, x, y, z))
{
ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z,
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
Random rand = new Random();
for(ItemStack stack : drops)
{
float f = 0.7F;
double d = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack);
entityitem.delayBeforeCanPickup = 10;
player.worldObj.spawnEntityInWorld(entityitem);
}
itemstack.damageItem(1, player);
player.addStat(StatList.mineBlockStatArray[id], 1);
}
}
return false;
}
public boolean canApply(ItemStack par1ItemStack, Enchantment par1Enchantment)
{
Enchantment EnchantmentUntouching = par1Enchantment;
return par1ItemStack.getItem().itemID == limpBase.shearsLimpiumGiga.itemID ? true : par1Enchantment.canApply(par1ItemStack);
}
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon(limpBase.modid + ":" + (this.getUnlocalizedName().substring(5)));
}
}
As far as I know, you actually set the enchantability of it in your material. What is your material defined as?
No, it is not a tool, shears aren't a EnumToolMaterial---They get enchanted directly in EnchantmentUntouching class
I want to take that same line of code and put it in my shears class so I don't have to reinvent the whole enchanting system but just implement my shears into the line of code instead of the vanilla shears. The problem is it uses super.canApply(par1ItemStack) where super refers to EnchantmentUntouching, but I need to replace that and make it still implement that enchantment.
That is the code from the EnchantmentUntouching class, I want it in my shears so I tried this, but it didn't work
public boolean canApply(ItemStack par1ItemStack, Enchantment par1Enchantment)
{
Enchantment EnchantmentUntouching = par1Enchantment;
return par1ItemStack.getItem().itemID == limpBase.shearsLimpiumGiga.itemID ? true : par1Enchantment.canApply(par1ItemStack);
}
But obviously since it isn't working, i want to know how to get it to work. Thanks for completely ignoring what I had written above...
Rollback Post to RevisionRollBack
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
I know I could add my own in there, but I DONT want to edit the base classes. Is there an override that I can do to allow mine to also be enchanted?
I was trying inside of my custom shears class something along the lines of
No errors, can run game fine, but still doesn't work :/ Any ideas?
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
Enchant your shears with silk touch? Why do you need a mod for this
Developer of Advent of Ascension
Come chat with us in the official Discord server!
Please consider supporting my development on Patreon. You might even get some little goodies in return
https://www.patreon.com/Tslat
I wrote this late at night and had kinda been waiting for a response; but right now i thought maybe to extend the ItemShears instead of just items. I'll try that nowEdit* Just checked, they already extend ItemShears
Also, I just want to be able to add specifically "silk touch". I don't want to make it enchantable with all of them and I have tried making it similar to how books get enchanted, but changing the array from "enchantmentList" to the specific enchantment, but it didn't work--unless i did something wrong, but now i just have the code stated above and would like to know if anyone has a fix for making it work.
my shears code just in case
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
No, it is not a tool, shears aren't a EnumToolMaterial---They get enchanted directly in EnchantmentUntouching class
I want to take that same line of code and put it in my shears class so I don't have to reinvent the whole enchanting system but just implement my shears into the line of code instead of the vanilla shears. The problem is it uses super.canApply(par1ItemStack) where super refers to EnchantmentUntouching, but I need to replace that and make it still implement that enchantment.
public boolean canApply(ItemStack par1ItemStack)
{
return par1ItemStack.getItem().itemID == Item.shears.itemID ? true : super.canApply(par1ItemStack);
}
That is the code from the EnchantmentUntouching class, I want it in my shears so I tried this, but it didn't work
public boolean canApply(ItemStack par1ItemStack, Enchantment par1Enchantment)
{
Enchantment EnchantmentUntouching = par1Enchantment;
return par1ItemStack.getItem().itemID == limpBase.shearsLimpiumGiga.itemID ? true : par1Enchantment.canApply(par1ItemStack);
}
But obviously since it isn't working, i want to know how to get it to work. Thanks for completely ignoring what I had written above...
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.