Premier commit - Extrait du pauvre jar après perte des sources

This commit is contained in:
Mysaa 2021-05-28 22:57:57 +02:00
commit 29ef10e9f9
54 changed files with 1355 additions and 0 deletions

View File

@ -0,0 +1,19 @@
torch_recharger.name=Torch recharger
coal_torch_recharger.name=Coal torch recharger
iron_torch_recharger.name=Iron torch recharger
quartz_torch_recharger.name=Quartz torch recharger
gold_torch_recharger.name=Gold torch recharger
redstone_torch_recharger.name=Redstone torch recharger
lapis_torch_recharger.name=Lapis torch recharger
diamond_torch_recharger.name=Diamond torch recharger
emerald_torch_recharger.name=Emerald torch recharger
torch_amulet.name=Torch amulet
coal_torch_amulet.name=Coal torch amulet
iron_torch_amulet.name=Iron torch amulet
quartz_torch_amulet.name=Quartz torch amulet
gold_torch_amulet.name=Gold torch amulet
redstone_torch_amulet.name=Redstone torch amulet
lapis_torch_amulet.name=Lapis torch amulet
diamond_torch_amulet.name=Diamond torch amulet
emerald_torch_amulet.name=Emerald torch amulet

View File

@ -0,0 +1,19 @@
torch_recharger.name=Rechargeur de torches
coal_torch_recharger.name=Rechargeur de torches en charbon
iron_torch_recharger.name=Rechargeur de torches en fer
quartz_torch_recharger.name=Rechargeur de torches en quartz
gold_torch_recharger.name=Rechargeur de torches en or
redstone_torch_recharger.name=Rechargeur de torches en redstone
lapis_torch_recharger.name=Rechargeur de torches en lapis
diamond_torch_recharger.name=Rechargeur de torches en diamant
emerald_torch_recharger.name=Rechargeur de torches en émeraude
torch_amulet.name=Amulette des torches
coal_torch_amulet.name=Amulette des torches en charbon
iron_torch_amulet.name=Amulette des torches en fer
quartz_torch_amulet.name=Amulette des torches en quartz
gold_torch_amulet.name=Amulette des torches en or
redstone_torch_amulet.name=Amulette des torches en redstone
lapis_torch_amulet.name=Amulette des torches en lapis
diamond_torch_amulet.name=Amulette des torches en diamant
emerald_torch_amulet.name=Amulette des torches en émeraude

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 795 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 794 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 920 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 956 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 841 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 897 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

View File

@ -0,0 +1,113 @@
package com.bernard.torch;
import com.bernard.torch.gui.TorchGuiHandler;
import com.bernard.torch.init.CoalStickAndTorchesRegister;
import com.bernard.torch.init.CommonProxy;
import com.bernard.torch.init.TorchBlocks;
import com.bernard.torch.init.TorchItems;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import java.io.PrintStream;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@Mod(modid="torch_mod", name="Torch mod", version="beta")
public class TorchMod
{
public static final String MODID = "torch_mod";
@Mod.Instance("torch_mod")
public static TorchMod MOD_INSTANCE;
@SidedProxy(clientSide="com.bernard.torch.init.ClientProxy", serverSide="com.bernard.torch.init.CommonProxy")
public static CommonProxy proxy;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
CoalStickAndTorchesRegister c = new CoalStickAndTorchesRegister();
CoalStickAndTorchesRegister.registerCoal(Items.coal, 4);
CoalStickAndTorchesRegister.registerCoal(Blocks.coal_block, 36);
CoalStickAndTorchesRegister.registerCoal(Blocks.coal_ore, 8);
CoalStickAndTorchesRegister.registerStick(Items.stick, 4);
CoalStickAndTorchesRegister.registerStick(Blocks.planks, 8);
CoalStickAndTorchesRegister.registerStick(Blocks.log, 32);
CoalStickAndTorchesRegister.registerStick(Blocks.log2, 32);
CoalStickAndTorchesRegister.registerStick(Blocks.deadbush, 3);
CoalStickAndTorchesRegister.registerTorch(Blocks.torch, 1);
CoalStickAndTorchesRegister.registerTorch(Blocks.glowstone, 4);
TorchItems.init();
TorchBlocks.init();
Item i = Items.coal;
System.out.println(CoalStickAndTorchesRegister.isStick(i));
System.out.println(CoalStickAndTorchesRegister.isCoal(i));
System.out.println(CoalStickAndTorchesRegister.isTorch(i));
}
@Mod.EventHandler
public void init(FMLInitializationEvent event)
{
NetworkRegistry.INSTANCE.registerGuiHandler(MOD_INSTANCE, new TorchGuiHandler());
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 0), new Object[] { " MM", "M M", "TM ", Character.valueOf('M'), Items.string,
Character.valueOf('T'), Blocks.torch });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 1), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), Items.coal,
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 0) });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 2), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), Items.iron_ingot,
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 1) });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 3), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), Items.quartz,
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 2) });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 4), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), Items.gold_ingot,
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 3) });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 5), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), Items.redstone,
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 4) });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 6), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), new ItemStack(Items.dye, 1, 4),
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 5) });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 7), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), Items.diamond,
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 6) });
GameRegistry.addShapedRecipe(new ItemStack(TorchItems.torchAmulet, 1, 8), new Object[] { " MM", "MIM", "TM ", Character.valueOf('M'), Items.emerald,
Character.valueOf('T'), Blocks.torch, Character.valueOf('I'), new ItemStack(TorchItems.torchAmulet, 1, 7) });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 0), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), Blocks.furnace, Character.valueOf('M'), Blocks.cobblestone });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 1), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 0), Character.valueOf('M'), Blocks.coal_block });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 2), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 1), Character.valueOf('M'), Blocks.iron_block });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 3), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 2), Character.valueOf('M'), Blocks.quartz_block });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 4), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 3), Character.valueOf('M'), Blocks.gold_block });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 5), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 4), Character.valueOf('M'), Blocks.redstone_block });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 6), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 5), Character.valueOf('M'), Blocks.lapis_block });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 7), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 6), Character.valueOf('M'), Blocks.diamond_block });
GameRegistry.addShapedRecipe(new ItemStack(TorchBlocks.torchRecharger, 1, 8), new Object[] { "T T", "CFC", "CMC", Character.valueOf('T'), Blocks.torch,
Character.valueOf('C'), Blocks.cobblestone, Character.valueOf('F'), new ItemStack(TorchBlocks.torchRecharger, 1, 7), Character.valueOf('M'), Blocks.emerald_block });
}
}

