Premier commit - Extrait du pauvre jar après perte des sources
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
package com.bernard.torch.blocks;
|
||||
|
||||
import com.bernard.torch.TorchMod;
|
||||
import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
public class TorchRechargerBlock
|
||||
extends Block
|
||||
{
|
||||
private IIcon iconTop;
|
||||
private IIcon iconBottom;
|
||||
private IIcon iconFaces;
|
||||
public static String[] names = { "torch_recharger", "coal_torch_recharger", "iron_torch_recharger", "quartz_torch_recharger", "gold_torch_recharger", "redstone_torch_recharger", "lapis_torch_recharger", "diamond_torch_recharger", "emerald_torch_recharger" };
|
||||
|
||||
|
||||
public IIcon[][] textures = new IIcon[names.length][3];
|
||||
|
||||
public TorchRechargerBlock() {
|
||||
super(Material.iron);
|
||||
setHarvestLevel("pickaxe", 2);
|
||||
setHardness(10.0F);
|
||||
setCreativeTab(CreativeTabs.tabDecorations);
|
||||
setLightLevel(10.0F);
|
||||
setResistance(1000.0F);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!world.isRemote) {
|
||||
TorchRechargerTileEntity te = (TorchRechargerTileEntity)world.getTileEntity(x, y, z);
|
||||
player.openGui(TorchMod.MOD_INSTANCE, 0, world, x, y, z);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int meta)
|
||||
{
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if ((te instanceof TorchRechargerTileEntity)) {
|
||||
TorchRechargerTileEntity torchRecharger = (TorchRechargerTileEntity)te;
|
||||
int torches = Math.floorDiv(torchRecharger.getTorchValue(), 4);
|
||||
int sticks = Math.floorDiv(torchRecharger.getStickValue(), 4);
|
||||
int coals = Math.floorDiv(torchRecharger.getCoalValue(), 4);
|
||||
double dropX = x + world.rand.nextFloat() * 0.8F + 0.1F;double dropY = y + world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
double dropZ = z + world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
while ((torches > 0) || (sticks > 0) || (coals > 0)) {
|
||||
if (torches > 0)
|
||||
{
|
||||
EntityItem item = new EntityItem(world, dropX, dropY, dropZ, new ItemStack(Blocks.torch, Math.min(torches, 64), 0));
|
||||
item.motionX = ((float)world.rand.nextGaussian() * 0.05F);
|
||||
item.motionY = ((float)world.rand.nextGaussian() * 0.05F + 0.2F);
|
||||
item.motionZ = ((float)world.rand.nextGaussian() * 0.05F);
|
||||
torches -= Math.min(torches, 64);
|
||||
world.spawnEntityInWorld(item);
|
||||
}
|
||||
if (sticks > 0)
|
||||
{
|
||||
EntityItem item = new EntityItem(world, dropX, dropY, dropZ, new ItemStack(Items.stick, Math.min(sticks, 64), 0));
|
||||
item.motionX = ((float)world.rand.nextGaussian() * 0.05F);
|
||||
item.motionY = ((float)world.rand.nextGaussian() * 0.05F + 0.2F);
|
||||
item.motionZ = ((float)world.rand.nextGaussian() * 0.05F);
|
||||
sticks -= Math.min(sticks, 64);
|
||||
world.spawnEntityInWorld(item);
|
||||
}
|
||||
if (coals > 0)
|
||||
{
|
||||
EntityItem item = new EntityItem(world, dropX, dropY, dropZ, new ItemStack(Items.coal, Math.min(coals, 64), 0));
|
||||
item.motionX = ((float)world.rand.nextGaussian() * 0.05F);
|
||||
item.motionY = ((float)world.rand.nextGaussian() * 0.05F + 0.2F);
|
||||
item.motionZ = ((float)world.rand.nextGaussian() * 0.05F);
|
||||
coals -= Math.min(coals, 64);
|
||||
world.spawnEntityInWorld(item);
|
||||
}
|
||||
}
|
||||
|
||||
world.updateNeighborsAboutBlockChange(x, y, z, block);
|
||||
world.removeTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, block, meta);
|
||||
}
|
||||
|
||||
public boolean hasTileEntity(int metadata)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public TileEntity createTileEntity(World world, int metadata)
|
||||
{
|
||||
return new TorchRechargerTileEntity();
|
||||
}
|
||||
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List l)
|
||||
{
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
l.add(new ItemStack(item, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
public void registerIcons(IIconRegister r)
|
||||
{
|
||||
for (int i = 0; i < this.textures.length; i++) {
|
||||
this.textures[i][0] = r.registerIcon("torch_mod:" + names[i] + "_bottom");
|
||||
this.textures[i][1] = r.registerIcon("torch_mod:" + names[i] + "_top");
|
||||
this.textures[i][2] = r.registerIcon("torch_mod:" + names[i] + "_side");
|
||||
}
|
||||
}
|
||||
|
||||
public int damageDropped(int meta)
|
||||
{
|
||||
return meta;
|
||||
}
|
||||
|
||||
public IIcon getIcon(int side, int meta)
|
||||
{
|
||||
if ((meta >= this.textures.length) || (meta < 0))
|
||||
return this.textures[0][0];
|
||||
switch (side) {
|
||||
case 0:
|
||||
return this.textures[meta][0];
|
||||
case 1:
|
||||
return this.textures[meta][1];
|
||||
}
|
||||
return this.textures[meta][2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/* */ package com.bernard.torch.blocks.itemblocs;
|
||||
/* */
|
||||
/* */ import com.bernard.torch.blocks.TorchRechargerBlock;
|
||||
/* */ import cpw.mods.fml.relauncher.Side;
|
||||
/* */ import cpw.mods.fml.relauncher.SideOnly;
|
||||
/* */ import java.util.List;
|
||||
/* */ import net.minecraft.block.Block;
|
||||
/* */ import net.minecraft.entity.player.EntityPlayer;
|
||||
/* */ import net.minecraft.item.ItemBlock;
|
||||
/* */ import net.minecraft.item.ItemStack;
|
||||
/* */ import net.minecraft.util.IIcon;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class TorchRechargerItemBlock
|
||||
/* */ extends ItemBlock
|
||||
/* */ {
|
||||
/* */ public TorchRechargerItemBlock(Block block)
|
||||
/* */ {
|
||||
/* 20 */ super(block);
|
||||
/* 21 */ setMaxDurability(0);
|
||||
/* 22 */ setHasSubtypes(true);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void addInformation(ItemStack s, EntityPlayer p, List l, boolean flag)
|
||||
/* */ {
|
||||
/* 27 */ super.addInformation(s, p, l, flag);
|
||||
/* 28 */ if (s.getMetadata() >= TorchRechargerBlock.names.length)
|
||||
/* 29 */ s.setMetadata(0);
|
||||
/* 30 */ l.add("Stockage de torches :" + com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity.maxTorchValueFromMeta[s.getMetadata()]);
|
||||
/* 31 */ l.add("Stockage de charbon :" + com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity.maxCoalValueFromMeta[s.getMetadata()]);
|
||||
/* 32 */ l.add("Stockage de batons :" + com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity.maxStickValueFromMeta[s.getMetadata()]);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */ public int getMetadata(int meta)
|
||||
/* */ {
|
||||
/* 38 */ return meta;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ @SideOnly(Side.CLIENT)
|
||||
/* */ public IIcon getIconFromDamage(int meta)
|
||||
/* */ {
|
||||
/* 44 */ return this.blockInstance.getIcon(2, meta);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public String getUnlocalizedName(ItemStack stack)
|
||||
/* */ {
|
||||
/* 49 */ int meta = stack.getMetadata();
|
||||
/* 50 */ if ((meta < 0) || (meta >= TorchRechargerBlock.names.length))
|
||||
/* 51 */ meta = 0;
|
||||
/* 52 */ return TorchRechargerBlock.names[meta];
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
package com.bernard.torch.blocks.tileentities;
|
||||
|
||||
import com.bernard.torch.api.ITorchRechargable;
|
||||
import com.bernard.torch.init.CoalStickAndTorchesRegister;
|
||||
import java.io.PrintStream;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TorchRechargerTileEntity extends TileEntity implements IInventory
|
||||
{
|
||||
int torchValue = 0; int stickValue = 0; int coalValue = 0;
|
||||
|
||||
|
||||
|
||||
public static final int[] maxCoalValueFromMeta = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
|
||||
public static final int[] maxStickValueFromMeta = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
|
||||
public static final int[] maxTorchValueFromMeta = { 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 };
|
||||
ItemStack stackStored;
|
||||
ItemStack stackCharging;
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound);
|
||||
this.torchValue = compound.getInteger("TorchValue");
|
||||
this.stickValue = compound.getInteger("StickValue");
|
||||
this.coalValue = compound.getInteger("CoalValue");
|
||||
if (compound.hasKey("StoredItem", 10)) {
|
||||
NBTTagCompound itemCompound = compound.getCompoundTag("StoredItem");
|
||||
this.stackStored = ItemStack.loadItemStackFromNBT(itemCompound);
|
||||
}
|
||||
if (compound.hasKey("ChargingItem", 10)) {
|
||||
NBTTagCompound itemCompound = compound.getCompoundTag("ChargingItem");
|
||||
this.stackCharging = ItemStack.loadItemStackFromNBT(itemCompound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound)
|
||||
{
|
||||
super.writeToNBT(compound);
|
||||
compound.setInteger("TorchValue", this.torchValue);
|
||||
compound.setInteger("StickValue", this.stickValue);
|
||||
compound.setInteger("CoalValue", this.coalValue);
|
||||
if (this.stackStored != null) {
|
||||
NBTTagCompound itemCompound = new NBTTagCompound();
|
||||
this.stackStored.writeToNBT(itemCompound);
|
||||
compound.setTag("StoredItem", itemCompound);
|
||||
}
|
||||
if (this.stackCharging != null) {
|
||||
NBTTagCompound itemCompound = new NBTTagCompound();
|
||||
this.stackCharging.writeToNBT(itemCompound);
|
||||
compound.setTag("ChargingItem", itemCompound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
writeToNBT(compound);
|
||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, compound);
|
||||
}
|
||||
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
|
||||
{
|
||||
readFromNBT(pkt.getNbtCompound());
|
||||
}
|
||||
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateEntity()
|
||||
{
|
||||
if (this.blockMetadata == -1)
|
||||
this.blockMetadata = 0;
|
||||
if (this.stackStored != null)
|
||||
updateStackStored();
|
||||
updateTransfers();
|
||||
updateCharging();
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void updateStackStored() {
|
||||
try {
|
||||
if (isItemValidForSlot(0, this.stackStored)) {
|
||||
if ((this.stickValue < maxStickValueFromMeta[this.blockMetadata]) &&
|
||||
(CoalStickAndTorchesRegister.isStick(this.stackStored.getItem()))) {
|
||||
int singleValue = CoalStickAndTorchesRegister.getStickValue(this.stackStored.getItem());
|
||||
if (singleValue * this.stackStored.stackSize + this.stickValue <= maxStickValueFromMeta[this.blockMetadata]) {
|
||||
this.stickValue += singleValue * this.stackStored.stackSize;
|
||||
this.stackStored = null;
|
||||
} else {
|
||||
for (int i = 0;
|
||||
this.stickValue + singleValue <= maxStickValueFromMeta[this.blockMetadata]; i++)
|
||||
this.stickValue += singleValue;
|
||||
this.stackStored.stackSize -= i;
|
||||
if (this.stackStored.stackSize <= 0) {
|
||||
this.stackStored = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((this.coalValue < maxCoalValueFromMeta[this.blockMetadata]) &&
|
||||
(CoalStickAndTorchesRegister.isCoal(this.stackStored.getItem()))) {
|
||||
int singleValue = CoalStickAndTorchesRegister.getCoalValue(this.stackStored.getItem());
|
||||
if (singleValue * this.stackStored.stackSize + this.coalValue <= maxCoalValueFromMeta[this.blockMetadata]) {
|
||||
this.coalValue += singleValue * this.stackStored.stackSize;
|
||||
this.stackStored = null;
|
||||
} else {
|
||||
for (int i = 0;
|
||||
this.coalValue + singleValue <= maxCoalValueFromMeta[this.blockMetadata]; i++)
|
||||
this.coalValue += singleValue;
|
||||
this.stackStored.stackSize -= i;
|
||||
if (this.stackStored.stackSize <= 0)
|
||||
this.stackStored = null;
|
||||
}
|
||||
}
|
||||
if ((this.torchValue < maxTorchValueFromMeta[this.blockMetadata]) &&
|
||||
(CoalStickAndTorchesRegister.isTorch(this.stackStored.getItem()))) {
|
||||
int singleValue = CoalStickAndTorchesRegister.getTorchValue(this.stackStored.getItem());
|
||||
if (singleValue * this.stackStored.stackSize + this.torchValue <= maxTorchValueFromMeta[this.blockMetadata]) {
|
||||
this.torchValue += singleValue * this.stackStored.stackSize;
|
||||
this.stackStored = null;
|
||||
} else {
|
||||
for (int i = 0;
|
||||
this.torchValue + singleValue <= maxTorchValueFromMeta[this.blockMetadata]; i++)
|
||||
this.torchValue += singleValue;
|
||||
this.stackStored.stackSize -= i;
|
||||
if (this.stackStored.stackSize <= 0)
|
||||
this.stackStored = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
System.err.println("NullPointer");
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTransfers() {
|
||||
if (this.torchValue < maxTorchValueFromMeta[this.blockMetadata]) {
|
||||
int torchNedded = maxTorchValueFromMeta[this.blockMetadata] - this.torchValue;
|
||||
if (torchNedded <= Math.min(this.coalValue, this.stickValue)) {
|
||||
this.torchValue = maxTorchValueFromMeta[this.blockMetadata];
|
||||
this.coalValue -= torchNedded;
|
||||
this.stickValue -= torchNedded;
|
||||
} else {
|
||||
int torchRecharged = Math.min(this.coalValue, this.stickValue);
|
||||
this.coalValue -= torchRecharged;
|
||||
this.stickValue -= torchRecharged;
|
||||
this.torchValue += torchRecharged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCharging() {
|
||||
if (isItemValidForSlot(1, this.stackCharging)) {
|
||||
ITorchRechargable torchRechargable = (ITorchRechargable)this.stackCharging.getItem();
|
||||
int nedded = torchRechargable.getLuxNedded(this.stackCharging);
|
||||
if (this.torchValue <= nedded) {
|
||||
torchRechargable.recharge(this.stackCharging, this.torchValue);
|
||||
this.torchValue = 0;
|
||||
} else {
|
||||
this.torchValue -= nedded;
|
||||
torchRechargable.recharge(this.stackCharging, nedded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
switch (slot) {
|
||||
case 0:
|
||||
return this.stackStored;
|
||||
case 1:
|
||||
return this.stackCharging;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
switch (slot) {
|
||||
case 0:
|
||||
if (this.stackStored == null)
|
||||
return null;
|
||||
ItemStack stack; if (amount >= this.stackStored.stackSize) {
|
||||
ItemStack stack = this.stackStored;
|
||||
this.stackStored = null;
|
||||
markDirty();
|
||||
} else {
|
||||
stack = this.stackStored.splitStack(amount);
|
||||
if (this.stackStored.stackSize <= 0)
|
||||
this.stackStored = null;
|
||||
markDirty();
|
||||
}
|
||||
return stack;
|
||||
case 1:
|
||||
if (this.stackCharging == null)
|
||||
return null;
|
||||
ItemStack stack; if (amount >= this.stackCharging.stackSize) {
|
||||
ItemStack stack = this.stackCharging;
|
||||
this.stackCharging = null;
|
||||
markDirty();
|
||||
} else {
|
||||
stack = this.stackCharging.splitStack(amount);
|
||||
if (this.stackCharging.stackSize <= 0)
|
||||
this.stackCharging = null;
|
||||
markDirty();
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
switch (slot) {
|
||||
case 0:
|
||||
ItemStack stack = this.stackStored;
|
||||
this.stackStored = null;
|
||||
return stack;
|
||||
case 1:
|
||||
ItemStack stack = this.stackCharging;
|
||||
this.stackCharging = null;
|
||||
return stack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
switch (slot) {
|
||||
case 0:
|
||||
this.stackStored = stack;
|
||||
return;
|
||||
case 1:
|
||||
this.stackCharging = stack;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public String getInventoryName()
|
||||
{
|
||||
return "tile.torch_recharger";
|
||||
}
|
||||
|
||||
public boolean isCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void openChest() {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void closeChest() {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
return false;
|
||||
switch (slot) {
|
||||
case 0:
|
||||
return CoalStickAndTorchesRegister.isRegistered(stack.getItem());
|
||||
|
||||
case 1:
|
||||
return stack.getItem() instanceof ITorchRechargable;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public int getTorchValue()
|
||||
{
|
||||
return this.torchValue;
|
||||
}
|
||||
|
||||
public int getStickValue() {
|
||||
return this.stickValue;
|
||||
}
|
||||
|
||||
public int getCoalValue() {
|
||||
return this.coalValue;
|
||||
}
|
||||
|
||||
public int getMaxTorchValue() {
|
||||
if (this.blockMetadata == -1) {
|
||||
this.blockMetadata = 0;
|
||||
}
|
||||
return maxTorchValueFromMeta[this.blockMetadata];
|
||||
}
|
||||
|
||||
public int getMaxStickValue() {
|
||||
if (this.blockMetadata == -1) {
|
||||
this.blockMetadata = 0;
|
||||
}
|
||||
return maxStickValueFromMeta[this.blockMetadata];
|
||||
}
|
||||
|
||||
public int getMaxCoalValue() {
|
||||
if (this.blockMetadata == -1) {
|
||||
this.blockMetadata = 0;
|
||||
}
|
||||
return maxCoalValueFromMeta[this.blockMetadata];
|
||||
}
|
||||
|
||||
public ItemStack getStackStored() {
|
||||
return this.stackStored;
|
||||
}
|
||||
|
||||
public ItemStack getStackCharging() {
|
||||
return this.stackCharging;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return this.torchValue + ";" + this.stickValue + ";" + this.coalValue + "p=" + this.xCoord + ";" + this.yCoord + ";" + this.zCoord;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user