What i'm trying to do before I release my mod is to have my wooden bucket have a durability.
I've got it so when I right-click it subtracts one use from a max of 10, but picking up or dropping water doesn't work because it changes the held item. I've though about two ideas:
1) Creating a variable of some form to apply durability to the bucket held, but this might carry over to all buckets held which would be bad.
2) Having multiple bucket id's: a bucket with 10 uses is one item, one with 9 left is another, etc. My worry is that that would take up a large amount of ID's, something I would rather avoid.
Doe's anyone have any ideas for me?
(Code for reference purposes)
package net.minecraft.src;
import java.util.Random;
public class ItemWoodenBucketTools extends Item
{
public ItemWoodenBucketTools(int i, int j)
{
super(i);
maxStackSize = 1;
setMaxDamage(10);
isFull = j;
}
I've got it so when I right-click it subtracts one use from a max of 10, but picking up or dropping water doesn't work because it changes the held item. I've though about two ideas:
1) Creating a variable of some form to apply durability to the bucket held, but this might carry over to all buckets held which would be bad.
2) Having multiple bucket id's: a bucket with 10 uses is one item, one with 9 left is another, etc. My worry is that that would take up a large amount of ID's, something I would rather avoid.
Doe's anyone have any ideas for me?
(Code for reference purposes)
package net.minecraft.src;
import java.util.Random;
public class ItemWoodenBucketTools extends Item
{
public ItemWoodenBucketTools(int i, int j)
{
super(i);
maxStackSize = 1;
setMaxDamage(10);
isFull = j;
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
itemstack.damageItem(1, entityplayer);
float f = 1.0F;
float f1 = entityplayer.prevRotationPitch + (entityplayer.rotationPitch - entityplayer.prevRotationPitch) * f;
float f2 = entityplayer.prevRotationYaw + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f;
double d = entityplayer.prevPosX + (entityplayer.posX - entityplayer.prevPosX) * (double)f;
double d1 = (entityplayer.prevPosY + (entityplayer.posY - entityplayer.prevPosY) * (double)f + 1.6200000000000001D) - (double)entityplayer.yOffset;
double d2 = entityplayer.prevPosZ + (entityplayer.posZ - entityplayer.prevPosZ) * (double)f;
Vec3D vec3d = Vec3D.createVector(d, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F);
float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F);
float f5 = -MathHelper.cos(-f1 * 0.01745329F);
float f6 = MathHelper.sin(-f1 * 0.01745329F);
float f7 = f4 * f5;
float f8 = f6;
float f9 = f3 * f5;
double d3 = 5D;
Vec3D vec3d1 = vec3d.addVector((double)f7 * d3, (double)f8 * d3, (double)f9 * d3);
MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do(vec3d, vec3d1, isFull == 0);
if(movingobjectposition == null)
{
return itemstack;
}
if(movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
{
int i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
if(!world.canMineBlock(entityplayer, i, j, k))
{
return itemstack;
}
if(isFull == 0)
{
if(!entityplayer.canPlayerEdit(i, j, k))
{
return itemstack;
}
if(world.getBlockMaterial(i, j, k) == Material.water && world.getBlockMetadata(i, j, k) == 0)
{
world.setBlockWithNotify(i, j, k, 0);
return new ItemStack(mod_simpletools.simplewoodenbucketwater);
}
} else
{
if(isFull < 0)
{
return new ItemStack(mod_simpletools.simplewoodenbucket);
}
if(movingobjectposition.sideHit == 0)
{
j--;
}
if(movingobjectposition.sideHit == 1)
{
j++;
}
if(movingobjectposition.sideHit == 2)
{
k--;
}
if(movingobjectposition.sideHit == 3)
{
k++;
}
if(movingobjectposition.sideHit == 4)
{
i--;
}
if(movingobjectposition.sideHit == 5)
{
i++;
}
if(!entityplayer.canPlayerEdit(i, j, k))
{
return itemstack;
}
if(world.isAirBlock(i, j, k) || !world.getBlockMaterial(i, j, k).isSolid())
{
if(world.worldProvider.isHellWorld && isFull == Block.waterMoving.blockID)
{
world.playSoundEffect(d + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
for(int l = 0; l < 8; l++)
{
world.spawnParticle("largesmoke", (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D);
}
} else
{
world.setBlockAndMetadataWithNotify(i, j, k, isFull, 0);
}
if(entityplayer.capabilities.depleteBuckets)
{
return itemstack;
} else
{
return new ItemStack(mod_simpletools.simplewoodenbucket);
}
}
}
}
if(isFull == 0 && (movingobjectposition.entityHit instanceof EntityCow))
{
return null;
}
return itemstack;
}
private int isFull;
}
-Lanvarok