View File

@ -0,0 +1,12 @@
package com.bernard.torch.api;
import net.minecraft.item.ItemStack;
public abstract interface ITorchRechargable
{
public abstract void recharge(ItemStack paramItemStack, int paramInt);
public abstract int getLuxNedded(ItemStack paramItemStack);
}

View File

@ -0,0 +1,146 @@
package com.bernard.torch.blocks;
import com.bernard.torch.TorchMod;
import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class TorchRechargerBlock
extends Block
{
private IIcon iconTop;
private IIcon iconBottom;
private IIcon iconFaces;
public static String[] names = { "torch_recharger", "coal_torch_recharger", "iron_torch_recharger", "quartz_torch_recharger", "gold_torch_recharger", "redstone_torch_recharger", "lapis_torch_recharger", "diamond_torch_recharger", "emerald_torch_recharger" };
public IIcon[][] textures = new IIcon[names.length][3];
public TorchRechargerBlock() {
super(Material.iron);
setHarvestLevel("pickaxe", 2);
setHardness(10.0F);
setCreativeTab(CreativeTabs.tabDecorations);
setLightLevel(10.0F);
setResistance(1000.0F);
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote) {
TorchRechargerTileEntity te = (TorchRechargerTileEntity)world.getTileEntity(x, y, z);
player.openGui(TorchMod.MOD_INSTANCE, 0, world, x, y, z);
}
return true;
}
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
{
TileEntity te = world.getTileEntity(x, y, z);
if ((te instanceof TorchRechargerTileEntity)) {
TorchRechargerTileEntity torchRecharger = (TorchRechargerTileEntity)te;
int torches = Math.floorDiv(torchRecharger.getTorchValue(), 4);
int sticks = Math.floorDiv(torchRecharger.getStickValue(), 4);
int coals = Math.floorDiv(torchRecharger.getCoalValue(), 4);
double dropX = x + world.rand.nextFloat() * 0.8F + 0.1F;double dropY = y + world.rand.nextFloat() * 0.8F + 0.1F;
double dropZ = z + world.rand.nextFloat() * 0.8F + 0.1F;
while ((torches > 0) || (sticks > 0) || (coals > 0)) {
if (torches > 0)
{
EntityItem item = new EntityItem(world, dropX, dropY, dropZ, new ItemStack(Blocks.torch, Math.min(torches, 64), 0));
item.motionX = ((float)world.rand.nextGaussian() * 0.05F);
item.motionY = ((float)world.rand.nextGaussian() * 0.05F + 0.2F);
item.motionZ = ((float)world.rand.nextGaussian() * 0.05F);
torches -= Math.min(torches, 64);
world.spawnEntityInWorld(item);
}
if (sticks > 0)
{
EntityItem item = new EntityItem(world, dropX, dropY, dropZ, new ItemStack(Items.stick, Math.min(sticks, 64), 0));
item.motionX = ((float)world.rand.nextGaussian() * 0.05F);
item.motionY = ((float)world.rand.nextGaussian() * 0.05F + 0.2F);
item.motionZ = ((float)world.rand.nextGaussian() * 0.05F);
sticks -= Math.min(sticks, 64);
world.spawnEntityInWorld(item);
}
if (coals > 0)
{
EntityItem item = new EntityItem(world, dropX, dropY, dropZ, new ItemStack(Items.coal, Math.min(coals, 64), 0));
item.motionX = ((float)world.rand.nextGaussian() * 0.05F);
item.motionY = ((float)world.rand.nextGaussian() * 0.05F + 0.2F);
item.motionZ = ((float)world.rand.nextGaussian() * 0.05F);
coals -= Math.min(coals, 64);
world.spawnEntityInWorld(item);
}
}
world.updateNeighborsAboutBlockChange(x, y, z, block);
world.removeTileEntity(x, y, z);
}
super.breakBlock(world, x, y, z, block, meta);
}
public boolean hasTileEntity(int metadata)
{
return true;
}
public TileEntity createTileEntity(World world, int metadata)
{
return new TorchRechargerTileEntity();
}
public void getSubBlocks(Item item, CreativeTabs tab, List l)
{
for (int i = 0; i < names.length; i++) {
l.add(new ItemStack(item, 1, i));
}
}
public void registerIcons(IIconRegister r)
{
for (int i = 0; i < this.textures.length; i++) {
this.textures[i][0] = r.registerIcon("torch_mod:" + names[i] + "_bottom");
this.textures[i][1] = r.registerIcon("torch_mod:" + names[i] + "_top");
this.textures[i][2] = r.registerIcon("torch_mod:" + names[i] + "_side");
}
}
public int damageDropped(int meta)
{
return meta;
}
public IIcon getIcon(int side, int meta)
{
if ((meta >= this.textures.length) || (meta < 0))
return this.textures[0][0];
switch (side) {
case 0:
return this.textures[meta][0];
case 1:
return this.textures[meta][1];
}
return this.textures[meta][2];
}
}

