Pof, tout pour la 1.12 !
This commit is contained in:
parent
4d0adcf14d
commit
9d266700cd
30
src/main/java/com/bernard/torch/IVariant.java
Normal file
30
src/main/java/com/bernard/torch/IVariant.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.bernard.torch;
|
||||||
|
|
||||||
|
import net.minecraft.util.IStringSerializable;
|
||||||
|
|
||||||
|
public interface IVariant {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Classe d'aide à la création d'Enum pour les items à multiples variantes
|
||||||
|
*/
|
||||||
|
public interface IEnumVariant extends IStringSerializable {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Permet de récupérer la metadata d'une variante
|
||||||
|
* @Return la metadata
|
||||||
|
*/
|
||||||
|
int getMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Classe d'aide à la création d'items à multiples variantes
|
||||||
|
*/
|
||||||
|
public interface IItemVariant {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Permet de récuperer les valeurs des variantes
|
||||||
|
* @Return le tableau comprenant les valeurs des variantes
|
||||||
|
*/
|
||||||
|
<T extends IEnumVariant> T[] getValues();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,109 +5,128 @@ import com.bernard.torch.init.CoalStickAndTorchesRegister;
|
|||||||
import com.bernard.torch.init.CommonProxy;
|
import com.bernard.torch.init.CommonProxy;
|
||||||
import com.bernard.torch.init.TorchBlocks;
|
import com.bernard.torch.init.TorchBlocks;
|
||||||
import com.bernard.torch.init.TorchItems;
|
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.Blocks;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.SidedProxy;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||||
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
@Mod(modid="torch_mod", name="Torch mod", version="beta")
|
@Mod(modid = "torch_mod", name = "Torch mod", version = "beta")
|
||||||
public class TorchMod
|
public class TorchMod {
|
||||||
{
|
public static final String MODID = "torch_mod";
|
||||||
public static final String MODID = "torch_mod";
|
@Mod.Instance("torch_mod")
|
||||||
@Mod.Instance("torch_mod")
|
public static TorchMod MOD_INSTANCE;
|
||||||
public static TorchMod MOD_INSTANCE;
|
@SidedProxy(clientSide = "com.bernard.torch.init.ClientProxy", serverSide = "com.bernard.torch.init.CommonProxy")
|
||||||
@SidedProxy(clientSide="com.bernard.torch.init.ClientProxy", serverSide="com.bernard.torch.init.CommonProxy")
|
public static CommonProxy proxy;
|
||||||
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 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void init(FMLInitializationEvent event) {
|
||||||
|
System.out.println("Registeration en cours");
|
||||||
|
NetworkRegistry.INSTANCE.registerGuiHandler(MOD_INSTANCE, new TorchGuiHandler());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void postInit(FMLPostInitializationEvent event) {
|
||||||
|
|
||||||
|
/* OLD RECIPES
|
||||||
|
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 });
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,11 +2,8 @@ package com.bernard.torch.api;
|
|||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public abstract interface ITorchRechargable
|
public abstract interface ITorchRechargable {
|
||||||
{
|
public abstract void recharge(ItemStack paramItemStack, int paramInt);
|
||||||
public abstract void recharge(ItemStack paramItemStack, int paramInt);
|
|
||||||
|
public abstract int getLuxNedded(ItemStack paramItemStack);
|
||||||
public abstract int getLuxNedded(ItemStack paramItemStack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,94 @@
|
|||||||
|
package com.bernard.torch.blocks;
|
||||||
|
|
||||||
|
import com.bernard.torch.IVariant;
|
||||||
|
import com.bernard.torch.items.EnumTorchAmulet;
|
||||||
|
|
||||||
|
public enum EnumTorchRecharger implements IVariant.IEnumVariant{
|
||||||
|
//Coal { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
|
||||||
|
//Stick { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
|
||||||
|
//Torch { 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 };
|
||||||
|
BASE(0,"base",128,128,256),
|
||||||
|
COAL(1,"coal",256,256,512)
|
||||||
|
;
|
||||||
|
|
||||||
|
private static final EnumTorchRecharger[] META_LOOKUP = new EnumTorchRecharger[values().length];
|
||||||
|
private final int meta;
|
||||||
|
private final String name;
|
||||||
|
private final int maxCoal;
|
||||||
|
private final int maxStick;
|
||||||
|
private final int maxTorch;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Crée une nouvelle variante
|
||||||
|
*
|
||||||
|
* @Param metaIn la meta de la variante
|
||||||
|
*
|
||||||
|
* @Param nameIn le nom
|
||||||
|
*
|
||||||
|
* @Param chatColorIn la couleur du texte
|
||||||
|
*/
|
||||||
|
private EnumTorchRecharger(int metaIn, String nameIn,int maxCoal,int maxStick,int maxTorch) {
|
||||||
|
|
||||||
|
this.meta = metaIn;
|
||||||
|
this.name = nameIn;
|
||||||
|
this.maxCoal = maxCoal;
|
||||||
|
this.maxStick = maxStick;
|
||||||
|
this.maxTorch = maxTorch;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retourne la meta de la variante
|
||||||
|
*
|
||||||
|
* @return meta
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getMeta() {
|
||||||
|
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retourne le nom de la variante
|
||||||
|
*
|
||||||
|
* @return name
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxCoal() {
|
||||||
|
return maxCoal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxStick() {
|
||||||
|
return maxStick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxTorch() {
|
||||||
|
return maxTorch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retourne la variante (l'unlocalized name) correspondant à la meta
|
||||||
|
*
|
||||||
|
* @Param la meta à chercher
|
||||||
|
*
|
||||||
|
* @return A, B ou C en fonction de la meta
|
||||||
|
*/
|
||||||
|
public static EnumTorchRecharger byMetadata(int meta) {
|
||||||
|
if (meta < 0 || meta >= META_LOOKUP.length) {
|
||||||
|
meta = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return META_LOOKUP[meta];
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (EnumTorchRecharger enumType : values()) {
|
||||||
|
META_LOOKUP[enumType.getMeta()] = enumType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,146 +1,152 @@
|
|||||||
package com.bernard.torch.blocks;
|
package com.bernard.torch.blocks;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import com.bernard.torch.IVariant;
|
||||||
import com.bernard.torch.TorchMod;
|
import com.bernard.torch.TorchMod;
|
||||||
import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
|
import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
import net.minecraft.block.properties.PropertyEnum;
|
||||||
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.command.InvalidBlockStateException;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
public class TorchRechargerBlock extends Block implements IVariant.IItemVariant{
|
||||||
|
/* 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 final static PropertyEnum<EnumTorchRecharger> level = PropertyEnum.create("level", EnumTorchRecharger.class);
|
||||||
|
|
||||||
|
public TorchRechargerBlock(String name) {
|
||||||
|
super(Material.IRON);
|
||||||
|
setUnlocalizedName(name);
|
||||||
|
setRegistryName(name);
|
||||||
|
setHarvestLevel("pickaxe", 2);
|
||||||
|
setHardness(10.0F);
|
||||||
|
setLightLevel(10.0F);
|
||||||
|
setResistance(1000.0F);
|
||||||
|
setDefaultState(getDefaultState().withProperty(level, EnumTorchRecharger.BASE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetaFromState(IBlockState state) {
|
||||||
|
return state.getValue(level).getMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBlockState getStateFromMeta(int meta) {
|
||||||
|
return super.getStateFromMeta(meta).withProperty(level, EnumTorchRecharger.byMetadata(meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BlockStateContainer createBlockState() {
|
||||||
|
return new BlockStateContainer(this, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
|
||||||
|
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||||
|
System.out.println("wow is "+world.isRemote);
|
||||||
|
if (!world.isRemote) {
|
||||||
|
TorchRechargerTileEntity te = (TorchRechargerTileEntity) world.getTileEntity(pos);
|
||||||
|
player.openGui(TorchMod.MOD_INSTANCE, 0, world, pos.getX(),pos.getY(),pos.getZ());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||||
|
TileEntity te = world.getTileEntity(pos);
|
||||||
|
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 = pos.getX() + world.rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
double dropY = pos.getY() + world.rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
double dropZ = pos.getZ() + 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.spawnEntity(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.spawnEntity(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.spawnEntity(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.breakBlock(world, pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasTileEntity() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||||
|
return new TorchRechargerTileEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@Override
|
||||||
|
public void getSubBlocks(final CreativeTabs tab, final NonNullList<ItemStack> subItems) {
|
||||||
|
final List<ItemStack> items = Stream.of(EnumTorchRecharger.values())
|
||||||
|
.map(enumType -> new ItemStack(this, 1, enumType.getMeta())) // Pour chaque variante, on crée un itemstack en fonction de sa meta
|
||||||
|
.collect(Collectors.toList()); // Et on les mets dans une liste
|
||||||
|
|
||||||
|
subItems.addAll(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int damageDropped(IBlockState state) {
|
||||||
|
return state.getBlock().getMetaFromState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class TorchRechargerBlock
|
@Override
|
||||||
extends Block
|
public EnumTorchRecharger[] getValues() {
|
||||||
{
|
return EnumTorchRecharger.values();
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,56 +1,48 @@
|
|||||||
/* */ package com.bernard.torch.blocks.itemblocs;
|
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];
|
|
||||||
/* */ }
|
|
||||||
/* */ }
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bernard.torch.blocks.EnumTorchRecharger;
|
||||||
|
import com.bernard.torch.blocks.TorchRechargerBlock;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockSapling;
|
||||||
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.biome.Biome.FlowerEntry;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
public class TorchRechargerItemBlock extends ItemBlock {
|
||||||
|
|
||||||
|
public TorchRechargerItemBlock(Block block) {
|
||||||
|
super(block);
|
||||||
|
setRegistryName(block.getRegistryName());
|
||||||
|
setMaxDamage(0);
|
||||||
|
setHasSubtypes(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInformation(ItemStack s, World worldIn, List<String> l, ITooltipFlag flagIn) {
|
||||||
|
super.addInformation(s, worldIn, l, flagIn);
|
||||||
|
l.add("Stockage de torches :"
|
||||||
|
+ EnumTorchRecharger.byMetadata(s.getMetadata()).getMaxTorch());
|
||||||
|
l.add("Stockage de charbon :"
|
||||||
|
+ EnumTorchRecharger.byMetadata(s.getMetadata()).getMaxCoal());
|
||||||
|
l.add("Stockage de batons :"
|
||||||
|
+ EnumTorchRecharger.byMetadata(s.getMetadata()).getMaxStick());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetadata(int meta) {
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnlocalizedName(ItemStack stack) {
|
||||||
|
return super.getUnlocalizedName() + "." + EnumTorchRecharger.byMetadata(stack.getMetadata()).getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,10 @@
|
|||||||
package com.bernard.torch.blocks.tileentities;
|
package com.bernard.torch.blocks.tileentities;
|
||||||
|
|
||||||
|
import com.bernard.torch.IVariant;
|
||||||
|
import com.bernard.torch.IVariant.IEnumVariant;
|
||||||
|
|
||||||
import com.bernard.torch.api.ITorchRechargable;
|
import com.bernard.torch.api.ITorchRechargable;
|
||||||
|
import com.bernard.torch.blocks.EnumTorchRecharger;
|
||||||
import com.bernard.torch.init.CoalStickAndTorchesRegister;
|
import com.bernard.torch.init.CoalStickAndTorchesRegister;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@ -9,358 +13,371 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class TorchRechargerTileEntity extends TileEntity implements IInventory
|
public class TorchRechargerTileEntity extends TileEntity implements IInventory {
|
||||||
{
|
int torchValue = 0;
|
||||||
int torchValue = 0; int stickValue = 0; int coalValue = 0;
|
int stickValue = 0;
|
||||||
|
int coalValue = 0;
|
||||||
|
|
||||||
|
ItemStack stackStored;
|
||||||
|
ItemStack stackCharging;
|
||||||
|
|
||||||
public static final int[] maxCoalValueFromMeta = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
|
public void readFromNBT(NBTTagCompound compound) {
|
||||||
public static final int[] maxStickValueFromMeta = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
|
super.readFromNBT(compound);
|
||||||
public static final int[] maxTorchValueFromMeta = { 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 };
|
this.torchValue = compound.getInteger("TorchValue");
|
||||||
ItemStack stackStored;
|
this.stickValue = compound.getInteger("StickValue");
|
||||||
ItemStack stackCharging;
|
this.coalValue = compound.getInteger("CoalValue");
|
||||||
|
if (compound.hasKey("StoredItem", 10)) {
|
||||||
public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound);
|
NBTTagCompound itemCompound = compound.getCompoundTag("StoredItem");
|
||||||
this.torchValue = compound.getInteger("TorchValue");
|
this.stackStored = new ItemStack(itemCompound);
|
||||||
this.stickValue = compound.getInteger("StickValue");
|
}
|
||||||
this.coalValue = compound.getInteger("CoalValue");
|
if (compound.hasKey("ChargingItem", 10)) {
|
||||||
if (compound.hasKey("StoredItem", 10)) {
|
NBTTagCompound itemCompound = compound.getCompoundTag("ChargingItem");
|
||||||
NBTTagCompound itemCompound = compound.getCompoundTag("StoredItem");
|
this.stackCharging = new ItemStack(itemCompound);
|
||||||
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)
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||||
{
|
super.writeToNBT(compound);
|
||||||
super.writeToNBT(compound);
|
compound.setInteger("TorchValue", this.torchValue);
|
||||||
compound.setInteger("TorchValue", this.torchValue);
|
compound.setInteger("StickValue", this.stickValue);
|
||||||
compound.setInteger("StickValue", this.stickValue);
|
compound.setInteger("CoalValue", this.coalValue);
|
||||||
compound.setInteger("CoalValue", this.coalValue);
|
if (this.stackStored != null) {
|
||||||
if (this.stackStored != null) {
|
NBTTagCompound itemCompound = new NBTTagCompound();
|
||||||
NBTTagCompound itemCompound = new NBTTagCompound();
|
this.stackStored.writeToNBT(itemCompound);
|
||||||
this.stackStored.writeToNBT(itemCompound);
|
compound.setTag("StoredItem", itemCompound);
|
||||||
compound.setTag("StoredItem", itemCompound);
|
}
|
||||||
}
|
if (this.stackCharging != null) {
|
||||||
if (this.stackCharging != null) {
|
NBTTagCompound itemCompound = new NBTTagCompound();
|
||||||
NBTTagCompound itemCompound = new NBTTagCompound();
|
this.stackCharging.writeToNBT(itemCompound);
|
||||||
this.stackCharging.writeToNBT(itemCompound);
|
compound.setTag("ChargingItem", itemCompound);
|
||||||
compound.setTag("ChargingItem", itemCompound);
|
}
|
||||||
}
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Packet getDescriptionPacket()
|
public boolean canUpdate() {
|
||||||
{
|
return true;
|
||||||
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 void updateEntity() {
|
||||||
|
if (this.stackStored != null)
|
||||||
|
updateStackStored();
|
||||||
|
updateTransfers();
|
||||||
|
updateCharging();
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
public ItemStack decrStackSize(int slot, int amount)
|
public void updateStackStored() {
|
||||||
{
|
try {
|
||||||
switch (slot) {
|
if (isItemValidForSlot(0, this.stackStored)) {
|
||||||
case 0:
|
if ((this.stickValue < EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxStick())
|
||||||
if (this.stackStored == null)
|
&& (CoalStickAndTorchesRegister.isStick(this.stackStored.getItem()))) {
|
||||||
return null;
|
int singleValue = CoalStickAndTorchesRegister.getStickValue(this.stackStored.getItem());
|
||||||
ItemStack stack; if (amount >= this.stackStored.stackSize) {
|
if (singleValue * this.stackStored.getCount() + this.stickValue <= EnumTorchRecharger
|
||||||
ItemStack stack = this.stackStored;
|
.byMetadata(getBlockMetadata()).getMaxStick()) {
|
||||||
this.stackStored = null;
|
this.stickValue += singleValue * this.stackStored.getCount();
|
||||||
markDirty();
|
this.stackStored = null;
|
||||||
} else {
|
} else {
|
||||||
stack = this.stackStored.splitStack(amount);
|
int absorbed = 0;
|
||||||
if (this.stackStored.stackSize <= 0)
|
for (int i = 0; this.stickValue + singleValue <= EnumTorchRecharger
|
||||||
this.stackStored = null;
|
.byMetadata(getBlockMetadata()).getMaxStick(); i++) {
|
||||||
markDirty();
|
this.stickValue += singleValue;
|
||||||
}
|
absorbed = i;
|
||||||
return stack;
|
}
|
||||||
case 1:
|
this.stackStored.setCount(stackStored.getCount() - absorbed);
|
||||||
if (this.stackCharging == null)
|
if (this.stackStored.getCount() <= 0) {
|
||||||
return null;
|
this.stackStored = null;
|
||||||
ItemStack stack; if (amount >= this.stackCharging.stackSize) {
|
}
|
||||||
ItemStack stack = this.stackCharging;
|
}
|
||||||
this.stackCharging = null;
|
}
|
||||||
markDirty();
|
if ((this.coalValue < EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxCoal())
|
||||||
} else {
|
&& (CoalStickAndTorchesRegister.isCoal(this.stackStored.getItem()))) {
|
||||||
stack = this.stackCharging.splitStack(amount);
|
int singleValue = CoalStickAndTorchesRegister.getCoalValue(this.stackStored.getItem());
|
||||||
if (this.stackCharging.stackSize <= 0)
|
if (singleValue * this.stackStored.getCount() + this.coalValue <= EnumTorchRecharger
|
||||||
this.stackCharging = null;
|
.byMetadata(getBlockMetadata()).getMaxCoal()) {
|
||||||
markDirty();
|
this.coalValue += singleValue * this.stackStored.getCount();
|
||||||
}
|
this.stackStored = null;
|
||||||
return stack;
|
} else {
|
||||||
}
|
int absorbed = 0;
|
||||||
return null;
|
|
||||||
}
|
for (int i = 0; this.coalValue + singleValue <= EnumTorchRecharger
|
||||||
|
.byMetadata(getBlockMetadata()).getMaxCoal(); i++) {
|
||||||
|
this.coalValue += singleValue;
|
||||||
|
absorbed = i;
|
||||||
|
}
|
||||||
|
this.stackStored.setCount(stackStored.getCount() - absorbed);
|
||||||
|
if (this.stackStored.getCount() <= 0)
|
||||||
|
this.stackStored = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((this.torchValue < EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxTorch())
|
||||||
|
&& (CoalStickAndTorchesRegister.isTorch(this.stackStored.getItem()))) {
|
||||||
|
int singleValue = CoalStickAndTorchesRegister.getTorchValue(this.stackStored.getItem());
|
||||||
|
if (singleValue * this.stackStored.getCount() + this.torchValue <= EnumTorchRecharger
|
||||||
|
.byMetadata(getBlockMetadata()).getMaxTorch()) {
|
||||||
|
this.torchValue += singleValue * this.stackStored.getCount();
|
||||||
|
this.stackStored = null;
|
||||||
|
} else {
|
||||||
|
int absorbed = 0;
|
||||||
|
for (int i = 0; this.torchValue + singleValue <= EnumTorchRecharger
|
||||||
|
.byMetadata(getBlockMetadata()).getMaxTorch(); i++) {
|
||||||
|
this.torchValue += singleValue;
|
||||||
|
absorbed = i;
|
||||||
|
}
|
||||||
|
this.stackStored.setCount(stackStored.getCount() - absorbed);
|
||||||
|
if (this.stackStored.getCount() <= 0)
|
||||||
|
this.stackStored = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
System.err.println("NullPointer");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTransfers() {
|
||||||
|
if (this.torchValue < EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxTorch()) {
|
||||||
|
int torchNedded = EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxTorch() - this.torchValue;
|
||||||
|
if (torchNedded <= Math.min(this.coalValue, this.stickValue)) {
|
||||||
|
this.torchValue = EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxTorch();
|
||||||
|
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 ItemStack getStackInSlotOnClosing(int slot)
|
public int getSizeInventory() {
|
||||||
{
|
return 2;
|
||||||
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)
|
public ItemStack getStackInSlot(int slot) {
|
||||||
{
|
switch (slot) {
|
||||||
switch (slot) {
|
case 0:
|
||||||
case 0:
|
return this.stackStored;
|
||||||
this.stackStored = stack;
|
case 1:
|
||||||
return;
|
return this.stackCharging;
|
||||||
case 1:
|
}
|
||||||
this.stackCharging = stack;
|
return null;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInventoryName()
|
|
||||||
{
|
|
||||||
return "tile.torch_recharger";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCustomInventoryName()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInventoryStackLimit()
|
|
||||||
{
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isUseableByPlayer(EntityPlayer player)
|
public ItemStack decrStackSize(int slot, int amount) {
|
||||||
{
|
ItemStack stack;
|
||||||
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this;
|
switch (slot) {
|
||||||
}
|
case 0:
|
||||||
|
if (this.stackStored == null)
|
||||||
|
return null;
|
||||||
|
if (amount >= this.stackStored.getCount()) {
|
||||||
|
stack = this.stackStored;
|
||||||
|
this.stackStored = null;
|
||||||
|
markDirty();
|
||||||
|
} else {
|
||||||
|
stack = this.stackStored.splitStack(amount);
|
||||||
|
if (this.stackStored.getCount() <= 0)
|
||||||
|
this.stackStored = null;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
case 1:
|
||||||
|
if (this.stackCharging == null)
|
||||||
|
return null;
|
||||||
|
if (amount >= this.stackCharging.getCount()) {
|
||||||
|
stack = this.stackCharging;
|
||||||
|
this.stackCharging = null;
|
||||||
|
markDirty();
|
||||||
|
} else {
|
||||||
|
stack = this.stackCharging.splitStack(amount);
|
||||||
|
if (this.stackCharging.getCount() <= 0)
|
||||||
|
this.stackCharging = null;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||||
|
ItemStack stack;
|
||||||
|
switch (slot) {
|
||||||
|
case 0:
|
||||||
|
stack = this.stackStored;
|
||||||
|
this.stackStored = null;
|
||||||
|
return stack;
|
||||||
|
case 1:
|
||||||
|
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 void openChest() {}
|
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||||
|
return this.world.getTileEntity(pos) == 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 void closeChest() {}
|
public int getTorchValue() {
|
||||||
|
return this.torchValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStickValue() {
|
||||||
|
return this.stickValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCoalValue() {
|
||||||
|
return this.coalValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxTorchValue() {
|
||||||
|
return EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxTorch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxStickValue() {
|
||||||
|
return EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxStick();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxCoalValue() {
|
||||||
|
return EnumTorchRecharger.byMetadata(getBlockMetadata()).getMaxCoal();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
public ItemStack getStackStored() {
|
||||||
{
|
return this.stackStored;
|
||||||
if (stack == null)
|
}
|
||||||
return false;
|
|
||||||
switch (slot) {
|
public ItemStack getStackCharging() {
|
||||||
case 0:
|
return this.stackCharging;
|
||||||
return CoalStickAndTorchesRegister.isRegistered(stack.getItem());
|
}
|
||||||
|
|
||||||
case 1:
|
public String toString() {
|
||||||
return stack.getItem() instanceof ITorchRechargable;
|
return this.torchValue + ";" + this.stickValue + ";" + this.coalValue + "p=" + this.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
@Override
|
||||||
}
|
public String getName() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasCustomName() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack removeStackFromSlot(int index) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUsableByPlayer(EntityPlayer player) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openInventory(EntityPlayer player) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeInventory(EntityPlayer player) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getField(int id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setField(int id, int value) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFieldCount() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,39 +1,39 @@
|
|||||||
/* */ package com.bernard.torch.gui;
|
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;
|
|
||||||
/* */ }
|
|
||||||
/* */ }
|
|
||||||
|
|
||||||
|
import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||||
|
|
||||||
|
public class TorchGuiHandler implements IGuiHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
if (ID == 0) {
|
||||||
|
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
|
||||||
|
System.out.println("wow is but "+te);
|
||||||
|
if ((te instanceof TorchRechargerTileEntity)) {
|
||||||
|
System.out.println("S:" + te.toString());
|
||||||
|
return new TorchRechargerContainer((TorchRechargerTileEntity) te, player.inventory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
if (ID == 0) {
|
||||||
|
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
|
||||||
|
if ((te instanceof TorchRechargerTileEntity)) {
|
||||||
|
System.out.println("C:" + te.toString());
|
||||||
|
return new TorchRechargerGuiContainer((TorchRechargerTileEntity) te, player.inventory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,102 +1,90 @@
|
|||||||
/* */ package com.bernard.torch.gui;
|
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;
|
|
||||||
/* */ }
|
|
||||||
/* */ }
|
|
||||||
/* */ }
|
|
||||||
|
|
||||||
|
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) {
|
||||||
|
this.tile = te;
|
||||||
|
this.tile.openChest();
|
||||||
|
addSlotToContainer(new InputSlot(this.tile, 0, 14, 33));
|
||||||
|
addSlotToContainer(new OutputSlot(this.tile, 1, 138, 33));
|
||||||
|
bindPlayerInventory(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindPlayerInventory(InventoryPlayer inventory) {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
for (int j = 0; j < 9; j++) {
|
||||||
|
addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
|
return this.tile.isUseableByPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onContainerClosed(EntityPlayer player) {
|
||||||
|
super.onContainerClosed(player);
|
||||||
|
this.tile.closeChest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
||||||
|
ItemStack stack = null;
|
||||||
|
Slot slot = (Slot) this.inventorySlots.get(slotIndex);
|
||||||
|
if ((slot != null) && (slot.getHasStack())) {
|
||||||
|
ItemStack stackBis = slot.getStack();
|
||||||
|
stack = stackBis.copy();
|
||||||
|
if (slotIndex < this.tile.getSizeInventory()) {
|
||||||
|
if (!mergeItemStack(stackBis, this.tile.getSizeInventory(), this.inventorySlots.size(), true)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if (!mergeItemStack(stackBis, 0, this.tile.getSizeInventory(), false)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (stackBis.getCount() == 0) {
|
||||||
|
slot.putStack((ItemStack) null);
|
||||||
|
} else {
|
||||||
|
slot.onSlotChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InputSlot extends Slot {
|
||||||
|
public InputSlot(IInventory inventory, int i, int j, int k) {
|
||||||
|
super(inventory, i, j, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isItemValid(ItemStack stack) {
|
||||||
|
if (stack == null)
|
||||||
|
return false;
|
||||||
|
return CoalStickAndTorchesRegister.isRegistered(stack.getItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OutputSlot extends Slot {
|
||||||
|
public OutputSlot(IInventory inventory, int i, int j, int k) {
|
||||||
|
super(inventory, i, j, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isItemValid(ItemStack stack) {
|
||||||
|
if (stack == null)
|
||||||
|
return false;
|
||||||
|
return stack.getItem() instanceof ITorchRechargable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,111 +11,76 @@ import net.minecraft.inventory.IInventory;
|
|||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import org.lwjgl.opengl.GL11;
|
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 class TorchRechargerGuiContainer
|
public TorchRechargerTileEntity tile;
|
||||||
extends GuiContainer
|
public IInventory playerInventory;
|
||||||
{
|
private float mouseX = 0.0F;
|
||||||
private static final ResourceLocation background = new ResourceLocation("torch_mod", "textures/guis/torch_recharger.png");
|
private float mouseY = 0.0F;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
|
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ées :");
|
||||||
|
li.add(Integer.toString(this.tile.getTorchValue(), 10));
|
||||||
|
drawHoveringText(li, (int) this.mouseX - k, (int) this.mouseY - l, this.fontRenderer);
|
||||||
|
} 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.fontRenderer);
|
||||||
|
} 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é :");
|
||||||
|
li.add(Integer.toString(this.tile.getStickValue(), 10));
|
||||||
|
drawHoveringText(li, (int) this.mouseX - k, (int) this.mouseY - l, this.fontRenderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
if ((this.mouseX >= k + 101) && (this.mouseX < k + 116) && (this.mouseY >= l + 8) && (this.mouseY < l + 81)) {
|
int meta = this.tile.getBlockMetadata();
|
||||||
List<String> li = new ArrayList();
|
if (meta < 0)
|
||||||
li.add("Torches stock�s :");
|
meta = 0;
|
||||||
li.add(Integer.toString(this.tile.getTorchValue(), 10));
|
int torchPixels = Math.floorDiv(this.tile.getTorchValue() * 80, this.tile.getMaxTorchValue());
|
||||||
drawHoveringText(li, (int)this.mouseX - k, (int)this.mouseY - l, this.fontRendererObj);
|
drawTexturedModalRect(k + 94, l + 1 + 80 - torchPixels, this.xSize, 80 - torchPixels, 29, torchPixels);
|
||||||
} else if ((this.mouseX >= k + 45) && (this.mouseX < k + 70) && (this.mouseY >= l + 9) && (this.mouseY < l + 38)) {
|
int coalPixels = Math.floorDiv(this.tile.getCoalValue() * 32, this.tile.getMaxCoalValue());
|
||||||
List<String> li = new ArrayList();
|
drawTexturedModalRect(k + 42, l + 7 + 32 - coalPixels, this.xSize, 112 - coalPixels, 30, coalPixels);
|
||||||
li.add("Charbon stock� :");
|
int stickPixels = Math.floorDiv(this.tile.getStickValue() * 40, this.tile.getMaxStickValue());
|
||||||
li.add(Integer.toString(this.tile.getCoalValue(), 10));
|
drawTexturedModalRect(k + 53, l + 39 + 40 - stickPixels, this.xSize, 152 - stickPixels, 9, stickPixels);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,9 +1,6 @@
|
|||||||
package com.bernard.torch.init;
|
package com.bernard.torch.init;
|
||||||
|
|
||||||
public class ClientProxy
|
public class ClientProxy extends CommonProxy {
|
||||||
extends CommonProxy
|
public void registerRenders() {
|
||||||
{
|
}
|
||||||
public void registerRenders() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,80 +1,93 @@
|
|||||||
/* */ package com.bernard.torch.init;
|
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();
|
|
||||||
/* */ }
|
|
||||||
/* */ }
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
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) {
|
||||||
|
registered.put(i, new Integer[] { Integer.valueOf(0), Integer.valueOf(Math.abs(value)) });
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
registered.put(s.getItem(), new Integer[] { Integer.valueOf(0), Integer.valueOf(Math.abs(value)) });
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
registered.put(Item.getItemFromBlock(b),
|
||||||
|
new Integer[] { Integer.valueOf(1), Integer.valueOf(Math.abs(value)) });
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
registered.put(i, new Integer[] { Integer.valueOf(2), Integer.valueOf(Math.abs(value)) });
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerTorch(Block b, int value) {
|
||||||
|
registered.put(Item.getItemFromBlock(b),
|
||||||
|
new Integer[] { Integer.valueOf(2), Integer.valueOf(Math.abs(value)) });
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if (!registered.containsKey(i))
|
||||||
|
return false;
|
||||||
|
return ((Integer[]) registered.get(i))[0].intValue() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRegistered(Item i) {
|
||||||
|
return registered.containsKey(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isStick(Item i) {
|
||||||
|
if (!registered.containsKey(i))
|
||||||
|
return false;
|
||||||
|
return ((Integer[]) registered.get(i))[0].intValue() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTorch(Item i) {
|
||||||
|
if (!registered.containsKey(i))
|
||||||
|
return false;
|
||||||
|
return ((Integer[]) registered.get(i))[0].intValue() == 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCoalValue(Item i) {
|
||||||
|
if (!isCoal(i))
|
||||||
|
return 0;
|
||||||
|
return ((Integer[]) registered.get(i))[1].intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getStickValue(Item i) {
|
||||||
|
if (!isStick(i))
|
||||||
|
return 0;
|
||||||
|
return ((Integer[]) registered.get(i))[1].intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getTorchValue(Item i) {
|
||||||
|
if (!isTorch(i))
|
||||||
|
return 0;
|
||||||
|
return ((Integer[]) registered.get(i))[1].intValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,6 @@
|
|||||||
package com.bernard.torch.init;
|
package com.bernard.torch.init;
|
||||||
|
|
||||||
public class CommonProxy
|
public class CommonProxy {
|
||||||
{
|
public void registerRenders() {
|
||||||
public void registerRenders() {}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,71 @@
|
|||||||
/* */ package com.bernard.torch.init;
|
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");
|
|
||||||
/* */ }
|
|
||||||
/* */ }
|
|
||||||
|
|
||||||
|
import com.bernard.torch.IVariant;
|
||||||
|
import com.bernard.torch.TorchMod;
|
||||||
|
|
||||||
|
import com.bernard.torch.blocks.TorchRechargerBlock;
|
||||||
|
import com.bernard.torch.blocks.itemblocs.TorchRechargerItemBlock;
|
||||||
|
import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
|
||||||
|
import com.bernard.torch.init.TorchItems.ModelHandler;
|
||||||
|
import com.bernard.torch.items.TorchAmulet;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockSapling;
|
||||||
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
|
||||||
|
import net.minecraft.client.renderer.block.statemap.StateMap;
|
||||||
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||||
|
import net.minecraftforge.client.model.BlockStateLoader;
|
||||||
|
import net.minecraftforge.client.model.ModelLoader;
|
||||||
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||||
|
import net.minecraftforge.event.RegistryEvent.Register;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(modid = TorchMod.MODID)
|
||||||
|
public class TorchBlocks {
|
||||||
|
public static TorchRechargerBlock torchRecharger;
|
||||||
|
private static BlockStateMapper bsMapper = new BlockStateMapper();
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
torchRecharger = new TorchRechargerBlock("torch_recharger");
|
||||||
|
torchRecharger.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||||
|
//GameRegistry.registerTileEntity(TorchRechargerTileEntity.class,torchRecharger.getRegistryName().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerBlocks(Register<Block> register) {
|
||||||
|
register.getRegistry().registerAll(torchRecharger);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerItemBlocks(Register<Item> register) {
|
||||||
|
register.getRegistry().registerAll(new TorchRechargerItemBlock(torchRecharger));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void modelRendererRegister(ModelRegistryEvent register) {
|
||||||
|
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(torchRecharger), 0, new ModelResourceLocation(torchRecharger.getRegistryName(), "inventory"));
|
||||||
|
// ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(torchRecharger), 1, new ModelResourceLocation(torchRecharger.getRegistryName()+".coal", "inventory"));
|
||||||
|
// rendererRegister(Item.getItemFromBlock(torchRecharger),0);
|
||||||
|
// rendererRegister(Item.getItemFromBlock(torchRecharger),1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void rendererRegister(Item i,int metadata) {
|
||||||
|
bsMapper.registerBlockStateMapper(torchRecharger, (new StateMap.Builder()).withName(torchRecharger.level).withSuffix("_torch_recharger").build());
|
||||||
|
ModelLoader.setCustomModelResourceLocation(i, metadata, new ModelResourceLocation(i.getRegistryName(), "inventory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -1,21 +1,119 @@
|
|||||||
/* */ package com.bernard.torch.init;
|
package com.bernard.torch.init;
|
||||||
/* */
|
|
||||||
/* */ import com.bernard.torch.items.TorchAmulet;
|
import com.bernard.torch.IVariant;
|
||||||
/* */ import cpw.mods.fml.common.registry.GameRegistry;
|
import com.bernard.torch.TorchMod;
|
||||||
/* */ import net.minecraft.creativetab.CreativeTabs;
|
import com.bernard.torch.items.TorchAmulet;
|
||||||
/* */ 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");
|
|
||||||
/* */ }
|
|
||||||
/* */ }
|
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||||
|
import net.minecraftforge.client.model.ModelLoader;
|
||||||
|
import net.minecraftforge.event.RegistryEvent.Register;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(modid = TorchMod.MODID)
|
||||||
|
public class TorchItems
|
||||||
|
{
|
||||||
|
public static TorchAmulet torchAmulet;
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
torchAmulet = new TorchAmulet("torch_amulet");
|
||||||
|
torchAmulet.setCreativeTab(CreativeTabs.TOOLS);
|
||||||
|
}
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerItems(Register<Item> register) {
|
||||||
|
register.getRegistry().registerAll(torchAmulet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerRenders(ModelRegistryEvent register) {
|
||||||
|
registerRender(torchAmulet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerRender(Item item) {
|
||||||
|
//ModelLoader.setCustomModelResourceLocation(item, 0,new ModelResourceLocation(item.getRegistryName(), "inventory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(Side.CLIENT)
|
||||||
|
public static class ModelHandler {
|
||||||
|
|
||||||
|
private static final ModelHandler INSTANCE = new ModelHandler();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enregistre les modèles des items
|
||||||
|
* @Param event L'évènement
|
||||||
|
*/
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerItemModels(final ModelRegistryEvent event) {
|
||||||
|
|
||||||
|
INSTANCE.registerVariantItemModels(torchAmulet, torchAmulet.getRegistryName().toString(),torchAmulet.getValues());
|
||||||
|
/* For non-variant models
|
||||||
|
final ModelResourceLocation fullModelLocation = new ModelResourceLocation(item.getRegistryName().toString, "inventory");
|
||||||
|
INSTANCE.registerItemModel(item, fullModelLocation);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enregistre le modèle d'un item
|
||||||
|
* Etape 2 : Permet de récupérer la meshDefinition de l'item
|
||||||
|
* @Param item L'item
|
||||||
|
* @Param modelLocation la localisation complète de l'item
|
||||||
|
*/
|
||||||
|
private void registerItemModel(final Item item, final ModelResourceLocation fullModelLocation) {
|
||||||
|
|
||||||
|
ModelBakery.registerItemVariants(item, fullModelLocation);
|
||||||
|
registerItemModel(item, new ItemMeshDefinition() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation getModelLocation(ItemStack stack) {
|
||||||
|
return fullModelLocation;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enregistre le modèle d'un item
|
||||||
|
* @Param item L'item
|
||||||
|
* @Param meshDefinition la meshDefinition de l'item
|
||||||
|
*/
|
||||||
|
private void registerItemModel(final Item item, final ItemMeshDefinition meshDefinition) {
|
||||||
|
|
||||||
|
ModelLoader.setCustomMeshDefinition(item, meshDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enregistre les modèles d'un item avec variantes
|
||||||
|
* @Param item L'item
|
||||||
|
* @Param modelLocation le nom de l'item dans le registre
|
||||||
|
* @Param values les variantes de l'item
|
||||||
|
*/
|
||||||
|
private <T extends IVariant.IEnumVariant> void registerVariantItemModels(final Item item, final String modelLocation, final T[] values) {
|
||||||
|
|
||||||
|
for (final T value : values) {
|
||||||
|
registerItemModelForMeta(item, value.getMeta(), modelLocation + "=" + value.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rengistre la variante d'un item
|
||||||
|
* @Param item L'item
|
||||||
|
* @Param metadata la meta de la variante
|
||||||
|
* @Param variantLocation la localisation de la variante
|
||||||
|
*/
|
||||||
|
private void registerItemModelForMeta(final Item item, final int metadata, final String variantLocation) {
|
||||||
|
|
||||||
|
ModelResourceLocation location = new ModelResourceLocation(item.getRegistryName(), variantLocation);
|
||||||
|
ModelLoader.setCustomModelResourceLocation(item, metadata, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
81
src/main/java/com/bernard/torch/items/EnumTorchAmulet.java
Normal file
81
src/main/java/com/bernard/torch/items/EnumTorchAmulet.java
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
package com.bernard.torch.items;
|
||||||
|
|
||||||
|
import com.bernard.torch.IVariant;
|
||||||
|
|
||||||
|
public enum EnumTorchAmulet implements IVariant.IEnumVariant {
|
||||||
|
|
||||||
|
//{ 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144 }
|
||||||
|
BASE(0,"base",1024),
|
||||||
|
COAL(1,"coal",2048),
|
||||||
|
;
|
||||||
|
|
||||||
|
private static final EnumTorchAmulet[] META_LOOKUP = new EnumTorchAmulet[values().length];
|
||||||
|
private final int meta;
|
||||||
|
private final String name;
|
||||||
|
private final int maxLux;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Crée une nouvelle variante
|
||||||
|
*
|
||||||
|
* @Param metaIn la meta de la variante
|
||||||
|
*
|
||||||
|
* @Param nameIn le nom
|
||||||
|
*
|
||||||
|
* @Param chatColorIn la couleur du texte
|
||||||
|
*/
|
||||||
|
private EnumTorchAmulet(int metaIn, String nameIn,int maxLux) {
|
||||||
|
|
||||||
|
this.meta = metaIn;
|
||||||
|
this.name = nameIn;
|
||||||
|
this.maxLux = maxLux;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retourne la meta de la variante
|
||||||
|
*
|
||||||
|
* @return meta
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getMeta() {
|
||||||
|
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retourne le nom de la variante
|
||||||
|
*
|
||||||
|
* @return name
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public int getMaxLux() {
|
||||||
|
return maxLux;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retourne la variante (l'unlocalized name) correspondant à la meta
|
||||||
|
*
|
||||||
|
* @Param la meta à chercher
|
||||||
|
*
|
||||||
|
* @return A, B ou C en fonction de la meta
|
||||||
|
*/
|
||||||
|
public static EnumTorchAmulet byMetadata(int meta) {
|
||||||
|
if (meta < 0 || meta >= META_LOOKUP.length) {
|
||||||
|
meta = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return META_LOOKUP[meta];
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (EnumTorchAmulet enumType : values()) {
|
||||||
|
META_LOOKUP[enumType.getMeta()] = enumType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,13 +1,15 @@
|
|||||||
package com.bernard.torch.items;
|
package com.bernard.torch.items;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import com.bernard.torch.IVariant.IItemVariant;
|
||||||
|
import com.bernard.torch.api.ITorchRechargable;
|
||||||
|
|
||||||
import baubles.api.BaubleType;
|
import baubles.api.BaubleType;
|
||||||
import baubles.api.IBauble;
|
import baubles.api.IBauble;
|
||||||
import com.bernard.torch.api.ITorchRechargable;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
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.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@ -15,188 +17,179 @@ import net.minecraft.init.Blocks;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.NonNullList;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
public class TorchAmulet extends Item implements IBauble, ITorchRechargable, IItemVariant {
|
||||||
|
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 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 TorchAmulet(final String name) {
|
||||||
|
setUnlocalizedName(name);
|
||||||
|
setRegistryName(name);
|
||||||
|
setMaxStackSize(1);
|
||||||
|
setHasSubtypes(true);
|
||||||
|
}
|
||||||
|
|
||||||
public class TorchAmulet
|
/*
|
||||||
extends Item
|
* Retourne l'unlocalized name correspondant à la variante
|
||||||
implements IBauble, ITorchRechargable
|
*
|
||||||
{
|
* @Param stack l'ItemStack
|
||||||
public static int yRelative = 0;
|
*
|
||||||
|
* @Return la variante correspondant à stack
|
||||||
public static final int size = 4;
|
*
|
||||||
public static final int ecart = 5;
|
* @see net.minecraft.item.Item#getUnlocalizedName(net.minecraft.item.ItemStack)
|
||||||
public static final int maxYRelative = 5;
|
*/
|
||||||
public static final int minYRelative = -5;
|
@Override
|
||||||
public static final int[] maxTorchesFromMeta = { 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144 };
|
public String getUnlocalizedName(ItemStack stack) {
|
||||||
|
return super.getUnlocalizedName() + "." + getTorchAmuletData(stack).getName();
|
||||||
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 EnumTorchAmulet getTorchAmuletData(ItemStack stack) {
|
||||||
|
int i = stack.getMetadata();
|
||||||
|
if(i >= getMetaCount())i=0;
|
||||||
|
return EnumTorchAmulet.byMetadata(i);
|
||||||
|
}
|
||||||
|
|
||||||
public static IIcon[] textures = new IIcon[names.length];
|
/*
|
||||||
|
* Permet de récupérer les items des variantes
|
||||||
public TorchAmulet() {
|
*
|
||||||
setMaxStackSize(1);
|
* @Param tab (CreativeTabs)
|
||||||
setHasSubtypes(true);
|
*
|
||||||
}
|
* @Param subItems les variantes
|
||||||
|
*
|
||||||
public void addInformation(ItemStack itemstack, EntityPlayer player, List l, boolean flag)
|
* @see
|
||||||
{
|
* net.minecraft.item.Item#getSubItems(net.minecraft.creativetab.CreativeTabs,
|
||||||
super.addInformation(itemstack, player, l, flag);
|
* net.minecraft.util.NonNullList)
|
||||||
if ((itemstack.stackTagCompound == null) || (!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
*/
|
||||||
itemstack.stackTagCompound = new NBTTagCompound();
|
@SideOnly(Side.CLIENT)
|
||||||
int meta = itemstack.getMetadata();
|
@Override
|
||||||
if (meta >= maxTorchesFromMeta.length)
|
public void getSubItems(final CreativeTabs tab, final NonNullList<ItemStack> subItems) {
|
||||||
meta = 0;
|
if(tab != CreativeTabs.TOOLS)return;
|
||||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
final List<ItemStack> items = Stream.of(EnumTorchAmulet.values())
|
||||||
}
|
.map(enumType -> new ItemStack(this, 1, enumType.getMeta())) // Pour chaque variante, on crée un
|
||||||
l.add("Torches left :" + itemstack.stackTagCompound.getInteger("TorchesLeft"));
|
// itemstack en fonction de sa meta
|
||||||
}
|
.collect(Collectors.toList()); // Et on les mets dans une liste
|
||||||
|
|
||||||
|
|
||||||
public int getMetadata(int meta)
|
subItems.addAll(items);
|
||||||
{
|
}
|
||||||
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)
|
@Override
|
||||||
{
|
public EnumTorchAmulet[] getValues() {
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
return EnumTorchAmulet.values();
|
||||||
|
}
|
||||||
|
|
||||||
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {}
|
public int getMetaCount() {
|
||||||
|
|
||||||
|
|
||||||
public boolean canEquip(ItemStack itemstack, EntityLivingBase player)
|
return EnumTorchAmulet.values().length;
|
||||||
{
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
|
public void addInformation(ItemStack itemstack, World worldIn, List<String> l, ITooltipFlag flagIn) {
|
||||||
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player)
|
super.addInformation(itemstack, worldIn, l, flagIn);
|
||||||
{
|
if ((itemstack.getTagCompound() == null) || (!itemstack.getTagCompound().hasKey("TorchesLeft", 3))) {
|
||||||
return true;
|
|
||||||
}
|
itemstack.setTagCompound(new NBTTagCompound());
|
||||||
|
itemstack.getTagCompound().setInteger("TorchesLeft", getTorchAmuletData(itemstack).getMaxLux());
|
||||||
public void recharge(ItemStack itemstack, int lux)
|
}
|
||||||
{
|
l.add("Torches left :" + itemstack.getTagCompound().getInteger("TorchesLeft"));
|
||||||
int meta = itemstack.getMetadata();
|
}
|
||||||
if ((itemstack.stackTagCompound == null) ||
|
|
||||||
(!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
public int getMetadata(int meta) {
|
||||||
itemstack.stackTagCompound = new NBTTagCompound();
|
return meta;
|
||||||
if (meta >= maxTorchesFromMeta.length)
|
}
|
||||||
meta = 0;
|
|
||||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
public void onCreated(ItemStack itemstack, World w, EntityPlayer pl) {
|
||||||
}
|
super.onCreated(itemstack, w, pl);
|
||||||
itemstack.stackTagCompound.setInteger("TorchesLeft", Math.min(itemstack.stackTagCompound.getInteger("TorchesLeft") + lux, maxTorchesFromMeta[meta]));
|
if ((itemstack.getTagCompound() == null) || (!itemstack.getTagCompound().hasKey("TorchesLeft", 3))) {
|
||||||
}
|
itemstack.setTagCompound(new NBTTagCompound());
|
||||||
|
int meta = itemstack.getMetadata();
|
||||||
public int getLuxNedded(ItemStack itemstack)
|
itemstack.getTagCompound().setInteger("TorchesLeft", getTorchAmuletData(itemstack).getMaxLux());
|
||||||
{
|
}
|
||||||
int meta = itemstack.getMetadata();
|
}
|
||||||
if ((itemstack.stackTagCompound == null) ||
|
|
||||||
(!itemstack.stackTagCompound.hasKey("TorchesLeft", 3))) {
|
public BaubleType getBaubleType(ItemStack itemstack) {
|
||||||
itemstack.stackTagCompound = new NBTTagCompound();
|
return BaubleType.AMULET;
|
||||||
if (meta >= maxTorchesFromMeta.length)
|
}
|
||||||
meta = 0;
|
|
||||||
itemstack.stackTagCompound.setInteger("TorchesLeft", maxTorchesFromMeta[meta]);
|
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
|
||||||
}
|
if ((itemstack.getTagCompound() == null) || (!itemstack.getTagCompound().hasKey("TorchesLeft", 3))) {
|
||||||
return maxTorchesFromMeta[meta] - itemstack.stackTagCompound.getInteger("TorchesLeft");
|
itemstack.setTagCompound(new NBTTagCompound());
|
||||||
}
|
int meta = itemstack.getMetadata();
|
||||||
|
itemstack.getTagCompound().setInteger("TorchesLeft", getTorchAmuletData(itemstack).getMaxLux());
|
||||||
|
}
|
||||||
|
if (itemstack.getTagCompound().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.world, new BlockPos(modX + x, y + yRelative, modZ + z))) {// TODO add random
|
||||||
|
// faketorch placing
|
||||||
|
itemstack.getTagCompound().setInteger("TorchesLeft",
|
||||||
|
itemstack.getTagCompound().getInteger("TorchesLeft") - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yRelative = yRelative == 4 ? -5 : yRelative + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean placeTorch(World w, BlockPos pos) {
|
||||||
|
if ((Blocks.TORCH.canPlaceBlockAt(w, pos)) && (w.getBlockState(pos).getBlock() == Blocks.AIR)) {
|
||||||
|
w.setBlockState(pos, Blocks.TORCH.getDefaultState());//XXX Check condition
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {
|
||||||
|
if ((itemstack.getTagCompound() == null) || (!itemstack.getTagCompound().hasKey("TorchesLeft", 3))) {
|
||||||
|
itemstack.setTagCompound(new NBTTagCompound());
|
||||||
|
int meta = itemstack.getMetadata();
|
||||||
|
itemstack.getTagCompound().setInteger("TorchesLeft", getTorchAmuletData(itemstack).getMaxLux());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.getTagCompound() == null) || (!itemstack.getTagCompound().hasKey("TorchesLeft", 3))) {
|
||||||
|
itemstack.setTagCompound(new NBTTagCompound());
|
||||||
|
itemstack.getTagCompound().setInteger("TorchesLeft", getTorchAmuletData(itemstack).getMaxLux());
|
||||||
|
}
|
||||||
|
itemstack.getTagCompound().setInteger("TorchesLeft",
|
||||||
|
Math.min(itemstack.getTagCompound().getInteger("TorchesLeft") + lux, getTorchAmuletData(itemstack).getMaxLux()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLuxNedded(ItemStack itemstack) {
|
||||||
|
int meta = itemstack.getMetadata();
|
||||||
|
if ((itemstack.getTagCompound() == null) || (!itemstack.getTagCompound().hasKey("TorchesLeft", 3))) {
|
||||||
|
itemstack.setTagCompound(new NBTTagCompound());
|
||||||
|
itemstack.getTagCompound().setInteger("TorchesLeft", getTorchAmuletData(itemstack).getMaxLux());
|
||||||
|
}
|
||||||
|
return getTorchAmuletData(itemstack).getMaxLux() - itemstack.getTagCompound().getInteger("TorchesLeft");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,10 +4,10 @@
|
|||||||
"name": "Torch mod",
|
"name": "Torch mod",
|
||||||
"description": "Un utilitaire pour placer des torches",
|
"description": "Un utilitaire pour placer des torches",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"mcversion": "1.7.10",
|
"mcversion": "1.12.2",
|
||||||
"url": "",
|
"url": "",
|
||||||
"updateUrl": "",
|
"updateUrl": "",
|
||||||
"authorList": ["Samsoule63"],
|
"authorList": ["Mysaa"],
|
||||||
"credits": "Azanor, pour son mod baubles,
|
"credits": "Azanor, pour son mod baubles,
|
||||||
le ressource pack Faithful, pour une partie des textures de ce mod,
|
le ressource pack Faithful, pour une partie des textures de ce mod,
|
||||||
UnwrittenFun , pour l'emprunt de la texture de l'amulette
|
UnwrittenFun , pour l'emprunt de la texture de l'amulette
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user