Premier commit - Extrait du pauvre jar après perte des sources
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
package com.bernard.torch.items;
|
||||
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import com.bernard.torch.api.ITorchRechargable;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.util.List;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
|
||||
|
||||
public class TorchAmulet
|
||||
extends Item
|
||||
implements IBauble, ITorchRechargable
|
||||
{
|
||||
public static int yRelative = 0;
|
||||
|
||||
public static final int size = 4;
|
||||
public static final int ecart = 5;
|
||||
public static final int maxYRelative = 5;
|
||||
public static final int minYRelative = -5;
|
||||
public static final int[] maxTorchesFromMeta = { 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144 };
|
||||
|
||||
public static String[] names = { "torch_amulet", "coal_torch_amulet", "iron_torch_amulet", "quartz_torch_amulet", "gold_torch_amulet", "redstone_torch_amulet", "lapis_torch_amulet", "diamond_torch_amulet", "emerald_torch_amulet" };
|
||||
|
||||
|
||||
public static IIcon[] textures = new IIcon[names.length];
|
||||
|
||||
public TorchAmulet() {
|
||||
setMaxStackSize(1);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack itemstack, EntityPlayer player, List l, boolean flag)
|
||||
{
|
||||
super.addInformation(itemstack, player, l, flag);
|
||||
if ((itemstack.stackTagCompound == null) || (!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
||||
itemstack.stackTagCompound = new NBTTagCompound();
|
||||
int meta = itemstack.getMetadata();
|
||||
if (meta >= maxTorchesFromMeta.length)
|
||||
meta = 0;
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
||||
}
|
||||
l.add("Torches left :" + itemstack.stackTagCompound.getInteger("TorchesLeft"));
|
||||
}
|
||||
|
||||
|
||||
public int getMetadata(int meta)
|
||||
{
|
||||
return meta;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
int meta = stack.getMetadata();
|
||||
if ((meta < 0) || (meta >= names.length))
|
||||
meta = 0;
|
||||
return names[meta];
|
||||
}
|
||||
|
||||
public void registerIcons(IIconRegister iconregister) {
|
||||
for (int i = 0; i < names.length; i++)
|
||||
{
|
||||
textures[i] = iconregister.registerIcon("torch_mod:" + names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item i, CreativeTabs creativeTabs, List list)
|
||||
{
|
||||
for (int metadata = 0; metadata < names.length; metadata++)
|
||||
{
|
||||
list.add(new ItemStack(i, 1, metadata));
|
||||
}
|
||||
}
|
||||
|
||||
public IIcon getIconFromDamage(int meta)
|
||||
{
|
||||
if ((meta < 0) || (meta >= names.length))
|
||||
meta = 0;
|
||||
return textures[meta];
|
||||
}
|
||||
|
||||
public void onCreated(ItemStack itemstack, World w, EntityPlayer pl)
|
||||
{
|
||||
super.onCreated(itemstack, w, pl);
|
||||
if ((itemstack.stackTagCompound == null) ||
|
||||
(!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
||||
itemstack.stackTagCompound = new NBTTagCompound();
|
||||
int meta = itemstack.getMetadata();
|
||||
if (meta >= maxTorchesFromMeta.length)
|
||||
meta = 0;
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BaubleType getBaubleType(ItemStack itemstack)
|
||||
{
|
||||
return BaubleType.AMULET;
|
||||
}
|
||||
|
||||
public void onWornTick(ItemStack itemstack, EntityLivingBase player)
|
||||
{
|
||||
if ((itemstack.stackTagCompound == null) ||
|
||||
(!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
||||
itemstack.stackTagCompound = new NBTTagCompound();
|
||||
int meta = itemstack.getMetadata();
|
||||
if (meta >= maxTorchesFromMeta.length)
|
||||
meta = 0;
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
||||
}
|
||||
if (itemstack.stackTagCompound.getInteger("TorchesLeft") > 0) {
|
||||
int modX = (int)player.posX - (int)player.posX % 5;
|
||||
int modZ = (int)player.posZ - (int)player.posZ % 5;
|
||||
int y = (int)player.posY;
|
||||
for (int x = -20; x <= 20; x += 5) {
|
||||
for (int z = -20; z <= 20; z += 5) {
|
||||
if (placeTorch(player.worldObj, modX + x, y + yRelative, modZ + z)) {
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", itemstack.stackTagCompound.getInteger("TorchesLeft") - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
yRelative = yRelative == 4 ? -5 : yRelative + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean placeTorch(World w, int x, int y, int z) {
|
||||
if ((Blocks.torch.canPlaceBlockAt(w, x, y, z)) && (w.isAirBlock(x, y, z))) {
|
||||
w.setBlock(x, y, z, Blocks.torch);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onEquipped(ItemStack itemstack, EntityLivingBase player)
|
||||
{
|
||||
if ((itemstack.stackTagCompound == null) ||
|
||||
(!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
||||
itemstack.stackTagCompound = new NBTTagCompound();
|
||||
int meta = itemstack.getMetadata();
|
||||
if (meta >= maxTorchesFromMeta.length)
|
||||
meta = 0;
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {}
|
||||
|
||||
|
||||
public boolean canEquip(ItemStack itemstack, EntityLivingBase player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void recharge(ItemStack itemstack, int lux)
|
||||
{
|
||||
int meta = itemstack.getMetadata();
|
||||
if ((itemstack.stackTagCompound == null) ||
|
||||
(!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
||||
itemstack.stackTagCompound = new NBTTagCompound();
|
||||
if (meta >= maxTorchesFromMeta.length)
|
||||
meta = 0;
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
||||
}
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", Math.min(itemstack.stackTagCompound.getInteger("TorchesLeft") + lux, maxTorchesFromMeta[meta]));
|
||||
}
|
||||
|
||||
public int getLuxNedded(ItemStack itemstack)
|
||||
{
|
||||
int meta = itemstack.getMetadata();
|
||||
if ((itemstack.stackTagCompound == null) ||
|
||||
(!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
||||
itemstack.stackTagCompound = new NBTTagCompound();
|
||||
if (meta >= maxTorchesFromMeta.length)
|
||||
meta = 0;
|
||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
||||
}
|
||||
return maxTorchesFromMeta[meta] - itemstack.stackTagCompound.getInteger("TorchesLeft");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user