View File

@ -0,0 +1,56 @@
/* */ package com.bernard.torch.blocks.itemblocs;
/* */
/* */ import com.bernard.torch.blocks.TorchRechargerBlock;
/* */ import cpw.mods.fml.relauncher.Side;
/* */ import cpw.mods.fml.relauncher.SideOnly;
/* */ import java.util.List;
/* */ import net.minecraft.block.Block;
/* */ import net.minecraft.entity.player.EntityPlayer;
/* */ import net.minecraft.item.ItemBlock;
/* */ import net.minecraft.item.ItemStack;
/* */ import net.minecraft.util.IIcon;
/* */
/* */
/* */
/* */ public class TorchRechargerItemBlock
/* */ extends ItemBlock
/* */ {
/* */ public TorchRechargerItemBlock(Block block)
/* */ {
/* 20 */ super(block);
/* 21 */ setMaxDurability(0);
/* 22 */ setHasSubtypes(true);
/* */ }
/* */
/* */ public void addInformation(ItemStack s, EntityPlayer p, List l, boolean flag)
/* */ {
/* 27 */ super.addInformation(s, p, l, flag);
/* 28 */ if (s.getMetadata() >= TorchRechargerBlock.names.length)
/* 29 */ s.setMetadata(0);
/* 30 */ l.add("Stockage de torches :" + com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity.maxTorchValueFromMeta[s.getMetadata()]);
/* 31 */ l.add("Stockage de charbon :" + com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity.maxCoalValueFromMeta[s.getMetadata()]);
/* 32 */ l.add("Stockage de batons :" + com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity.maxStickValueFromMeta[s.getMetadata()]);
/* */ }
/* */
/* */
/* */ public int getMetadata(int meta)
/* */ {
/* 38 */ return meta;
/* */ }
/* */
/* */ @SideOnly(Side.CLIENT)
/* */ public IIcon getIconFromDamage(int meta)
/* */ {
/* 44 */ return this.blockInstance.getIcon(2, meta);
/* */ }
/* */
/* */ public String getUnlocalizedName(ItemStack stack)
/* */ {
/* 49 */ int meta = stack.getMetadata();
/* 50 */ if ((meta < 0) || (meta >= TorchRechargerBlock.names.length))
/* 51 */ meta = 0;
/* 52 */ return TorchRechargerBlock.names[meta];
/* */ }
/* */ }

View File

@ -0,0 +1,366 @@
package com.bernard.torch.blocks.tileentities;
import com.bernard.torch.api.ITorchRechargable;
import com.bernard.torch.init.CoalStickAndTorchesRegister;
import java.io.PrintStream;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TorchRechargerTileEntity extends TileEntity implements IInventory
{
int torchValue = 0; int stickValue = 0; int coalValue = 0;
public static final int[] maxCoalValueFromMeta = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
public static final int[] maxStickValueFromMeta = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
public static final int[] maxTorchValueFromMeta = { 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 };
ItemStack stackStored;
ItemStack stackCharging;
public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound);
this.torchValue = compound.getInteger("TorchValue");
this.stickValue = compound.getInteger("StickValue");
this.coalValue = compound.getInteger("CoalValue");
if (compound.hasKey("StoredItem", 10)) {
NBTTagCompound itemCompound = compound.getCompoundTag("StoredItem");
this.stackStored = ItemStack.loadItemStackFromNBT(itemCompound);
}
if (compound.hasKey("ChargingItem", 10)) {
NBTTagCompound itemCompound = compound.getCompoundTag("ChargingItem");
this.stackCharging = ItemStack.loadItemStackFromNBT(itemCompound);
}
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setInteger("TorchValue", this.torchValue);
compound.setInteger("StickValue", this.stickValue);
compound.setInteger("CoalValue", this.coalValue);
if (this.stackStored != null) {
NBTTagCompound itemCompound = new NBTTagCompound();
this.stackStored.writeToNBT(itemCompound);
compound.setTag("StoredItem", itemCompound);
}
if (this.stackCharging != null) {
NBTTagCompound itemCompound = new NBTTagCompound();
this.stackCharging.writeToNBT(itemCompound);
compound.setTag("ChargingItem", itemCompound);
}
}
public Packet getDescriptionPacket()
{
NBTTagCompound compound = new NBTTagCompound();
writeToNBT(compound);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, compound);
}
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
readFromNBT(pkt.getNbtCompound());
}
public boolean canUpdate()
{
return true;
}
public void updateEntity()
{
if (this.blockMetadata == -1)
this.blockMetadata = 0;
if (this.stackStored != null)
updateStackStored();
updateTransfers();
updateCharging();
markDirty();
}
public void updateStackStored() {
try {
if (isItemValidForSlot(0, this.stackStored)) {
if ((this.stickValue < maxStickValueFromMeta[this.blockMetadata]) &&
(CoalStickAndTorchesRegister.isStick(this.stackStored.getItem()))) {
int singleValue = CoalStickAndTorchesRegister.getStickValue(this.stackStored.getItem());
if (singleValue * this.stackStored.stackSize + this.stickValue <= maxStickValueFromMeta[this.blockMetadata]) {
this.stickValue += singleValue * this.stackStored.stackSize;
this.stackStored = null;
} else {
for (int i = 0;
this.stickValue + singleValue <= maxStickValueFromMeta[this.blockMetadata]; i++)
this.stickValue += singleValue;
this.stackStored.stackSize -= i;
if (this.stackStored.stackSize <= 0) {
this.stackStored = null;
}
}
}
if ((this.coalValue < maxCoalValueFromMeta[this.blockMetadata]) &&
(CoalStickAndTorchesRegister.isCoal(this.stackStored.getItem()))) {
int singleValue = CoalStickAndTorchesRegister.getCoalValue(this.stackStored.getItem());
if (singleValue * this.stackStored.stackSize + this.coalValue <= maxCoalValueFromMeta[this.blockMetadata]) {
this.coalValue += singleValue * this.stackStored.stackSize;
this.stackStored = null;
} else {
for (int i = 0;
this.coalValue + singleValue <= maxCoalValueFromMeta[this.blockMetadata]; i++)
this.coalValue += singleValue;
this.stackStored.stackSize -= i;
if (this.stackStored.stackSize <= 0)
this.stackStored = null;
}
}
if ((this.torchValue < maxTorchValueFromMeta[this.blockMetadata]) &&
(CoalStickAndTorchesRegister.isTorch(this.stackStored.getItem()))) {
int singleValue = CoalStickAndTorchesRegister.getTorchValue(this.stackStored.getItem());
if (singleValue * this.stackStored.stackSize + this.torchValue <= maxTorchValueFromMeta[this.blockMetadata]) {
this.torchValue += singleValue * this.stackStored.stackSize;
this.stackStored = null;
} else {
for (int i = 0;
this.torchValue + singleValue <= maxTorchValueFromMeta[this.blockMetadata]; i++)
this.torchValue += singleValue;
this.stackStored.stackSize -= i;
if (this.stackStored.stackSize <= 0)
this.stackStored = null;
}
}
}
} catch (NullPointerException e) {
System.err.println("NullPointer");
}
}
public void updateTransfers() {
if (this.torchValue < maxTorchValueFromMeta[this.blockMetadata]) {
int torchNedded = maxTorchValueFromMeta[this.blockMetadata] - this.torchValue;
if (torchNedded <= Math.min(this.coalValue, this.stickValue)) {
this.torchValue = maxTorchValueFromMeta[this.blockMetadata];
this.coalValue -= torchNedded;
this.stickValue -= torchNedded;
} else {
int torchRecharged = Math.min(this.coalValue, this.stickValue);
this.coalValue -= torchRecharged;
this.stickValue -= torchRecharged;
this.torchValue += torchRecharged;
}
}
}
public void updateCharging() {
if (isItemValidForSlot(1, this.stackCharging)) {
ITorchRechargable torchRechargable = (ITorchRechargable)this.stackCharging.getItem();
int nedded = torchRechargable.getLuxNedded(this.stackCharging);
if (this.torchValue <= nedded) {
torchRechargable.recharge(this.stackCharging, this.torchValue);
this.torchValue = 0;
} else {
this.torchValue -= nedded;
torchRechargable.recharge(this.stackCharging, nedded);
}
}
}
public int getSizeInventory()
{
return 2;
}
public ItemStack getStackInSlot(int slot)
{
switch (slot) {
case 0:
return this.stackStored;
case 1:
return this.stackCharging;
}
return null;
}
public ItemStack decrStackSize(int slot, int amount)
{
switch (slot) {
case 0:
if (this.stackStored == null)
return null;
ItemStack stack; if (amount >= this.stackStored.stackSize) {
ItemStack stack = this.stackStored;
this.stackStored = null;
markDirty();
} else {
stack = this.stackStored.splitStack(amount);
if (this.stackStored.stackSize <= 0)
this.stackStored = null;
markDirty();
}
return stack;
case 1:
if (this.stackCharging == null)
return null;
ItemStack stack; if (amount >= this.stackCharging.stackSize) {
ItemStack stack = this.stackCharging;
this.stackCharging = null;
markDirty();
} else {
stack = this.stackCharging.splitStack(amount);
if (this.stackCharging.stackSize <= 0)
this.stackCharging = null;
markDirty();
}
return stack;
}
return null;
}
public ItemStack getStackInSlotOnClosing(int slot)
{
switch (slot) {
case 0:
ItemStack stack = this.stackStored;
this.stackStored = null;
return stack;
case 1:
ItemStack stack = this.stackCharging;
this.stackCharging = null;
return stack;
}
return null;
}
public void setInventorySlotContents(int slot, ItemStack stack)
{
switch (slot) {
case 0:
this.stackStored = stack;
return;
case 1:
this.stackCharging = stack;
return;
}
}
public String getInventoryName()
{
return "tile.torch_recharger";
}
public boolean isCustomInventoryName()
{
return false;
}
public int getInventoryStackLimit()
{
return 64;
}
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this;
}
public void openChest() {}
public void closeChest() {}
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
if (stack == null)
return false;
switch (slot) {
case 0:
return CoalStickAndTorchesRegister.isRegistered(stack.getItem());
case 1:
return stack.getItem() instanceof ITorchRechargable;
}
return false;
}
public int getTorchValue()
{
return this.torchValue;
}
public int getStickValue() {
return this.stickValue;
}
public int getCoalValue() {
return this.coalValue;
}
public int getMaxTorchValue() {
if (this.blockMetadata == -1) {
this.blockMetadata = 0;
}
return maxTorchValueFromMeta[this.blockMetadata];
}
public int getMaxStickValue() {
if (this.blockMetadata == -1) {
this.blockMetadata = 0;
}
return maxStickValueFromMeta[this.blockMetadata];
}
public int getMaxCoalValue() {
if (this.blockMetadata == -1) {
this.blockMetadata = 0;
}
return maxCoalValueFromMeta[this.blockMetadata];
}
public ItemStack getStackStored() {
return this.stackStored;
}
public ItemStack getStackCharging() {
return this.stackCharging;
}
public String toString()
{
return this.torchValue + ";" + this.stickValue + ";" + this.coalValue + "p=" + this.xCoord + ";" + this.yCoord + ";" + this.zCoord;
}
}

View File

@ -0,0 +1,39 @@
/* */ package com.bernard.torch.gui;
/* */
/* */ import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
/* */ import cpw.mods.fml.common.network.IGuiHandler;
/* */ import java.io.PrintStream;
/* */ import net.minecraft.entity.player.EntityPlayer;
/* */ import net.minecraft.tileentity.TileEntity;
/* */ import net.minecraft.world.World;
/* */
/* */ public class TorchGuiHandler implements IGuiHandler
/* */ {
/* */ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
/* */ {
/* 14 */ if (ID == 0) {
/* 15 */ TileEntity te = world.getTileEntity(x, y, z);
/* 16 */ if ((te instanceof TorchRechargerTileEntity)) {
/* 17 */ System.out.println("S:" + te.toString());
/* 18 */ return new TorchRechargerContainer((TorchRechargerTileEntity)te, player.inventory);
/* */ }
/* */ }
/* */
/* 22 */ return null;
/* */ }
/* */
/* */ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
/* */ {
/* 27 */ if (ID == 0) {
/* 28 */ TileEntity te = world.getTileEntity(x, y, z);
/* 29 */ if ((te instanceof TorchRechargerTileEntity)) {
/* 30 */ System.out.println("C:" + te.toString());
/* 31 */ return new TorchRechargerGuiContainer((TorchRechargerTileEntity)te, player.inventory);
/* */ }
/* */ }
/* */
/* 35 */ return null;
/* */ }
/* */ }

View File

@ -0,0 +1,102 @@
/* */ package com.bernard.torch.gui;
/* */
/* */ import com.bernard.torch.api.ITorchRechargable;
/* */ import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
/* */ import com.bernard.torch.init.CoalStickAndTorchesRegister;
/* */ import java.util.List;
/* */ import net.minecraft.entity.player.EntityPlayer;
/* */ import net.minecraft.entity.player.InventoryPlayer;
/* */ import net.minecraft.inventory.Container;
/* */ import net.minecraft.inventory.IInventory;
/* */ import net.minecraft.inventory.Slot;
/* */ import net.minecraft.item.ItemStack;
/* */
/* */ public class TorchRechargerContainer extends Container
/* */ {
/* */ TorchRechargerTileEntity tile;
/* */
/* */ public TorchRechargerContainer(TorchRechargerTileEntity te, InventoryPlayer inventory)
/* */ {
/* 20 */ this.tile = te;
/* 21 */ this.tile.openChest();
/* 22 */ addSlotToContainer(new InputSlot(this.tile, 0, 14, 33));
/* 23 */ addSlotToContainer(new OutputSlot(this.tile, 1, 138, 33));
/* 24 */ bindPlayerInventory(inventory);
/* */ }
/* */
/* */ public void bindPlayerInventory(InventoryPlayer inventory)
/* */ {
/* 29 */ for (int i = 0; i < 3; i++) {
/* 30 */ for (int j = 0; j < 9; j++) {
/* 31 */ addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
/* */ }
/* */ }
/* 34 */ for (i = 0; i < 9; i++) {
/* 35 */ addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
/* */ }
/* */ }
/* */
/* */ public boolean canInteractWith(EntityPlayer player)
/* */ {
/* 41 */ return this.tile.isUseableByPlayer(player);
/* */ }
/* */
/* */ public void onContainerClosed(EntityPlayer player)
/* */ {
/* 46 */ super.onContainerClosed(player);
/* 47 */ this.tile.closeChest();
/* */ }
/* */
/* */ public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)
/* */ {
/* 52 */ ItemStack stack = null;
/* 53 */ Slot slot = (Slot)this.inventorySlots.get(slotIndex);
/* 54 */ if ((slot != null) && (slot.getHasStack())) {
/* 55 */ ItemStack stackBis = slot.getStack();
/* 56 */ stack = stackBis.copy();
/* 57 */ if (slotIndex < this.tile.getSizeInventory()) {
/* 58 */ if (!mergeItemStack(stackBis, this.tile.getSizeInventory(), this.inventorySlots.size(), true)) {
/* 59 */ return null;
/* */ }
/* 61 */ } else if (!mergeItemStack(stackBis, 0, this.tile.getSizeInventory(), false)) {
/* 62 */ return null;
/* */ }
/* 64 */ if (stackBis.stackSize == 0) {
/* 65 */ slot.putStack((ItemStack)null);
/* */ } else {
/* 67 */ slot.onSlotChanged();
/* */ }
/* */ }
/* 70 */ return stack;
/* */ }
/* */
/* */ public class InputSlot extends Slot
/* */ {
/* */ public InputSlot(IInventory inventory, int i, int j, int k) {
/* 76 */ super(i, j, k);
/* */ }
/* */
/* */ public boolean isItemValid(ItemStack stack)
/* */ {
/* 81 */ if (stack == null)
/* 82 */ return false;
/* 83 */ return CoalStickAndTorchesRegister.isRegistered(stack.getItem());
/* */ }
/* */ }
/* */
/* */ public class OutputSlot extends Slot
/* */ {
/* */ public OutputSlot(IInventory inventory, int i, int j, int k) {
/* 90 */ super(i, j, k);
/* */ }
/* */
/* */ public boolean isItemValid(ItemStack stack)
/* */ {
/* 95 */ if (stack == null)
/* 96 */ return false;
/* 97 */ return stack.getItem() instanceof ITorchRechargable;
/* */ }
/* */ }
/* */ }

View File

@ -0,0 +1,121 @@
package com.bernard.torch.gui;
import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class TorchRechargerGuiContainer
extends GuiContainer
{
private static final ResourceLocation background = new ResourceLocation("torch_mod", "textures/guis/torch_recharger.png");
public TorchRechargerTileEntity tile;
public IInventory playerInventory;
private float mouseX = 0.0F; private float mouseY = 0.0F;
public TorchRechargerGuiContainer(TorchRechargerTileEntity te, InventoryPlayer inventory) {
super(new TorchRechargerContainer(te, inventory));
this.tile = te;
this.playerInventory = inventory;
this.allowUserInput = false;
this.xSize = 176;
this.ySize = 166;
}
public boolean doesGuiPauseGame()
{
return false;
}
public void drawScreen(int x, int y, float par3)
{
this.mouseX = x;
this.mouseY = y;
super.drawScreen(x, y, par3);
}
protected void drawGuiContainerForegroundLayer(int x, int y)
{
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
if ((this.mouseX >= k + 101) && (this.mouseX < k + 116) && (this.mouseY >= l + 8) && (this.mouseY < l + 81)) {
List<String> li = new ArrayList();
li.add("Torches stock�s :");
li.add(Integer.toString(this.tile.getTorchValue(), 10));
drawHoveringText(li, (int)this.mouseX - k, (int)this.mouseY - l, this.fontRendererObj);
} else if ((this.mouseX >= k + 45) && (this.mouseX < k + 70) && (this.mouseY >= l + 9) && (this.mouseY < l + 38)) {
List<String> li = new ArrayList();
li.add("Charbon stock� :");
li.add(Integer.toString(this.tile.getCoalValue(), 10));
drawHoveringText(li, (int)this.mouseX - k, (int)this.mouseY - l, this.fontRendererObj);
} else if ((this.mouseX >= k + 56) && (this.mouseX < k + 60) && (this.mouseY >= l + 40) && (this.mouseY < l + 67)) {
List<String> li = new ArrayList();
li.add("Batons stock�s :");
li.add(Integer.toString(this.tile.getStickValue(), 10));
drawHoveringText(li, (int)this.mouseX - k, (int)this.mouseY - l, this.fontRendererObj);
}
}
protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int meta = this.tile.blockMetadata;
if (meta < 0)
meta = 0;
int torchPixels = Math.floorDiv(this.tile.getTorchValue() * 80, this.tile.getMaxTorchValue());
drawTexturedModalRect(k + 94, l + 1 + 80 - torchPixels, this.xSize, 80 - torchPixels, 29, torchPixels);
int coalPixels = Math.floorDiv(this.tile.getCoalValue() * 32, this.tile.getMaxCoalValue());
drawTexturedModalRect(k + 42, l + 7 + 32 - coalPixels, this.xSize, 112 - coalPixels, 30, coalPixels);
int stickPixels = Math.floorDiv(this.tile.getStickValue() * 40, this.tile.getMaxStickValue());
drawTexturedModalRect(k + 53, l + 39 + 40 - stickPixels, this.xSize, 152 - stickPixels, 9, stickPixels);
}
}

View File

@ -0,0 +1,9 @@
package com.bernard.torch.init;
public class ClientProxy
extends CommonProxy
{
public void registerRenders() {}
}

View File

@ -0,0 +1,80 @@
/* */ package com.bernard.torch.init;
/* */
/* */ import java.util.HashMap;
/* */ import java.util.Map;
/* */ import net.minecraft.block.Block;
/* */ import net.minecraft.item.Item;
/* */ import net.minecraft.item.ItemStack;
/* */
/* */
/* */
/* */ public class CoalStickAndTorchesRegister
/* */ {
/* 13 */ private static Map<Item, Integer[]> registered = new HashMap();
/* */ private static final int coalValue = 0;
/* */ private static final int stickValue = 1;
/* */ private static final int torchValue = 2;
/* */
/* */ public static void registerCoal(Item i, int value) {
/* 19 */ registered.put(i, new Integer[] { Integer.valueOf(0), Integer.valueOf(Math.abs(value)) });
/* */ }
/* */
/* 22 */ public static void registerCoal(Block b, int value) { registered.put(Item.getItemFromBlock(b), new Integer[] { Integer.valueOf(0), Integer.valueOf(Math.abs(value)) }); }
/* */
/* */ public static void registerCoal(ItemStack s, int value) {
/* 25 */ registered.put(s.getItem(), new Integer[] { Integer.valueOf(0), Integer.valueOf(Math.abs(value)) });
/* */ }
/* */
/* 28 */ public static void registerStick(Item i, int value) { registered.put(i, new Integer[] { Integer.valueOf(1), Integer.valueOf(Math.abs(value)) }); }
/* */
/* */ public static void registerStick(Block b, int value) {
/* 31 */ registered.put(Item.getItemFromBlock(b), new Integer[] { Integer.valueOf(1), Integer.valueOf(Math.abs(value)) });
/* */ }
/* */
/* 34 */ public static void registerStick(ItemStack s, int value) { registered.put(s.getItem(), new Integer[] { Integer.valueOf(1), Integer.valueOf(Math.abs(value)) }); }
/* */
/* */ public static void registerTorch(Item i, int value) {
/* 37 */ registered.put(i, new Integer[] { Integer.valueOf(2), Integer.valueOf(Math.abs(value)) });
/* */ }
/* */
/* 40 */ public static void registerTorch(Block b, int value) { registered.put(Item.getItemFromBlock(b), new Integer[] { Integer.valueOf(2), Integer.valueOf(Math.abs(value)) }); }
/* */
/* */
/* 43 */ public static void registerTorch(ItemStack s, int value) { registered.put(s.getItem(), new Integer[] { Integer.valueOf(2), Integer.valueOf(Math.abs(value)) }); }
/* */
/* */ public static boolean isCoal(Item i) {
/* 46 */ if (!registered.containsKey(i))
/* 47 */ return false;
/* 48 */ return ((Integer[])registered.get(i))[0].intValue() == 0;
/* */ }
/* */
/* 51 */ public static boolean isRegistered(Item i) { return registered.containsKey(i); }
/* */
/* */ public static boolean isStick(Item i) {
/* 54 */ if (!registered.containsKey(i))
/* 55 */ return false;
/* 56 */ return ((Integer[])registered.get(i))[0].intValue() == 1;
/* */ }
/* */
/* 59 */ public static boolean isTorch(Item i) { if (!registered.containsKey(i))
/* 60 */ return false;
/* 61 */ return ((Integer[])registered.get(i))[0].intValue() == 2;
/* */ }
/* */
/* 64 */ public static int getCoalValue(Item i) { if (!isCoal(i))
/* 65 */ return 0;
/* 66 */ return ((Integer[])registered.get(i))[1].intValue();
/* */ }
/* */
/* 69 */ public static int getStickValue(Item i) { if (!isStick(i))
/* 70 */ return 0;
/* 71 */ return ((Integer[])registered.get(i))[1].intValue();
/* */ }
/* */
/* 74 */ public static int getTorchValue(Item i) { if (!isTorch(i))
/* 75 */ return 0;
/* 76 */ return ((Integer[])registered.get(i))[1].intValue();
/* */ }
/* */ }

View File

@ -0,0 +1,8 @@
package com.bernard.torch.init;
public class CommonProxy
{
public void registerRenders() {}
}

View File

@ -0,0 +1,22 @@
/* */ package com.bernard.torch.init;
/* */
/* */ import com.bernard.torch.blocks.TorchRechargerBlock;
/* */ import com.bernard.torch.blocks.itemblocs.TorchRechargerItemBlock;
/* */ import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
/* */ import cpw.mods.fml.common.registry.GameRegistry;
/* */ import net.minecraft.block.Block;
/* */
/* */
/* */ public class TorchBlocks
/* */ {
/* */ public static Block torchRecharger;
/* */
/* */ public static void init()
/* */ {
/* 16 */ torchRecharger = new TorchRechargerBlock().setUnlocalizedName("torch_recharger");
/* 17 */ GameRegistry.registerBlock(torchRecharger, TorchRechargerItemBlock.class, "torch_recharger");
/* 18 */ GameRegistry.registerTileEntity(TorchRechargerTileEntity.class, "torch_mod:torch_recharger_te");
/* */ }
/* */ }

View File

@ -0,0 +1,21 @@
/* */ package com.bernard.torch.init;
/* */
/* */ import com.bernard.torch.items.TorchAmulet;
/* */ import cpw.mods.fml.common.registry.GameRegistry;
/* */ import net.minecraft.creativetab.CreativeTabs;
/* */ import net.minecraft.item.Item;
/* */
/* */
/* */
/* */ public class TorchItems
/* */ {
/* */ public static Item torchAmulet;
/* */
/* */ public static void init()
/* */ {
/* 16 */ torchAmulet = new TorchAmulet().setUnlocalizedName("torch_amulet").setTextureName("torch_mod:torch_amulet").setCreativeTab(CreativeTabs.tabTools);
/* 17 */ GameRegistry.registerItem(torchAmulet, "torch_amulet");
/* */ }
/* */ }

View File

@ -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");
}
}

20
mcmod.info Normal file
View File

@ -0,0 +1,20 @@
[
{
"modid": "torch_mod",
"name": "Torch mod",
"description": "Un utilitaire pour placer des torches",
"version": "1.0",
"mcversion": "1.7.10",
"url": "",
"updateUrl": "",
"authorList": ["Samsoule63"],
"credits": "Azanor, pour son mod baubles,
le ressource pack Faithful, pour une partie des textures de ce mod,
UnwrittenFun , pour l'emprunt de la texture de l'amulette
et enfin, minecraftforgefrance , qui m'a permis,
grâce à ses tutos et à son forum de faire ce mod",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]